Search code examples
rubycucumberfeature-file

Passing parameter in "Examples:" table of "Scenario Outline:" in a feature file


Here as you can see I am trying fetch a value from .yml file located in config/environments in Examples: table.

But instead of fetching it is sending the value as it is?

Is it possible to pass parameter like this? If Yes, how?

If not, which Ruby or Cucumber feature/concept refrains user to do so and why?

Feature: Verify login of all test users
I want to verify all test users can login.
  Scenario Outline: Login as different users on the website
    Given I am on login page
    When I enter "<username>" and password
    Then I click Login button
    And I see "<user>" successfully logged in
    Examples:
    |user|username|
    |testuser1|#{FigNewton.test1_email}|
    |testuser2|FigNewton.test2_email|

Solution

  • Answer to query1: You can parametrize via Examples: table but not directly passing value using FigNewton gem because it is a .feature file not a Ruby .rb file.

    Answer to query2: How you do it: Parametrize and Loop it on username and in you steps definition mention what to do when particular user name found. By this you can easily parametrize.

    1. Examples:

      |user|username|
      |testuser1|test1|
      |testuser2|test2|
      
    2. Step definition

      When(/^I enter "([^"]*)" and password$/) do |username|
      case username
      when 'test1'
        on(LoginPage).user_email = FigNewton.test1_email
      when 'test'
        on(LoginPage).user_email = FigNewton.test2_email
      end
      ....
      ....
      end