Home > QA > Running selenium script parallel in multiple browsers using TestNg

Running selenium script parallel in multiple browsers using TestNg

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();
}
}

This Article is TAGGED in , , . BOOKMARK THE permalink.

Avatar photo
Amit Bharamasali
Automation Software Test Engineer. Skills: Manual Testing, Selenium, Java, Protractor, JavaScript, Katalon Studio, Groovy, Appium, Sahi, Sahi Script and UI/UX testing.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">