From d49607b5a141c68a15e7ebb957e2ff02165a35d9 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 27 Aug 2013 23:05:33 +0200 Subject: [PATCH] Improved browser tests. --- test/browser/aaa_getting_started_test.rb | 14 ++---- .../agent_ticket_actions_level1_test.rb | 9 ++-- .../agent_ticket_actions_level2_test.rb | 13 ++--- test/browser/auth_customer_test.rb | 41 +++++++-------- test/browser/auth_master_test.rb | 13 +++-- test/browser/customer_ticket_create_test.rb | 11 ++-- test/browser/maintenance_message_test.rb | 32 ++++++------ test/browser/manage_test.rb | 44 +++++----------- test/browser/prefereces_test.rb | 22 +++----- test/browser_test_helper.rb | 50 +++++++++++++------ 10 files changed, 106 insertions(+), 143 deletions(-) diff --git a/test/browser/aaa_getting_started_test.rb b/test/browser/aaa_getting_started_test.rb index 899515f48..702d03e58 100644 --- a/test/browser/aaa_getting_started_test.rb +++ b/test/browser/aaa_getting_started_test.rb @@ -64,7 +64,6 @@ class AaaGettingStartedTest < TestCase { :name => 'getting started - agent 1', :action => [ - { :execute => 'match', :css => 'body', @@ -100,16 +99,9 @@ class AaaGettingStartedTest < TestCase :result => '#getting_started', }, { - :execute => 'wait', - :value => 2, - }, - - # check action - { - :execute => 'match', - :css => 'body', - :value => 'Invitation sent', - :match_result => true, + :execute => 'watch_for', + :area => 'body', + :value => 'Invitation sent', }, { :execute => 'match', diff --git a/test/browser/agent_ticket_actions_level1_test.rb b/test/browser/agent_ticket_actions_level1_test.rb index 8d3df0f6d..7adee9666 100644 --- a/test/browser/agent_ticket_actions_level1_test.rb +++ b/test/browser/agent_ticket_actions_level1_test.rb @@ -58,13 +58,12 @@ class AgentTicketActionLevel1Test < TestCase }, { :execute => 'wait', - :value => 4, + :value => 2, }, { - :execute => 'match', - :css => 'body', - :value => 'some body 1234 äöüß', - :match_result => true, + :execute => 'watch_for', + :area => 'body', + :value => 'some body 1234 äöüß', }, { :execute => 'click', diff --git a/test/browser/agent_ticket_actions_level2_test.rb b/test/browser/agent_ticket_actions_level2_test.rb index 7e391fd45..45ebe023e 100644 --- a/test/browser/agent_ticket_actions_level2_test.rb +++ b/test/browser/agent_ticket_actions_level2_test.rb @@ -240,15 +240,10 @@ class AgentTicketActionsLevel2Test < TestCase :css => '.active button', }, { - :execute => 'wait', - :value => 4, - }, - { - :where => :instance1, - :execute => 'match', - :css => 'body', - :value => 'some update 4711', - :match_result => true, + :where => :instance1, + :execute => 'watch_for', + :area => 'body', + :value => 'some update 4711', }, # verify empty text in input body diff --git a/test/browser/auth_customer_test.rb b/test/browser/auth_customer_test.rb index 1bc461b2f..4f9646885 100644 --- a/test/browser/auth_customer_test.rb +++ b/test/browser/auth_customer_test.rb @@ -68,28 +68,22 @@ class AuthCustomerTest < TestCase :result => false, }, { - :execute => 'match', - :css => 'body', - :value => 'nicole.braun@zammad.org', - :match_result => true, + :execute => 'watch_for', + :area => 'body', + :value => 'nicole.braun@zammad.org', }, { - :execute => 'reload', + :execute => 'reload', }, { - :execute => 'wait', - :value => 3, + :execute => 'watch_for', + :area => 'body', + :value => 'nicole.braun@zammad.org', }, { - :execute => 'match', - :css => 'body', - :value => 'nicole.braun@zammad.org', - :match_result => true, - }, - { - :execute => 'match', - :element => :cookie, - :value => 'expires=>nil', + :execute => 'match', + :element => :cookie, + :value => 'expires=>nil', }, ], }, @@ -162,18 +156,17 @@ class AuthCustomerTest < TestCase :result => false, }, { - :execute => 'match', - :css => 'body', - :value => 'nicole.braun@zammad.org', - :match_result => true, + :execute => 'watch_for', + :area => 'body', + :value => 'nicole.braun@zammad.org', }, { - :execute => 'match', - :element => :cookie, - :value => 'expires=>.+?\d{4}.+?,', + :execute => 'match', + :element => :cookie, + :value => 'expires=>.+?\d{4}.+?,', }, { - :execute => 'logout', + :execute => 'logout', }, ], }, diff --git a/test/browser/auth_master_test.rb b/test/browser/auth_master_test.rb index 1ddcf58c7..571a984ee 100644 --- a/test/browser/auth_master_test.rb +++ b/test/browser/auth_master_test.rb @@ -63,15 +63,14 @@ class AuthMasterTest < TestCase # check action { - :execute => 'check', - :css => '#login', - :result => false, + :execute => 'check', + :css => '#login', + :result => false, }, { - :execute => 'match', - :css => 'body', - :value => 'master@example', - :match_result => true, + :execute => 'watch_for', + :area => 'body', + :value => 'master@example', }, ], }, diff --git a/test/browser/customer_ticket_create_test.rb b/test/browser/customer_ticket_create_test.rb index d22f50045..4e07d65da 100644 --- a/test/browser/customer_ticket_create_test.rb +++ b/test/browser/customer_ticket_create_test.rb @@ -74,14 +74,9 @@ class CustomerTicketCreateTest < TestCase :type => 'submit', }, { - :execute => 'wait', - :value => 4, - }, - { - :execute => 'match', - :css => 'body', - :value => 'some body 1234 äöüß', - :match_result => true, + :execute => 'watch_for', + :area => 'body', + :value => 'some body 1234 äöüß', }, ], }, diff --git a/test/browser/maintenance_message_test.rb b/test/browser/maintenance_message_test.rb index 4cba5d562..6ea644f9b 100644 --- a/test/browser/maintenance_message_test.rb +++ b/test/browser/maintenance_message_test.rb @@ -58,17 +58,16 @@ class MaintenanceMessageTest < TestCase :match_result => false, }, { - :where => :instance2, - :execute => 'check', - :css => '.modal-header', - :result => true, + :where => :instance2, + :execute => 'check', + :css => '.modal-header', + :result => true, }, { - :where => :instance2, - :execute => 'match', - :css => 'body', - :value => message, - :match_result => true, + :where => :instance2, + :execute => 'watch_for', + :area => 'body', + :value => message, }, { :where => :instance2, @@ -129,16 +128,15 @@ class MaintenanceMessageTest < TestCase :result => false, }, { - :where => :instance2, - :execute => 'match', - :css => 'body', - :value => message + ' #2', - :match_result => true, + :where => :instance2, + :execute => 'watch_for', + :area => 'body', + :value => message + ' #2', }, { - :where => :instance2, - :execute => 'click', - :css => 'div.modal-header .close', + :where => :instance2, + :execute => 'click', + :css => 'div.modal-header .close', }, { :execute => 'wait', diff --git a/test/browser/manage_test.rb b/test/browser/manage_test.rb index 1d4ae7584..682abbea6 100644 --- a/test/browser/manage_test.rb +++ b/test/browser/manage_test.rb @@ -70,14 +70,9 @@ class ManageTest < TestCase :css => '.modal button.submit', }, { - :execute => 'wait', - :value => 5, - }, - { - :execute => 'match', - :css => 'body', - :value => random, - :match_result => true, + :execute => 'watch_for', + :area => 'body', + :value => random, }, { :execute => 'click', @@ -97,14 +92,9 @@ class ManageTest < TestCase :css => '.modal button.submit', }, { - :execute => 'wait', - :value => 5, - }, - { - :execute => 'match', - :css => 'body', - :value => '2Manage Lastname' + random, - :match_result => true, + :execute => 'watch_for', + :area => 'body', + :value => '2Manage Lastname' + random, }, { :execute => 'wait', @@ -150,14 +140,9 @@ class ManageTest < TestCase :css => '.modal button.submit', }, { - :execute => 'wait', - :value => 5, - }, - { - :execute => 'match', - :css => 'body', - :value => random, - :match_result => true, + :execute => 'watch_for', + :area => 'body', + :value => random, }, { :execute => 'click', @@ -182,14 +167,9 @@ class ManageTest < TestCase :css => '.modal button.submit', }, { - :execute => 'wait', - :value => 5, - }, - { - :execute => 'match', - :css => 'body', - :value => 'some sla update ' + random, - :match_result => true, + :execute => 'watch_for', + :area => 'body', + :value => 'some sla update ' + random, }, { :execute => 'wait', diff --git a/test/browser/prefereces_test.rb b/test/browser/prefereces_test.rb index f010214f1..230a41030 100644 --- a/test/browser/prefereces_test.rb +++ b/test/browser/prefereces_test.rb @@ -34,14 +34,9 @@ class PreferencesTest < TestCase :css => '#language button', }, { - :execute => 'wait', - :value => 6, - }, - { - :execute => 'match', - :css => 'body', - :value => 'Sprache', - :match_result => true, + :execute => 'watch_for', + :area => 'body', + :value => 'Sprache', }, { :execute => 'select', @@ -53,14 +48,9 @@ class PreferencesTest < TestCase :css => '#language button', }, { - :execute => 'wait', - :value => 4, - }, - { - :execute => 'match', - :css => 'body', - :value => 'Language', - :match_result => true, + :execute => 'watch_for', + :area => 'body', + :value => 'Language', }, ], }, diff --git a/test/browser_test_helper.rb b/test/browser_test_helper.rb index db38b3424..cc5f4036a 100644 --- a/test/browser_test_helper.rb +++ b/test/browser_test_helper.rb @@ -161,6 +161,13 @@ class TestCase < Test::Unit::TestCase def browser_element_action(test, action, instance) puts "NOTICE #{Time.now.to_s}: " + action.inspect + if action[:execute] !~ /accept|dismiss/i + cookies = instance.manage.all_cookies + cookies.each {|cookie| + puts " COOKIE " + cookie.to_s + } + end + sleep 0.1 if action[:css] if action[:css].match '###stack###' @@ -228,13 +235,26 @@ class TestCase < Test::Unit::TestCase instance.find_element( { :css => 'a[href="#current_user"]' } ).click sleep 0.1 instance.find_element( { :css => 'a[href="#logout"]' } ).click - sleep 2 - login = instance.find_element( { :css => '#login' } ) - if !login - assert( false, "(#{test[:name]}) no login box found!" ) - return - end - assert( true, "(#{test[:name]}) logout" ) + (1..6).each {|loop| + login = instance.find_element( { :css => '#login' } ) + if login + assert( true, "(#{test[:name]}) logout" ) + return + end + } + assert( false, "(#{test[:name]}) no login box found!" ) + return + elsif action[:execute] == 'watch_for' + (1..24).each { |loop| + element = instance.find_element( { :css => action[:area] } ) + text = element.text + if text =~ /#{action[:value]}/i + assert( true, "(#{test[:name]}) '#{action[:value]}' found in '#{text}'" ) + return + end + sleep 0.5 + } + assert( false, "(#{test[:name]}) '#{action[:value]}' found in '#{text}'" ) return elsif action[:execute] == 'create_ticket' instance.find_element( { :css => 'a[href="#new"]' } ).click @@ -244,7 +264,7 @@ class TestCase < Test::Unit::TestCase assert( false, "(#{test[:name]}) no ticket create screen found!" ) return end - sleep 4 + sleep 2 element = instance.find_element( { :css => '.active .ticket_create input[name="customer_id_autocompletion"]' } ) element.clear element.send_keys( 'nico' ) @@ -272,12 +292,14 @@ class TestCase < Test::Unit::TestCase end sleep 0.1 instance.find_element( { :css => '.active .form-actions button[type="submit"]' } ).click - sleep 6 - if instance.current_url !~ /#{Regexp.quote('#ticket/zoom/')}/ - assert( true, "(#{test[:name]}) ticket creation failed, can't get zoom url" ) - return - end - assert( true, "(#{test[:name]}) ticket created" ) + (1..14).each {|loop| + if instance.current_url =~ /#{Regexp.quote('#ticket/zoom/')}/ + assert( true, "(#{test[:name]}) ticket created" ) + return + end + sleep 0.5 + } + assert( true, "(#{test[:name]}) ticket creation failed, can't get zoom url" ) return elsif action[:execute] == 'close_all_tasks' for i in 1..100