Cross Browser Testing : Is to check that your web application works as expected in different browsers.If we are using Selenium WebDriver, we can automate test cases using Internet Explorer, FireFox, Chrome, Safari browsers.To execute test cases with different browsers in the same machine at same time we can integrate TestNG with Selenium WebDriver.
Lets create a class Testng_BC.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.Reporter;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class Testng_BC
{
public WebDriver fd;
@Test
@Parameters({“browser”})
public void browserTest(String str) throws Exception
{
if(str.matches(“firefox”))
{
fd=new FirefoxDriver();
fd.get(“https://seleniumbycharan.wordpress.com”);
fd.close();
}
if(str.matches(“ie”))
{
//Following code is to set the ie driver with webdriver property.You need IE Driver //server. download from here.
System.setProperty(“webdriver.ie.driver”,”F:\\Selenium_project\\IEDriverServer.exe”);
fd=new InternetExplorerDriver();
fd.get(“https://seleniumbycharan.wordpress.com”);
fd.close();
}
else {
Reporter.log(“test failed”);
}
}
}
Now create testng.xml file and paste the below code
<suite name=”Suite“>