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

View file

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