Specflow: maintain one Examples table for many Scenario Outlines Specflow: maintain one Examples table for many Scenario Outlines selenium selenium

Specflow: maintain one Examples table for many Scenario Outlines


I think the most maintainable approach is to parameterize the browser that gets used by setting an environment variable before running the test. Inside your Given step definition, you can use Environment.GetVariable("...") to retrieve the value at runtime.

Another alternative is to create a special text file that contains the name of the browser to use. Open this file and read the contents in your Given step definition.

If you have an automated build, you could set up a power shell or batch file that sets this text file to the first browser, runs all the tests, then sets the text file to the next browser and reruns the tests. Rinse and repeat for each browser you want to use.

You could throw this into the <appSettings> of the test project in Visual Studio and utilize config transformations. When running the NUnit tests from the command line you can switch the configuration:

nunit-console nunit.tests.csproj /config:Firefoxnunit-console nunit.tests.csproj /config:InternetExplorernunit-console nunit.tests.csproj /config:Chromenunit-console nunit.tests.csproj /config:Safari

The downside is you create one build configuration for each browser, but it should do the trick.


I don't believe that you can do this in specflow (or in any gherkin language implementation). As mentioned in the related question you can have a background to provide a table, but I'm not certain that this can be used to provide examples in scenario outlines, at least I've never seen this used and I'm not sure how it could work.

Possible (dirty) solutions I can think of would be along the lines of having a script which scanned your feature files and updated the examples when you add a new browser (I can't imagine this is very often), or having a code snippet to add the examples text if the typing it in every scenario outline is the problem.


SpecFlow advises to use tags for these kind of scenarios. Maybe you did the Bookstore tutorial, then you'll recognize it from the tags that indicated if a scenario was a system or a browser test.

@Chrome @Firefox @IE    # <- feature wide, applicable for all scenariosFeature: Open GoogleScenario: Open Google in the browser    Given the browser is active    When I navigate to "https://www.google.co.uk/"    Then the title should be 'Google'@Lynx    # <- additional browser for a specific scenarioScenario: There is a Search button    Given the browser is active    When I navigate to "https://www.google.co.uk/"    Then I should see a button with label "Search"

Now you can run the testrunner for each tag/category.