Showing posts with label Selenium 2. Show all posts
Showing posts with label Selenium 2. Show all posts

Monday, January 21, 2013

Cross Browser Testing using Selenium 2

Recently I was working in a POC for Cross Browser testing using Selenium 2. My objective is to automate the application in IE, Firefox, Chrome and Safari ( MAC). I will share basic code and observation in this post.
 Prerequisite: Web Driver 2.25.jar, Eclipse IDE, ChromeDriver.exe, IE Driver.exe, Safari Extension.


  • On IE 7 or higher on Windows Vista or Windows 7, you must set the Protected Mode settings for each zone to be the same value. The value can be on or off, as long as it is the same for every zone. To set the Protected Mode settings, choose "Internet Options..." from the Tools menu, and click on the Security tab. For each zone, there will be a check box at the bottom of the tab labeled "Enable Protected Mode".
  • The browser zoom level must be set to 100% so that the native mouse events can be set to the correct coordinates for IE driver.
  • As Safari web driver is not available, currently Safari Driver is implemented as a Safari browser extension. Refer below link to configure safari extension
http://rationaleemotions.wordpress.com/2012/05/25/working-with-safari-driver/


Code:
public class ResourceManager {
     private WebDriver driver;
     public static WebDriver globalSeleniumInstance;
                 
     @Parameters({ "browser"})
      public void beforeSuite(int browser) throws MalformedURLException
                 {
                System.out.println("browser is "+ browser);
                switch(browser)
                {
                case 1 :
                                System.out.println("Running FireFox");
               driver = new FirefoxDriver();
                                break;
                  
               case 2 :
                                 System.setProperty("webdriver.chrome.driver","C:\\Seleniumworkspace\\BasicTN8\\chromedriver.exe");
                                  System.out.println("Running Chrome");
                                driver = new ChromeDriver();
                                break;
                  
               case 3 :
                   System.setProperty("webdriver.ie.driver","C:\\Seleniumworkspace\\BasicTN8\\IEDriverServer.exe");
                                DesiredCapabilities dc = DesiredCapabilities.internetExplorer();
          dc.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); 
              driver = new InternetExplorerDriver(dc);
                                driver.manage().deleteAllCookies();
                                break;
               case 4:
                                System.out.println("Running Safari");
                                driver = new SafariDriver();
break;
               default :
                                driver = new FirefoxDriver();
                                break;
          
          
           }
      globalSeleniumInstance = driver;
  }

  @AfterSuite
  public void afterSuite() throws InterruptedException {
                                 System.out.println("after Suite");
                                 Thread.sleep(5000);
                                 driver.quit();
                                  }
 
 
}

Observation:  Chrome and Firefox driver worked very well.  I faced some issue with IE Driver. IEDriver is slow compare to Chrome and Firefox driver. Also some time we are getting out of focus issue with IE Driver.
As stated earlier, Safari driver is not fully functional, some operation like Drag & Drop are not yet supported. As an alternative we can use java script to perform those operations or can use Java.awt.robot class to simulate mouse movement or Drag & Drop operation in Safari Web driver.