From 1d520f3b47414c8f97f4286cd8872b935acccf4d Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sun, 14 Dec 2014 14:13:46 +0100 Subject: [PATCH] Improved handling of closing browser windows. --- test/browser/aaa_getting_started_test.rb | 7 +++-- test/browser_test_helper.rb | 37 ++++++++++-------------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/test/browser/aaa_getting_started_test.rb b/test/browser/aaa_getting_started_test.rb index 5797c4338..1d62a2031 100644 --- a/test/browser/aaa_getting_started_test.rb +++ b/test/browser/aaa_getting_started_test.rb @@ -157,13 +157,13 @@ class AaaGettingStartedTest < TestCase :execute => 'watch_for', :area => 'body', :value => 'verify', - :timeout => 70, + :timeout => 20, }, { :execute => 'watch_for', :area => 'body', :value => 'invite', - :timeout => 60, + :timeout => 100, }, { :execute => 'check', @@ -291,12 +291,13 @@ class AaaGettingStartedTest < TestCase :execute => 'watch_for', :area => 'body', :value => 'verify', - :timeout => 80, + :timeout => 20, }, { :execute => 'watch_for', :area => 'body', :value => 'invite', + :timeout => 100, }, { :execute => 'check', diff --git a/test/browser_test_helper.rb b/test/browser_test_helper.rb index a65948275..7d3438c25 100644 --- a/test/browser_test_helper.rb +++ b/test/browser_test_helper.rb @@ -20,12 +20,12 @@ class TestCase < Test::Unit::TestCase def browser_instance if !@browsers - @browsers = [] + @browsers = {} end if !ENV['REMOTE_URL'] || ENV['REMOTE_URL'].empty? local_browser = Selenium::WebDriver.for( browser.to_sym ) browser_instance_preferences(local_browser) - @browsers.push local_browser + @browsers[local_browser.hash] = local_browser return local_browser end @@ -38,9 +38,16 @@ class TestCase < Test::Unit::TestCase :desired_capabilities => caps, ) browser_instance_preferences(local_browser) - @browsers.push local_browser + @browsers[local_browser.hash] = local_browser return local_browser end + + def browser_instance_close(local_browser) + return if !@browsers[local_browser.hash] + @browsers.delete( local_browser.hash ) + local_browser.quit + end + def browser_instance_preferences(local_browser) #local_browser.manage.window.resize_to(1024, 1024) if ENV['REMOTE_URL'] !~ /saucelabs/i @@ -55,21 +62,9 @@ class TestCase < Test::Unit::TestCase def teardown return if !@browsers - - # only shut down browser type once on local webdriver tests - # otherwise this error will happen "Errno::ECONNREFUSED: Connection refused - connect(2)" - if !ENV['REMOTE_URL'] - shutdown = {} - @browsers.each{ |local_browser| - next if shutdown[ local_browser.browser ] - shutdown[ local_browser.browser ] = true - local_browser.quit - } - else - @browsers.each{ |local_browser| - local_browser.quit - } - end + @browsers.each { |hash, local_browser| + browser_instance_close(local_browser) + } end # Add more helper methods to be used by all tests here... @@ -133,8 +128,8 @@ class TestCase < Test::Unit::TestCase } end } - instance1.close - instance2.close + browser_instance_close(instance1) + browser_instance_close(instance2) end def browser_single_test(tests, keep_connection = false) @@ -160,7 +155,7 @@ class TestCase < Test::Unit::TestCase if keep_connection return instance end - instance.close + browser_instance_close(instance) end def browser_element_action(test, action, instance)