I am automating test cases for a website using selenium-webdriver and cucumber in ruby. I need each feature to run in a particular order and using the same browser window. A
I had a similar problem in creating a spec_helper file. I did the following (simplified for locally-run firefox) for my purposes and it works very, very reliably. RSpec will use the same browser window for all it
blocks in your _spec.rb file.
Rspec.configure do |config|
config.before(:all) do
@driver = Selenium::WebDriver.for :firefox
end
config.after(:all) do
@driver.quit
end
end
If you switch to :each
instead of :all
, you can use a separate browser instance for each assertion block... again, with :each
RSpec will give a new browser instance for each it
. Both are useful depending on the circumstance.