How do I perform tag driven cross-browser testing in Cucumber for Java?

3.4k Views Asked by At

I want to run a scenario in multiple browsers by tagging it with the desired browser(s).

For example:

Feature: Smoke Test
    @Chrome @Firefox
    Scenario: the site should launch in all browsers
        Given the site is online
        When I navigate to site
        Then the site should display in all browsers

I am currently able to run tests on one browser at a time with:

Feature: Smoke Test
    @Chrome
    Scenario: the site should launch in all browsers
        Given the site is online
        When I navigate to site
        Then the site should display in all browsers

    @Firefox
    Scenario: the site should launch in all browsers
        Given the site is online
        When I navigate to site
        Then the site should display in all browsers

How can this be implemented? Or, if it cannot, why?

1

There are 1 best solutions below

1
On BEST ANSWER

If you use JUnit to run your scenarios you can use @CucumberOptions to specify which tags to execute, and use separate test classes for the two tags:

@RunWith(Cucumber.class)
@CucumberOptions(tags = "@Chrome")
public class ChromeTest { }

@RunWith(Cucumber.class)
@CucumberOptions(tags = "@Firefox")
public class FirefoxTest { }

Launching of the browser should be possible with scenario hooks, which can also specify to which tags they apply:

@Before("@Chrome")
public void launchChrome() {
}