Hi Nutan, you can use TestNG to perform multi-browser testing, though you have to execute selenium web driver through testing.xml only. You first need to create a test script to test facebook login page:
public class TestCase1 {
// Here Browser parameter we will take from testng.xml
@Test
@Parameters("Browser")
public void test1(String browser) {
if(browser.equalsIgnoreCase("FF")){
System.setProperty("webdriver.gecko.driver", "./drivers/geckodriver.exe");
WebDriver driver=new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://www.facebook.com");
driver.quit();
}
else if(browser.equalsIgnoreCase("IE")){
System.setProperty("webdriver.ie.driver", "./drivers/iedriver.exe");
WebDriver driver=new InternetExplorerDriver();
driver.manage().window().maximize();
driver.get("http://www.facebook.com");
driver.quit();
}
else if(browser.equalsIgnoreCase("GC")){
System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe");
WebDriver driver=new InternetExplorerDriver();
driver.manage().window().maximize();
driver.get("http://www.facebook.com");
driver.quit();
}
}
}
Now, create a TestNG.xml file to pass the parameters:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<---Here parallel is an attribute which specify the mode of execution and thread-count specify how many browser should open--->
<suite name="Suite" parallel="tests" thread-count="2">
<test name="Test">
<parameter name="Browser" value="FF" />
<classes>
<class name="SampleTestcases.TestCase1"/>
</classes>
</test>
<test name="Test1">
<parameter name="Browser" value="IE" />
<classes>
<class name="SampleTestcases.TestCase1"/>
</classes>
</test>
<test name="Test2">
<parameter name="Browser" value="GC" />
<classes>
<class name="SampleTestcases.TestCase1"/>
</classes>
</test>
</suite>
And that's it, run the testng.xml file and it will run 3 test cases, testing all 3 browsers.