Improved speed of tests.

This commit is contained in:
Martin Edenhofer 2015-02-24 02:31:17 +01:00
parent a5bbd8891b
commit 747e18a200
2 changed files with 112 additions and 148 deletions

View file

@ -3,149 +3,97 @@ require 'browser_test_helper'
class SettingTest < TestCase
def test_setting
tests = [
{
:name => 'setting',
:action => [
{
:execute => 'click',
:css => 'a[href="#manage"]',
},
{
:execute => 'click',
:css => 'a[href="#settings/security"]',
},
{
:execute => 'click',
:css => 'a[href="#third_party_auth"]',
},
{
:execute => 'check',
:css => '#auth_facebook select[name="auth_facebook"]',
:result => true,
},
@browser = browser_instance
login(
:username => 'master@example.com',
:password => 'test',
:url => browser_url,
)
tasks_close_all()
click( :css => 'a[href="#manage"]' )
click( :css => 'a[href="#settings/security"]' )
click( :css => 'a[href="#third_party_auth"]' )
# set yes
{
:execute => 'select',
:css => '#auth_facebook select[name="auth_facebook"]',
select(
:css => '#auth_facebook select[name="{boolean}auth_facebook"]',
:value => 'yes',
},
{
:execute => 'click',
:css => '#auth_facebook button[type=submit]',
},
{
:execute => 'wait',
:value => 6,
},
{
:execute => 'match',
:css => '#auth_facebook select[name="auth_facebook"]',
)
click( :css => '#auth_facebook button[type=submit]' )
watch_for(
:css => '#auth_facebook select[name="{boolean}auth_facebook"]',
:value => 'yes',
:match_result => true,
},
{
:execute => 'match',
:css => '#auth_facebook select[name="auth_facebook"]',
)
match_not(
:css => '#auth_facebook select[name="{boolean}auth_facebook"]',
:value => 'no',
:match_result => false,
},
)
# set no
{
:execute => 'select',
:css => '#auth_facebook select[name="auth_facebook"]',
select(
:css => '#auth_facebook select[name="{boolean}auth_facebook"]',
:value => 'no',
},
{
:execute => 'click',
:css => '#auth_facebook button[type=submit]',
},
{
:execute => 'wait',
:value => 6,
},
{
:execute => 'match',
:css => '#auth_facebook select[name="auth_facebook"]',
)
click( :css => '#auth_facebook button[type=submit]' )
watch_for(
:css => '#auth_facebook select[name="{boolean}auth_facebook"]',
:value => 'no',
)
match_not(
:css => '#auth_facebook select[name="{boolean}auth_facebook"]',
:value => 'yes',
:match_result => false,
},
{
:execute => 'match',
:css => '#auth_facebook select[name="auth_facebook"]',
:value => 'no',
:match_result => true,
},
)
# set key and secret
{
:execute => 'set',
set(
:css => '#auth_facebook_credentials input[name=app_id]',
:value => 'id_test1234äöüß',
},
{
:execute => 'set',
)
set(
:css => '#auth_facebook_credentials input[name=app_secret]',
:value => 'secret_test1234äöüß',
},
{
:execute => 'click',
:css => '#auth_facebook_credentials button[type=submit]',
},
{
:execute => 'wait',
:value => 6,
},
{
:execute => 'match',
)
click( :css => '#auth_facebook_credentials button[type=submit]' )
sleep 4
watch_for(
:css => '#auth_facebook_credentials input[name=app_id]',
:value => 'id_test1234äöüß',
:match_result => true,
},
{
:execute => 'match',
)
watch_for(
:css => '#auth_facebook_credentials input[name=app_secret]',
:value => 'secret_test1234äöüß',
:match_result => true,
},
)
# set key and secret again
{
:execute => 'set',
set(
:css => '#auth_facebook_credentials input[name=app_id]',
:value => '---',
},
{
:execute => 'set',
)
set(
:css => '#auth_facebook_credentials input[name=app_secret]',
:value => '---',
},
{
:execute => 'click',
:css => '#auth_facebook_credentials button[type=submit]',
},
{
:execute => 'wait',
:value => 6,
},
{
:execute => 'match',
)
click( :css => '#auth_facebook_credentials button[type=submit]' )
sleep 4
watch_for(
:css => '#auth_facebook_credentials input[name=app_id]',
:value => '---',
:match_result => true,
},
{
:execute => 'match',
)
watch_for(
:css => '#auth_facebook_credentials input[name=app_secret]',
:value => '---',
:match_result => true,
},
)
],
},
]
browser_signle_test_with_login(tests, { :username => 'master@example.com' })
reload()
watch_for(
:css => '#auth_facebook_credentials input[name=app_id]',
:value => '---',
)
watch_for(
:css => '#auth_facebook_credentials input[name=app_secret]',
:value => '---',
)
end
end

View file

@ -275,9 +275,16 @@ class TestCase < Test::Unit::TestCase
def select(params)
instance = params[:browser] || @browser
begin
element = instance.find_elements( { :css => params[:css] } )[0]
dropdown = Selenium::WebDriver::Support::Select.new(element)
dropdown.select_by(:text, params[:value])
rescue
# just try again
element = instance.find_elements( { :css => params[:css] } )[0]
dropdown = Selenium::WebDriver::Support::Select.new(element)
dropdown.select_by(:text, params[:value])
end
end
=begin
@ -379,7 +386,7 @@ class TestCase < Test::Unit::TestCase
end
end
# match pn attribute
# match on attribute
if params[:attribute]
text = element.attribute( params[:attribute] )
elsif params[:css] =~ /(input|textarea)/i
@ -489,6 +496,7 @@ class TestCase < Test::Unit::TestCase
:browser => browser1,
:css => true,
:value => 'some text',
:attribute => 'some_attribute' # optional
:timeout => '16', # in sec, default 16
)
@ -507,7 +515,15 @@ class TestCase < Test::Unit::TestCase
element = instance.find_elements( { :css => params[:css] } )[0]
if element #&& element.displayed?
begin
# match pn attribute
if params[:attribute]
text = element.attribute( params[:attribute] )
elsif params[:css] =~ /(input|textarea)/i
text = element.attribute('value')
else
text = element.text
end
if text =~ /#{params[:value]}/i
assert( true, "'#{params[:value]}' found in '#{text}'" )
sleep 0.5