Added new browser tests.
This commit is contained in:
parent
b64ebb9225
commit
b6adaa28d6
4 changed files with 201 additions and 57 deletions
|
@ -1,5 +1,5 @@
|
||||||
<div class="well well-chat span3">
|
<div class="well well-chat span3">
|
||||||
<h4><%- @T('Chat') %><a href="#" class="close">×</a></h4>
|
<h4><%- @T('Chat') %><a href="#" id="chat_toogle" class="close">×</a></h4>
|
||||||
<div id="chat_content" <% if !@isShown: %>class="hide"<% end %>>
|
<div id="chat_content" <% if !@isShown: %>class="hide"<% end %>>
|
||||||
<div id="chat_log_container" class="max-size-scroll">
|
<div id="chat_log_container" class="max-size-scroll">
|
||||||
<% for message in @messages: %>
|
<% for message in @messages: %>
|
||||||
|
|
|
@ -142,7 +142,7 @@ EventMachine.run {
|
||||||
# list all current clients
|
# list all current clients
|
||||||
client_list = Session.list
|
client_list = Session.list
|
||||||
client_list.each {|local_client_id, local_client|
|
client_list.each {|local_client_id, local_client|
|
||||||
if local_client_id != client_id
|
if local_client_id.to_s != client_id.to_s
|
||||||
|
|
||||||
# broadcast to recipient list
|
# broadcast to recipient list
|
||||||
if data['recipient'] && data['recipient']['user_id']
|
if data['recipient'] && data['recipient']['user_id']
|
||||||
|
|
82
test/browser/chat.rb
Normal file
82
test/browser/chat.rb
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
# encoding: utf-8
|
||||||
|
require 'browser_test_helper'
|
||||||
|
|
||||||
|
class Chat < ActiveSupport::TestCase
|
||||||
|
test 'websocket' do
|
||||||
|
message = 'message 1äöüß ' + rand(99999999999999999).to_s
|
||||||
|
tests = [
|
||||||
|
{
|
||||||
|
:name => 'start',
|
||||||
|
:instance1 => Watir::Browser.new,
|
||||||
|
:instance2 => Watir::Browser.new,
|
||||||
|
:instance1_username => 'm@edenhofer.de',
|
||||||
|
:instance1_password => 'test',
|
||||||
|
:instance2_username => 'm@edenhofer.de',
|
||||||
|
:instance2_password => 'test',
|
||||||
|
:url => 'http://localhost:3000',
|
||||||
|
:action => [
|
||||||
|
{
|
||||||
|
:where => :instance1,
|
||||||
|
:execute => 'check',
|
||||||
|
:element => :form,
|
||||||
|
:id => 'login',
|
||||||
|
:result => false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
:where => :instance2,
|
||||||
|
:execute => 'check',
|
||||||
|
:element => :form,
|
||||||
|
:id => 'login',
|
||||||
|
:result => false,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
:where => :instance1,
|
||||||
|
:execute => 'click',
|
||||||
|
:element => :a,
|
||||||
|
:id => 'chat_toogle',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
:where => :instance1,
|
||||||
|
:execute => 'set',
|
||||||
|
:element => :text_field,
|
||||||
|
:name => 'chat_message',
|
||||||
|
:value => message,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
:where => :instance1,
|
||||||
|
:execute => 'send_key',
|
||||||
|
:element => :text_field,
|
||||||
|
:name => 'chat_message',
|
||||||
|
:value => :enter,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
:execute => 'wait',
|
||||||
|
:value => 3,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
:where => :instance1,
|
||||||
|
:execute => 'match',
|
||||||
|
:element => :div,
|
||||||
|
:id => 'chat_log_container',
|
||||||
|
:value => message,
|
||||||
|
:match_result => true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
:where => :instance2,
|
||||||
|
:execute => 'match',
|
||||||
|
:element => :div,
|
||||||
|
:id => 'chat_log_container',
|
||||||
|
:value => message,
|
||||||
|
:match_result => true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
:execute => 'wait',
|
||||||
|
:value => 10,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
browser_double_test(tests)
|
||||||
|
end
|
||||||
|
end
|
|
@ -6,12 +6,12 @@ require 'watir-webdriver'
|
||||||
class ActiveSupport::TestCase
|
class ActiveSupport::TestCase
|
||||||
|
|
||||||
# Add more helper methods to be used by all tests here...
|
# Add more helper methods to be used by all tests here...
|
||||||
def browser_signle_test_with_login(tests)
|
def browser_login(data)
|
||||||
all_tests = [
|
all_tests = [
|
||||||
{
|
{
|
||||||
:name => 'login',
|
:name => 'login',
|
||||||
:instance => Watir::Browser.new,
|
:instance => data[:instance] || Watir::Browser.new,
|
||||||
:url => 'http://localhost:3000',
|
:url => data[:url] || 'http://localhost:3000',
|
||||||
:action => [
|
:action => [
|
||||||
{
|
{
|
||||||
:execute => 'wait',
|
:execute => 'wait',
|
||||||
|
@ -27,13 +27,13 @@ class ActiveSupport::TestCase
|
||||||
:execute => 'set',
|
:execute => 'set',
|
||||||
:element => :text_field,
|
:element => :text_field,
|
||||||
:name => 'username',
|
:name => 'username',
|
||||||
:value => 'nicole.braun@zammad.org',
|
:value => data[:username] || 'nicole.braun@zammad.org',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
:execute => 'set',
|
:execute => 'set',
|
||||||
:element => :text_field,
|
:element => :text_field,
|
||||||
:name => 'password',
|
:name => 'password',
|
||||||
:value => 'test'
|
:value => data[:password] || 'test'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
:execute => 'click',
|
:execute => 'click',
|
||||||
|
@ -53,11 +53,51 @@ class ActiveSupport::TestCase
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
return all_tests
|
||||||
|
end
|
||||||
|
|
||||||
|
def browser_signle_test_with_login(tests)
|
||||||
|
all_tests = browser_login( {} )
|
||||||
all_tests = all_tests.concat( tests )
|
all_tests = all_tests.concat( tests )
|
||||||
browser_single_test(all_tests)
|
browser_single_test(all_tests)
|
||||||
end
|
end
|
||||||
|
|
||||||
def browser_single_test(tests)
|
def browser_double_test(tests)
|
||||||
|
instance1 = browser_single_test( browser_login({
|
||||||
|
:instance => tests[0][:instance1],
|
||||||
|
:username => tests[0][:instance1_username],
|
||||||
|
:password => tests[0][:instance1_password],
|
||||||
|
:url => tests[0][:url],
|
||||||
|
}), true )
|
||||||
|
instance2 = browser_single_test( browser_login({
|
||||||
|
:instance => tests[0][:instance2],
|
||||||
|
:username => tests[0][:instance2_username],
|
||||||
|
:password => tests[0][:instance2_password],
|
||||||
|
:url => tests[0][:url],
|
||||||
|
}), true )
|
||||||
|
tests.each { |test|
|
||||||
|
if test[:action]
|
||||||
|
test[:action].each { |action|
|
||||||
|
if action[:execute] == 'wait'
|
||||||
|
sleep action[:value]
|
||||||
|
next
|
||||||
|
end
|
||||||
|
next if !action[:where]
|
||||||
|
if action[:where] == :instance1
|
||||||
|
instance = instance1
|
||||||
|
else
|
||||||
|
instance = instance2
|
||||||
|
end
|
||||||
|
|
||||||
|
browser_element_action(test, action, instance)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
}
|
||||||
|
instance1.close
|
||||||
|
instance2.close
|
||||||
|
end
|
||||||
|
|
||||||
|
def browser_single_test(tests, keep_connection = false)
|
||||||
instance = nil
|
instance = nil
|
||||||
tests.each { |test|
|
tests.each { |test|
|
||||||
if test[:instance]
|
if test[:instance]
|
||||||
|
@ -72,7 +112,17 @@ class ActiveSupport::TestCase
|
||||||
sleep action[:value]
|
sleep action[:value]
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
browser_element_action(test, action, instance)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
}
|
||||||
|
if keep_connection
|
||||||
|
return instance
|
||||||
|
end
|
||||||
|
instance.close
|
||||||
|
end
|
||||||
|
|
||||||
|
def browser_element_action(test, action, instance)
|
||||||
if action[:id]
|
if action[:id]
|
||||||
element = instance.send( action[:element], { :id => action[:id] } )
|
element = instance.send( action[:element], { :id => action[:id] } )
|
||||||
if action[:result] == false
|
if action[:result] == false
|
||||||
|
@ -117,13 +167,25 @@ class ActiveSupport::TestCase
|
||||||
element.set( action[:value] )
|
element.set( action[:value] )
|
||||||
elsif action[:execute] == 'click'
|
elsif action[:execute] == 'click'
|
||||||
element.click
|
element.click
|
||||||
|
elsif action[:execute] == 'send_key'
|
||||||
|
element.send_keys action[:value]
|
||||||
|
elsif action[:execute] == 'match'
|
||||||
|
if element.text =~ /#{Regexp.quote(action[:value])}/
|
||||||
|
if action[:match_result]
|
||||||
|
assert( true, "(#{test[:name]}) matching '#{action[:value]}' in content '#{element.text}'" )
|
||||||
|
else
|
||||||
|
assert( false, "(#{test[:name]}) matching '#{action[:value]}' in content '#{element.text}' but should not!" )
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if !action[:match_result]
|
||||||
|
assert( true, "(#{test[:name]}) not matching '#{action[:value]}' in content '#{element.text}'" )
|
||||||
|
else
|
||||||
|
assert( false, "(#{test[:name]}) not matching '#{action[:value]}' in content '#{element.text}' but should not!" )
|
||||||
|
end
|
||||||
|
end
|
||||||
elsif action[:execute] == 'check'
|
elsif action[:execute] == 'check'
|
||||||
else
|
else
|
||||||
assert( false, "(#{test[:name]}) unknow action '#{action[:execute]}'" )
|
assert( false, "(#{test[:name]}) unknow action '#{action[:execute]}'" )
|
||||||
end
|
end
|
||||||
}
|
|
||||||
end
|
|
||||||
}
|
|
||||||
instance.close
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue