简体   繁体   中英

SpecFlow Re-usable step definitions

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM