From f71c142829fa92d5a68bb99fd41f621d90b19300 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sun, 22 Feb 2015 23:20:05 +0100 Subject: [PATCH] Improved speed of tests. --- test/browser/agent_user_manage_test.rb | 298 ++++++--------- test/browser/customer_ticket_create_test.rb | 129 +++---- test/browser/prefereces_test.rb | 111 ++---- .../signup_password_change_and_reset_test.rb | 10 +- test/browser/taskbar_task_test.rb | 350 ++++++------------ test/browser_test_helper.rb | 75 +++- 6 files changed, 385 insertions(+), 588 deletions(-) diff --git a/test/browser/agent_user_manage_test.rb b/test/browser/agent_user_manage_test.rb index 792fa29d6..72705dd56 100644 --- a/test/browser/agent_user_manage_test.rb +++ b/test/browser/agent_user_manage_test.rb @@ -7,197 +7,113 @@ class AgentUserManageTest < TestCase firstname = 'Customer Firstname' lastname = 'Customer Lastname' fullname = "#{ firstname } #{ lastname } <#{ customer_user_email }>" - tests = [ - { - :name => 'create customer', - :action => [ - { - :execute => 'close_all_tasks', - }, - { - :execute => 'wait', - :value => 1, - }, - { - :execute => 'click', - :css => 'a[href="#new"]', - }, - { - :execute => 'click', - :css => 'a[href="#ticket/create"]', - }, - { - :execute => 'click', - :css => '.active .newTicket [name="customer_id_completion"]', - }, - { - :execute => 'sendkey', - :value => [:arrow_down] - }, - { - :execute => 'wait', - :value => 1, - }, - { - :execute => 'click', - :css => '.active .newTicket .recipientList-entry.js-user-new', - }, - { - :execute => 'wait', - :value => 1, - }, - { - :execute => 'set', - :css => '.modal input[name="firstname"]', - :value => firstname, - }, - { - :execute => 'set', - :css => '.modal input[name="lastname"]', - :value => lastname, - }, - { - :execute => 'set', - :css => '.modal input[name="email"]', - :value => customer_user_email, - }, - { - :execute => 'click', - :css => '.modal button.js-submit', - }, - { - :execute => 'wait', - :value => 4, - }, - # check is used is selected - { - :execute => 'match', - :css => '.active input[name="customer_id"]', - :value => '^\d+$', - :no_quote => true, - :match_result => true, - }, - { - :execute => 'match', - :css => '.active input[name="customer_id_completion"]', - :value => firstname, - :no_quote => true, - :match_result => true, - }, - { - :execute => 'match', - :css => '.active input[name="customer_id_completion"]', - :value => lastname, - :no_quote => true, - :match_result => true, - }, - { - :execute => 'match', - :css => '.active input[name="customer_id_completion"]', - :value => customer_user_email, - :no_quote => true, - :match_result => true, - }, - { - :execute => 'match', - :css => '.active input[name="customer_id_completion"]', - :value => fullname, - :no_quote => true, - :match_result => true, - }, - { - :execute => 'wait', - :value => 4, - }, + @browser = browser_instance + login( + :username => 'agent1@example.com', + :password => 'test', + :url => browser_url, + ) + tasks_close_all() - # call new ticket screen again - { - :execute => 'close_all_tasks', - :discard_changes => 1, - }, - { - :execute => 'click', - :css => 'a[href="#new"]', - }, - { - :execute => 'click', - :css => 'a[href="#ticket/create"]', - }, - { - :execute => 'wait', - :value => 2, - }, - { - :execute => 'match', - :css => '.active input[name="customer_id"]', - :value => '^\d+$', - :no_quote => true, - :match_result => false, - }, - { - :execute => 'match', - :css => '.active input[name="customer_id_completion"]', - :value => firstname, - :no_quote => true, - :match_result => false, - }, - { - :execute => 'set', - :css => '.active .newTicket input[name="customer_id_completion"]', - :value => customer_user_email, - }, - { - :execute => 'wait', - :value => 3, - }, - { - :execute => 'sendkey', - :value => [:arrow_down] - }, - { - :execute => 'wait', - :value => 1, - }, - { - :execute => 'click', - :css => '.active .newTicket .recipientList-entry.js-user.is-active', - }, - { - :execute => 'wait', - :value => 1, - }, - { - :execute => 'match', - :css => '.active input[name="customer_id"]', - :value => '^\d+$', - :no_quote => true, - :match_result => true, - }, - { - :execute => 'match', - :css => '.active input[name="customer_id_completion"]', - :value => firstname, - :no_quote => true, - :match_result => true, - }, - { - :execute => 'match', - :css => '.active input[name="customer_id_completion"]', - :value => lastname, - :no_quote => true, - :match_result => true, - }, - { - :execute => 'match', - :css => '.active input[name="customer_id_completion"]', - :value => fullname, - :no_quote => true, - :match_result => true, - }, - ], - }, - ] - browser_signle_test_with_login(tests, { :username => 'agent1@example.com' }) + sleep 1 + + # create customer + click( :css => 'a[href="#new"]' ) + click( :css => 'a[href="#ticket/create"]' ) + click( :css => '.active .newTicket [name="customer_id_completion"]' ) + sendkey( :value => :arrow_down ) + sleep 1 + click( :css => '.active .newTicket .recipientList-entry.js-user-new' ) + sleep 1 + + set( + :css => '.modal input[name="firstname"]', + :value => firstname, + ) + set( + :css => '.modal input[name="lastname"]', + :value => lastname, + ) + set( + :css => '.modal input[name="email"]', + :value => customer_user_email, + ) + + click( :css => '.modal button.js-submit' ) + sleep 4 + + # check is used to check selected + match( + :css => '.active input[name="customer_id"]', + :value => '^\d+$', + :no_quote => true, + ) + match( + :css => '.active input[name="customer_id_completion"]', + :value => firstname, + ) + match( + :css => '.active input[name="customer_id_completion"]', + :value => lastname, + ) + match( + :css => '.active input[name="customer_id_completion"]', + :value => customer_user_email, + ) + match( + :css => '.active input[name="customer_id_completion"]', + :value => fullname, + ) + sleep 4 + + # call new ticket screen again + tasks_close_all( :discard_changes => 1 ) + + click( :css => 'a[href="#new"]' ) + click( :css => 'a[href="#ticket/create"]' ) + sleep 2 + + match( + :css => '.active input[name="customer_id"]', + :value => '', + ) + match( + :css => '.active input[name="customer_id_completion"]', + :value => '', + ) + set( + :css => '.active .newTicket input[name="customer_id_completion"]', + :value => customer_user_email, + ) + sleep 3 + sendkey( :value => :arrow_down ) + sleep 1 + click( :css => '.active .newTicket .recipientList-entry.js-user.is-active' ) + sleep 1 + + # check is used to check selected + match( + :css => '.active input[name="customer_id"]', + :value => '^\d+$', + :no_quote => true, + ) + match( + :css => '.active input[name="customer_id_completion"]', + :value => firstname, + ) + match( + :css => '.active input[name="customer_id_completion"]', + :value => lastname, + ) + match( + :css => '.active input[name="customer_id_completion"]', + :value => customer_user_email, + ) + match( + :css => '.active input[name="customer_id_completion"]', + :value => fullname, + ) end -end + +end \ No newline at end of file diff --git a/test/browser/customer_ticket_create_test.rb b/test/browser/customer_ticket_create_test.rb index 715a20484..eeb81603f 100644 --- a/test/browser/customer_ticket_create_test.rb +++ b/test/browser/customer_ticket_create_test.rb @@ -3,88 +3,53 @@ require 'browser_test_helper' class CustomerTicketCreateTest < TestCase def test_customer_ticket_create - tests = [ - { - :name => 'customer ticket create', - :action => [ - { - :execute => 'click', - :css => 'a[href="#new"]', - }, - { - :execute => 'click', - :css => 'a[href="#customer_ticket_new"]', - }, - { - :execute => 'wait', - :value => 2, - }, - { - :execute => 'check', - :css => '.newTicket', - :result => true, - }, - { - :execute => 'select', - :css => '.newTicket select[name="group_id"]', - :value => 'Users', - }, - { - :execute => 'set', - :css => '.newTicket input[name="title"]', - :value => 'some subject 123äöü', - }, - { - :execute => 'set', - :css => '.newTicket [data-name="body"]', - :value => 'some body 123äöü', - }, - { - :execute => 'click', - :css => '.newTicket button.submit', - }, - { - :execute => 'wait', - :value => 5, - }, - { - :execute => 'check', - :element => :url, - :result => '#ticket/zoom/', - }, + @browser = browser_instance + login( + :username => 'nicole.braun@zammad.org', + :password => 'test', + :url => browser_url, + ) - # check ticket - { - :execute => 'match', - :css => '.active div.ticket-article', - :value => 'some body 123äöü', - :match_result => true, - }, + # customer ticket create + click( :css => 'a[href="#new"]' ) + click( :css => 'a[href="#customer_ticket_new"]' ) + sleep 2 - # update ticket - { - :execute => 'check', - :css => '.active [data-name="body"]', - :result => true, - }, - { - :execute => 'set', - :css => '.active [data-name="body"]', - :value => 'some body 1234 äöüß', - }, - { - :execute => 'click', - :css => '.active button.js-submit', - :type => 'submit', - }, - { - :execute => 'watch_for', - :area => 'body', - :value => 'some body 1234 äöüß', - }, - ], - }, - ] - browser_signle_test_with_login(tests) + select( + :css => '.newTicket select[name="group_id"]', + :value => 'Users', + ) + + set( + :css => '.newTicket input[name="title"]', + :value => 'some subject 123äöü', + ) + set( + :css => '.newTicket [data-name="body"]', + :value => 'some body 123äöü', + ) + click( :css => '.newTicket button.submit' ) + sleep 5 + + # check if ticket is shown + location_check( :url => '#ticket/zoom/' ) + + match( + :css => '.active div.ticket-article', + :value => 'some body 123äöü', + :no_quote => true, + ) + + # update ticket + set( + :css => '.active [data-name="body"]', + :value => 'some body 1234 äöüß', + ) + click( :css => '.active button.js-submit' ) + + watch_for( + :css => '.active div.ticket-article', + :value => 'some body 1234 äöüß', + ) end -end +end \ No newline at end of file diff --git a/test/browser/prefereces_test.rb b/test/browser/prefereces_test.rb index b15f646e6..bad40182d 100644 --- a/test/browser/prefereces_test.rb +++ b/test/browser/prefereces_test.rb @@ -3,75 +3,46 @@ require 'browser_test_helper' class PreferencesTest < TestCase def test_preferences - tests = [ - { - :name => 'preferences', - :action => [ - { - :execute => 'click', - :css => 'a[href="#current_user"]', - }, - { - :execute => 'click', - :css => 'a[href="#profile"]', - }, - { - :execute => 'click', - :css => 'a[href="#profile/language"]', - }, - { - :execute => 'select', - :css => '.language_item select[name="locale"]', - :value => 'Deutsch', - }, - { - :execute => 'click', - :css => '.content button[type="submit"]', - }, - { - :execute => 'watch_for', - :area => 'body', - :value => 'Sprache', - }, - { - :execute => 'select', - :css => '.language_item select[name="locale"]', - :value => 'English (United States)', - }, - { - :execute => 'click', - :css => '.content button[type="submit"]', - }, - { - :execute => 'watch_for', - :area => 'body', - :value => 'Language', - }, - { - :execute => 'select', - :css => '.language_item select[name="locale"]', - :value => 'Deutsch', - }, - { - :execute => 'click', - :css => '.content button[type="submit"]', - }, - { - :execute => 'watch_for', - :area => 'body', - :value => 'Sprache', - }, - { - :execute => 'reload', - }, - { - :execute => 'watch_for', - :area => 'body', - :value => 'Sprache', - }, - ], - }, - ] - browser_signle_test_with_login(tests) + @browser = browser_instance + login( + :username => 'nicole.braun@zammad.org', + :password => 'test', + :url => browser_url, + ) + click( :css => 'a[href="#current_user"]' ) + click( :css => 'a[href="#profile"]' ) + click( :css => 'a[href="#profile/language"]' ) + select( + :css => '.language_item select[name="locale"]', + :value => 'Deutsch', + ) + click( :css => '.content button[type="submit"]' ) + watch_for( + :css => 'body', + :value => 'Sprache', + ) + select( + :css => '.language_item select[name="locale"]', + :value => 'English (United States)', + ) + click( :css => '.content button[type="submit"]' ) + watch_for( + :css => 'body', + :value => 'Language', + ) + select( + :css => '.language_item select[name="locale"]', + :value => 'Deutsch', + ) + click( :css => '.content button[type="submit"]' ) + watch_for( + :css => 'body', + :value => 'Sprache', + ) + reload() + watch_for( + :css => 'body', + :value => 'Sprache', + ) end end \ No newline at end of file diff --git a/test/browser/signup_password_change_and_reset_test.rb b/test/browser/signup_password_change_and_reset_test.rb index 97ded50e1..988a05302 100644 --- a/test/browser/signup_password_change_and_reset_test.rb +++ b/test/browser/signup_password_change_and_reset_test.rb @@ -33,8 +33,7 @@ class SignupPasswordChangeAndResetTest < TestCase click( :css => 'button.submit' ) sleep 5 - result = exists( :css => '.signup' ) - assert( !result, ".signup still exists" ) + exists_not( :css => '.signup' ) match( :css => '.user-menu .user a', @@ -152,10 +151,9 @@ class SignupPasswordChangeAndResetTest < TestCase location( :url => browser_url + '/#password_reset' ) sleep 1 - match( - :css => 'body', - :value => 'password', - :should_not_match => true, + match_not( + :css => 'body', + :value => 'password', ) logout() diff --git a/test/browser/taskbar_task_test.rb b/test/browser/taskbar_task_test.rb index 9f9778eec..866f0b1e4 100644 --- a/test/browser/taskbar_task_test.rb +++ b/test/browser/taskbar_task_test.rb @@ -3,244 +3,122 @@ require 'browser_test_helper' class TaskbarTaskTest < TestCase def test_persistant_task_a - tests = [ - { - :name => 'persistant task', - :action => [ - { - :execute => 'wait', - :value => 2, - }, - { - :execute => 'close_all_tasks', - }, - { - :execute => 'wait', - :value => 1, - }, - { - :execute => 'click', - :css => 'a[href="#new"]', - }, - { - :execute => 'click', - :css => 'a[href="#ticket/create"]', - }, - { - :execute => 'wait', - :value => 3, - }, - { - :execute => 'check', - :css => '.active .newTicket', - :result => true, - }, - { - :execute => 'set', - :css => '.active .newTicket input[name="title"]', - :value => 'some test AAA', - }, - { - :execute => 'wait', - :value => 12, - }, - ], - }, - ] - browser_signle_test_with_login(tests, { :username => 'agent1@example.com' }) + @browser = browser_instance + login( + :username => 'agent1@example.com', + :password => 'test', + :url => browser_url, + ) + tasks_close_all() + + # persistant task + click( :css => 'a[href="#new"]' ) + click( :css => 'a[href="#ticket/create"]' ) + set( + :css => '.active .newTicket input[name="title"]', + :value => 'some test AAA', + ) + sleep 10 end def test_persistant_task_b - tests = [ - { - :name => 'persistant task', - :action => [ - { - :execute => 'wait', - :value => 4, - }, - { - :execute => 'click', - :css => '.task', - }, - { - :execute => 'wait', - :value => 1, - }, - { - :execute => 'match', - :css => 'body', - :value => 'some test AAA', - :match_result => true, - }, - { - :execute => 'close_all_tasks', - }, - { - :execute => 'match', - :css => 'body', - :value => 'some test AAA', - :match_result => false, - }, - ], - }, - ] - browser_signle_test_with_login(tests, { :username => 'agent1@example.com' }) + @browser = browser_instance + login( + :username => 'agent1@example.com', + :password => 'test', + :url => browser_url, + ) + sleep 3 + + # check if task still exists + click( :css => '.task' ) + + match( + :css => '.active .newTicket input[name="title"]', + :value => 'some test AAA', + ) + + tasks_close_all() + + exists_not( :css => '.active .newTicket input[name="title"]' ) end def test_persistant_task_with_relogin - tests = [ - { - :name => 'agent1 - create persistant task', - :action => [ - { - :execute => 'wait', - :value => 2, - }, - { - :execute => 'close_all_tasks', - }, - { - :execute => 'click', - :css => 'a[href="#new"]', - }, - { - :execute => 'click', - :css => 'a[href="#ticket/create"]', - }, - { - :execute => 'wait', - :value => 2, - }, - { - :execute => 'set', - :css => '.active .newTicket input[name="title"]', - :value => 'INBOUND TEST#1', - }, - { - :execute => 'wait', - :value => 4, - }, - { - :execute => 'set', - :css => '.active .newTicket [data-name="body"]', - :value => 'INBOUND BODY TEST#1', - }, - { - :execute => 'click', - :css => 'a[href="#new"]', - }, - { - :execute => 'click', - :css => 'a[href="#ticket/create"]', - }, - { - :execute => 'wait', - :value => 2, - }, - { - :execute => 'set', - :css => '.active .newTicket input[name="title"]', - :value => 'OUTBOUND TEST#1', - }, - { - :execute => 'wait', - :value => 1, - }, - { - :execute => 'set', - :css => '.active .newTicket [data-name="body"]', - :value => 'OUTBOUND BODY TEST#1', - }, - { - :execute => 'wait', - :value => 12, - }, - { - :execute => 'logout', - }, - { - :execute => 'check', - :css => '#login', - :result => true, - }, - { - :execute => 'wait', - :value => 10, - }, - ], - }, - { - :name => 'relogin with master - task are not viewable', - :action => [ - { - :execute => 'login', - :username => 'master@example.com', - :password => 'test', - }, - { - :execute => 'wait', - :value => 6, - }, - { - :execute => 'match', - :css => 'body', - :value => 'INBOUND TEST#1', - :match_result => false, - }, - { - :execute => 'match', - :css => 'body', - :value => 'OUTBOUND TEST#1', - :match_result => false, - }, - { - :execute => 'logout', - }, - { - :execute => 'check', - :css => '#login', - :result => true, - }, - { - :execute => 'match', - :css => 'body', - :value => 'INBOUND TEST#1', - :match_result => false, - }, - { - :execute => 'match', - :css => 'body', - :value => 'OUTBOUND TEST#1', - :match_result => false, - }, - ], - }, - { - :name => 'relogin with agent - task are viewable', - :action => [ - { - :execute => 'login', - :username => 'agent1@example.com', - :password => 'test', - }, - { - :execute => 'wait', - :value => 3, - }, - { - :execute => 'match', - :css => 'body', - :value => 'INBOUND TEST#1', - :match_result => true, - }, - { - :execute => 'match', - :css => 'body', - :value => 'OUTBOUND TEST#1', - :match_result => true, - }, - ], - }, - ] - browser_signle_test_with_login(tests, { :username => 'agent1@example.com' }) + @browser = browser_instance + login( + :username => 'agent1@example.com', + :password => 'test', + :url => browser_url, + ) + tasks_close_all() + + click( :css => 'a[href="#new"]' ) + click( :css => 'a[href="#ticket/create"]' ) + set( + :css => '.active .newTicket input[name="title"]', + :value => 'INBOUND TEST#1', + ) + set( + :css => '.active .newTicket [data-name="body"]', + :value => 'INBOUND BODY TEST#1', + ) + + click( :css => 'a[href="#new"]' ) + click( :css => 'a[href="#ticket/create"]' ) + set( + :css => '.active .newTicket input[name="title"]', + :value => 'OUTBOUND TEST#1', + ) + set( + :css => '.active .newTicket [data-name="body"]', + :value => 'OUTBOUND BODY TEST#1', + ) + sleep 10 + + logout() + sleep 4 + + # relogin with master - task are not viewable + login( + :username => 'master@example.com', + :password => 'test', + :url => browser_url, + ) + sleep 3 + + match_not( + :css => 'body', + :value => 'INBOUND TEST#1', + ) + match_not( + :css => 'body', + :value => 'OUTBOUND TEST#1', + ) + logout() + sleep 2 + + match_not( + :css => 'body', + :value => 'INBOUND TEST#1', + ) + match_not( + :css => 'body', + :value => 'OUTBOUND TEST#1', + ) + + # relogin with agent - task are viewable + login( + :username => 'agent1@example.com', + :password => 'test', + :url => browser_url, + ) + sleep 3 + + match( + :css => 'body', + :value => 'INBOUND TEST#1', + ) + match( + :css => 'body', + :value => 'OUTBOUND TEST#1', + ) end -end +end \ No newline at end of file diff --git a/test/browser_test_helper.rb b/test/browser_test_helper.rb index efcdca1ac..2e945a823 100644 --- a/test/browser_test_helper.rb +++ b/test/browser_test_helper.rb @@ -153,6 +153,22 @@ class TestCase < Test::Unit::TestCase instance.get( params[:url] ) end +=begin + + location_check( + :browser => browser1, + :url => 'http://someurl', + ) + +=end + + def location_check(params) + instance = params[:browser] || @browser + if instance.current_url !~ /#{Regexp.quote(params[:url])}/ + raise "url #{instance.current_url} is not matching #{params[:url]}" + end + assert( true, "url #{instance.current_url} is matching #{params[:url]}" ) + end =begin @@ -192,10 +208,27 @@ class TestCase < Test::Unit::TestCase def exists(params) instance = params[:browser] || @browser - if instance.find_elements( { :css => params[:css] } )[0] - return true + if !instance.find_elements( { :css => params[:css] } )[0] + raise "#{params[:css]} dosn't exist, but should" end - false + true + end + +=begin + + exists_not( + :browser => browser1, + :css => '.some_class', + ) + +=end + + def exists_not(params) + instance = params[:browser] || @browser + if instance.find_elements( { :css => params[:css] } )[0] + raise "#{params[:css]} exists but should not" + end + true end =begin @@ -228,6 +261,24 @@ class TestCase < Test::Unit::TestCase sleep 0.1 end +=begin + + select( + :browser => browser1, + :css => '.some_class', + :value => 'Some Value', + ) + +=end + + def select(params) + instance = params[:browser] || @browser + + element = instance.find_elements( { :css => params[:css] } )[0] + dropdown = Selenium::WebDriver::Support::Select.new(element) + dropdown.select_by(:text, params[:value]) + end + =begin sendkey( @@ -319,6 +370,24 @@ class TestCase < Test::Unit::TestCase return match end +=begin + + match_not( + :browser => browser1, + :css => '#content .text-1', + :value => 'some test for browser and some other for browser', + :attribute => 'some_attribute', # match on attribute + :should_not_match => true, + :no_quote => false, # use regex + ) + +=end + + def match_not(params) + params[:should_not_match] = true + match(params) + end + =begin cookie(