2

i am doing automated testing using calabash-ios. I want to be able to run cucumber once and have it run x times for x user names and run through the gamut of test scenarios.

i want to use this:

Given I login as [#{country-name}] user using id [#{Login-name}] and pwd "PASSWORD" and have a global variable that can store the values for both country and user name.

i had hoped to use scripts to run cucumber x times and set the value for the global variables each time. is this possible? and if so, could someone point me in the right direction?

i tried using : @@Loginname=value but got this error: features/step_definitions/common.rb:1: warning: class variable access from toplevel uninitialized class variable @@Login in Object (NameError)

failing which, will it be possible to access data stored in a xml or css file using calabash?

s5v
  • 495
  • 5
  • 20

1 Answers1

4

If you want to run the same cucumber run many times with some different variables you can just use environment variables.

Given I login as "ENV['COUNTRY_NAME']" user using id "ENV['LOGIN_NAME']" and pwd "PASSWORD"

And then when you run the tests

LOGIN_NAME='login name' COUNTRY_NAME=country bundle exec cucumber 

And then of course you can put all of the lines you want to run into a bat or sh script.

One thing to be careful of is to use the environment variables or another one to change the path for the outputs so you don't overwrite them.

However, a more elegant solution would be to handle it with a rake task that ran all of the other tasks. The most efficient way to write that would depend on how many different runs you need.

task :all => [:task1, :task2, :task3]

EDIT: To make your scenarios more readable, you should use a generic placeholder in the scenario and hide the environment variables in the step definition.

    Given I login as a user

Might have a step definition that looked like:

Given /^I login as a user$/ do
  ... set up your page object here ...     
  login_page.login(ENV['COUNTRY_NAME'], ENV['LOGIN_NAME'])
end
alannichols
  • 1,496
  • 1
  • 10
  • 20
  • thank you. did not think about using env variables. that should do the trick. i do not know what a rake task is, and that will be my first task that i look up after i have my tests running using sh scripts and env variables. – s5v Apr 16 '15 at 05:41
  • i tried what you suggested. my question is, how do i make use of the env variables in steps? i attempted to use COUNTRY_NAME as it is, and [\ENV[\'COUNTRY_NAME'\]\]. hope you can help me with this. – s5v Apr 16 '15 at 12:00
  • To reference them in your code you call them like this - ENV['COUNTRY_NAME']. I've updated my answer at the bottom to make it nicer though. Hopefully it makes sense. – alannichols Apr 20 '15 at 10:35