Search code examples
c#automationbddspecflowgherkin

Can I call one feature file into some another feature file present in same suite (solution for calling scenarios will also do)


I have a test suite where I have multiple BDD scenarios present in different feature files like mentioned below,

**FeatureFile1**

Scenario: User is performing 123 funtionality

Given A,B,E,F,G
When User does A
Then Output is Aresult
When User does B
Then Output is Bresult
When User does E
Then Output is Eresult
When USer does F
Then Output is Fresult
When User does G
Then Output is Gresult


**FeatureFile2**

Senario: User is performing 4567 functionality

Given M,N,A,B,E,F,G,P,Q
When User does M
Then Output is Mresult
When User does N
Then Output is Nresult
When User does A
Then Output is Aresult
When User does B
Then Output is Bresult
When User does E
Then Output is Eresult
When USer does F
Then Output is Fresult
When User does G
Then Output is Gresult
When User does P
Then Output is Presult
When User does Q
Then Output is Qresult



**FeatureFile3**

Senario: User is performing 890 functionality
Given U,V,A,B,E,F,G,X,Y,Z
When User does U
Then Output is Uresult
When User does V
Then Output is Vresult
When User does A
Then Output is Aresult
and User does B
Then Output is Bresult
When User does E
Then Output is Eresult
When USer does F
Then Output is Fresult
When User does G
Then Output is Gresult
When User does X
Then Output is Xresult
When User does Y
Then Output is Yresult
When User does Z
Then Output is Zresult

If you closely look my 1st feature file is totally repeated in my 2nd and 3rd file(in between steps).

Is there any way by which I can call my 1st feature file in other files using single line(FeatureFile2 understands that it has to call FeatureFile1, likewise for other cases as well)

These will reduce copy+paste for me and also my other scenarios(lengthy one's) will look compact and presentable. Since I am new to BDD and C# expecting a help. I tried looking out for solution but was not able to find anything concrete.

If I could call scenario present in FeatureFile1 in FeatureFile2...That will also do.

What code should be written????

Framework using Specflow || Language for coding C# || BDD Language Gherkin


Solution

  • The way I usually solve this situation is to create a step which wraps up several other steps and then call this in the second and third features. you can see an example of this approach in this answer