可以在Java接口中定义测试步骤定义吗?

可以在Java接口中定义测试步骤定义吗?,java,cucumber,automated-tests,Java,Cucumber,Automated Tests,我想在Java接口中定义Cucumber测试步骤定义 public interface ITestSteps { @Before public void setUpLocal() throws Throwable; @When("^Landing screen is visible$") public void Landing_Screen_is_visible() throws Throwable; } 2个其他类将实现此接口: public class A

我想在Java接口中定义Cucumber测试步骤定义

public interface ITestSteps {
    @Before
    public void setUpLocal() throws Throwable;

    @When("^Landing screen is visible$")
    public void Landing_Screen_is_visible() throws Throwable;
}
2个其他类将实现此接口:

public class AppleTestSteps implements ITestSteps { ... } 
public class AndroidTestSteps implements ITestSteps { ... } 
我有一个TestFactory类,它使用环境名称(Android或Apple)获取属性并初始化对象:

ITestSteps steps = TestFactory(platformName);
问题:Cucumber按名称执行所需步骤,而不引用对象。采取
Landing\u Screen\u可见()
步骤。Landing\u Screen\u可见()

在尝试按名称查找需求之前,是否可以实现接口?制造静电


或者,是否有其他实施步骤的方法?(相同的步骤但不同的实现)

您要寻找的是驱动程序模式,即在不同的测试环境中使用相同的步骤但使用不同的应用程序驱动程序

abstract class MyApplicationDriver {

     abstract void login();
然后是Android的实现

class AndriodApplicationDriver extends MyApplicationDriver {

     void login(){};
然后是另一个

class AppleTestDriver extends MyApplicationDriver {

    void login(){};
在测试中使用MyApplicationDriver作为接口,然后在上下文中使用实现,您必须查看World对象,了解如何做到这一点