Multiple step definition found for specflow feature steps -


i have 2 feature files same scenarios. when create definitions them first feature1.cs file has steps. when click on second feature file , generate definition reuses functions first feature1.cs file, scenarios duplicate.

now have [beforescenario] both file. when run second feature file, ends using [beforescenario] of first file.

i noticed binding tag in feature1.cs file had names of both of feature file

[binding, scope(feature = "feature1"), scope(feature="feature2")] 

so removed second feature2 , placed in feature2.cs file.

now, able run [beforefeature] feature2.cs when click on scenario step , go defination says "multiple steps found" inspite of reusable steps being in feature1.cs file itself.

i hope makes sense.

the first thing need realize step definitions in specflow global. illustrate that, lets have 3 files: feature1.feature, feature2.feature , mystepdefs.cs.

in mystepdefs.cs have following code:

[given(@"i have asked new question")] public void givenihaveaskedanewquestion{    //some code } 

now in feature1 file have scenario

scenario: ask question , bad answer given have asked new question when answer , answer not helpful should downvote answer  , should explain why not answer question 

and in feature2 file have scenario

scenario: ask question , answer given have asked new question when answer , answer helpful should upvote answer  , should mark answer accepted 

in case reuse given step, need 1 step definition, not 1 each feature.

now explain have 2 [beforescenario] stepdefs. these run before every scenario, if same thing, again need one. if different things , want them run before given feature/scenario, recommend have @ this, need assign scope these bindings looks this:

 [beforescenario, scope(//your scope)]  

this way beforescenario steps run given scope


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -