如何在Cucumber for Java中执行标记驱动的跨浏览器测试?

时间:2014-11-11 15:50:43

标签: java cucumber bdd cucumber-jvm

我希望通过使用所需的浏览器标记它来在多个浏览器中运行场景。

例如:

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

我目前能够一次在一个浏览器上运行测试:

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

如何实施?或者,如果不能,为什么?

1 个答案:

答案 0 :(得分:2)

如果使用JUnit运行场景,可以使用@CucumberOptions指定要执行的标记,并为这两个标记使用单独的测试类:

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

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

应该可以使用场景挂钩启动浏览器,它还可以指定它们适用的标签:

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