Moved to css selectors for browser tests. Fixed setting widget.

This commit is contained in:
Martin Edenhofer 2013-02-22 11:36:00 +01:00
parent 093f1df438
commit 97377bf138
11 changed files with 424 additions and 143 deletions

View file

@ -31,13 +31,11 @@ class App.SettingsAreaItem extends App.Controller
# defaults
directValue = 0
directData = undefined
for item in @setting.options['form']
directValue = +1
directData = @setting.state.value[item.name]
directValue += 1
if directValue > 1
item['default'] = directData
for item in @setting.options['form']
item['default'] = @setting.state.value[item.name]
else
item['default'] = @setting.state.value
@ -62,7 +60,7 @@ class App.SettingsAreaItem extends App.Controller
directValue = 0
directData = undefined
for item in @setting.options['form']
directValue = +1
directValue += 1
directData = params[item.name]
if directValue > 1

View file

@ -15,14 +15,14 @@
<div class="span6 master_user">
<h2><%- @T( 'Master Agent' ) %></h2>
<form class="form-stacked" id="form-master">
<button class="btn btn-primary submit"><%- @T( 'Next...' ) %></button>
<button type="submit" class="btn btn-primary submit"><%- @T( 'Next...' ) %></button>
</form>
</div>
<% end %>
<div class="span6 agent_user hide">
<h2><%- @T( 'Invite Agents' ) %></h2>
<form class="form-stacked" id="form-agent">
<button class="btn btn-primary submit"><%- @T( 'Send invitation' ) %></button>
<button type="submit" class="btn btn-primary submit"><%- @T( 'Send invitation' ) %></button>
</form>
</div>
<div class="span6">

View file

@ -1,4 +1,4 @@
<form class="">
<form class="" id="<%= @setting.name %>">
<h2><%- @T( @setting.title ) %></h2>
<p><%- @T( @setting.description ) %></p>
<div id="form-item"></div>

View file

@ -0,0 +1,83 @@
# encoding: utf-8
require 'browser_test_helper'
class AaaGettingStarted < ActiveSupport::TestCase
test 'getting started' do
tests = [
{
:name => 'start',
:instance => Watir::Browser.new,
:url => 'http://localhost:3000/#getting_started',
:action => [
{
:execute => 'wait',
:value => 6,
},
{
:execute => 'check',
:css => '#form-master',
:result => true,
},
],
},
{
:name => 'getting started',
:action => [
{
:execute => 'set',
:css => 'input[name="firstname"]',
:value => 'Test Master',
},
{
:execute => 'set',
:css => 'input[name="lastname"]',
:value => 'Agent',
},
{
:execute => 'set',
:css => 'input[name="email"]',
:value => 'master@example.com',
},
{
:execute => 'set',
:element => :text_field,
:css => 'input[name="password"]',
:value => 'test1234äöüß',
},
{
:execute => 'set',
:css => 'input[name="password_confirm"]',
:value => 'test1234äöüß',
},
{
:execute => 'click',
:css => '#form-master button[type="submit"]',
},
{
:execute => 'wait',
:value => 5,
},
{
:execute => 'check',
:css => '#login',
:result => false,
},
{
:execute => 'check',
:element => :url,
:result => '#getting_started',
},
# check action
{
:execute => 'match',
:css => 'body',
:value => 'Invite Agents',
:match_result => true,
},
],
},
]
browser_single_test(tests)
end
end

View file

@ -11,20 +11,17 @@ class Auth < ActiveSupport::TestCase
:action => [
{
:execute => 'check',
:element => :form,
:id => 'login',
:css => '#login',
:result => true,
},
{
:execute => 'check',
:element => :button,
:type => 'submit',
:css => '#login button',
:result => true,
},
{
:execute => 'click',
:element => :button,
:type => 'submit',
:css => '#login button',
},
{
:execute => 'wait',
@ -32,8 +29,7 @@ class Auth < ActiveSupport::TestCase
},
{
:execute => 'check',
:element => :form,
:id => 'login',
:css => '#login',
:result => true,
},
],
@ -47,37 +43,40 @@ class Auth < ActiveSupport::TestCase
},
{
:execute => 'check',
:element => :form,
:id => 'login',
:css => '#login',
:result => true,
},
{
:execute => 'set',
:element => :text_field,
:name => 'username',
:css => 'input[name="username"]',
:value => 'nicole.braun@zammad.org',
},
{
:execute => 'set',
:element => :text_field,
:name => 'password',
:css => 'input[name="password"]',
:value => 'test'
},
{
:execute => 'click',
:element => :button,
:type => 'submit',
:css => '#login button',
},
{
:execute => 'wait',
:value => 3,
},
# check action
{
:execute => 'check',
:element => :form,
:id => 'login',
:css => '#login',
:result => false,
},
{
:execute => 'match',
:css => 'body',
:value => 'nicole.braun@zammad.org',
:match_result => true,
},
],
},
]

View file

@ -0,0 +1,85 @@
# encoding: utf-8
require 'browser_test_helper'
class AuthMaster < ActiveSupport::TestCase
test 'authentication' do
tests = [
{
:name => 'start',
:instance => Watir::Browser.new,
:url => 'http://localhost:3000',
:action => [
{
:execute => 'check',
:css => '#login',
:result => true,
},
{
:execute => 'check',
:css => '#login button',
:result => true,
},
{
:execute => 'click',
:css => '#login button',
},
{
:execute => 'wait',
:value => 3,
},
{
:execute => 'check',
:css => '#login',
:result => true,
},
],
},
{
:name => 'login',
:action => [
{
:execute => 'wait',
:value => 2,
},
{
:execute => 'check',
:css => '#login',
:result => true,
},
{
:execute => 'set',
:css => 'input[name="username"]',
:value => 'master@example.com',
},
{
:execute => 'set',
:css => 'input[name="password"]',
:value => 'test1234äöüß'
},
{
:execute => 'click',
:css => '#login button',
},
{
:execute => 'wait',
:value => 3,
},
# check action
{
:execute => 'check',
:css => '#login',
:result => false,
},
{
:execute => 'match',
:css => 'body',
:value => 'master@example',
:match_result => true,
},
],
},
]
browser_single_test(tests)
end
end

View file

@ -9,45 +9,40 @@ class Chat < ActiveSupport::TestCase
:name => 'start',
:instance1 => Watir::Browser.new,
:instance2 => Watir::Browser.new,
:instance1_username => 'm@edenhofer.de',
:instance1_username => 'master@example.com',
:instance1_password => 'test',
:instance2_username => 'm@edenhofer.de',
:instance2_username => 'master@example.com',
:instance2_password => 'test',
:url => 'http://localhost:3000',
:action => [
{
:where => :instance1,
:execute => 'check',
:element => :form,
:id => 'login',
:css => '#login',
:result => false,
},
{
:where => :instance2,
:execute => 'check',
:element => :form,
:id => 'login',
:css => '#login',
:result => false,
},
{
:where => :instance1,
:execute => 'click',
:element => :a,
:id => 'chat_toogle',
:css => '#chat_toogle',
},
{
:where => :instance1,
:execute => 'set',
:element => :text_field,
:name => 'chat_message',
:css => 'input[name="chat_message"]',
:value => message,
},
{
:where => :instance1,
:execute => 'send_key',
:element => :text_field,
:name => 'chat_message',
:css => 'input[name="chat_message"]',
:value => :enter,
},
{
@ -57,16 +52,14 @@ class Chat < ActiveSupport::TestCase
{
:where => :instance1,
:execute => 'match',
:element => :div,
:id => 'chat_log_container',
:css => '#chat_log_container',
:value => message,
:match_result => true,
},
{
:where => :instance2,
:execute => 'match',
:element => :div,
:id => 'chat_log_container',
:css => '#chat_log_container',
:value => message,
:match_result => true,
},

View file

@ -9,8 +9,7 @@ class CustomerTicketCreate < ActiveSupport::TestCase
:action => [
{
:execute => 'click',
:element => :link,
:href => '#customer_ticket_new',
:css => 'a[href="#customer_ticket_new"]',
},
{
:execute => 'wait',
@ -18,8 +17,7 @@ class CustomerTicketCreate < ActiveSupport::TestCase
},
{
:execute => 'check',
:element => :div,
:id => 'form_create',
:css => '#form_create',
:result => true,
},
{
@ -28,26 +26,22 @@ class CustomerTicketCreate < ActiveSupport::TestCase
},
{
:execute => 'select',
:element => :select_list,
:name => 'group_id',
:css => '#form_create select[name="group_id"]',
:value => 'Users',
},
{
:execute => 'set',
:element => :text_field,
:name => 'subject',
:css => '#form_create input[name="subject"]',
:value => 'some subject 123äöü',
},
{
:execute => 'set',
:element => :text_field,
:name => 'body',
:css => '#form_create textarea[name="body"]',
:value => 'some body 123äöü',
},
{
:execute => 'click',
:element => :button,
:type => 'submit',
:css => 'button[type="submit"]',
},
{
:execute => 'wait',
@ -55,8 +49,7 @@ class CustomerTicketCreate < ActiveSupport::TestCase
},
{
:execute => 'check',
:element => :form,
:id => 'login',
:css => '#login',
:result => false,
},
{
@ -68,8 +61,7 @@ class CustomerTicketCreate < ActiveSupport::TestCase
# check ticket
{
:execute => 'match',
:element => :div,
:class => 'article',
:css => 'div.article',
:value => 'some body 123äöü',
:match_result => true,
},
@ -77,19 +69,17 @@ class CustomerTicketCreate < ActiveSupport::TestCase
# update ticket
{
:execute => 'check',
:element => :text_field,
:name => 'body',
:css => 'textarea[name="body"]',
:result => true,
},
{
:execute => 'set',
:element => :text_field,
:name => 'body',
:css => 'textarea[name="body"]',
:value => 'some body 1234 äöüß',
},
{
:execute => 'click',
:element => :button,
:css => 'button',
:type => 'submit',
},
{
@ -98,7 +88,7 @@ class CustomerTicketCreate < ActiveSupport::TestCase
},
{
:execute => 'match',
:element => :body,
:css => 'body',
:value => 'some body 1234 äöüß',
:match_result => true,
},

View file

@ -9,13 +9,11 @@ class Preferences < ActiveSupport::TestCase
:action => [
{
:execute => 'click',
:element => :link,
:href => '#current_user',
:css => 'a[href="#current_user"]',
},
{
:execute => 'click',
:element => :link,
:href => '#profile',
:css => 'a[href="#profile"]',
},
{
:execute => 'wait',
@ -23,8 +21,7 @@ class Preferences < ActiveSupport::TestCase
},
{
:execute => 'click',
:element => :link,
:href => '#profile/language',
:css => 'a[href="#profile/language"]',
},
{
:execute => 'wait',
@ -32,8 +29,7 @@ class Preferences < ActiveSupport::TestCase
},
{
:execute => 'check',
:element => :div,
:id => 'language',
:css => '#language',
:result => true,
},
{
@ -42,14 +38,12 @@ class Preferences < ActiveSupport::TestCase
},
{
:execute => 'select',
:element => :select_list,
:name => 'locale',
:css => '#language select[name="locale"]',
:value => 'Deutsch',
},
{
:execute => 'click',
:element => :button,
:type => 'submit',
:css => '#language button',
},
{
:execute => 'wait',
@ -57,26 +51,23 @@ class Preferences < ActiveSupport::TestCase
},
{
:execute => 'check',
:element => :form,
:id => 'login',
:css => '#login',
:result => false,
},
{
:execute => 'match',
:element => :body,
:css => 'body',
:value => 'Sprache',
:match_result => true,
},
{
:execute => 'select',
:element => :select_list,
:name => 'locale',
:css => '#language select[name="locale"]',
:value => 'English (United States)',
},
{
:execute => 'click',
:element => :button,
:type => 'submit',
:css => '#language button',
},
{
:execute => 'wait',
@ -84,7 +75,7 @@ class Preferences < ActiveSupport::TestCase
},
{
:execute => 'match',
:element => :body,
:css => 'body',
:value => 'Language',
:match_result => true,
},

159
test/browser/setting.rb Normal file
View file

@ -0,0 +1,159 @@
# encoding: utf-8
require 'browser_test_helper'
class TestSetting < ActiveSupport::TestCase
test 'setting' do
tests = [
{
:name => 'setting',
:action => [
{
:execute => 'click',
:css => 'a[href="#settings"]',
},
{
:execute => 'click',
:css => 'a[href="#settings/security"]',
},
{
:execute => 'click',
:css => 'a[href="#settings/security/third_party_auth"]',
},
{
:execute => 'wait',
:value => 2,
},
{
:execute => 'check',
:css => '#auth_facebook select[name="auth_facebook"]',
:result => true,
},
# set yes
{
:execute => 'select',
:css => '#auth_facebook select[name="auth_facebook"]',
:value => 'yes',
},
{
:execute => 'click',
:css => '#auth_facebook button[type=submit]',
},
{
:execute => 'wait',
:value => 2,
},
{
:execute => 'match',
:css => '#auth_facebook select[name="auth_facebook"]',
:value => 'yes',
:match_result => true,
},
{
:execute => 'match',
:css => '#auth_facebook select[name="auth_facebook"]',
:value => 'no',
:match_result => false,
},
{
:execute => 'wait',
:value => 2,
},
# set no
{
:execute => 'select',
:css => '#auth_facebook select[name="auth_facebook"]',
:value => 'no',
},
{
:execute => 'click',
:css => '#auth_facebook button[type=submit]',
},
{
:execute => 'wait',
:value => 2,
},
{
:execute => 'match',
:css => '#auth_facebook select[name="auth_facebook"]',
:value => 'yes',
:match_result => false,
},
{
:execute => 'match',
:css => '#auth_facebook select[name="auth_facebook"]',
:value => 'no',
:match_result => true,
},
# set key and secret
{
:execute => 'set',
:css => '#auth_facebook_credentials input[name=app_id]',
:value => 'id_test1234äöüß',
},
{
:execute => 'set',
:css => '#auth_facebook_credentials input[name=app_secret]',
:value => 'secret_test1234äöüß',
},
{
:execute => 'click',
:css => '#auth_facebook_credentials button[type=submit]',
},
{
:execute => 'wait',
:value => 2,
},
{
:execute => 'match',
:css => '#auth_facebook_credentials input[name=app_id]',
:value => 'id_test1234äöüß',
:match_result => true,
},
{
:execute => 'match',
:css => '#auth_facebook_credentials input[name=app_secret]',
:value => 'secret_test1234äöüß',
:match_result => true,
},
# set key and secret again
{
:execute => 'set',
:css => '#auth_facebook_credentials input[name=app_id]',
:value => '---',
},
{
:execute => 'set',
:css => '#auth_facebook_credentials input[name=app_secret]',
:value => '---',
},
{
:execute => 'click',
:css => '#auth_facebook_credentials button[type=submit]',
},
{
:execute => 'wait',
:value => 2,
},
{
:execute => 'match',
:css => '#auth_facebook_credentials input[name=app_id]',
:value => '---',
:match_result => true,
},
{
:execute => 'match',
:css => '#auth_facebook_credentials input[name=app_secret]',
:value => '---',
:match_result => true,
},
],
},
]
browser_signle_test_with_login(tests, { :username => 'master@example.com' })
end
end

View file

@ -19,26 +19,22 @@ class ActiveSupport::TestCase
},
{
:execute => 'check',
:element => :form,
:id => 'login',
:css => '#login',
:result => true,
},
{
:execute => 'set',
:element => :text_field,
:name => 'username',
:css => 'input[name="username"]',
:value => data[:username] || 'nicole.braun@zammad.org',
},
{
:execute => 'set',
:element => :text_field,
:name => 'password',
:css => 'input[name="password"]',
:value => data[:password] || 'test'
},
{
:execute => 'click',
:element => :button,
:type => 'submit',
:css => '#login button',
},
{
:execute => 'wait',
@ -46,8 +42,7 @@ class ActiveSupport::TestCase
},
{
:execute => 'check',
:element => :form,
:id => 'login',
:css => '#login',
:result => false,
},
],
@ -56,8 +51,8 @@ class ActiveSupport::TestCase
return all_tests
end
def browser_signle_test_with_login(tests)
all_tests = browser_login( {} )
def browser_signle_test_with_login(tests, login = {})
all_tests = browser_login( login )
all_tests = all_tests.concat( tests )
browser_single_test(all_tests)
end
@ -123,44 +118,12 @@ class ActiveSupport::TestCase
end
def browser_element_action(test, action, instance)
if action[:id]
element = instance.send( action[:element], { :id => action[:id] } )
if action[:css]
element = instance.element( { :css => action[:css] } )
if action[:result] == false
assert( !element.exists?, "(#{test[:name]}) Element #{action[:element]} with id #{action[:id]} exists" )
assert( !element.exists?, "(#{test[:name]}) Element with css '#{action[:css]}' exists" )
else
assert( element.exists?, "(#{test[:name]}) Element #{action[:element]} with id #{action[:id]} doesn't exist" )
end
elsif action[:type]
if action[:result] == false
element = instance.send( action[:element], { :type => action[:type] } )
assert( !element.exists?, "(#{test[:name]}) Element #{action[:element]} with type #{action[:type]} exists" )
else
element = instance.send( action[:element], { :type => action[:type] } )
assert( element.exists?, "(#{test[:name]}) Element #{action[:element]} with type #{action[:type]} doesn't exist" )
end
elsif action[:class]
if action[:result] == false
element = instance.send( action[:element], { :class => action[:class] } )
assert( !element.exists?, "(#{test[:name]}) Element #{action[:element]} with class #{action[:class]} exists" )
else
element = instance.send( action[:element], { :class => action[:class] } )
assert( element.exists?, "(#{test[:name]}) Element #{action[:element]} with class #{action[:class]} doesn't exist" )
end
elsif action[:name]
if action[:result] == false
element = instance.send( action[:element], { :name => action[:name] } )
assert( !element.exists?, "(#{test[:name]}) Element #{action[:element]} with name #{action[:name]} exists" )
else
element = instance.send( action[:element], { :name => action[:name] } )
assert( element.exists?, "(#{test[:name]}) Element #{action[:element]} with name #{action[:name]} doesn't exist" )
end
elsif action[:href]
if action[:result] == false
element = instance.send( action[:element], { :href => action[:href] } )
assert( !element.exists?, "(#{test[:name]}) Element #{action[:element]} with href #{action[:href]} exists" )
else
element = instance.send( action[:element], { :href => action[:href] } )
assert( element.exists?, "(#{test[:name]}) Element #{action[:element]} with href #{action[:href]} doesn't exist" )
assert( element.exists?, "(#{test[:name]}) Element with css '#{action[:css]}' doesn't exist" )
end
elsif action[:element] == :url
if instance.url =~ /#{Regexp.quote(action[:result])}/
@ -168,31 +131,51 @@ class ActiveSupport::TestCase
else
assert( false, "(#{test[:name]}) url #{instance.url} is not matching #{action[:result]}" )
end
elsif action[:element] == :body
element = instance.send( action[:element] )
else
assert( false, "(#{test[:name]}) unknow selector for '#{action[:element]}'" )
end
if action[:execute] == 'set'
element.set( action[:value] )
element.to_subtype.set( action[:value] )
elsif action[:execute] == 'select'
element.select( action[:value] )
element.to_subtype.select( action[:value] )
elsif action[:execute] == '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[:css] =~ /select/
success = element.to_subtype.selected?(action[:value])
if action[:match_result]
assert( true, "(#{test[:name]}) matching '#{action[:value]}' in content '#{element.text}'" )
if success
assert( true, "(#{test[:name]}) matching '#{action[:value]}' in select list" )
else
assert( false, "(#{test[:name]}) matching '#{action[:value]}' in content '#{element.text}' but should not!" )
assert( false, "(#{test[:name]}) not matching '#{action[:value]}' in select list" )
end
else
if success
assert( false, "(#{test[:name]}) not matching '#{action[:value]}' in select list" )
else
assert( true, "(#{test[:name]}) matching '#{action[:value]}' in select list" )
end
end
else
if action[:css] =~ /input|textarea/i
text = element.to_subtype.value
else
text = element.text
end
if text =~ /#{Regexp.quote(action[:value])}/
if action[:match_result]
assert( true, "(#{test[:name]}) matching '#{action[:value]}' in content '#{text}'" )
else
assert( false, "(#{test[:name]}) matching '#{action[:value]}' in content '#{text}' but should not!" )
end
else
if !action[:match_result]
assert( true, "(#{test[:name]}) not matching '#{action[:value]}' in content '#{element.text}'" )
assert( true, "(#{test[:name]}) not matching '#{action[:value]}' in content '#{text}'" )
else
assert( false, "(#{test[:name]}) not matching '#{action[:value]}' in content '#{element.text}' but should not!" )
assert( false, "(#{test[:name]}) not matching '#{action[:value]}' in content '#{text}' but should not!" )
end
end
end
elsif action[:execute] == 'check'