1

Background:

  1. There are more than 500 users. Their user name and password are stored in a CSV file.
  2. Each user must pass this .feature file which consists of 18 scenarios.

Problem: I know we can use data tables, scenario outline, but data mentioned here will be limited to associated scenarios only not for entire feature file.
I want once .feature done executing first row of data it should go to next row from CSV file, and continue doing it until the end of CSV file.

I tried replacing Data table with MS Excel sheet, used (POI apache files to read spreadsheet), but again same thing happened it ran for that particular scenario only.

E.g. This a .feature file

@regression @userValidation
Feature: User permission validation

  Scenario Outline: Verify that user is able to login
    Given I am on login page
    When I enter "username" and "password"
    Then I see new user successfully loggedin
 Examples:
      | username |password|  // picked from excel sheet
      | uname    |pwd     |  // picked from excel sheet

  Scenario: Verify that user can change the password
    Given I am on user profile page
    When I enter change password twice
    Then I get password successfully changed pop-up

Now, scenario one keep on running 500 times (number of rows in csv file) once all data is finished, it starts second scenario. What I want is it both scenario should run for row 1, then both scenario should for row 2 and so on for 500 times.

How can I do it? Is there a Java or Junit way to do it, if not possible in Cucumber?

I am using Java, Selenium WebDriver, JUnit, Cucumber, Maven on Windows

paul
  • 4,333
  • 16
  • 71
  • 144

1 Answers1

0

One of the way is adding examples in each scenario in the feature file, you are already reading data from external source so it will not duplicate data at scenario level. Still you need to add examples to each scenario. For example:

@regression @userValidation
Feature: User permission validation

Scenario Outline: Verify that user is able to login
    .....
Examples:
      | username |password|  // picked from excel sheet
      | uname    |pwd     |  // picked from excel sheet

Scenario Outline: Verify that user can change the password
  ...
Examples:
      | username |password|  // picked from excel sheet
      | uname    |pwd     |  // picked from excel sheet

In this case you need to be cautious on execution order of each scenario. If you use gherkin with qaf, it may look like below:

@regression @userValidation
Feature: User permission validation

 Scenario: Verify that user is able to login
    .....
 Examples: {'datafile':'resources/usersdata.csv'}

 Scenario: Verify that user can change the password
  ...
 Examples: {'datafile':'resources/usersdata.csv'}

More over, with latest BDD2 syntax, you can have your feature file as below:

@regression @userValidation
@datafile:resources/usersdata.csv
Feature: User permission validation

 Scenario: Verify that user is able to login
    .....

 Scenario: Verify that user can change the password
  ...

Regarding execution order, qaf makes sure to run scenario in order they defined in feature file. Still you can specify priority in meta-data when using BDD2 syntax, for instance, @priority:1 on first scenario, @priority:2 on second and so forth.

Other alternate for above case is change first scenario as per-condition and consider it as background, for that refer how to use background with examples.

user861594
  • 5,733
  • 3
  • 29
  • 45