user1523236
user1523236

Reputation: 1473

Launch different browsers using Capybara/Cucumber

I wish to be able to run my tests against different browsers. I have written the following method to do this and this is in my env file.

def startbrowser()
  if BROWSER == "ff"
    Capybara.register_driver :selenium do |app|
      Capybara::Selenium::Driver.new(app, :browser => :firefox )
    end


    else
    Capybara.register_driver :selenium do |app|
      Capybara::Selenium::Driver.new(app, :browser => :chrome )
    end
end


  session = startbrowser()
  session.visit(@base_url)

The above should launch firefox if ff is supplied but should default to chrome as this is the browser I use for most of my testing. So the command I would use in the terminal would be: cucumber --tags @tests BROWSER=ff.

However this does not work. It does not give me an error, but it always launches firefox even if I dont supply 'BROWSER = ff' part. In theory it should default to chrome. I can successfully launch chrome browser if I don't have the command in the method, but I wish to be able to switch between browsers and run different jobs from jenkins. Anybody got any idea what im doing wrong here?

Thanks!

Upvotes: 1

Views: 1351

Answers (1)

Nat Ritmeyer
Nat Ritmeyer

Reputation: 5678

The problem is that you're trying to access an environment variable incorrectly. You should change the following line:

if BROWSER == "ff"

...to...

if ENV['BROWSER'] == "ff"

Upvotes: 2

Related Questions