Operations with calls in streams in steps lead to the error "No corresponding step defined"

I am following the described technique here

using a step defined as

[Given("some base scenario has happened")]
public void SomeBaseScenarioHasHappened()
{
   Given("some condition");
   And("some action");
   When("some result");
}

      

from a script like

Scenario: Some dependant scenario
Given some condition 
And some base scenario has happened
When some other action
Then some other result

      

However step

  When some other condition

      

gives the following error -> No matching step definition found for step. Use the following code to create it:

[When(@"some other condition")]
public void Whensome other condition()
{
ScenarioContext.Current.Pending();
}

      

I can get around this problem if the base script only uses "Given"

[Given("some base scenario has happened")]
public void SomeBaseScenarioHasHappened()
{
   Given("some condition");
   Given"some action");
   Given("some result");
}

      

however, this is not what I should have done. Am I missing something? Why can't the base script be called using AND?

+4


source to share


4 answers


There are only three types of steps in Specflow. Given

, When

and Then

. When you use step c And

in a scenario description, SpecFlow looks at the previous step type and assumes that your step And

is of the same type.

So when you write this

Scenario: Some dependant scenario
    Given some base scenario has happened
    And some other condition
    When some other action
    Then some other result

      

Specflow looks for a step that has bindings:

    Given("some base scenario has happened")
    Given("some other condition")
    When("some other action")
    Then("some other result")

      

Note that there is no binding And

?

So, your solution is to make sure that in your tricky step, you should avoid using And

and just use the same binding (or one of them if they have several) as in the original step. Your final solution should look something like this:

[Given("some condition")]
public void SomeCondition()
{
   ...
}

[When("some action")]
public void SomeAction()
{
   ...
}

[Then("some result")]
public void SomeResult()
{
   ...
}

[Given("some base scenario has happened")]
public void SomeBaseScenarioHasHappened()
{
   Given("some condition");
   When("some action");
   Then("some result");
}

[Given("some other condition")]
public void SomeOtherCondition()
{
   ...
}

[When("some other action")]
public void SomeOtherAction()
{
   ...
}

[Then("some other result")]
public void SomeOtherResult()
{
   ...
}

      



You cannot use And

in compound steps because no steps are actually linked to And

, no such link exists. The only bindings are Given

, When

or Then

. Keywords And

and But

are only used when generating executable unit tests, steps using these keywords are still associated with step Given

, When

or Then

.

In certain scenarios, things are handled in order, and you can easily tell what is actually a step And

based on the step, he appears after, so when specflow generates a reference to the step, he knows what type of pitch to use (either a Given

, When

or a Then

) ... When you call one step from another step, you are explicitly calling one of these bindings step by step, and you must call it the binding it is associated with. So if it's linked to the binding Given

like this:

[Given("some other condition")]
public void SomeOtherCondition()
{
   ...
}

      

then you have to call it like this:

Given("Some other condition");

      

but you can refer to it like this:

Given some condition
And some other condition

      

as specflow knows when it generates a unit test, which And some other condition

actually calls the Given

bound stage

+6


source


Possible solutions

Use value instead of And

Scenario: Some dependant scenario
Given some base scenario has happened
Given some other condition   
When some other action
Then some other result

      

or



Mark a step with more than one binding, for example

[Given(@"some other condition")]
[When(@"some other condition")]
public void Whensome other condition()
{

      

but it won't always make sense, so only use it when it really makes sense.

+2


source


This question was previously answered correctly above.

I just ran into the same error "No matching step definition found for one or more steps".

The reason I got this problem was because I forgot to put the [Binding, Scope (Feature = "My Feature")] attribute just above my steps class, which is needed to match "Feature: My Feature" at the top parts. my function file.

I just taught that I would write it down here to help someone who sees the same error, but for a different reason that I have outlined.

0


source


try to check if there are empty spaces in your proposal. ie: some description is given (empty space) So, the method will display like this: [Given ("Some description")]

0


source







All Articles