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

如何在Cucumber for Java中执行标记驱动的跨浏览器测试?,java,cucumber,bdd,cucumber-jvm,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 @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

如何实现这一点?或者,如果不能,为什么?

如果使用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() {
}

如果使用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() {
}

如果使用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() {
}

如果使用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() {
}

事实证明,这并没有产生我想要的确切结果。然而,它确实回答了我的问题,并大大提高了我对Cumber工作原理的理解。谢谢。事实证明,这并没有产生我想要的确切结果。然而,它确实回答了我的问题,并大大提高了我对Cumber工作原理的理解。谢谢。事实证明,这并没有产生我想要的确切结果。然而,它确实回答了我的问题,并大大提高了我对Cumber工作原理的理解。谢谢。事实证明,这并没有产生我想要的确切结果。然而,它确实回答了我的问题,并大大提高了我对Cumber工作原理的理解。非常感谢。