15

有没有办法让 SpecFlow 重用步骤定义?

在其他工具中,我使用了 GivenWhenThen 基类,其中包含诸如

WhenAnOrderIsCreated - 这将初始化一个受保护的订单成员,以供继承类使用。

似乎无法与 SpecFlow 一起使用(似乎不喜欢继承)

有没有办法跨功能共享步骤?

非常感谢

4

1 回答 1

29

为什么是的,这是可能的 - 查看步骤功能中的调用步骤(https://specflow.org/documentation/Calling-Steps-from-Step-Definitions/

简而言之,您创建一个从 Steps 继承的步骤定义类,如下所示:

[Binding]
public class CallingStepsFromStepDefinitionSteps : Steps
{}

然后你可以像这样简单地调用其他步骤:

[Given(@"I am logged in")]
public void GivenIAmLoggedIn()
{
     Given("I am on the index page");
     When("I enter my unsername nad password");
     And("I click the login button");
     incStepCount();
}

我希望我正确理解了您的问题,并且这是对它的回答

于 2011-03-08T05:57:49.820 回答