Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the current executing step information in Specflow

We are trying to take screenshots for each step.

Everything works fine. But we are not able to correlate the screenshots to the steps which created them.

What we would like is something like FeatureContext.FeatureInfo and ScenarioContext.ScenarioInfo. But at individual step level. So that we can tag the screenshots accordingly.

like image 620
NotAgain says Reinstate Monica Avatar asked Nov 04 '14 00:11

NotAgain says Reinstate Monica


Video Answer


1 Answers

EDIT

Classes have been added which expose:

ScenarioStepContext.StepInfo.Text and ScenarioStepContext.StepInfo.StepDefinitionType

Which should give you what you want.

Original answer This is not currently possible, although I have just (yesterday) submitted a pull request which adds this functionality. If you are happy with building specflow yourself then you can clone my fork of the specflow repo and switch to the ScenarioStepContext branch, then open the TechTalk.Specflow_VS2013.sln and build the project yourself.

First you need to give specflow a new version number for the nuget package. Open the SpecFlow.nuspec file and edit the version to be something higher than the current version (I used 1.9.3.4), then build the solution (you need to installed the VS2013 SDK, and other VS SDKs if you want to build those versions).

Once the solution is built, you will need to install the vsix from

\SpecFlow\IdeIntegration\Vs2013Integration\bin\Debug\TechTalk.SpecFlow.Vs2013Integration.vsix

and then add the nuget package from

\SpecFlow\Installer\NuGetPackages\bin\SpecFlow.1.9.3.4.nupkg.

Once you have done this you will be able to access ScenarioStepContext.StepInfo.Text and ScenarioStepContext.StepInfo.StepDefinitionType to be able to tag the elements you want with the current step details.

We are currently using this, but please raise any issues on the PR at the main Specflow github page and I'll fix them if I can.

like image 93
Sam Holder Avatar answered Sep 25 '22 00:09

Sam Holder