Skip to content

Commit

Permalink
Merge pull request teamcapybara#347 from jonleighton/master
Browse files Browse the repository at this point in the history
The at_exit hook to quit the selenium browser should not execute for unrelated child processes
  • Loading branch information
jnicklas committed May 23, 2011
2 parents aeb62d6 + 6dc024f commit cfb6ba9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/capybara/selenium/driver.rb
Expand Up @@ -13,8 +13,10 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
def browser
unless @browser
@browser = Selenium::WebDriver.for(options[:browser], options.reject { |key,val| SPECIAL_OPTIONS.include?(key) })

main = Process.pid
at_exit do
@browser.quit
quit if Process.pid == main
end
end
@browser
Expand Down Expand Up @@ -110,6 +112,12 @@ def within_window(selector, &blk)
browser.switch_to.window(handle, &blk)
end

def quit
@browser.quit
rescue Errno::ECONNREFUSED
# Browser must have already gone
end

private

def load_wait_for_ajax_support
Expand Down
14 changes: 14 additions & 0 deletions spec/driver/selenium_driver_spec.rb
@@ -1,4 +1,5 @@
require 'spec_helper'
require 'rbconfig'

describe Capybara::Selenium::Driver do
before do
Expand All @@ -12,4 +13,17 @@
it_should_behave_like "driver with support for window switching"
it_should_behave_like "driver without status code support"
it_should_behave_like "driver with cookies support"

unless Config::CONFIG['host_os'] =~ /mswin|mingw/
it "should not interfere with forking child processes" do
# Launch a browser, which registers the at_exit hook
browser = Capybara::Selenium::Driver.new(TestApp).browser

# Fork an unrelated child process. This should not run the code in the at_exit hook.
pid = fork { "child" }
Process.wait2(pid)[1].exitstatus.should == 0

browser.quit
end
end
end

0 comments on commit cfb6ba9

Please sign in to comment.