Thursday, 4 September 2014

Cross browser Testing in Selenium WebDriver

How can we test an application in multiple browsers by using selenium webdriver:

Steps:

     1.We have to know the .exe file of the browser where it is installed in the PC.

     2.We have to take the path of .exe file of required browser.

     3.We have to create an xml to name the browser as the <parameter> attributes name.

     4.We have to use the @Parameter to pass the input through xml.

Some piece of code is required to automate the browser.

package TestNG;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class CrossBrowser {

@Test
    @Parameters("browserType")  // use @Parameters to pass the input through xml
    public void dummyTest(String browserType){
        WebDriver driver;
        if(browserType.equals("FF")){
            driver= new FirefoxDriver();
            driver.quit();
        }else if(browserType.equals("Chrome")){
            System.setProperty("webdriver.chrome.driver", "D:\\selenium        jars\\chrome\\chromedriver.exe");
            driver = new ChromeDriver();
            driver.quit();
        }
 }
}

build.xml:

<?xml version="1.0" encoding="UTF-8"?>

<suite name=”Suite1″ verbose=”1″ parallel=”tests”>

<test name=”Generic FirstApplication” >
<parameter name=”browser” value=”Firefox”></parameter>

<classes>
<class name=”TestNG” />
</classes>
</test>

<test name=”Generic FirstApplication_chrome” >
<parameter name=”browser” value=”Chrome”></parameter>
<classes>
<class name=”TestNG” />
</classes>
</test>
<!–suite>–>



To know FAQ's on Selenium Please ClickHere
To know SQL's Queries Required For Testers Please ClickHere

No comments:

Post a Comment