When covering cross-browser testing using Selenium WebDriver, how do you provide the browser and version information to the tool (e.g. BrowserStack, Sauce Labs)? For example, you're wanting to execute your tests against multiple versions of Chrome, Edge etc.

I have been experimenting with reading a CSV file of browser data and using that to set Selenium capabilities before iterating through that CSV file in the code. Now, I am wondering if there's a better way, generally, as I suspect this method will affect parallel execution.

2 Answers 2


How to do it

1)Create your Script to test a LogIn application using the TestNG class.

2) Pass ‘Browser Type’ as parameters using TestNG annotations to the before method of the TestNG class. This method will launch only the browser, which will be provided as a parameter. package automationFramework;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.ie.InternetExplorerDriver;

import org.testng.annotations.AfterClass;

import org.testng.annotations.BeforeClass;

import org.testng.annotations.Parameters;

import org.testng.annotations.Test;

public class MultiBrowser {

 public WebDriver driver;



  // Passing Browser parameter from TestNG xml

  public void before the test(String browser) {

  // If the browser is Firefox, then do this

  if(browser.equalsIgnoreCase("firefox")) {

   driver = new FirefoxDriver();

  // If the browser is IE, then do this   

  }else if (browser.equalsIgnoreCase("ie")) { 

   // Here I am setting up the path for my iedriver

   System.setProperty("webdriver.ie.driver", "D:\ToolsQA\OnlineStore\drivers\IEDriverServer.exe");

   driver = new InternetExplorerDriver();


  // Doesn't the browser type, launch the Website



  // Once Before a method is completed, the Test method will start

  @Test public void login() throws InterruptedException {






  @AfterClass public void afterTest() {




3) Create a TestNG XML for running your test. Configure the TestNG XML for passing parameters i.e. to tell which browser should be used for Running the Test.

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="Suite" parallel="none">

 <test name="FirefoxTest">

 <parameter name="browser" value="firefox" />


 <class name="automationFramework.MultiBrowser" />



 <test name="IETest">

 <parameter name="browser" value="ie" />


 <class name="automationFramework.MultiBrowser" />




Note: You can set any number of Browsers here and just for the example purpose I have set up only two main browsers.

4) Now it’s time to run the XML. Run the test by right click on the testng.xml file and select Run As > TestNG Suite.

Note: TestNg will execute the test one by one. You may like to perform parallel tests, the next topic will cover that.


In case you are using NUnit, you can specify the details directly in the NUnit App.config file. You can view the details in the link: https://github.com/browserstack/nunit-browserstack/blob/master/NUnit-BrowserStack/App.config

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.