This post was most recently updated on July 30th, 2024
We can run selenium scripts parallely in multiple browsers using TestNg.xml configuration.
Below is the configuration we need to make in TestNg.xml to run in chrome and firefox browsers.
Below is the sample code. It opens mundrisoft.com website in chrome and firefox browser and performs some operation on it.
package AutoIt;
import java.io.IOException;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.server.handler.SendKeys;
class MultiBrowser{
WebDriver driver;
@Parameters(“browser”)
@Test
public void parellelExecution(String browser){
if(browser.equalsIgnoreCase(“chrome”)) {
System.setProperty(“webdriver.chrome.driver”, “.//drivers//chromedriver.exe”);
driver=new ChromeDriver();
}
else if (browser.equalsIgnoreCase(“firefox”)){
System.setProperty(“webdriver.gecko.driver”,”.//drivers//geckodriver.exe”);
driver =new FirefoxDriver();
}
driver.get(“http://mundrisoft.com”);
driver.manage().window().maximize();
driver.findElement(By.xpath(“//div[text()=’Capabilities’]”)).click();
driver.findElement(By.xpath(“//div[text()=’Case Studies’]”)).click();
}
}