Saturday, 13 December 2014

Ruby Cucumber - table data and parametrization

Scenario

 @test Scenario Outline: Testing for table and data
  Given I login with data <credentials>
  Then I test with data
    |first_name|last_name|middle_name|dob          |mobile_no |    |vicky     |G     |venu       |XXXXXXXX   |99xxxxxxxx    |  And I log out successfully

  Examples:  |credentials         |  |"myusername,mypassword"|

Step Definition:

Given(/^I login with data "([^"]*)"$/) do |credentials|
  puts credentials.class
  if credentials.include?(',')
    @arr_data=credentials.split(',')
    puts 'username is: '+ @arr_data[0]
    puts 'password is: '+ @arr_data[1]
  endend

Then(/^I test with data$/) do |table|
  begin  table.hashes.each do |hash|
     puts "first_name: #{hash['first_name']}"     puts "last_name: #{hash['last_name']}"     puts "middle_name: #{hash['middle_name']}"     puts "dob: #{hash['dob']}"     puts "mobile_no: #{hash['mobile_no']}"  end  rescue Exception=> e    puts e.message
  end
end
And(/^I log out successfully$/) do  pass
end

+++++++++++++++++Output++++++++++++++++++++

String

username is: myusername
password is: mypassword

first_name: vicky
last_name: gopi
middle_name: venu
dob: 09021986
mobile_no: 99xxxxxxxx

No comments:

Post a Comment