-1

I am implementing Specflow as suggested here

The challenge for me currently is - My single Tests execution combines multiple features. So I noticed when we have a a chained step definitions flow - Some of Step definitions throw Step Binding error-

Example below-Feature is to select one of the results, based on the selection the page header changes. So I already have written a feature for search which will be re-used within this feature-

Feature File
    Given Search a specific account <searchText> to match <column>
    When A specific checkbox is selected <searchText>
    Then The header should display the id

Scenarios: 
    | searchText     | column        |
    | "AutoName21944" |  "Account Name" |

Step definitions:

[Given(@"Search a specific account ""(.*)"" to match ""(.*)""")]
public void GivenSearchASpecificAccountToMatch(string acctName, string column)
{
  Given[PreCondition for Search step] 
  When("I search for Portfolio " + acctName+" in ") - *Step reused from Search*
  Then("the result should display records with " + acctName + " in column " + column)- *Step reused from search feature*
}

When A specific checkbox is selected <searchText>
{
}

When we try running the above feature file - get Error on No Step Binding for Then("@ the result should display records with AutoName(.*) in column Account Name)

Is the reason behind Failure due to using When from Setting Account feature after Then from Search feature?

 [Then(@"the result should display records with (.*) for (.*) in column (.*)")]
        public void ThenTheResultShouldDisplayRecordsWithAutoInColumnAccountID(string searchTxt,string field,string col)
        {
          HomePage hm=new HomePage();
        }
Community
  • 1
  • 1
ReuseAutomator
  • 410
  • 3
  • 14
  • please post the code for you step bindings for the steps you have listed above, and feature above as they are in your project. As it is above the the `Given Search a specific account to match ` will not match `[Given(@"Search a specific account ""(.*)"" to match ""(.*)""")]` as there are no `"` in your feature file. When you have mismatched steps seeing the steps and bindings is important to decide what is going wrong. – Sam Holder Jul 28 '15 at 06:33
  • @Sam-Updated the code above. Since the error displays binding issue with Then at Autoname(.*), assumed its issue with Specflow not considering the input as string. That's reason passing value as a string in examples@ Sam - Do let me know whats the error above as All steps are bound but still throws error during execution. – ReuseAutomator Jul 28 '15 at 07:20
  • you did not include the definition of the step `Then("the result should display records with "` in your code. without seeing the `Then` attribute on this step it will be difficult to diagnose this issue – Sam Holder Jul 28 '15 at 08:02
  • @Sam-reusing same attributes search Text and column field of example for then. Basically for both when and then of search feature, search Text and column used. Wondering if using when,then and again when of set account feature causes issue. Is it expecting then as previous step ended in then. – ReuseAutomator Jul 28 '15 at 17:55
  • as I said please post your step definitions and your exact error message. Your error message has a space at the front and doesn't match your method call. If you cannot post accurate information then it is impossible to help. What you want to do is very possible, I've done it many times but without an accurate repro I cannot help you to solve the problem – Sam Holder Jul 28 '15 at 19:02

2 Answers2

0

I think your problem is that you have included quotes in your examples. I don't think this is necessary.

try changing to this:

Feature File
    Given Search a specific account <searchText> to match <column>
    When A specific checkbox is selected <searchText>
    Then The header should display the id

Scenarios: 
    | searchText    |  column       |
    | AutoName21944 |  Account Name |

you have not made things easy by posting incomplete code which does not compile though, so the issue might be something else. You have not posted your step definition you expect to be called for this step:

Then("the result should display records with " + acctName + " in column " + column);

without this information is is very difficult to let you know why it is not being called. If you want to be helped then the best thing you can do is to provide the additional information requested.

Sam Holder
  • 32,535
  • 13
  • 101
  • 181
  • @Sam-will look into it tomorrow and inform. Been busy with other projects. Thanks – ReuseAutomator Jul 30 '15 at 10:02
  • @Sam-If I do not include quotes, the step definition for above is something like this - Given(@"Search a specific account AutoName(.*) to match Account Name"). This seems to not be reusable from other features as I might not need to prefix AutoName - I might search with different searchText. Maybe, I am missing something in here. – ReuseAutomator Aug 03 '15 at 01:32
0

Updated the code above. Realized ,had updated the base step definition after it had been reused in other features.Did realize the issue, one was missing 'for', and also passing 3 variables in Then. When I am calling it in other feature - using only 2 variables. So after for I need to pass space when reusing it.(Is this absolutely necessary? as did not work without a blank value)

Then("the result should display records with " + acctName + " for <space> in column " + column)
ReuseAutomator
  • 410
  • 3
  • 14