top of page

Cross Browser Testing in Cucumber BDD Framework

Thinking to implement cross browser testing in cucumber project? This blog might help you get started!!

I am writing this blog to capture how we implemented cross browser testing in Cucumber BDD project using TestNG with Selenium WebDriver.

Note : All steps are related to the framework we have created for project it may vary in terms of the methods and java class mentioned throughout. But still Hope this will help.

What is Cross Browser Testing?

Cross browser testing is an approach through which you can test your website (or web application) on different browsers (IE, Chrome, Firefox etc) browser versions, and operating systems. It is essential for ensuring that the product experience is uniform across browsers and platforms (or operating systems).

Why Cross Browser Testing is important?

Manually testing a website across multiple browsers is tedious task. Let's take an example where you have to execute 20 test cases manually. Now if you are expected to run same tests on five different browsers you have to execute 100 test cases in total. The time taken becomes longer. However, if these tests are automated using Selenium, Where you just have start execution it will be more convenient.

Also Cross browser compatibility testing helps web developers with pinpointing browser-specific compatibility errors so they can be debugged quickly.

Cross Browser Testing in Cucumber with TestNG

TestNG is a testing framework, Let's look advantages of using TestNG,

  1. TestNG with Maven supports parallel execution ( )

  2. Supports advance annotations like @Parameters/@DataProvider/@BeforeTest/@AfterTest/@BeforeSuite/@AfterSuite etc.

  3. Annotations add flexibility to your project so that you can use your project in the way you want.

Pre-requisite :

You should have basic framework for BDD approach with Cucumber and all related dependency added to your POM file. Example POM file with required dependency

<!-- -->






<!-- -->







<!-- -->






<!-- -->






<!-- -->






We followed below steps to setup cross browser testing in our project:
  1. Specify the browser values in the TestNG XML file.

  2. Create a method to set and get Browser value.

  3. Initialize a parameter with the name browser in Test Runner file.

  4. Initialize the browser driver depending on the parameter value that can be access by getBrowserType method, For a browser value equal to Chrome, initialize a chrome driver, and so on.

  5. Call getBrowserType() method when initializing driver.

Step 1: Specify the parameter browser values in the TestNG XML file.

​<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE suite SYSTEM "">

<suite name="Suite">

<test thread-count="3" name="TestChrome">

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


<class name="runner.TestRunner"></class>


</test> <!-- Test -->

<test thread-count="3" name="Testfirefox">

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


<class name="runner.TestRunner"></class>


</test> <!-- Test -->

<test thread-count="3" name="Testedge">

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


<class name="runner.TestRunner"></class>


</test> <!-- Test -->

</suite> <!-- Suite -->

Step 2: Create a method setBrowserType and getBrowserType

Here, In our project we are getting all the configuration using utility that we have created "" so we created setBrowserType and getBrowserType methods in same utility file.

​public class ConfigReader {

private static String browserType = null;

public static void setBrowserType(String browser) {

browserType = browser;


public static String getBrowserType() throws Throwable {

if (browserType != null)

return browserType;


throw new RuntimeException("browser not specified in the testng.xml");


Step 3: Initialize a parameter with the name browser in Test Runner file.

You should have cucumber runner extending the AbstractCucumberTestNG class,

public class TestRunner extends AbstractTestNGCucumberTests {

@DataProvider(parallel = false)

public Object[][] scenarios() {

return super.scenarios();



@Parameters({ "browser" })

public void defineBrowser(String browser) throws Throwable {




@BeforeTest annotation is used. This will ensure that browser value is set and web-driver is initialized for the same before the test is started

@Parameters annotation is used. This ensures that any parameter that is passed to test in testng.xml is automatically captured. ( )

So now our Runner is ready.

Step 4: Initialize the browser driver depending on the parameter value that can be access by getBrowserType method

Let’s jump to Selenium web-driver initialization, we have created DriverFactory class java file that includes WebDriver initialization method,

public WebDriver initializeDrivers(String browser) {

if (browser.equalsIgnoreCase("firefox")) {"Testing on firefox");


driver = new FirefoxDriver();

} else if (browser.equalsIgnoreCase("chrome")) {"Testing on chrome");


driver = new ChromeDriver();

} else if (browser.equalsIgnoreCase("safari")) {"Testing on safari");


driver = new SafariDriver();

} else if (browser.equalsIgnoreCase("edge")) {"Testing on Edge");


driver = new EdgeDriver();


// Set Page load timeout



return driver;


Step 5: Call getBrowserType() method when initializing driver

In our project we have used Hooks class java file to initialize the driver by calling method from DriverFactory class


public static void before() throws Throwable {

//Get browser Type from config file"Loading Config file");


String browser = ConfigReader.getBrowserType();

//Initialize driver from driver factory

driverfactory = new DriverFactory();

driver = driverfactory.initializeDrivers(browser);"Initializing driver for : "+browser);


Now all setup is done and we are ready to run project, play to see the output

Allure Report looks like :

Thank you !! Keep Learning !!

Please provide your valuable comments !!


3,472 views6 comments

Recent Posts

See All


Rated 0 out of 5 stars.
No ratings yet

Add a rating

@dhvanikapatel Can you please share how you have integrated the above mentioned allure report for cross browser testing.

Replying to

Hi Bishal, As I am using Cucumber framework with TestNG followed below steps,

  1. Added dependency for Allure in POM.xml file(

  2. Added Plugin in TestRunner file ( )

  3. Updated testng.xml file as mentioned in blog.

  4. Run Project it will create "allure-results" folder.

  5. Generate report from command line "allure serve <Path to allure-results folder>"

Visit for more information.



Aug 10, 2023

Do we need to remove the Cucumber Options in runner file (which has feature file, Glue, pretty), I tried the same way, Im getting error that cucumber options are blocking to execute in parallel using testng xml.

Aug 15, 2023
Replying to

Hi, No need to remove Cucumber Options in runner file. Can you send exact error? Just FYI this configuration will launch browsers sequentially as shown in output video not in parallel mode.


Jun 08, 2023
Rated 5 out of 5 stars.

Covered everything, thanks


May 26, 2023
Rated 5 out of 5 stars.

Nice detailed information.

bottom of page