gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 22:35:56 24 4
gpt4 key购买 nike

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

例如:

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 { }

应该可以使用场景 Hook 启动浏览器,场景 Hook 还可以指定它们应用到哪些标签:

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

关于java - 如何在 Cucumber for Java 中执行标记驱动的跨浏览器测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26868832/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com