SpecFlow.VisualStudio icon indicating copy to clipboard operation
SpecFlow.VisualStudio copied to clipboard

Feature file lines always purple when using bindings from external assemblies

Open evilC opened this issue 7 years ago • 11 comments

I have bindings in an external assembly (As per the specflow docs here)
We need this, as we are making a generic library of Step Definitions that can be used in any of our test suites.
It works, however some specflow functionality does not appear to work.
Namely:
All steps are highlighted purple (Indicating that it cannot be matched with a binding)
If you select a step and hit F12 or right-click and select "Go To Step Definition", it says it cannot find a matching binding.
However, the code runs OK, and if you debug it, you can step from the feature file into the step definition file, so it appears that the problem is only with the Specflow plugin, not with the nuget package?
Does anyone know how to fix this?
I uploaded the test SLN used in the video here. Specflow broken Go To Step Definition enter image description here

evilC avatar Apr 20 '17 19:04 evilC

Aha! I managed to fix it.
I found this comment on an old closed issue where the author says the problem is due to binding files of the same name but different paths.
However, in my case, a file of the same name used to exist, but no longer does.
It seems that maybe VS is failing to forget this filename, then this bug layers on top to cause a problem.

In the SLN I posted, I made a new test project and added new files keeping default name, so StepDefinition1.cs was the filename for the Step Definition in both projects, however I had deleted it (Via VS) from the SharedStepsTest project.
The bottom screenshot is chopped off, but trust me, there is no StepDefinition1.cs below Hooks1.cs.
The file is also not present on the disk.
I had used "Clean Solution".
I had also rebuilt the feature files.

So if you follow a logical path that you might in a tutorial on using this feature, it does not work until you change the name of the Step Definition file.

evilC avatar Apr 20 '17 21:04 evilC

Any progress fixing this?

evilC avatar Sep 08 '17 11:09 evilC

@evilC Not unfortunately...

gasparnagy avatar Oct 04 '17 09:10 gasparnagy

Is this fixed in the new release?

yoyo-array0825 avatar Oct 30 '18 22:10 yoyo-array0825

@yoyo-array0825 No. If it was, we would have closed this issue.

SabotageAndi avatar Oct 31 '18 07:10 SabotageAndi

https://github.com/techtalk/SpecFlow/wiki/Troubleshooting-Visual-Studio-Integration#steps-are-not-recognised-even-though-there-are-matching-step-definitions

FestTestQA avatar Jan 24 '19 16:01 FestTestQA

Hello, I had this problem yesterday and after trying all the workarounds I finally solved it by uninstalling SpecFlow and installing it again.

The underlying problem is described in this post: https://github.com/techtalk/SpecFlow/issues/502#issuecomment-389337654 SpecFlow fails to correctly generate the .cache files.

Helpdesk tactics at it's finest, if something doesn't work, restart, unplug and plug, uninstall then reinstall :)

dod0o avatar Apr 04 '19 12:04 dod0o

Uninstalling and reinstalling Visual Studio 2017's Specflow extension did not seem to fix the issue for me (looked like a simple workaround so was hoping this would work). I ending up having to copy the binding for each sentence individually, and past the binding into the file that already has that binding in it ... then save all files... then I could delete the dummy binding method and then the Specflow feature file would once again have a good link between the Gherkin sentence and the binding code.

just another temporary fix and anyone who just has a few lines of Gherkin that got purpled out.

fractalocity avatar Oct 16 '19 15:10 fractalocity

Deveroom (https://github.com/specsolutions/deveroom-visualstudio) processes the step definitions from the compiled assemblies so it is pretty stable for external assemblies too.

gasparnagy avatar Oct 16 '19 17:10 gasparnagy

Hey guys I found a workaround. Go to your Step Definition and in the Binding attribute, add a character to the Gherkin phrase and save file. Return to your .feature file and add that character to the test step. This should reevaluate the step definition file and recognize the binding. Then return to the Step Definition and remove the extra character, save, and do the same in the .feature file. The original Gherkin sentence should have the binding restored. In my case, this resolved ALL of my missing bindings.

  1. [Given(@"I append ""(.*)"" to Scenario title")] - missing binding in MyTest.feature
  2. Modified to [Given(@"I append ""(.*)"" to Scenario titles")] (notice the extra 's' at the end) - save file
  3. Return to MyTest.feature and add 's' to test line - notice the purple goes away and now user can "Go To Step Definition"
  4. Return to Step Definition and remove the 's' and resave. Do the same in MyTest.feature.

dchessher avatar Dec 01 '20 18:12 dchessher

Steps to resolve

  1. remove [Binding] attribute in step definition and save the file
  2. Again add [Binding] attribute as it is and save step definition file
  3. Now compile the solution hopefully it will get resolve the solution

Bhushan784 avatar Dec 11 '20 13:12 Bhushan784