Is this a bug in my code, or a bug in Selenium, RSpec, etc.?
The Cucumber tests I'm writing need to shut down and re-launch the Chrome driver. However, I can't get this second driver to shut down properly. The stripped-down example below shows the problem: (The code below is RSpec only because it demonstrates the issue without adding the complexity of Cucumber.)
require 'selenium-webdriver'
RSpec.configure do |config|
config.before(:suite) do
$driver = Selenium::WebDriver.for :chrome
end
end
describe "A potential rspec/selenium/chrome driver bug" do
it "doesn't play nice with at_exit" do
# quit the initial driver and start a new one.
$driver.quit
$driver = Selenium::WebDriver.for :chrome
end # it
end # end describe
at_exit do
$driver.quit
end
When I run this code I get the following error:
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/http.rb:878:in `initialize': Connection refused - connect(2) (Errno::ECONNREFUSED)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/http.rb:878:in `open'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/http.rb:878:in `block in connect'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/timeout.rb:52:in `timeout'
I can tell that the second chromedriver process no longer running when the at_exit
block runs. This causes a problem because whatever mechanism is causing the shutdown is leaving the Chrome window open.
RSpec's after(:suite)
mechanism works as expected. Is there a corresponding mechanism for Cucumber (other than at_exit
, which isn't working in this case)? Or, is there a way to prevent chomedriver from exiting before the at_exit
block runs (so I can shut it down using the quit
method as expected)?
I'm running Ruby 2.0.0 on Mac OS 10.9.5 using the latest selenium and rspec packages.