Cross Browser Testing on Selenium (IE,FF,Chrome) - InternetExplorerDriver,ChromeDriver,FirefoxDriver

Compatibility Table for Selenium Jar Versions 2.44.0 & 2.45.0 and Browser Versions!!!






We have to set the System properties to execute the Selenium Web-Driver Script on Internet Browser (IE)


Pre-requisite for IE Browser->
1.  Download the zip file as mentioned in the above table.
Example: 
Suppose if am using selenium-java.2.45.0.zip in your project. Please  download the IE Driver from the link as http://selenium-release.storage.googleapis.com/2.45/IEDriverServer_x64_2.45.0.zip
2. Unzip the file. It contains the following files.









3. Right click on the IEDriverServer.exe file and  get the path of the IEDriverServer.exe. Make a note of it and update the location in the below program.




























Path to the File  IEDriverServer.exe -> 
D:\\Selenium\\Selenium Jars\\IEDriverServer_x64_2.45.0\\IEDriverServer.exe

System.setProperty("webdriver.ie.driver","D:\\Selenium\\Selenium Jars\\IEDriverServer_x64_2.45.0\\IEDriverServer.exe");

Program -> IEDriver.java
package Browsers;

import java.io.File;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;


public class IEDriver {


public static void main(String args[]) 
{
 //Setting the System Property
System.setProperty("webdriver.ie.driver","Path to the File  IEDriverServer.exe");  
WebDriver driver = new InternetExplorerDriver();
driver.get("http://dl.dropbox.com/u/55228056/bmicalculator.html");//Invocation
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(1,TimeUnit.MINUTES);
WebElement height = driver.findElement(By.id("heightCMS"));
height.sendKeys("181");
}

}

Issues faced during the execution of Selenium WebDriver Script against the Internet Explorer Driver:
Issue 1: Zoom should be set to 100%
Exception:
Started InternetExplorerDriver server (64-bit)
2.25.2.0
Listening on port 14060
Exception in thread "main" org.openqa.selenium.WebDriverException: Unexpected error launching Internet Explorer. Browser zoom level was set to 0%. It should be set to 100% (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 1.70 seconds
Solution:
zoom percentage for IE should be set to 100%.  To verify Goto ->View->Zoom (100%)
Issue 2: protected-mode should be set to same level for all the zones.
Exception:
org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode must be set to the same value (enabled or disabled) for all zones. (WARNING: The server did not provide any stacktrace information)

Command duration or timeout: 1.39 seconds
Build info: version: '2.34.0', revision: '11cd0ef', time: '2013-08-06 17:11:28'
System info: os.name: 'Windows 8', os.arch: 'amd64', os.version: '6.2', java.version: '1.7.0_09'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver

Solution:
This error is because of the security settings in IE.
>> Open IE , then go to Tools>>Security tab .
>>Now either check or uncheck the "Enable Protected Mode" checkbox for all zones i.e Internet , Local internet, Trusted Sites, Restricted Sites.

Executing the Selenium Web-Driver Script on Chrome Browser:
Pre-requisite for Chrome Browser->
1.  Download the zip file as mentioned in the above table.
Example: 
Suppose if am using selenium-java.2.45.0.zip in your project. Please download the Chrome Driver from the link as http://chromedriver.storage.googleapis.com/index.html?path=2.14/
2. Unzip the file. It contains the following files.












3. Get the path of the ChromeDriver.exe. Make a note of it and update the location in the below program.






























Path to the File  IEDriverServer.exe -> 
D:\Selenium\Selenium Jars\chromedriver_win32\\chromedriver.exe

System.setProperty("webdriver.ie.driver","D:\\Selenium\\Selenium Jars\\chromedriver_win32\\chromedriver.exe");

Program->ChromeDriverEx .java
package Browsers;

import java.io.File;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class ChromeDriverEx {


public static void main(String args[])
{
     //Setting the System Property
    System.setProperty("webdriver.chrome.driver","Path to the File  ChromeDriverServer.exe");  
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://dl.dropbox.com/u/55228056/bmicalculator.html");
driver.manage().timeouts().implicitlyWait(1,TimeUnit.MINUTES);
WebElement height = driver.findElement(By.id("heightCMS"));
height.sendKeys("181");
}


}



Maven - Build Tool - Invocation of JUNIT & TESTNG from POM (Project Object Model)






Maven is a build automation tool. From Selenium perspective we should be mainly understanding the following sections of the POM (Project Object Model)

1. DEPENDENCIES : 
           Selenium Web-driver mainly depends on  jar for compilation and execution of program. Also if we implement Java Framework - TESTNG / JUNIT, we need add the dependencies for TESTNG / JUNIT as well. Also dependencies gives you the information, that what is the version of the jar we are using for compiling and executing the program.
Also, all the required jars are downloaded into the folder c:\\users\.m2 folder.
.m2 folder is repository folder created by maven, used for referring to the jars required for compilation and execution of program.

SELENIUM DEPENDENCIES:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.45.0</version>
</dependency>
REFERENCE:
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.8</version>
</dependency>
REFERENCE:
http://mvnrepository.com/artifact/org.testng/testng/6.8.8

JUNIT DEPENDENCIES:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
</dependency>
REFERENCE:
http://mvnrepository.com/artifact/junit/junit/4.4       
         
2. PLUGINS

Plugins helps to execute the JUNIT/TESTNG programs to execute.
Also in case of JUNIT we have to include Suite class. And in the case of TESTNG we have to include the testng.xml file.

JUNIT PLUGIN INFORMATION
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.18.1</version>
    <dependencies>
      <dependency>
        <groupId>org.apache.maven.surefire</groupId>
        <artifactId>surefire-junit47</artifactId>
        <version>2.18.1</version>
      </dependency>
    </dependencies>
    <configuration>
<includes>
            <include>JunitTestSuite.java</include>
          </includes>
    </configuration>
</plugin>
REFERENCES
http://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html

TESTNG PLUGIN INFORMATION:
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.18.1</version>
    <dependencies>
      <dependency>
        <groupId>org.apache.maven.surefire</groupId>
        <artifactId>surefire-junit47</artifactId>
        <version>2.18.1</version>
      </dependency>
    </dependencies>
    <configuration>
<includes>
            <include>testng.xml</include>
          </includes>
    </configuration>

</plugin>
REFERENCES:
http://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html

Implementation of Page Object Model - Java Design Pattern:

Page Object Model is the most popular Design pattern used by the developers as a best practice to develop the project.  Before get into the Page Object Model lets discuss the steps to follow once joined as a Automation Tester in the Company.
Steps to Follow:
1. Acquire Domain knowledge for the project.
2. Understand the (SRS) Software Requirement Specification. 
3. Understanding Manual Test cases Ex: Sanity or Regression Test cases     
4. Executing manual Test cases     
5. Identify the Actions perform in each and every page.  
Example: Consider the website Wikipedia. In the main page user can do the search by providing the input and Select the Language and click on Go button as shown below:








void enterText(String inputData)- To enter the text the Search Text-box Ex: India
void selectLanguage(String lang)- To Select a language Ex: English
void clickOnNext()-> To click on the Go Button
boolean verifyText(String expected)->To verify the Text
SearchResultsPage search(String inputData,String lang)-> Clicking on the Go button, navigates to the Search Result Page. So, this function returns an next page object.
Usually the Methods return the Other Page Objects.
6. Write down the methods in every Page.java. 
7. Identify common functions related to Framework.  
getDriverInstance(String browserType)
launchApp(String url)
closeBrowser()
readExcel(String FileName)     
8. Write testcases using Testng Java Framework and invoke the Page related methods in testcases as shown the below program:
Testng Program: WikiTests.java
package com.wiki.tests;
import org.junit.Assert;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import com.wiki.lib.AppLibrary;
import com.wiki.pages.HomePage;
import com.wiki.pages.SearchResultsPage;

public class WikiTests {

AppLibrary appLib;
static WebDriver driver;
HomePage hPage;
SearchResultsPage sPage;

@Parameters({"browserType","url"})
@BeforeClass
public void invokeBrowser(String browserType,String url)
{
appLib = new AppLibrary();
driver =appLib.getDriverInstance(browserType);
appLib.launchApp(url);

}
@Parameters({"searchInput","lang"})
@Test
public void verifySearchResults(String searchInput,String lang)
{
hPage = new HomePage(driver);
sPage = hPage.search(searchInput,lang);
boolean result = sPage.verifyText(searchInput);
Assert.assertTrue(result);
}
}
HomePage.java
package com.wiki.pages;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.Select;
public class HomePage {
WebDriver driver;
public HomePage(WebDriver driver) 
{
this.driver= driver;
}
public void enterText(String inputData)
{
                    driver.findElement(By.id("searchInput")).sendKeys(inputData);
}
public void selectLanguage(String lang)
{
Select select = new Select(driver.findElement(By.id("searchLanguage")));
select.selectByVisibleText(lang);
}
public void clickOnNext()
{
driver.findElement(By.name("go")).click();
}
 
public boolean verifyText(String expected)
{
String actual = driver.findElement(By.xpath("//a[@href='//www.wikidata.org/']/text()")).getText();
boolean b=false;
if(actual.equals(expected))
{
b= true;
}
return b;

}
public SearchResultsPage search(String inputData,String lang)
{
enterText(inputData);  
selectLanguage(lang) ;  
clickOnNext();  

SearchResultsPage s1 =new SearchResultsPage(driver);
return s1;
}



}

References:
 https://code.google.com/p/selenium/wiki/PageObjects

 Advantages of Page Object Model: 
1. Maintenance of Code is easily  done.   
2. Duplication of Code is removed   
3. Save Time & Effort