SpecFlow Re-usable step definitions

天大地大妈咪最大 提交于 2019-12-18 11:55:54

问题


Is there a way to have SpecFlow reuse Step Definitions?

In other tools I have used a GivenWhenThen base class that contains methods such as

WhenAnOrderIsCreated -- this inits a protected order member to be used by inheriting classes.

Just cant seem to get this working with SpecFlow (doesnt seem to like inheritance)

Is there a way to share steps across features?

Many thanks


回答1:


Why yes it's possible - check out the calling steps from step feature (https://specflow.org/documentation/Calling-Steps-from-Step-Definitions/)

In short you create a step definition class that inherits from Steps like this:

[Binding]
public class CallingStepsFromStepDefinitionSteps : Steps
{}

And then you can simply call other steps like this:

[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();
}

I hope I understood your question correctly and that this was an answer to it



来源:https://stackoverflow.com/questions/5228030/specflow-re-usable-step-definitions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!