Saturday, 31 December 2016

C# Visual Studio - SpecFlow Step Definition file

Prerequisite:
Feature file is already created.
Creating the feature file: https://automation-home.blogspot.in/2016/12/c-visual-studio-specflow-feature-file.html


Create the class for step defintions

 Enter the class name and click 'Add' button.
   ex: SampleFirstFeatureSteps.cs
       As a best practice, follow file name ends with 'Steps' <<FileName>>Steps.cs

Class file for step definitions is created.

Mouse right click on step in feature file and select the 'Generate Step Definitions'.

Click 'Preview' button.

Step definition skeleton preview is displayed, close the preview.

Copy the methods(i.e. step definitions methods)

Open the step definitions class file(i.e. 'SampleFirstFeatureSteps.cs'),
   paste the methods(i.e. step definitions) in class   

Since references are missing, shows compilation error for the methods.

Add the missing references by clicking (Ctrl+.)  

Open the feature file, right click on the step and select 'Go To Definition'.

Click 'No' button to close.
There is no binding between Feature file and Step Definitions.
Since there is no binding above dialog window is displayed.

Add the attribute [Binding] for class in Step Definition file.

Remove Unncessary Usings.

Observe the colour for steps in feature file, before and after adding [Binding] attribute for Step Definition class.
Open the Feature file, mouse over on the step right click and select 'Go To Definition'.
    This time when 'Go To Definition' is selected, Steps defintion file is opened(i.e Binding of feature file and step defintion file is successfull).

As a best practice place the feature file in 'Features' folder and step definitions file in 'Step_Definitions' folder.

<< Previous

No comments:

Post a Comment