Improved handling of closing browser windows.

This commit is contained in:
Martin Edenhofer 2014-12-14 14:13:46 +01:00
parent a00410758a
commit 1d520f3b47
2 changed files with 20 additions and 24 deletions

View file

@ -157,13 +157,13 @@ class AaaGettingStartedTest < TestCase
:execute => 'watch_for', :execute => 'watch_for',
:area => 'body', :area => 'body',
:value => 'verify', :value => 'verify',
:timeout => 70, :timeout => 20,
}, },
{ {
:execute => 'watch_for', :execute => 'watch_for',
:area => 'body', :area => 'body',
:value => 'invite', :value => 'invite',
:timeout => 60, :timeout => 100,
}, },
{ {
:execute => 'check', :execute => 'check',
@ -291,12 +291,13 @@ class AaaGettingStartedTest < TestCase
:execute => 'watch_for', :execute => 'watch_for',
:area => 'body', :area => 'body',
:value => 'verify', :value => 'verify',
:timeout => 80, :timeout => 20,
}, },
{ {
:execute => 'watch_for', :execute => 'watch_for',
:area => 'body', :area => 'body',
:value => 'invite', :value => 'invite',
:timeout => 100,
}, },
{ {
:execute => 'check', :execute => 'check',

View file

@ -20,12 +20,12 @@ class TestCase < Test::Unit::TestCase
def browser_instance def browser_instance
if !@browsers if !@browsers
@browsers = [] @browsers = {}
end end
if !ENV['REMOTE_URL'] || ENV['REMOTE_URL'].empty? if !ENV['REMOTE_URL'] || ENV['REMOTE_URL'].empty?
local_browser = Selenium::WebDriver.for( browser.to_sym ) local_browser = Selenium::WebDriver.for( browser.to_sym )
browser_instance_preferences(local_browser) browser_instance_preferences(local_browser)
@browsers.push local_browser @browsers[local_browser.hash] = local_browser
return local_browser return local_browser
end end
@ -38,9 +38,16 @@ class TestCase < Test::Unit::TestCase
:desired_capabilities => caps, :desired_capabilities => caps,
) )
browser_instance_preferences(local_browser) browser_instance_preferences(local_browser)
@browsers.push local_browser @browsers[local_browser.hash] = local_browser
return local_browser return local_browser
end 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) def browser_instance_preferences(local_browser)
#local_browser.manage.window.resize_to(1024, 1024) #local_browser.manage.window.resize_to(1024, 1024)
if ENV['REMOTE_URL'] !~ /saucelabs/i if ENV['REMOTE_URL'] !~ /saucelabs/i
@ -55,21 +62,9 @@ class TestCase < Test::Unit::TestCase
def teardown def teardown
return if !@browsers return if !@browsers
@browsers.each { |hash, local_browser|
# only shut down browser type once on local webdriver tests browser_instance_close(local_browser)
# 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
end end
# Add more helper methods to be used by all tests here... # Add more helper methods to be used by all tests here...
@ -133,8 +128,8 @@ class TestCase < Test::Unit::TestCase
} }
end end
} }
instance1.close browser_instance_close(instance1)
instance2.close browser_instance_close(instance2)
end end
def browser_single_test(tests, keep_connection = false) def browser_single_test(tests, keep_connection = false)
@ -160,7 +155,7 @@ class TestCase < Test::Unit::TestCase
if keep_connection if keep_connection
return instance return instance
end end
instance.close browser_instance_close(instance)
end end
def browser_element_action(test, action, instance) def browser_element_action(test, action, instance)