Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpecFlow Re-usable step definitions

Tags:

c#

bdd

specflow

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

like image 380
Chris McKelt Avatar asked Mar 08 '11 03:03

Chris McKelt


1 Answers

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

like image 114
Marcus Hammarberg Avatar answered Oct 03 '22 08:10

Marcus Hammarberg