Error when using the same browser instance for several features on Cucumber

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!

Answers


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

Need Your Help

Task Schedule Refusal

windows-xp scheduled-tasks

Although some might not think of it as programming related, it certainly is. The task Scheduler is a program. It's launching a process that I have written. Stating that it's a common problem i...

Import a python module without the .py extension

python import

I have a file called foobar (without .py extension). In the same directory I have another python file that tries to import it: