No matching step binding found for this step exception - specflow

I've created a very simple feature file. When go to the definition by pressing F12. I get an error
No matching step binding found for this step.
Its being thrown for my When step.
Feature: ItemBag
Scenario Outline: Add item to bag until 200 is reached
Given I navigate to the homepage
And I search for trainers
When I add to the bag
Then trainers are added till 200 is reached

You need to create a Step file. It should be like this:
public class Steps
{
[Binding]
public void InavigateToTheHomepage()
{
this step implementation;
}
public void nextStep()
{
this step implementation;
}
}
This class should contain implementation for all of your steps. After that you shouldn't receive this kind of error.

Related

Facing issue using QAF common step og click and clear methods

Facing some weird issue when using QAF common steps. We just facing in “I click” and “I clear” methods so far.
Step to reproduce:
Step: And I click on "LOGIN_btn||rt.loc.e8R5BmyEUI"
#QAFTestStep(description = "I click on {0}")
public static void iClick(String locator) throws Exception {
click(locator);
}
Result: Fail
Issue: Unable to locate login button.
Here, Element locator is absolutely fine and if I change method name like “iClickOn” or “iClickABC” like below then its working fine as expected.
#QAFTestStep(description = "I click on {0}")
public static void iClickOn(String locator) throws Exception {
click(locator);
}
Result: Pass
Another approach is also working fine. If I removed “On” from step then its working fine.
Step: And I click "LOGIN_btn||rt.loc.e8R5BmyEUI"
#QAFTestStep(description = "I click {0}")
public static void iClick(String locator) throws Exception {
click(locator);
}
Result: Pass
Note: Same issue I'm facing in I clear locator as well.
Kindly check and confirm is there any restriction to use words in steps or what could be the problem here.
Check all entries of step.provider.pkg. Most probably the reason is you have another library specifying step with same name with same description and step loaded from it.
For example if you are using Perfecto-Quantum it has step with same name and description. The simplest way to find out is editor content-assist in IDE. You will see all available step definitions in content assist.

When compiling Specflow project - generation error reported

I am creating a new Specflow project in VS2017. I have added 1 rule in the features file and generated the initial steps code. However, when I attempt to build the project I get the following 2 errors.
(1) CS1029 #error: 'Generation error: Object reference not set to an instance of an object.'
(2) Custom tool error: Generation error: Object reference not set to an instance of an object.
Feature file contains,
Feature: Change_Theme_Change_Scheme
#Change_Theme_Change_Scheme
Scenario: Verfy change of scheme
Given I log into Admin site
And I navigate to Colour Scheme page
And I select the Kumho theme
When I click the Save Theme button
Then Check website main menu background is Red
Steps file contains,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TechTalk.SpecFlow;
namespace Tyres_and_Service_Tester.Steps
{
[Binding]
public sealed class Change_Theme_Change_Scheme
{
[Given(#"I log into Admin site")]
public void GivenILogIntoAdminSite()
{
ScenarioContext.Current.Pending();
}
[Given(#"I navigate to Colour Scheme page")]
public void GivenINavigateToColourSchemePage()
{
ScenarioContext.Current.Pending();
}
[Given(#"I select the Kumho theme")]
public void GivenISelectTheKumhoTheme()
{
ScenarioContext.Current.Pending();
}
[When(#"I click the Save Theme button")]
public void WhenIClickTheSaveThemeButton()
{
ScenarioContext.Current.Pending();
}
[Then(#"Check website main menu background is Red")]
public void ThenCheckWebsiteMainMenuBackgroundIsRed()
{
ScenarioContext.Current.Pending();
}
}
}
Image of project references
I've not come across this before when building Specflow projects with earlier versions of VS, and cannot figure out what I've done differently
Many thanks for any help. Tony
Thank you for all your responses. I decided to start from scratch again adding the Specflow packages to VS, and recreating the features, steps etc. As you might of guessed it worked this time - so I'm at a loss what might of been going on. Anyway this question can be closed.

Specflow calling steps within steps causes "No matching step definition" error

I am following the technique outlined here
using a step defined like
[Given("some base scenario has happened")]
public void SomeBaseScenarioHasHappened()
{
Given("some condition");
And("some action");
When("some result");
}
from a scenario like
Scenario: Some dependant scenario
Given some condition
And some base scenario has happened
When some other action
Then some other result
However the step
When some other condition
produces the following error
-> No matching step definition found for the step. Use the following code to create one:
[When(#"some other condition")]
public void Whensome other condition()
{
ScenarioContext.Current.Pending();
}
I can work around the problem by having the base scenario only use 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 to do.
Am I missing something?
Why cant the base scenario be called using an AND ?
In Specflow there are only 3 types of steps. Given, When and Then. When you use a step with And in your scenario description SpecFlow looks at the previous type of step and assumes that your And step 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 step which have bindings:
Given("some base scenario has happened")
Given("some other condition")
When("some other action")
Then("some other result")
Notice there is no And binding?
So your solution is to to ensure that in your composite step you must avoid using And and just use the same binding (or one of them if they have multiple) that the original step had. 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 can't use And in the composite steps because no steps are actually bound with an And, there is no such binding - The only bindings are Given, When or Then. The And and But keywords are only used when generating the unit tests that are run, the steps using those keywords are still bound to a Given, When or Then step ultimately.
In a scenario definition the things are processed in order and you can easily tell what an And step actually is based on the step it appears after, so when specflow generates the step bindings it knows what step type to use (either a Given, When or Then). When you are calling a a step from within another step you are explicitly calling one of those step bindings and you have to call it with the binding that it is bound with. So if it was bound with a Given binding like this:
[Given("some other condition")]
public void SomeOtherCondition()
{
...
}
then you have to call it like this from the code:
Given("Some other condition");
but you could refer to it like this in a scenario:
Given some condition
And some other condition
because specflow knows when it generates the unit test that the And some other condition is actually calling a Given bound step
This question has been previously answered correctly above.
I just came across the same error "No matching step definition found for one or more steps".
The reason that I had this issue, was that I had forgotten to put the attribute [Binding, Scope(Feature = "My Feature")] just above my steps c# code class which links methods to feature file, which is needed to match "Feature: My Feature" at the top of my feature file.
I just taught that I would document it here to help someone else that was seeing the same error but for the different reason that I outlined.
Possible solutions
Use Given 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
Tag the step with more than one binding, e.g.
[Given(#"some other condition")]
[When(#"some other condition")]
public void Whensome other condition()
{
but this won't always make semantic sense, so use this only when it really does make sense.
try verifying if your sentence has empty spaces. i.e: Given some description(empty space)
so, in the method will appear like: [Given("some description ")]

mini-profiler drop some steps

I'm starting to use Stackoverflow MiniProfiler on my ASP MVC 4 web application.
I've put only the Start and Stop calls in BeginRequest and EndRequest respectively.
I've add to one action some steps like so:
private ActionResult MyAction(string id)
{
using (MiniProfiler.Current.Step("GatherReportItems")) {
...
}
using (MiniProfiler.Current.Step("BuildReportViewModel")) {
...
}
using (MiniProfiler.Current.Step("AddingExtraInfo")) {
...
}
}
The problem is that on the first request to that action I can see all 3 steps, on any further request I see only the first step and not any of the others.
When I debug my application I can see inside MiniProfiler.Current -> Head -> Children that all the 3 steps are there. It is in the client display (after clicking on the timing box) that I can see only part of the steps.
I've now notice that there is a small link name show trivial at the bottom of the profiling details popup which add the very short timings

Specflow ignores When step in F# step assembly

I am using VS2010, SpecFlow 1.9.0, NUnit 2.6.2 and ReSharper 7.1. I have a feature file taken from the example:
Feature: SpecFlowFeature1
In order to avoid silly mistakes
As a math idiot
I want to be told the sum of two numbers
#mytag
Scenario: Add two numbers
Given I have entered 50 into the calculator
And I have entered 70 into the calculator
When I press the add button
Then the result should be 120 on the screen
I have implemented the step definitions in a separate F# assembly:
[<TechTalk.SpecFlow.Binding>]
module StepDefinitions
open TechTalk.SpecFlow
open NUnit.Framework
let [<Given>] ``I have entered (.*) into the calculator`` (a: int) =
ScenarioContext.Current.Pending()
let [<When>] ``I press the add button`` =
ScenarioContext.Current.Pending()
let [<Then>] ``the result should be (.*) on the screen`` (r: int) =
ScenarioContext.Current.Pending()
I have told SpecFlow where to find them via the stepAssemblies tag in app.config
However, when I run the test, it finds the Given and Then steps, but not the When step. The error I get is:
No matching step definition found for one or more steps.
using System;
using TechTalk.SpecFlow;
namespace MyNamespace
{
[Binding]
public class StepDefinitions
{
[When(#"I press the add button")]
public void WhenIPressTheAddButton()
{
ScenarioContext.Current.Pending();
}
}
}
Given I have entered 50 into the calculator
-> pending: StepDefinitions.I have entered (.*) into the calculator(50)
And I have entered 70 into the calculator
-> skipped because of previous errors
When I press the add button
-> No matching step definition found for the step. Use the following code to create one:
[When(#"I press the add button")]
public void WhenIPressTheAddButton()
{
ScenarioContext.Current.Pending();
}
Then the result should be 120 on the screen
-> skipped because of previous errors
Have I gone wrong somewhere, or is there a bug with F# support?
The correct translation of the C# is actually
let [<When>] ``I press the add button``() =
ScenarioContext.Current.Pending()
Note the extra (). As this was missing in the original version, the function had a different signature which meant that it wasn't found.

Resources