Domanda

I'm trying to execute an entire SpecFlow Feature using three different UserID/Password combinations. I'm struggling to find a way to do this in the .feature file without having to introduce any loops in the MSTest.

On the Scenario level I'm doing this:

Scenario Template: Verify the addition functionality
Given the value <x>
And the value <y>
When I add the values together 
Then the result should be <z>

Examples:
|x|y|z|
|1|2|3|
|2|2|4|
|2|3|5|

Is there a way to do a similar table at the feature level that will cause the entire feature to be executed for each row in the table?

Is there other functionality available to do the same thing?

È stato utile?

Soluzione 2

"Is there a way to do a similar table at the feature level that will cause the entire feature to be executed for each row in the table?"

No, Specflow (and indeed the Gherkin language) doesn't have a concept of a "Feature Outline" i.e. a way of specifying a collection of features which should be run in their entirety.

You could possibly achiever what you are looking for by making use of Specflow tags to tag related scenarios. You could then use your test runner to trigger the testing of all the scenarios with that tag e.g.

@related
Scenario: A
    Given ...etc...

@related
Scenario: B
    Given ...etc.

Altri suggerimenti

I don't think the snippet you have is working is it? I've updated the below with the corrections I think you need (as Fresh also points out) and a couple of possible improvements.

With this snippet, you'll see that the scenario is run for each line in the table of examples. So, the first test will connect with 'Bob' and 'password', ask your tool to add 1 and 2 and check that the answer is 3.

I've also added an ID column - that is optional but I find it much easier to read the results with an ID number.

Scenario Outline: Verify the addition functionality
    Given I am connecting with <username> and <password>
    When I add <x> and <y> together 
    Then the result should be <total>

Examples:
    | ID | username | password | x | y | total |
    | 1  | Bob      | password | 1 | 2 | 3     |
    | 2  | Helen    | Hello123 | 1 | 2 | 3     |
    | 3  | Dave     | pa£sword | 1 | 2 | 3     |
    | 4  | Bob      | password | 2 | 3 | 5     |
    | 5  | Helen    | Hello123 | 2 | 3 | 5     |
    | 6  | Dave     | pa£sword | 2 | 3 | 5     |
    | 7  | Bob      | password | 2 | 2 | 4     |
    | 8  | Helen    | Hello123 | 2 | 2 | 4     |
    | 9  | Dave     | pa£sword | 2 | 2 | 4     |

SpecFlow+ Runner (aka SpecRun, http://www.specflow.org/plus/), provides infrastructure (called test targets) to be able to run the same test suite (or selected scenarios) with different settings. With this you can solve problems like the one you have mentioned. It can be also used to run the same web tests with different browsers, etc. Check this screencast for details: http://www.youtube.com/watch?v=RZYV4Dvhw3w

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top