1

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

Suraj Gupta
  • 390
  • 1
  • 9
  • 25

2 Answers2

1

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

Community
  • 1
  • 1
Sam Holder
  • 32,535
  • 13
  • 101
  • 181
  • `public class MySteps: Steps //Inheriting this base class is vital or the methods used below won't be available { [Given("I have created an order")] public void CreateOrder() { Given("I want to create a sales order"); Given("I open the sales order page"); Given("I click the add new order button"); Then("a new sales order is created"); } }` I am able to inherit the functions from parent class but I am not able to directly write the Given statements inside the given as stated above.. Am I not doing correctly? – Suraj Gupta Nov 28 '15 at 20:45
  • Since I am passing all my command/data from the When and Then(Expected Results) statements, I need something which can pickup the When/Then statements and pass the inline parameters from these statements(which are called in child class using inheritance) which in then would call the mapped methods. – Suraj Gupta Nov 28 '15 at 20:54
  • @surajgupta I'm not sure what the issue is. Please ask another question staying clearly why this will not work for you, with examples, and I'll try and answer it. Please post a comment here with link once you have done that – Sam Holder Nov 28 '15 at 21:32
  • hi @samholder.. I have added another [question](http://stackoverflow.com/questions/33984359/calling-entire-feature-fileor-only-when-steps-into-another-feature-file) with more details please have a look. – Suraj Gupta Nov 29 '15 at 15:21
0

We use vstest console. For example, when scenario does not prepared data, In first step we run special feature for data preparing How do I launch application one from another in C#?

About parameters for console running is this How do you run SpecFlow scenarios from the command line using MSTest?

Community
  • 1
  • 1
Jan Regent
  • 21
  • 5