5

How to parameterize tables in Specflow? Here is my feature file -

Feature: Login

    As a User,
    should land on ***** Login page
    Enter valid Username and password
    Home page displayed-Validate Logout link

Scenario: Successful login
    Given I am on **** Login page
    When I enter automation and autopassword
    Then the logout link should be displayed

    Scenario: Successful parameterized Login
    Given I am on **** Login page
    When I enter:
    | Username    | Password     |
    | automation  | autopassword |
    | misc        | misc123      |
    Then the Logout link should be displayed

Here are my queries - I want to test a login using the second row values - misc & misc123. How can I call it using selenium? How can I make the parameterized part a complete scenario set- considering there are more scenarios after logging in? The test runs a complete feature with the first row and then execute the test logging in as second.

4
  • If you want to use multiple logins one by one then you can do keywork driver setup means get value from excel for username and pass and pass it to web page using selenium web driver code. OR you can create array and store value in that and then pass it for logins. Feb 6, 2015 at 6:30
  • How do we integrate the feature file on specflow to get value from excel? Is it possible to keyword drive? Feb 8, 2015 at 1:13
  • Please check all details here : ontestautomation.com/… Feb 9, 2015 at 3:49
  • Hello Chan, if possible could you approve my answer?
    – Mo H.
    Mar 10, 2015 at 13:40

1 Answer 1

5

Instead of using using a Table element, turn it into a Scenario Outline. So your Scenario would become.

Scenario Outline: Successful Login
Given I am on **** Login
When I enter <UserName> and <Password>
Then the logout link should be displayed

Examples: 
| UserName | Password |
| Foo      | Bar      |
| Bar      | Foo      |

This will run through each set of examples.

3
  • I am new to Specflow , so maybe the solution to my issue is simple. But when I update my existing feature file to include Scenario outline, getting this Error - #error There are no examples defined for the scenario outline.In Step definition added this step - [When(@"I enter (.*) and (.*)")] public void WhenIEnterAnd(string uname, string pwd) { LoginPage vlp = new LoginPage(WebBrowser.Current); vlp.Login(uname, pwd); Feb 9, 2015 at 0:38
  • Thanks Muhammad - Kind of answered my previous query myself. Missed the keyword Examples & Scenarios. Feb 9, 2015 at 1:16
  • I'm glad you were able to figure it out
    – Mo H.
    Feb 9, 2015 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.