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:

  1. env.rb creates new driver
  2. driver defines at_exit hook quit itself
  3. env.rb defines at_exit hook quit driver
  4. cucumber features run
  5. at_exit hook env.rb called
  6. driver's at_exit hook 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

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -