Repeat scenarios for different examples

1.2k views Asked by At

I am trying to run some test written in specflow using Scenario Outlines where I have the input and out out parameterised, this is fine, and I can do it.

However I also would like to then repeat all the tests across multiple browsers.

This means having one set of parameters to define the test scenarios and another set to iterate over for all the different variations of environment setup (browser type)

as a simple example of what I am trying to do I have a web page that has links on it, each link is authorized based on ad group membership (web site is an intranet one using windows authentication) so I have the tests:

Scenario Outline: Only authorised users can click through links on main page
Given a user <name> in domain "ad" with password <password> 
And the home page is loaded
When I click the link <link>
Then the page has "title" <title>
Scenarios:
| name    | password  | link                        | title                                              |
| user1 | VMoney123 | "link1" | "You are not authorized to see this section"       |
| user2 | VMoney123 | "link1" | "Success"       |
| user2 | VMoney123 | "link2" | "Success" |

But when I naively try to add Examples to iterate the browser flavours:

Scenario Outline: Only authorised users can click through links on main page
Given a user <name> in domain "ad" with password <password>
And a <browser> browser
And the home page is loaded
When I click the link <link>
Then the page has "title" <title>
Examples:
| browser |
| "chrome"  |
| "ie"      |
Scenarios:
| name    | password  | link                        | title                                              |
| name    | password  | link                        | title                                              |
| user1 | VMoney123 | "link1" | "You are not authorized to see this section"       |
| user2 | VMoney123 | "link1" | "Success"       |
| user2 | VMoney123 | "link2" | "Success" |

and the build gives the error:

CS1029  #error: 'Generation error: The example sets must provide the same parameters.'

Obviously I could do this by having 6 Scenarios (or examples), but if I need to expand this out to another 5 browsers that would mean an extra 15 scenarios, it becomes unweildy quickly, surely there is a way...

1

There are 1 answers

0
Andreas Willich On

Your feature is not valid Gherkin. Have a look at the reference of it here: https://cucumber.io/docs/reference

To run the same scenario for different browsers, have a look at this example: https://github.com/techtalk/SpecFlow.Plus.Examples/tree/master/SeleniumWebTest
It uses the SpecFlow+Runner to achieve the support of different browsers.


Full disclosure: I am on of the developers of SpecFlow and SpecFlow+.