Improved speed of tests.

This commit is contained in:
Martin Edenhofer 2015-02-23 23:37:00 +01:00
parent 6b4436d17e
commit 1a3affa659
2 changed files with 347 additions and 552 deletions

View file

@ -2,170 +2,62 @@
require 'browser_test_helper' require 'browser_test_helper'
class AgentTicketActionLevel0Test < TestCase class AgentTicketActionLevel0Test < TestCase
def test_I def test_text_modules
random = 'text_module_test_' + rand(99999999).to_s random = 'text_module_test_' + rand(99999999).to_s
random2 = 'text_module_test_' + rand(99999999).to_s random2 = 'text_module_test_' + rand(99999999).to_s
# user @browser = browser_instance
tests = [ login(
{ :username => 'master@example.com',
:name => 'add #1', :password => 'test',
:action => [ :url => browser_url,
{ )
:execute => 'close_all_tasks', tasks_close_all()
# create new text modules
text_module_create(
:data => {
:name => 'some name' + random,
:keywords => random,
:content => 'some content' + random,
}, },
{ )
:execute => 'click', text_module_create(
:css => 'a[href="#manage"]', :data => {
:name => 'some name' + random2,
:keywords => random2,
:content => 'some content' + random2,
}, },
{ )
:execute => 'click',
:css => 'a[href="#manage/text_modules"]', # try to use them
}, click( :css => 'a[href="#new"]' )
{ click( :css => 'a[href="#ticket/create"]' )
:execute => 'click', sleep 2
:css => 'a[data-type="new"]',
}, set(
{ :css => '.active div[data-name=body]',
:execute => 'wait', :value => 'test ::' + random
:value => 1, )
}, watch_for(
{ :css => '.active .shortcut',
:execute => 'set',
:css => '.modal input[name=name]',
:value => 'some name' + random,
},
{
:execute => 'set',
:css => '.modal input[name="keywords"]',
:value => random, :value => random,
}, )
{ sendkey(
:execute => 'set', :value => :arrow_down,
:css => '.modal textarea[name="content"]', )
:value => 'some content' + random, sleep 1
}, click( :css => '.active .shortcut > ul> li > a' )
{
:execute => 'click', watch_for(
:css => '.modal button.js-submit',
},
{
:execute => 'watch_for',
:area => '#content table',
:value => 'some name' + random,
},
{
:execute => 'watch_for_disappear',
:area => '.modal',
},
],
},
{
:name => 'add #2',
:action => [
{
:execute => 'click',
:css => 'a[href="#manage"]',
},
{
:execute => 'click',
:css => 'a[href="#manage/text_modules"]',
},
{
:execute => 'click',
:css => 'a[data-type="new"]',
},
{
:execute => 'wait',
:value => 1,
},
{
:execute => 'set',
:css => '.modal input[name=name]',
:value => 'some name' + random2,
},
{
:execute => 'set',
:css => '.modal input[name="keywords"]',
:value => random2,
},
{
:execute => 'set',
:css => '.modal textarea[name="content"]',
:value => 'some content' + random2,
},
{
:execute => 'click',
:css => '.modal button.js-submit',
},
{
:execute => 'watch_for',
:area => '#content table',
:value => 'some name' + random2,
},
{
:execute => 'watch_for_disappear',
:area => '.modal',
},
],
},
{
:name => 'verify usage',
:action => [
{
:execute => 'click',
:css => 'a[href="#new"]',
},
{
:execute => 'click',
:css => 'a[href="#ticket/create"]',
},
{
:execute => 'watch_for',
:area => '.active div[data-name=body]',
:value => '',
},
{
:execute => 'wait',
:value => 3,
},
{
:execute => 'set_ticket_attributes',
:body => 'test ::' + random,
},
{
:execute => 'watch_for',
:area => '.active .shortcut',
:value => random,
},
{
:execute => 'sendkey',
:value => [:arrow_down]
},
{
:execute => 'wait',
:value => 1,
},
{
:execute => 'click',
:css => '.active .shortcut > ul> li > a',
},
{
:execute => 'wait',
:value => 1,
},
{
:execute => 'match',
:css => '.active div[data-name=body]', :css => '.active div[data-name=body]',
:value => 'some content' + random, :value => 'some content' + random,
:match_result => true, )
}, tasks_close_all( :discard_changes => true )
],
},
]
browser_signle_test_with_login(tests, { :username => 'master@example.com' }) # test with two browser windows
end
def test_II
random = 'text_II_module_test_' + rand(99999999).to_s random = 'text_II_module_test_' + rand(99999999).to_s
user_rand = rand(99999999).to_s user_rand = rand(99999999).to_s
@ -175,408 +67,238 @@ class AgentTicketActionLevel0Test < TestCase
email = 'agent-text-module-' + user_rand + '@example.com' email = 'agent-text-module-' + user_rand + '@example.com'
password = 'agentpw' password = 'agentpw'
# user # use current session
tests = [ browser1 = @browser
{
:name => 'start', browser2 = browser_instance
:instance1 => browser_instance, login(
:instance2 => browser_instance, :browser => browser2,
:instance1_username => 'master@example.com', :username => 'agent1@example.com',
:instance1_password => 'test', :password => 'test',
:instance2_username => 'agent1@example.com', :url => browser_url,
:instance2_password => 'test', )
:action => [ tasks_close_all(
# create ticket :browser => browser2,
{ )
:where => :instance2,
:execute => 'close_all_tasks', # create new ticket
}, ticket_create(
{ :browser => browser2,
:where => :instance2, :data => {
:execute => 'create_ticket',
:subject => 'A',
:customer => '', :customer => '',
:do_not_submit => true, :title => 'A',
}, },
{ :do_not_submit => true,
:where => :instance2, )
:execute => 'create_ticket', ticket_create(
:browser => browser2,
:data => {
:customer => '', :customer => '',
:subject => 'B', :title => 'B',
:do_not_submit => true,
}, },
:do_not_submit => true,
)
# create new text module # create new text module
{ text_module_create(
:where => :instance1, :browser => browser1,
:execute => 'click', :data => {
:css => 'a[href="#manage"]', :name => 'some name' + random,
}, :keywords => random,
{ :content => 'some content <%= @ticket.customer.lastname %>' + random,
:where => :instance1,
:execute => 'click',
:css => 'a[href="#manage/text_modules"]',
},
{
:where => :instance1,
:execute => 'click',
:css => 'a[data-type="new"]',
},
{
:execute => 'wait',
:value => 1,
},
{
:where => :instance1,
:execute => 'set',
:css => '.modal input[name=name]',
:value => 'some name' + random,
},
{
:where => :instance1,
:execute => 'set',
:css => '.modal input[name="keywords"]',
:value => random,
},
{
:where => :instance1,
:execute => 'set',
:css => '.modal textarea[name="content"]',
:value => 'some content <%= @ticket.customer.lastname %>' + random,
},
{
:where => :instance1,
:execute => 'click',
:css => '.modal button.js-submit',
},
{
:where => :instance1,
:execute => 'watch_for',
:area => '#content table',
:value => random,
},
{
:where => :instance1,
:execute => 'watch_for_disappear',
:area => '.modal',
}, },
)
], # create user to test placeholder
}, user_create(
:browser => browser1,
# create user :data => {
{
:name => 'create user',
:action => [
{
:where => :instance1,
:execute => 'create_user',
:login => login, :login => login,
:firstname => firstname, :firstname => firstname,
:lastname => lastname, :lastname => lastname,
:email => email, :email => email,
:password => password, :password => password,
}, },
], )
},
{ # check if text module exists in instance2, for ready to use
:name => 'check if text module exists in instance2, for ready to use', set(
:action => [ :browser => browser2,
{
:execute => 'wait',
:value => 4,
},
{
:where => :instance2,
:execute => 'set_ticket_attributes',
:body => '::' + random,
},
{
:execute => 'wait',
:value => 2,
},
{
:where => :instance2,
:execute => 'sendkey',
:value => [:arrow_down]
},
{
:execute => 'wait',
:value => 1,
},
{
:where => :instance2,
:execute => 'click',
:css => '.active .shortcut > ul> li > a',
},
{
:execute => 'wait',
:value => 1,
},
# instance.execute_script( '$(".content.active div[data-name=body]").focus()' )
#execute] == 'js'
# result = instance.execute_script( action[:value
{
:where => :instance2,
:execute => 'match',
:css => '.active div[data-name=body]', :css => '.active div[data-name=body]',
:value => 'some content ' + random, :value => 'test ::' + random
:match_result => true, )
}, watch_for(
{ :browser => browser2,
:execute => 'wait', :css => '.active .shortcut',
:value => 3, :value => random,
}, )
{ sendkey(
:where => :instance2, :browser => browser2,
:execute => 'set', :value => :arrow_down,
)
sleep 1
click(
:browser => browser2,
:css => '.active .shortcut > ul> li > a',
)
watch_for(
:browser => browser2,
:css => '.active div[data-name=body]',
:value => 'some content' + random,
)
sleep 2
set(
:browser => browser2,
:css => '.active .newTicket input[name="customer_id_completion"]', :css => '.active .newTicket input[name="customer_id_completion"]',
:value => 'nicole', :value => 'nicole',
}, )
{ sleep 4
:execute => 'wait', sendkey(
:value => 4, :browser => browser2,
}, :value => :arrow_down,
{ )
:where => :instance2, sleep 1
:execute => 'sendkey',
:value => [:arrow_down] click(
}, :browser => browser2,
{
:execute => 'wait',
:value => 1,
},
{
:where => :instance2,
:execute => 'click',
:css => '.active .newTicket .recipientList-entry.js-user.is-active', :css => '.active .newTicket .recipientList-entry.js-user.is-active',
}, )
{ sleep 1
:execute => 'wait',
:value => 1, set(
}, :browser => browser2,
{ :css => '.active div[data-name=body]',
:where => :instance2, :value => '::' + random,
:execute => 'set_ticket_attributes', )
:body => '::' + random, sleep 1
}, sendkey(
{ :browser => browser2,
:execute => 'wait', :value => :arrow_down,
:value => 1, )
}, sleep 1
{ click(
:where => :instance2, :browser => browser2,
:execute => 'sendkey',
:value => [:arrow_down]
},
{
:execute => 'wait',
:value => 1,
},
{
:where => :instance2,
:execute => 'click',
:css => '.active .shortcut > ul> li > a', :css => '.active .shortcut > ul> li > a',
}, )
{ watch_for(
:execute => 'wait', :browser => browser2,
:value => 1,
},
{
:where => :instance2,
:execute => 'match',
:css => '.active div[data-name=body]', :css => '.active div[data-name=body]',
:value => 'some content Braun' + random, :value => 'some content Braun' + random,
:match_result => true, )
},
],
},
{
:name => 'verify zoom',
:action => [
{ # verify zoom
:where => :instance1, click(
:execute => 'click', :browser => browser1,
:css => 'a[href="#manage"]', :css => 'a[href="#manage"]',
}, )
# create ticket # create ticket
{ ticket_create(
:where => :instance2, :browser => browser2,
:execute => 'create_ticket', :data => {
:group => 'Users', :group => 'Users',
:subject => 'some subject 123äöü', :subject => 'some subject 123äöü',
:body => 'some body 123äöü', :body => 'some body 123äöü',
}, },
)
# check ticket set(
{ :browser => browser2,
:where => :instance2, :css => '.active div[data-name=body]',
:execute => 'match', :value => 'test',
:css => '.active div.ticket-article', )
:value => 'some body 123äöü', sleep 1
:match_result => true,
},
# check ticket zoom set(
{ :browser => browser2,
:execute => 'wait', :css => '.active div[data-name=body]',
:value => 4, :value => '::' + random,
}, )
{ sleep 1
:where => :instance2, sendkey(
:execute => 'set_ticket_attributes', :browser => browser2,
:body => 'test', :value => :arrow_down,
}, )
{ sleep 1
:execute => 'wait', click(
:value => 2, :browser => browser2,
},
{
:where => :instance2,
:execute => 'set_ticket_attributes',
:body => '::' + random,
},
{
:execute => 'wait',
:value => 1,
},
{
:where => :instance2,
:execute => 'sendkey',
:value => [:arrow_down]
},
{
:execute => 'wait',
:value => 1,
},
{
:where => :instance2,
:execute => 'click',
:css => '.active .shortcut > ul> li > a', :css => '.active .shortcut > ul> li > a',
}, )
{
:execute => 'wait', watch_for(
:value => 1, :browser => browser2,
},
{
:where => :instance2,
:execute => 'match',
:css => '.active div[data-name=body]', :css => '.active div[data-name=body]',
:value => 'some content Braun' + random, :value => 'some content Braun' + random,
:match_result => true, )
},
],
},
{
:name => 'change customer',
:action => [
{ # change customer
:where => :instance1, click(
:execute => 'click', :browser => browser1,
:css => 'a[href="#manage"]', :css => 'a[href="#manage"]',
}, )
{ click(
:where => :instance2, :browser => browser2,
:execute => 'click',
:css => '.active div[data-tab="ticket"] .js-actions .select-arrow', :css => '.active div[data-tab="ticket"] .js-actions .select-arrow',
}, )
{ click(
:where => :instance2, :browser => browser2,
:execute => 'click',
:css => '.active div[data-tab="ticket"] .js-actions a[data-type="customer-change"]', :css => '.active div[data-tab="ticket"] .js-actions a[data-type="customer-change"]',
}, )
{ sleep 1
:execute => 'wait',
:value => 1, set(
}, :browser => browser2,
{
:where => :instance2,
:execute => 'set',
:css => '.modal [name="customer_id_completion"]', :css => '.modal [name="customer_id_completion"]',
:value => firstname, :value => firstname,
}, )
{ sleep 4
:execute => 'wait', sendkey(
:value => 4, :browser => browser2,
}, :value => :arrow_down,
{ )
:where => :instance2, sleep 1
:execute => 'sendkey',
:value => [:arrow_down] click(
}, :browser => browser2,
{
:execute => 'wait',
:value => 1,
},
{
:where => :instance2,
:execute => 'click',
:css => '.modal .recipientList-entry.js-user.is-active', :css => '.modal .recipientList-entry.js-user.is-active',
}, )
{ sleep 1
:execute => 'wait', click(
:value => 1, :browser => browser2,
},
{
:where => :instance2,
:execute => 'click',
:css => '.modal-content .js-submit', :css => '.modal-content .js-submit',
}, )
{
:where => :instance2, watch_for_disappear(
:execute => 'watch_for_disappear', :browser => browser2,
:area => '.modal', :css => '.modal',
}, )
{ sleep 1
:execute => 'wait',
:value => 1, watch_for(
}, :browser => browser2,
{ :css => '.active div[data-name=body]',
:where => :instance2, :value => '::' + random,
:execute => 'set_ticket_attributes', )
:body => '::' + random, sleep 1
},
{ sendkey(
:execute => 'wait', :browser => browser2,
:value => 1, :value => :arrow_down,
}, )
{ sleep 1
:where => :instance2,
:execute => 'sendkey', click(
:value => [:arrow_down] :browser => browser2,
},
{
:execute => 'wait',
:value => 1,
},
{
:where => :instance2,
:execute => 'click',
:css => '.active .shortcut > ul> li > a', :css => '.active .shortcut > ul> li > a',
}, )
{
:execute => 'wait', watch_for(
:value => 1, :browser => browser2,
},
{
:where => :instance2,
:execute => 'match',
:css => '.active div[data-name=body]', :css => '.active div[data-name=body]',
:value => 'some content ' + lastname, :value => 'some content ' + lastname,
:match_result => true, )
},
{
:execute => 'wait',
:value => 2,
},
],
},
]
browser_double_test(tests)
end end
end end

View file

@ -518,6 +518,35 @@ class TestCase < Test::Unit::TestCase
raise "'#{params[:value]}' found in '#{text}'" raise "'#{params[:value]}' found in '#{text}'"
end end
=begin
watch_for_disappear(
:browser => browser1,
:css => true,
:timeout => '16', # in sec, default 16
)
=end
def watch_for_disappear(params = {})
instance = params[:browser] || @browser
timeout = 16
if action[:timeout]
timeout = params[:timeout]
end
loops = (timeout).to_i
text = ''
(1..loops).each { |loop|
element = instance.find_elements( { :css => params[:css] } )[0]
if !element #|| element.displayed?
assert( true, "not found" )
return true
end
sleep 1
}
raise "#{test[:css]}) still exsists"
end
=begin =begin
@ -1086,6 +1115,50 @@ class TestCase < Test::Unit::TestCase
raise "sla creation failed" raise "sla creation failed"
end end
=begin
text_module_create(
:browser => browser2,
:data => {
:name => 'some sla' + random,
:keywords => 'some keywords',
:content => 'some content',
},
)
=end
def text_module_create(params = {})
instance = params[:browser] || @browser
data = params[:data]
instance.find_elements( { :css => 'a[href="#manage"]' } )[0].click
instance.find_elements( { :css => 'a[href="#manage/text_modules"]' } )[0].click
sleep 2
instance.find_elements( { :css => 'a[data-type="new"]' } )[0].click
sleep 2
element = instance.find_elements( { :css => '.modal input[name=name]' } )[0]
element.clear
element.send_keys( data[:name] )
element = instance.find_elements( { :css => '.modal input[name=keywords]' } )[0]
element.clear
element.send_keys( data[:keywords] )
element = instance.find_elements( { :css => '.modal textarea[name=content]' } )[0]
element.clear
element.send_keys( data[:content] )
instance.find_elements( { :css => '.modal button.js-submit' } )[0].click
(1..8).each {|loop|
element = instance.find_elements( { :css => 'body' } )[0]
text = element.text
if text =~ /#{Regexp.quote(data[:name])}/
assert( true, "text module created" )
return true
end
sleep 1
}
raise "text module creation failed"
end
# Add more helper methods to be used by all tests here... # Add more helper methods to be used by all tests here...
def browser_login(data) def browser_login(data)
all_tests = [ all_tests = [