0

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|
paul
  • 4,333
  • 16
  • 71
  • 144

3 Answers3

1

First of all this is a pretty poor feature, better would be

Scenario: Test Users can login
   Given there are some test users
   When the test users login
   Then all test users should be logged in

or something like that. Features are for stating what you want to do and why, not how you do things.

IF you do the above then all the programming will be done in the step definitions. This will allow you do do whatever you want.

You can implement this quite easily e.g

Given 'there are some test users' do
  @test_users = create_test_users
end

When 'the test users login' do
  @login_results = login_each(@test_users)
end

Then 'all test users should be logged in' do
  expect(check_for_errors(@login_results).count).to eql 0
end

then implement the methods you need in a step helper e.g

module TestUsersLoginStepHelper
  def create_test_users
    ...

  def login_each(users)
    users.each do 
      ...
  ...
end
World TestUsersLoginStepHelper

By putting all the work in the step definitions, you make your live much easier, as you can use the full power of ruby to do what you need

diabolist
  • 3,990
  • 1
  • 11
  • 15
  • this is not what I asked in the question. But thanks for correcting the `.feature` file. – paul Jan 23 '15 at 06:28
  • Your welcome. So many questions about features, involve some sort of attempt to do programming in the feature. Features are not designed for programming, which is why its so difficult and clumsy to do programming in them. Do the programming lower down and everything becomes easier – diabolist Jan 23 '15 at 06:57
0

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
    
paul
  • 4,333
  • 16
  • 71
  • 144
-1

You can use this DDD scenario in project whenever its needed - by using this we do not need to create multiple test cases, it will fetch data value from Example outline.

Feature file : Test case

Scenario Outline: Login to application

When I enter "username>" and "password>"

Then I click Login button

And I see user successfully logged in

Examples:

|username|password|

|abc@gmail.com|Test1234!|

|abc@yahoo.com|Test1234!|


Step definition:

When(/^I enter "([^"])" and "([^"])"$/) do |username,password|

sleep 20

on(Login).email_edit_text_element.send_keys username on(Login).password_edit_text_element.send_keys password

end

Then(/^I click Login button$/) do sleep 20

on(Login).login_button_element.click

end

Then(/^I see user successfully logged in$/) do

expect(on(Login).account_bg_cover_element.displayed?).to be_truthy

puts 'Login Success' end

In ruby file, you have created methods, you are calling that methods in step definition. It will work. make sure about the name of parameter you are passing.