在不同 java 文件中构建 Cucumber JVM 步骤定义

Structuring Cucumber JVM step definitions in different java files

我正在做一个基于 Appium-cucumber-Java 的自动化项目,它会随着时间的推移而增长。

目前,我在 iOS 的一个文件和 Android 的另一个文件中有步骤定义 Given,When,Then。 这两个文件都是从一个公共基础测试 class 扩展而来的。 我在这两个文件中都使用 new 关键字初始化所需的页面对象。

现在,我想将其模块化并创建一个 CommonStepDefs 文件。但是我开始出现空指针异常。

您能否建议使用与此类似的任何方法或示例示例来构建此

提前致谢。

public class AndroidTestsStepDefs_usingFactory extends BaseTestClass {

AndroidChooseCountryPage androidChooseCountryPage;
AndroidCountrySelectionPage androidCountrySelectionPage;
OrderPrints orderPrints;
AndroidHomePage androidHomePage;
TourPage tourPage;

public AndroidTestsStepDefs_usingFactory() throws IOException, AWTException {
}


@Given("^the app has been installed$")
public void the_app_has_been_installed() throws Throwable {
    initializeDriver("android");
    super.setCoreAppType("Android");
}

您有兴趣在步骤定义文件之间共享状态。

Java 中共享状态的惯用法是使用依赖注入创建一个在所有步骤之间共享的公共对象。

如果您的项目使用依赖注入框架,请使用相同的框架在步骤定义之间共享状态 类。 Cucumber-JVM 支持许多不同的依赖注入框架。可能支持你的。

如果你不使用依赖注入,我建议使用 PicoContainer。

我已经写了两篇关于这个主题的博客 post。使用

共享状态