Added feature to check if browser supports accessing cookies via selenium.

This commit is contained in:
Martin Edenhofer 2013-06-25 16:00:28 +02:00
parent 167f41fc6b
commit 41abfde4f6

View file

@ -4,6 +4,17 @@ require 'rails/test_help'
require 'selenium-webdriver' require 'selenium-webdriver'
class TestCase < Test::Unit::TestCase class TestCase < Test::Unit::TestCase
def browser
ENV['BROWSER'] || 'firefox'
end
def browser_support_cookies
if browser =~ /(internet_explorer|ie)/i
return false
end
return true
end
def browser_url def browser_url
ENV['BROWSER_URL'] || 'http://localhost:3000' ENV['BROWSER_URL'] || 'http://localhost:3000'
end end
@ -13,24 +24,21 @@ class TestCase < Test::Unit::TestCase
@browsers = [] @browsers = []
end end
if !ENV['REMOTE_URL'] if !ENV['REMOTE_URL']
if !ENV['BROWSER'] local_browser = Selenium::WebDriver.for( browser.to_sym )
ENV['BROWSER'] = 'firefox' @browsers.push local_browser
end return local_browser
browser = Selenium::WebDriver.for( ENV['BROWSER'].to_sym )
@browsers.push browser
return browser
end end
caps = Selenium::WebDriver::Remote::Capabilities.send( ENV['BROWSER'] ) caps = Selenium::WebDriver::Remote::Capabilities.send( browser )
caps.platform = ENV['BROWSER_OS'] || 'Windows 2008' caps.platform = ENV['BROWSER_OS'] || 'Windows 2008'
caps.version = ENV['BROWSER_VERSION'] || '8' caps.version = ENV['BROWSER_VERSION'] || '8'
browser = Selenium::WebDriver.for( local_browser = Selenium::WebDriver.for(
:remote, :remote,
:url => ENV['REMOTE_URL'], :url => ENV['REMOTE_URL'],
:desired_capabilities => caps, :desired_capabilities => caps,
) )
@browsers.push browser @browsers.push local_browser
return browser return local_browser
end end
def teardown def teardown
@ -39,10 +47,10 @@ class TestCase < Test::Unit::TestCase
# only shut down browser type once # only shut down browser type once
# otherwise this error will happen "Errno::ECONNREFUSED: Connection refused - connect(2)" # otherwise this error will happen "Errno::ECONNREFUSED: Connection refused - connect(2)"
shutdown = {} shutdown = {}
@browsers.each{ |browser| @browsers.each{ |local_browser|
next if shutdown[ browser.browser ] next if shutdown[ local_browser.browser ]
shutdown[ browser.browser ] = true shutdown[ local_browser.browser ] = true
browser.quit local_browser.quit
} }
end end
@ -194,6 +202,9 @@ class TestCase < Test::Unit::TestCase
end end
return return
elsif action[:element] == :cookie elsif action[:element] == :cookie
if !browser_support_cookies
assert( true, "(#{test[:name]}) '#{action[:value]}' ups browser is not supporting reading cookies")
end
cookies = instance.manage.all_cookies cookies = instance.manage.all_cookies
cookies.each {|cookie| cookies.each {|cookie|
if cookie.to_s =~ /#{action[:value]}/i if cookie.to_s =~ /#{action[:value]}/i