ruby - Selenium chromedriver not playing nice with at_exit -
is bug in code, or bug in selenium, rspec, etc.?
the cucumber tests i'm writing need shut down , re-launch chrome driver. however, can't second driver shut down properly. stripped-down example below shows problem: (the code below rspec because demonstrates issue without adding complexity of cucumber.)
require 'selenium-webdriver' rspec.configure |config| config.before(:suite) $driver = selenium::webdriver.for :chrome end end describe "a potential rspec/selenium/chrome driver bug" "doesn't play nice at_exit" # quit initial driver , start new one. $driver.quit $driver = selenium::webdriver.for :chrome end # end # end describe at_exit $driver.quit end when run code 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) /system/library/frameworks/ruby.framework/versions/2.0/usr/lib/ruby/2.0.0/net/http.rb:878:in `open' /system/library/frameworks/ruby.framework/versions/2.0/usr/lib/ruby/2.0.0/net/http.rb:878:in `block in connect' /system/library/frameworks/ruby.framework/versions/2.0/usr/lib/ruby/2.0.0/timeout.rb:52:in `timeout' i can tell second chromedriver process no longer running when at_exit block runs. causes problem because whatever mechanism causing shutdown leaving chrome window open.
rspec's after(:suite) mechanism works expected. there corresponding mechanism cucumber (other at_exit, isn't working in case)? or, there way prevent chomedriver exiting before at_exit block runs (so can shut down using quit method expected)?
i'm running ruby 2.0.0 on mac os 10.9.5 using latest selenium , rspec packages.
the problem bug in code. driver needs created before env.rb defines own at_exit hook. here's why:
a typical env.rb cucumber looks this:
$driver = selenium::webdriver.for :chrome, :switches => %w[--disable-cache --ignore-certificate-errors] at_exit $driver.quit end the code creates driver object (selenium::webdriver.for :chrome) registers at_exit hook shuts down chromedriver process.
at_exit hooks run in opposite order created. therefore, typical execution of cucumber looks this:
env.rbcreates new driver- driver defines
at_exithook quit itself env.rbdefinesat_exithook quit driver- cucumber features run
at_exithookenv.rbcalled- driver's
at_exithook called
in case, created driver inside cucumber feature, caused driver's at_exit hook defined after at_exit hook in env.rb. result, driver's at_exit hook runs first, causing call $driver.quit in env.rb fail.
the best solution in case create second driver when necessary , destroy second driver @ end of scenario (as opposed replacing primary driver new one).
thanks alex rodionov pointing out mistakes. https://github.com/seleniumhq/selenium/issues/742
Comments
Post a Comment