如何重用另一个步骤定义中的方法 class Appium/Cucumber/Java
How to reuse a method from another step definition class Appium/Cucumber/Java
尝试在另一个 class 中重用一个方法,像这样初始化 class:
public class SettingsStepDefs {
public Scenario scenario;
@Autowired
public AndroidBase androidBase;
public GenericStepDefs genericStepDefs;
@Before
public void before(Scenario scenario) {
this.scenario = scenario;
genericStepDefs = new GenericStepDefs();
然后稍后使用方法
genericStepDefs.iTapDone();
但是我在上面的行中收到空指针异常。
iTapDone() 中的代码是有效的,如果我复制该行并在 SettingsStepDefs 上使用它,它就可以工作。
提前致谢。
您需要在步骤之间共享 GenericStepDefs
的实例。由于未设置变量 genericStepDefs
,您将得到 NullPointerException。
您似乎在使用 Spring,因为您使用了注释 @Autowired
。查看 Cucumber 与 Spring 的共享状态。这是通过为 Cucumber-JVM 设置 Spring 来完成的。依赖关系
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-spring</artifactId>
<version>1.2.5</version>
</dependency>
需要。
尝试在另一个 class 中重用一个方法,像这样初始化 class:
public class SettingsStepDefs {
public Scenario scenario;
@Autowired
public AndroidBase androidBase;
public GenericStepDefs genericStepDefs;
@Before
public void before(Scenario scenario) {
this.scenario = scenario;
genericStepDefs = new GenericStepDefs();
然后稍后使用方法
genericStepDefs.iTapDone();
但是我在上面的行中收到空指针异常。
iTapDone() 中的代码是有效的,如果我复制该行并在 SettingsStepDefs 上使用它,它就可以工作。
提前致谢。
您需要在步骤之间共享 GenericStepDefs
的实例。由于未设置变量 genericStepDefs
,您将得到 NullPointerException。
您似乎在使用 Spring,因为您使用了注释 @Autowired
。查看 Cucumber 与 Spring 的共享状态。这是通过为 Cucumber-JVM 设置 Spring 来完成的。依赖关系
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-spring</artifactId>
<version>1.2.5</version>
</dependency>
需要。