简体   繁体   中英

Specflow. Parametrized tests

I have such user story:

Given I am on the 'Login page'
When I enter following credentials
     |Email |Pass |
     |email1|pass1|
     |email2|pass2|
Then I get next 'Error' messages
     |ErrorMessage |
     |ErrorMessage1|
     |ErrorMessage2|

How can this be done? The problem is that by my implementation, web driver is entering all the credentials from first table, and then try to assert error messages, but I need test to be run multiple times(kind of a loop).

you need to use a scenario outline :

Scenario Outline: some name...
    Given I am on the 'Login page'
    When I enter the email <email> and password <password>
    Then I get next the error message <errorMessage>
Examples:
    | email | password | errorMessage |
    | email1| pass1    | ErrorMessage1|
    | email2| pass2    | ErrorMessage2|

this will run the same test twice, once for each row in the Examples table. If you want the test to be run more times, just add more rows to the Examples table

As was pointed out in the comments, Examples is the defined term in gerkin, but Scenarios or Examples works fine in SpecFlow

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM