My Thoughts: June 2012

Tuesday, June 19

Handling "drag and drop" actions using WebDriver(Selenium 2)


Automating rich web application is even more interesting since it involves advanced user interactions.

Say we have a web application which drag an item from one location and then drop it at another location.These kind of drag and drops are cant be automated with one single statement .In WebDriver we have a separatae "Actions" class to handle advanced user interactions(say drag and drop) on web page.

Here is the documentation on how to automate advanced user interactions :
http://code.google.com/p/selenium/wiki/AdvancedUserInteractions

Here is the sample code using TestNG framework
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class draganddrop {
 
 WebDriver driver;
 
 @BeforeTest
 public void start(){
  FirefoxProfile profile = new FirefoxProfile();
  profile.setEnableNativeEvents(true);
  driver = new FirefoxDriver(profile);
 }

 @Test
 public void start1(){
  driver.get("http://jqueryui.com/droppable/");
  driver.switchTo().frame(0);  
  driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
  WebElement dragElement=driver.findElement(By.id("draggable"));
  WebElement dropElement=driver.findElement(By.id("droppable"));
    
  Actions builder = new Actions(driver);  // Configure the Action
  Action dragAndDrop = builder.clickAndHold(dragElement)
    .moveToElement(dropElement)
    .release(dropElement)
    .build();  // Get the action
    dragAndDrop.perform(); // Execute the Action
 }
}

Monday, June 11

Apple Store is down

Hey guys did you visit "Apple Store" today ? Right now it is down.

They are updating Apple Store for us .Let us hope to see some good stuff .. :)




Sunday, June 10

List of supported Google country specific(regional) domain list

When we type google world wide domain address (www.google.com) in the browser address bar then we will automatically get redirected to country specific domain. Do you have any idea how many supported regional domains google has ?
Well, If you don't know then here is the list of Google country specific domains list :
www.google.com
www.google.ad 
www.google.ae
www.google.com.af
www.google.com.ag
www.google.com.ai
www.google.am
www.google.co.ao
www.google.com.ar
www.google.as
www.google.at
www.google.com.au
www.google.az
www.google.ba
www.google.com.bd
www.google.be
www.google.bf
www.google.bg
www.google.com.bh
www.google.bi
www.google.bj
www.google.com.bn
www.google.com.bo
www.google.com.br
www.google.bs
www.google.co.bw
www.google.by
www.google.com.bz
www.google.ca
www.google.cd
www.google.cf
www.google.cg
www.google.ch
www.google.ci
www.google.co.ck
www.google.cl
www.google.cm
www.google.cn
www.google.co.cr
www.google.com.cu
www.google.cv
www.google.com.cy
www.google.cz
www.google.de
www.google.dj
www.google.dk
www.google.dm
www.google.com.do
www.google.dz
www.google.com.ec
www.google.ee
www.google.com.eg
www.google.es
www.google.com.et
www.google.fi
www.google.com.fj
www.google.fm
www.google.fr
www.google.ga
www.google.ge
www.google.gg
www.google.com.gh
www.google.com.gi
www.google.gl
www.google.gm
www.google.gp
www.google.gr
www.google.com.gt
www.google.gy
www.google.com.hk
www.google.hn
www.google.hr
www.google.ht
www.google.hu
www.google.co.id
www.google.ie
www.google.co.il
www.google.im
www.google.co.in
www.google.iq
www.google.is
www.google.it
www.google.je
www.google.com.jm
www.google.jo
www.google.co.jp
www.google.co.ke
www.google.com.kh
www.google.ki
www.google.kg
www.google.co.kr
www.google.com.kw
www.google.kz
www.google.la
www.google.com.lb
www.google.li
www.google.lk
www.google.co.ls
www.google.lt
www.google.lu
www.google.lv
www.google.com.ly
www.google.co.ma
www.google.md
www.google.me
www.google.mg
www.google.mk
www.google.ml
www.google.mn
www.google.ms
www.google.com.mt
www.google.mu
www.google.mv
www.google.mw
www.google.com.mx
www.google.com.my
www.google.co.mz
www.google.com.na
www.google.com.nf
www.google.com.ng
www.google.com.ni
www.google.ne
www.google.nl
www.google.no
www.google.com.np
www.google.nr
www.google.nu
www.google.co.nz
www.google.com.om
www.google.com.pa
www.google.com.pe
www.google.com.ph
www.google.com.pk
www.google.pl
www.google.pn
www.google.com.pr
www.google.ps
www.google.pt
www.google.com.py
www.google.com.qa
www.google.ro
www.google.rw
www.google.com.sa
www.google.com.sb
www.google.sc
www.google.se
www.google.com.sg
www.google.sh
www.google.si
www.google.sk
www.google.com.sl
www.google.sn
www.google.so
www.google.sm
www.google.st
www.google.com.sv
www.google.td
www.google.tg
www.google.co.th
www.google.com.tj
www.google.tk
www.google.tl
www.google.tm
www.google.tn
www.google.to
www.google.com.tr
www.google.tt
www.google.com.tw
www.google.co.tz
www.google.com.ua
www.google.co.ug
www.google.co.uk
www.google.com.uy
www.google.co.uz
www.google.com.vc
www.google.co.ve
www.google.vg
www.google.co.vi
www.google.com.vn
www.google.vu
www.google.ws
www.google.rs
www.google.co.za
www.google.co.zm
www.google.co.zw
www.google.cat
Reference :
1.http://www.google.com/supported_domains
2.http://en.wikipedia.org/wiki/List_of_Google_domains

Sunday, June 3

Checking the Web Page load time using WebDriver

Most of the time we would like to check the performance of site like the page load time. But in WebDriver we don't have any direct method to do this. So here is the sample code to achieve this using TestNG framework:
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class CheckPageLoadTime{
 
 WebDriver driver;
 
 @BeforeTest
 public void start(){ 
  driver = new FirefoxDriver();
 }
 
 @Test
 public void LoadTime(){
  
 long startTime = System.currentTimeMillis()/1000;
 System.out.println("The startTime is "+startTime);
 //Set the acceptable Page load time to 60 sec
 driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS); 
 driver.get("http://google.com/");  
 WebElement search = driver.findElement(By.name("q"));
 //Iterate through the loop as long as time(60sec) is with in the acceptable Page load time
 while(((System.currentTimeMillis()/1000)-startTime)<60){
         if(search.isDisplayed()){
  long endTime = System.currentTimeMillis()/1000;
  System.out.println("The endTime is "+endTime);
  long loadTime = endTime - startTime;
  System.out.println("Totaltime: " +loadTime + " seconds"); 
      break;
  }  
   }     
     }
    
}
Here is the output of above program(It may vary for you)
The startTime is 1338712185
The endTime is 1338712215
Totaltime: 30 seconds