Mario
Mario

Reputation: 19

SpecFlow: To run feature file with multiple scenarios several times with different parameters

I'm wondering why we can run Scenario several times with different parameters but cannot run whole feature file with different parameters.

Our feature files consists of many scenarios and feature file corresponds to Test Case, but when we need to run the same feature file, but with different parameter(s) then whole feature file has to be duplicated... Is there any possibility to parametrize whole feature file?

Upvotes: 1

Views: 2048

Answers (1)

Varun R.J
Varun R.J

Reputation: 31

I don't know whether you are aware of the Scenario Outline.

The Scenario Outline keyword can be used to run the same Scenario multiple times, with different combinations of values


Copying and pasting scenarios to use different values quickly becomes tedious and repetitive as shown in the below example:

Scenario: Successful Login with Valid Credentials
   Given User is at the Home Page
   And Navigate to LogIn Page
   When User enter "testuser_1" and "Test@123"
   And Click on the LogIn button
   Then Successful LogIN message should display

Scenario: Successful Login with Valid Credentials
   Given User is at the Home Page
   And Navigate to LogIn Page
   When User enter "testuser_2" and "Test@153"
   And Click on the LogIn button
   Then Successful LogIN message should display

We can collapse these two similar scenarios into a Scenario Outline.

Scenario outlines allow us to more concisely express these scenarios through the use of a template with < > - delimited parameters:

Scenario Outline: Successful Login with Valid Credentials
   Given User is at the Home Page
   And Navigate to LogIn Page
   When User enter <username> and <password>
   And Click on the LogIn button
   Then Successful LogIN message should display
Examples:
| username   | password |
| testuser_1 | Test@123 |
| testuser_2 | Test@153 |

A Scenario Outline must contain an Examples (or Scenarios) section. Its steps are interpreted as a template which is never directly run. Instead, the Scenario Outline is run once for each row in the Examples section beneath it (not counting the first header row).

The steps can use <> delimited parameters that reference headers in the examples table. Cucumber will replace these parameters with values from the table before it tries to match the step against a step definition.

Upvotes: 1

Related Questions