I came across a need to run my tests across multiple environments.  For example:
Integration Environment, vs QA 1 vs QA 2.  Different versions or branches of the web app could be stood up in either location.

The method I used to achieve this was with the use of hooks.  But I hit a little snag, and found out my error.

What I did was this:

In my /support/env.rb file (within the Cucumber folder), I have this:
def browser_name
  (ENV[‘BROWSER’] ||= ‘firefox’).downcase.to_sym
end

def environment
  (ENV[‘ENVI’] ||= ‘int’).downcase.to_sym
end

Before do  |scenario|
  p “Starting #{scenario}”
  if environment == :int
    @browser = Watir::Browser.new browser_name
    @browser.goto “http://integration.atmysite.com:8080”
    @browser.send_keys :return
  elsif environment == :qa1
    @browser = Watir::Browser.new browser_name
    @browser.goto “http://qa1.atmysite.com:8080”
    @browser.send_keys :return
  else
    @browser = Watir::Browser.new browser_name
    @browser.goto “http://qa2.atmysite.com:8080”
    @browser.send_keys :return
  end
end

The first method defines the browser from the command line, this is useful for use with Jenkins or other batch file runs, that I can set the browser to be used in the test via the command line.  I learned this from an online resource someplace.

The second method there is similar – I based this on the previous. I’m saying take the value ENVI and it’s value… then in the Before block I say:
If that environment method is :int, then run this login block… if it’s :qa1, run this login block… else go to this other location.

I’ll prob enhance that to where’s instead of if statements at some point.

Where I initially errored on this, I was setting the equality to “int” rather then “int”… and I couldn’t figure out why it wasn’t working.  So I debugged it, by putting in a puts environment during the test run.  It was outputting :int.  So the parameter value was getting set as a symbol (i.e. :something.)

Once I updated the if statements to be :int, :qa1, :qa2 everything worked great.

Now I dont need the login helper I was using.  This before hook takes care of the login, based on the environment value I pass.

Leave a Reply

Your email address will not be published. Required fields are marked *