我有两个带有两个不同标签的场景。如何根据标签调整所需的chrome功能?对于@mobile标签,我想运行以下代码:
DesiredCapabilities mobileCapabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("no-sandbox");
options.setExperimentalOption("mobileEmulation", getMobileEmualtor());
mobileCapabilities.setCapability(ChromeOptions.CAPABILITY, options);
@desktop
Scenario: Normal desktop test
Given Open landing page
Then I do normal test on desktop view
@mobile
Scenario: Test with a user of smaller browser view
Given Open landing page
Then I chekc elements for mobile responsive page
您可以在挂钩中使用标记表达式
https://github.com/cucumber/cucumber-jvm/tree/main/cucumber-java#before--之后
public class StepDefinitions {
private WebDriver driver;
@Before("@mobile")
public void before(Scenario scenario) {
driver = createWebDriverForMobile();
}
@Before("not @mobile")
public void before(Scenario scenario) {
driver = createWebDriverForDesktop();
}
@Given("Open landing page")
public void openLandingPage() {
driver.get(....);
}
}