Question

I have a problem creating browser instances for Cucumber drivers. If i create the object on env.rb inside the “Before do” as:

Before do
@browser = Watir::Browser.new 'firefox'
end

…works fine, opening a new browser for each feature and closing it on the “After do”.

That slows the execution because a new browser starts and closes every feature. But if i create the @browser out of the “Before do” in order to have the same browser session for all the features, i have the following error:

**Unable to pick a platform for the provided browser (RuntimeError)**

...launching no test at all. I'm using the page-objects gem, ruby-on-rails...

Can you tell me please what am i doing wrong? Thank you so much!

Was it helpful?

Solution

I am not exactly sure where the error you are getting is coming from, but I would guess it is is a scope issue. If you declare @browser just in env.rb (not in the hook), then @browser will be nil in your steps.

Alister Scott had a good example of setting up to only open the browser once (http://watir.com/2011/01/22/simple-cucumber-watir-page-object-pattern-framework/).

Basically you want the following (noting which variables are browser vs @browser):

browser = Watir::Browser.new 'firefox'

Before do
  @browser = browser
end

at_exit do
  browser.close
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top