Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature file lines always purple when using bindings from external assemblies #179

Open
evilC opened this issue Apr 20, 2017 · 11 comments
Open

Comments

@evilC
Copy link

evilC commented Apr 20, 2017

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
Copy link
Author

evilC commented Apr 20, 2017

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
Copy link
Author

evilC commented Sep 8, 2017

Any progress fixing this?

@gasparnagy
Copy link
Contributor

@evilC Not unfortunately...

@yoyo-array0825
Copy link

Is this fixed in the new release?

@SabotageAndi
Copy link
Contributor

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

@dod0o
Copy link

dod0o commented Apr 4, 2019

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 :)

@fractalocity
Copy link

fractalocity commented Oct 16, 2019

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.

@gasparnagy
Copy link
Contributor

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

@dchessher
Copy link

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.

@Bhushan784
Copy link

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

@SabotageAndi SabotageAndi transferred this issue from SpecFlowOSS/SpecFlow Apr 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants