0

我想在 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_Screen_is_visible()不采取steps.Landing_Screen_is_visible()

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

或者可能有另一种实现黄瓜步骤的方法?(相同的步骤但不同的实现)

4

1 回答 1

0

您正在寻找的是驱动程序模式,其中您具有相同的步骤定义,但在不同的测试环境中使用时使用不同的应用程序驱动程序示例

abstract class MyApplicationDriver {

     abstract void login();

然后为Android实现

class AndriodApplicationDriver extends MyApplicationDriver {

     void login(){};

然后另一个

class AppleTestDriver extends MyApplicationDriver {

    void login(){};

在测试中使用 MyApplicationDriver 作为接口,然后在上下文中使用实现,您必须查看 World 对象以了解如何执行此操作

于 2013-10-25T09:29:52.680 回答