The at_exit hook to quit the selenium browser should not execute for unrelated child processes
This commit is contained in:
parent
aeb62d6063
commit
97da26eef4
|
@ -13,8 +13,10 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
|
||||||
def browser
|
def browser
|
||||||
unless @browser
|
unless @browser
|
||||||
@browser = Selenium::WebDriver.for(options[:browser], options.reject { |key,val| SPECIAL_OPTIONS.include?(key) })
|
@browser = Selenium::WebDriver.for(options[:browser], options.reject { |key,val| SPECIAL_OPTIONS.include?(key) })
|
||||||
|
|
||||||
|
main = Process.pid
|
||||||
at_exit do
|
at_exit do
|
||||||
@browser.quit
|
quit if Process.pid == main
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@browser
|
@browser
|
||||||
|
@ -110,6 +112,12 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
|
||||||
browser.switch_to.window(handle, &blk)
|
browser.switch_to.window(handle, &blk)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def quit
|
||||||
|
@browser.quit
|
||||||
|
rescue Errno::ECONNREFUSED
|
||||||
|
# Browser must have already gone
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def load_wait_for_ajax_support
|
def load_wait_for_ajax_support
|
||||||
|
|
|
@ -12,4 +12,15 @@ describe Capybara::Selenium::Driver do
|
||||||
it_should_behave_like "driver with support for window switching"
|
it_should_behave_like "driver with support for window switching"
|
||||||
it_should_behave_like "driver without status code support"
|
it_should_behave_like "driver without status code support"
|
||||||
it_should_behave_like "driver with cookies support"
|
it_should_behave_like "driver with cookies support"
|
||||||
|
|
||||||
|
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
|
||||||
|
|
Loading…
Reference in New Issue