Moved back to selenium-webdriver for browser testing.

This commit is contained in:
Martin Edenhofer 2013-02-23 23:54:48 +01:00
parent b899c03f93
commit e35ac9b468
11 changed files with 116 additions and 58 deletions

View file

@ -72,7 +72,6 @@ group :development, :test do
gem 'simplecov-rcov' gem 'simplecov-rcov'
# UI tests w/ Selenium # UI tests w/ Selenium
#gem 'selenium-webdriver' gem 'selenium-webdriver'
gem 'watir-webdriver'
end end

View file

@ -1,17 +1,17 @@
# encoding: utf-8 # encoding: utf-8
require 'browser_test_helper' require 'browser_test_helper'
class AaaGettingStarted < ActiveSupport::TestCase class AaaGettingStartedTest < TestCase
test 'getting started' do def test_getting_started
tests = [ tests = [
{ {
:name => 'start', :name => 'start',
:instance => Watir::Browser.new, :instance => browser_instance,
:url => 'http://localhost:3000/#getting_started', :url => browser_url + '/#getting_started',
:action => [ :action => [
{ {
:execute => 'wait', :execute => 'wait',
:value => 6, :value => 1,
}, },
{ {
:execute => 'check', :execute => 'check',

View file

@ -1,13 +1,13 @@
# encoding: utf-8 # encoding: utf-8
require 'browser_test_helper' require 'browser_test_helper'
class Auth < ActiveSupport::TestCase class AuthTest < TestCase
test 'authentication' do def test_authentication
tests = [ tests = [
{ {
:name => 'start', :name => 'start',
:instance => Watir::Browser.new, :instance => browser_instance,
:url => 'http://localhost:3000', :url => browser_url,
:action => [ :action => [
{ {
:execute => 'check', :execute => 'check',

View file

@ -1,13 +1,13 @@
# encoding: utf-8 # encoding: utf-8
require 'browser_test_helper' require 'browser_test_helper'
class AuthMaster < ActiveSupport::TestCase class AuthMasterTest < TestCase
test 'authentication' do def test_authentication
tests = [ tests = [
{ {
:name => 'start', :name => 'start',
:instance => Watir::Browser.new, :instance => browser_instance,
:url => 'http://localhost:3000', :url => browser_url,
:action => [ :action => [
{ {
:execute => 'check', :execute => 'check',

View file

@ -1,19 +1,19 @@
# encoding: utf-8 # encoding: utf-8
require 'browser_test_helper' require 'browser_test_helper'
class Chat < ActiveSupport::TestCase class ChatTest < TestCase
test 'websocket' do def test_websocket
message = 'message 1äöüß ' + rand(99999999999999999).to_s message = 'message 1äöüß ' + rand(99999999999999999).to_s
tests = [ tests = [
{ {
:name => 'start', :name => 'start',
:instance1 => Watir::Browser.new, :instance1 => browser_instance,
:instance2 => Watir::Browser.new, :instance2 => browser_instance,
:instance1_username => 'master@example.com', :instance1_username => 'master@example.com',
:instance1_password => 'test', :instance1_password => 'test',
:instance2_username => 'master@example.com', :instance2_username => 'master@example.com',
:instance2_password => 'test', :instance2_password => 'test',
:url => 'http://localhost:3000', :url => browser_url,
:action => [ :action => [
{ {
:where => :instance1, :where => :instance1,
@ -27,7 +27,24 @@ class Chat < ActiveSupport::TestCase
:css => '#login', :css => '#login',
:result => false, :result => false,
}, },
{
:where => :instance1,
:execute => 'click',
:css => '#chat_toogle',
},
{
:execute => 'wait',
:value => 4,
},
{
:where => :instance1,
:execute => 'click',
:css => '#chat_toogle',
},
{
:execute => 'wait',
:value => 1,
},
{ {
:where => :instance1, :where => :instance1,
:execute => 'click', :execute => 'click',
@ -47,7 +64,7 @@ class Chat < ActiveSupport::TestCase
}, },
{ {
:execute => 'wait', :execute => 'wait',
:value => 3, :value => 6,
}, },
{ {
:where => :instance1, :where => :instance1,
@ -63,10 +80,10 @@ class Chat < ActiveSupport::TestCase
:value => message, :value => message,
:match_result => true, :match_result => true,
}, },
{ # {
:execute => 'wait', # :execute => 'wait',
:value => 10, # :value => 1,
}, # },
], ],
}, },
] ]

View file

@ -1,8 +1,8 @@
# encoding: utf-8 # encoding: utf-8
require 'browser_test_helper' require 'browser_test_helper'
class CustomerTicketCreate < ActiveSupport::TestCase class CustomerTicketCreateTest < TestCase
test 'customer ticket create' do def test_customer_ticket_create
tests = [ tests = [
{ {
:name => 'customer ticket create', :name => 'customer ticket create',

View file

@ -1,8 +1,8 @@
# encoding: utf-8 # encoding: utf-8
require 'browser_test_helper' require 'browser_test_helper'
class Preferences < ActiveSupport::TestCase class PreferencesTest < TestCase
test 'preferences' do def test_preferences
tests = [ tests = [
{ {
:name => 'preferences', :name => 'preferences',

View file

@ -1,8 +1,8 @@
# encoding: utf-8 # encoding: utf-8
require 'browser_test_helper' require 'browser_test_helper'
class TestSetting < ActiveSupport::TestCase class SettingTest < TestCase
test 'setting' do def test_setting
tests = [ tests = [
{ {
:name => 'setting', :name => 'setting',

View file

@ -1,23 +1,19 @@
# encoding: utf-8 # encoding: utf-8
require 'browser_test_helper' require 'browser_test_helper'
class Signup < ActiveSupport::TestCase class SignupTest < TestCase
test 'signup' do def test_signup
signup_user_email = 'signup-test-' + rand(999999).to_s + '@example.com' signup_user_email = 'signup-test-' + rand(999999).to_s + '@example.com'
tests = [ tests = [
{ {
:name => 'start', :name => 'start',
:instance => Watir::Browser.new, :instance => browser_instance,
:url => 'http://localhost:3000', :url => browser_url,
:action => [ :action => [
{ {
:execute => 'click', :execute => 'click',
:css => 'a[href="#signup"]', :css => 'a[href="#signup"]',
}, },
{
:execute => 'wait',
:value => 1,
},
{ {
:execute => 'check', :execute => 'check',
:css => '#form-signup', :css => '#form-signup',
@ -59,7 +55,7 @@ class Signup < ActiveSupport::TestCase
}, },
{ {
:execute => 'wait', :execute => 'wait',
:value => 3, :value => 2,
}, },
# check action # check action

View file

@ -1,17 +1,50 @@
ENV["RAILS_ENV"] = "test" ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__) require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help' require 'rails/test_help'
require 'watir-webdriver' #require 'watir-webdriver'
require 'selenium-webdriver'
class ActiveSupport::TestCase class TestCase < Test::Unit::TestCase
def browser_url
ENV['BROWSER_URL'] || 'http://localhost:3000'
end
def browser_instance
if !@browsers
@browsers = []
end
if !ENV['REMOTE_URL']
browser = Selenium::WebDriver.for :firefox
@browsers.push browser
return browser
end
# return Watir::Browser.new if !ENV['REMOTE_URL']
caps = Selenium::WebDriver::Remote::Capabilities.send( ENV['BROWSER'] )
caps.platform = ENV['BROWSER_OS'] || 'Windows 2008'
caps.version = ENV['BROWSER_VERSION'] || '8'
Selenium::WebDriver.for(
:remote,
:url => ENV['REMOTE_URL'],
:desired_capabilities => caps,
)
end
def teardown
return if !@browsers
@browsers.each{ |browser|
browser.close
}
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 = [
{ {
:name => 'login', :name => 'login',
:instance => data[:instance] || Watir::Browser.new, :instance => data[:instance] || browser_instance,
:url => data[:url] || 'http://localhost:3000', :url => data[:url] || browser_url,
:action => [ :action => [
{ {
:execute => 'wait', :execute => 'wait',
@ -99,7 +132,7 @@ class ActiveSupport::TestCase
instance = test[:instance] instance = test[:instance]
end end
if test[:url] if test[:url]
instance.goto( test[:url] ) instance.get( test[:url] )
end end
if test[:action] if test[:action]
test[:action].each { |action| test[:action].each { |action|
@ -119,32 +152,45 @@ class ActiveSupport::TestCase
def browser_element_action(test, action, instance) def browser_element_action(test, action, instance)
if action[:css] if action[:css]
element = instance.element( { :css => action[:css] } ) begin
element = instance.find_element( { :css => action[:css] } )
rescue
element = nil
end
if action[:result] == false if action[:result] == false
assert( !element.exists?, "(#{test[:name]}) Element with css '#{action[:css]}' exists" ) assert( !element, "(#{test[:name]}) Element with css '#{action[:css]}' exists" )
else else
assert( element.exists?, "(#{test[:name]}) Element with css '#{action[:css]}' doesn't exist" ) assert( element, "(#{test[:name]}) Element with css '#{action[:css]}' doesn't exist" )
end end
elsif action[:element] == :url elsif action[:element] == :url
if instance.url =~ /#{Regexp.quote(action[:result])}/ if instance.current_url =~ /#{Regexp.quote(action[:result])}/
assert( true, "(#{test[:name]}) url #{instance.url} is matching #{action[:result]}" ) assert( true, "(#{test[:name]}) url #{instance.current_url} is matching #{action[:result]}" )
else else
assert( false, "(#{test[:name]}) url #{instance.url} is not matching #{action[:result]}" ) assert( false, "(#{test[:name]}) url #{instance.current_url} is not matching #{action[:result]}" )
end end
else else
assert( false, "(#{test[:name]}) unknow selector for '#{action[:element]}'" ) assert( false, "(#{test[:name]}) unknow selector for '#{action[:element]}'" )
end end
if action[:execute] == 'set' if action[:execute] == 'set'
element.to_subtype.set( action[:value] ) element.send_keys( action[:value] )
elsif action[:execute] == 'select' elsif action[:execute] == 'select'
element.to_subtype.select( action[:value] ) dropdown = Selenium::WebDriver::Support::Select.new(element)
dropdown.select_by(:text, action[:value])
elsif action[:execute] == 'click' elsif action[:execute] == 'click'
element.click element.click
elsif action[:execute] == 'send_key' elsif action[:execute] == 'send_key'
element.send_keys action[:value] element.send_keys action[:value]
elsif action[:execute] == 'match' elsif action[:execute] == 'match'
if action[:css] =~ /select/ if action[:css] =~ /select/
success = element.to_subtype.selected?(action[:value]) dropdown = Selenium::WebDriver::Support::Select.new(element)
success = false
if dropdown.selected_options
dropdown.selected_options.each {|option|
if option.text == action[:value]
success = true
end
}
end
if action[:match_result] if action[:match_result]
if success if success
assert( true, "(#{test[:name]}) matching '#{action[:value]}' in select list" ) assert( true, "(#{test[:name]}) matching '#{action[:value]}' in select list" )
@ -159,8 +205,8 @@ class ActiveSupport::TestCase
end end
end end
else else
if action[:css] =~ /input|textarea/i if action[:css] =~ /input/i
text = element.to_subtype.value text = element.attribute('value')
else else
text = element.text text = element.text
end end

View file

@ -96,4 +96,4 @@ class TagTest < ActiveSupport::TestCase
assert( !list.include?( test[:tag_add][:item] ), "Tag entry destroyed") assert( !list.include?( test[:tag_add][:item] ), "Tag entry destroyed")
} }
end end
end end