gpt4 book ai didi

java - Cucumber:如果不能使用 Cucumber 继承,如何创建 BaseSteps 类?

转载 作者:行者123 更新时间:2023-12-02 02:52:14 24 4
gpt4 key购买 nike

Cucumber:如果不能使用 Cucumber 继承,如何创建 BaseSteps 类?

Login Steps 继承 CommonSteps 类:

    public class LoginSteps extends CommonSteps {

WebDriver driver = getDriver();

@Given("^User navigates to the \"([^\"]*)\" website$")
public void user_navigates_to_the_website(String url) throws Throwable {
basePage.loadUrl(url);
}

@And("^User entered the \"([^\"]*)\" username$")
public void user_entered_the_username(String username) throws Throwable {
loginPage.setUsername(username);
}






public class CommonSteps {
@After
public void close_browser_window(Scenario scenario) throws Exception {
if (scenario.isFailed()) {
scenario.embed(((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES), "image/png");
}
}
}

最佳答案

当您想要在不同类中实现的步骤之间共享状态时,Java 中惯用的解决方案(即 Cucumber-JVM)是​​使用依赖注入(inject)。

Cucumber 支持许多不同的依赖注入(inject)框架。如果您的项目已经使用了它,那么您的依赖框架很可能是受支持的。

如果你不使用依赖注入(inject)框架,我建议你使用PicoContainer 。如果你需要知道如何使用它,我写了一篇博文describing如何在步骤之间共享状态。

关于java - Cucumber:如果不能使用 Cucumber 继承,如何创建 BaseSteps 类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43638838/

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