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()
},
{ click( :css => 'a[href="#manage"]' )
:execute => 'click', click( :css => 'a[href="#settings/security"]' )
:css => 'a[href="#settings/security"]', click( :css => 'a[href="#third_party_auth"]' )
},
{
:execute => 'click',
:css => 'a[href="#third_party_auth"]',
},
{
:execute => 'check',
:css => '#auth_facebook select[name="auth_facebook"]',
:result => true,
},
# set yes # set yes
{ select(
:execute => 'select', :css => '#auth_facebook select[name="{boolean}auth_facebook"]',
:css => '#auth_facebook select[name="auth_facebook"]',
:value => 'yes', :value => 'yes',
}, )
{ click( :css => '#auth_facebook button[type=submit]' )
:execute => 'click', watch_for(
:css => '#auth_facebook button[type=submit]', :css => '#auth_facebook select[name="{boolean}auth_facebook"]',
},
{
:execute => 'wait',
:value => 6,
},
{
:execute => 'match',
:css => '#auth_facebook select[name="auth_facebook"]',
:value => 'yes', :value => 'yes',
:match_result => true, )
}, match_not(
{ :css => '#auth_facebook select[name="{boolean}auth_facebook"]',
:execute => 'match',
:css => '#auth_facebook select[name="auth_facebook"]',
:value => 'no', :value => 'no',
:match_result => false, )
},
# set no # set no
{ select(
:execute => 'select', :css => '#auth_facebook select[name="{boolean}auth_facebook"]',
:css => '#auth_facebook select[name="auth_facebook"]',
:value => 'no', :value => 'no',
}, )
{ click( :css => '#auth_facebook button[type=submit]' )
:execute => 'click', watch_for(
:css => '#auth_facebook button[type=submit]', :css => '#auth_facebook select[name="{boolean}auth_facebook"]',
}, :value => 'no',
{ )
:execute => 'wait', match_not(
:value => 6, :css => '#auth_facebook select[name="{boolean}auth_facebook"]',
},
{
:execute => 'match',
:css => '#auth_facebook select[name="auth_facebook"]',
:value => 'yes', :value => 'yes',
:match_result => false, )
},
{
:execute => 'match',
:css => '#auth_facebook select[name="auth_facebook"]',
:value => 'no',
:match_result => true,
},
# set key and secret # 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 => 'id_test1234äöüß',
}, )
{ set(
:execute => 'set',
:css => '#auth_facebook_credentials input[name=app_secret]', :css => '#auth_facebook_credentials input[name=app_secret]',
:value => 'secret_test1234äöüß', :value => 'secret_test1234äöüß',
}, )
{ click( :css => '#auth_facebook_credentials button[type=submit]' )
:execute => 'click', sleep 4
:css => '#auth_facebook_credentials button[type=submit]', watch_for(
},
{
:execute => 'wait',
:value => 6,
},
{
:execute => 'match',
:css => '#auth_facebook_credentials input[name=app_id]', :css => '#auth_facebook_credentials input[name=app_id]',
:value => 'id_test1234äöüß', :value => 'id_test1234äöüß',
:match_result => true, )
}, watch_for(
{
:execute => 'match',
:css => '#auth_facebook_credentials input[name=app_secret]', :css => '#auth_facebook_credentials input[name=app_secret]',
:value => 'secret_test1234äöüß', :value => 'secret_test1234äöüß',
:match_result => true, )
},
# set key and secret again # set key and secret again
{ set(
:execute => 'set',
:css => '#auth_facebook_credentials input[name=app_id]', :css => '#auth_facebook_credentials input[name=app_id]',
:value => '---', :value => '---',
}, )
{ set(
:execute => 'set',
:css => '#auth_facebook_credentials input[name=app_secret]', :css => '#auth_facebook_credentials input[name=app_secret]',
:value => '---', :value => '---',
}, )
{ click( :css => '#auth_facebook_credentials button[type=submit]' )
:execute => 'click', sleep 4
:css => '#auth_facebook_credentials button[type=submit]', watch_for(
},
{
:execute => 'wait',
:value => 6,
},
{
:execute => 'match',
:css => '#auth_facebook_credentials input[name=app_id]', :css => '#auth_facebook_credentials input[name=app_id]',
:value => '---', :value => '---',
:match_result => true, )
}, watch_for(
{
:execute => 'match',
:css => '#auth_facebook_credentials input[name=app_secret]', :css => '#auth_facebook_credentials input[name=app_secret]',
:value => '---', :value => '---',
:match_result => true, )
},
], reload()
},
] watch_for(
browser_signle_test_with_login(tests, { :username => 'master@example.com' }) :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
begin
element = instance.find_elements( { :css => params[:css] } )[0] element = instance.find_elements( { :css => params[:css] } )[0]
dropdown = Selenium::WebDriver::Support::Select.new(element) dropdown = Selenium::WebDriver::Support::Select.new(element)
dropdown.select_by(:text, params[:value]) 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
@ -489,6 +496,7 @@ class TestCase < Test::Unit::TestCase
:browser => browser1, :browser => browser1,
:css => true, :css => true,
:value => 'some text', :value => 'some text',
:attribute => 'some_attribute' # optional
:timeout => '16', # in sec, default 16 :timeout => '16', # in sec, default 16
) )
@ -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
# 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 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