2012-12-14 10:14:48 +00:00
|
|
|
ENV["RAILS_ENV"] = "test"
|
|
|
|
require File.expand_path('../../config/environment', __FILE__)
|
2013-02-23 22:54:48 +00:00
|
|
|
require 'selenium-webdriver'
|
2012-12-14 10:14:48 +00:00
|
|
|
|
2013-02-23 22:54:48 +00:00
|
|
|
class TestCase < Test::Unit::TestCase
|
2013-06-25 14:00:28 +00:00
|
|
|
def browser
|
|
|
|
ENV['BROWSER'] || 'firefox'
|
|
|
|
end
|
|
|
|
|
|
|
|
def browser_support_cookies
|
|
|
|
if browser =~ /(internet_explorer|ie)/i
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2013-02-23 22:54:48 +00:00
|
|
|
def browser_url
|
|
|
|
ENV['BROWSER_URL'] || 'http://localhost:3000'
|
|
|
|
end
|
|
|
|
|
|
|
|
def browser_instance
|
|
|
|
if !@browsers
|
2014-12-14 13:13:46 +00:00
|
|
|
@browsers = {}
|
2013-02-23 22:54:48 +00:00
|
|
|
end
|
2013-08-11 07:56:58 +00:00
|
|
|
if !ENV['REMOTE_URL'] || ENV['REMOTE_URL'].empty?
|
2013-06-25 14:00:28 +00:00
|
|
|
local_browser = Selenium::WebDriver.for( browser.to_sym )
|
2013-07-24 18:09:20 +00:00
|
|
|
browser_instance_preferences(local_browser)
|
2014-12-14 13:13:46 +00:00
|
|
|
@browsers[local_browser.hash] = local_browser
|
2013-06-25 14:00:28 +00:00
|
|
|
return local_browser
|
2013-02-23 22:54:48 +00:00
|
|
|
end
|
|
|
|
|
2013-08-11 07:56:58 +00:00
|
|
|
caps = Selenium::WebDriver::Remote::Capabilities.send( browser )
|
2015-01-23 22:24:03 +00:00
|
|
|
if ENV['BROWSER_OS']
|
|
|
|
caps.platform = ENV['BROWSER_OS']
|
|
|
|
end
|
|
|
|
if ENV['BROWSER_VERSION']
|
|
|
|
caps.version = ENV['BROWSER_VERSION']
|
|
|
|
end
|
2013-06-25 14:00:28 +00:00
|
|
|
local_browser = Selenium::WebDriver.for(
|
2013-02-23 22:54:48 +00:00
|
|
|
:remote,
|
|
|
|
:url => ENV['REMOTE_URL'],
|
|
|
|
:desired_capabilities => caps,
|
|
|
|
)
|
2013-07-24 18:09:20 +00:00
|
|
|
browser_instance_preferences(local_browser)
|
2014-12-14 13:13:46 +00:00
|
|
|
@browsers[local_browser.hash] = local_browser
|
2013-06-25 14:00:28 +00:00
|
|
|
return local_browser
|
2013-02-23 22:54:48 +00:00
|
|
|
end
|
2014-12-14 13:13:46 +00:00
|
|
|
|
|
|
|
def browser_instance_close(local_browser)
|
|
|
|
return if !@browsers[local_browser.hash]
|
|
|
|
@browsers.delete( local_browser.hash )
|
|
|
|
local_browser.quit
|
|
|
|
end
|
|
|
|
|
2013-07-24 18:09:20 +00:00
|
|
|
def browser_instance_preferences(local_browser)
|
2013-11-14 21:30:44 +00:00
|
|
|
#local_browser.manage.window.resize_to(1024, 1024)
|
2013-07-24 18:09:20 +00:00
|
|
|
if ENV['REMOTE_URL'] !~ /saucelabs/i
|
|
|
|
if @browsers.size < 1
|
|
|
|
local_browser.manage.window.move_to(0, 0)
|
|
|
|
else
|
|
|
|
local_browser.manage.window.move_to(1024, 0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local_browser.manage.timeouts.implicit_wait = 3 # seconds
|
|
|
|
end
|
2013-02-23 22:54:48 +00:00
|
|
|
|
|
|
|
def teardown
|
|
|
|
return if !@browsers
|
2014-12-14 13:13:46 +00:00
|
|
|
@browsers.each { |hash, local_browser|
|
|
|
|
browser_instance_close(local_browser)
|
|
|
|
}
|
2013-02-23 22:54:48 +00:00
|
|
|
end
|
2012-12-14 10:14:48 +00:00
|
|
|
|
|
|
|
# Add more helper methods to be used by all tests here...
|
2012-12-14 12:16:04 +00:00
|
|
|
def browser_login(data)
|
2013-02-12 00:56:23 +00:00
|
|
|
all_tests = [
|
2012-12-14 10:14:48 +00:00
|
|
|
{
|
|
|
|
:name => 'login',
|
2013-02-23 22:54:48 +00:00
|
|
|
:instance => data[:instance] || browser_instance,
|
|
|
|
:url => data[:url] || browser_url,
|
2012-12-14 10:14:48 +00:00
|
|
|
:action => [
|
|
|
|
{
|
2013-07-25 09:11:20 +00:00
|
|
|
:execute => 'login',
|
|
|
|
:username => data[:username] || 'nicole.braun@zammad.org',
|
|
|
|
:password => data[:password] || 'test'
|
2012-12-14 10:14:48 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
];
|
2012-12-14 12:16:04 +00:00
|
|
|
return all_tests
|
|
|
|
end
|
|
|
|
|
2013-02-22 10:36:00 +00:00
|
|
|
def browser_signle_test_with_login(tests, login = {})
|
|
|
|
all_tests = browser_login( login )
|
2012-12-14 10:14:48 +00:00
|
|
|
all_tests = all_tests.concat( tests )
|
|
|
|
browser_single_test(all_tests)
|
|
|
|
end
|
|
|
|
|
2012-12-14 12:16:04 +00:00
|
|
|
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|
|
2014-12-09 19:10:38 +00:00
|
|
|
|
|
|
|
# wait
|
2012-12-14 12:16:04 +00:00
|
|
|
if action[:execute] == 'wait'
|
|
|
|
sleep action[:value]
|
|
|
|
next
|
|
|
|
end
|
2014-12-09 19:10:38 +00:00
|
|
|
|
|
|
|
# ignore no browser defined action
|
2012-12-14 12:16:04 +00:00
|
|
|
next if !action[:where]
|
2014-12-09 19:10:38 +00:00
|
|
|
|
|
|
|
# set current browser
|
2012-12-14 12:16:04 +00:00
|
|
|
if action[:where] == :instance1
|
|
|
|
instance = instance1
|
|
|
|
else
|
|
|
|
instance = instance2
|
|
|
|
end
|
|
|
|
browser_element_action(test, action, instance)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
}
|
2014-12-14 13:13:46 +00:00
|
|
|
browser_instance_close(instance1)
|
|
|
|
browser_instance_close(instance2)
|
2012-12-14 12:16:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def browser_single_test(tests, keep_connection = false)
|
2012-12-14 10:14:48 +00:00
|
|
|
instance = nil
|
2013-04-23 18:36:09 +00:00
|
|
|
@stack = nil
|
2012-12-14 10:14:48 +00:00
|
|
|
tests.each { |test|
|
|
|
|
if test[:instance]
|
|
|
|
instance = test[:instance]
|
|
|
|
end
|
|
|
|
if test[:url]
|
2013-02-23 22:54:48 +00:00
|
|
|
instance.get( test[:url] )
|
2012-12-14 10:14:48 +00:00
|
|
|
end
|
|
|
|
if test[:action]
|
|
|
|
test[:action].each { |action|
|
|
|
|
if action[:execute] == 'wait'
|
|
|
|
sleep action[:value]
|
|
|
|
next
|
|
|
|
end
|
2012-12-14 12:16:04 +00:00
|
|
|
browser_element_action(test, action, instance)
|
2012-12-14 10:14:48 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
}
|
2012-12-14 12:16:04 +00:00
|
|
|
if keep_connection
|
|
|
|
return instance
|
|
|
|
end
|
2014-12-14 13:13:46 +00:00
|
|
|
browser_instance_close(instance)
|
2012-12-14 10:14:48 +00:00
|
|
|
end
|
2013-06-08 22:35:18 +00:00
|
|
|
|
2012-12-14 12:16:04 +00:00
|
|
|
def browser_element_action(test, action, instance)
|
2013-08-20 20:37:39 +00:00
|
|
|
puts "NOTICE #{Time.now.to_s}: " + action.inspect
|
2013-08-27 21:05:33 +00:00
|
|
|
if action[:execute] !~ /accept|dismiss/i
|
2014-10-14 00:13:19 +00:00
|
|
|
#cookies = instance.manage.all_cookies
|
|
|
|
#cookies.each {|cookie|
|
|
|
|
# puts " COOKIE " + cookie.to_s
|
|
|
|
#}
|
2013-08-27 21:05:33 +00:00
|
|
|
end
|
|
|
|
|
2013-07-25 09:11:20 +00:00
|
|
|
sleep 0.1
|
2013-02-22 10:36:00 +00:00
|
|
|
if action[:css]
|
2013-06-18 20:58:29 +00:00
|
|
|
if action[:css].match '###stack###'
|
|
|
|
action[:css].gsub! '###stack###', @stack
|
|
|
|
end
|
2013-02-23 22:54:48 +00:00
|
|
|
begin
|
2013-06-08 22:35:18 +00:00
|
|
|
if action[:range] == 'all'
|
|
|
|
element = instance.find_elements( { :css => action[:css] } )
|
|
|
|
else
|
|
|
|
element = instance.find_element( { :css => action[:css] } )
|
|
|
|
end
|
2013-02-23 22:54:48 +00:00
|
|
|
rescue
|
|
|
|
element = nil
|
|
|
|
end
|
2012-12-14 12:16:04 +00:00
|
|
|
if action[:result] == false
|
2013-02-23 22:54:48 +00:00
|
|
|
assert( !element, "(#{test[:name]}) Element with css '#{action[:css]}' exists" )
|
2012-12-14 12:16:04 +00:00
|
|
|
else
|
2013-02-23 22:54:48 +00:00
|
|
|
assert( element, "(#{test[:name]}) Element with css '#{action[:css]}' doesn't exist" )
|
2012-12-14 12:16:04 +00:00
|
|
|
end
|
|
|
|
elsif action[:element] == :url
|
2013-02-23 22:54:48 +00:00
|
|
|
if instance.current_url =~ /#{Regexp.quote(action[:result])}/
|
|
|
|
assert( true, "(#{test[:name]}) url #{instance.current_url} is matching #{action[:result]}" )
|
2012-12-14 12:16:04 +00:00
|
|
|
else
|
2013-02-23 22:54:48 +00:00
|
|
|
assert( false, "(#{test[:name]}) url #{instance.current_url} is not matching #{action[:result]}" )
|
2012-12-14 12:16:04 +00:00
|
|
|
end
|
2013-06-18 21:36:07 +00:00
|
|
|
elsif action[:element] == :title
|
|
|
|
title = instance.title
|
|
|
|
if title =~ /#{action[:value]}/i
|
2013-06-24 08:09:59 +00:00
|
|
|
assert( true, "(#{test[:name]}) matching '#{action[:value]}' in title '#{title}'" )
|
2013-06-18 21:36:07 +00:00
|
|
|
else
|
2013-06-24 08:09:59 +00:00
|
|
|
assert( false, "(#{test[:name]}) not matching '#{action[:value]}' in title '#{title}'" )
|
2013-06-18 21:36:07 +00:00
|
|
|
end
|
|
|
|
return
|
2013-06-23 21:32:45 +00:00
|
|
|
elsif action[:element] == :cookie
|
2013-06-25 14:00:28 +00:00
|
|
|
if !browser_support_cookies
|
|
|
|
assert( true, "(#{test[:name]}) '#{action[:value]}' ups browser is not supporting reading cookies")
|
2013-07-14 11:43:37 +00:00
|
|
|
return
|
2013-06-25 14:00:28 +00:00
|
|
|
end
|
2013-06-23 21:32:45 +00:00
|
|
|
cookies = instance.manage.all_cookies
|
|
|
|
cookies.each {|cookie|
|
|
|
|
if cookie.to_s =~ /#{action[:value]}/i
|
2013-06-24 08:09:59 +00:00
|
|
|
assert( true, "(#{test[:name]}) matching '#{action[:value]}' in cookie '#{cookie.to_s}'" )
|
2013-06-23 21:32:45 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
}
|
2013-06-25 12:24:39 +00:00
|
|
|
assert( false, "(#{test[:name]}) not matching '#{action[:value]}' in cookie '#{cookies.to_s}'" )
|
2013-06-23 21:32:45 +00:00
|
|
|
return
|
2013-03-22 08:29:44 +00:00
|
|
|
elsif action[:element] == :alert
|
|
|
|
element = instance.switch_to.alert
|
2013-07-25 09:11:20 +00:00
|
|
|
elsif action[:execute] == 'login'
|
2014-12-09 19:10:38 +00:00
|
|
|
element = instance.find_elements( { :css => '#login input[name="username"]' } )[0]
|
2013-08-11 12:06:44 +00:00
|
|
|
if !element
|
2013-07-25 09:11:20 +00:00
|
|
|
assert( false, "(#{test[:name]}) no login box found!" )
|
|
|
|
return
|
|
|
|
end
|
|
|
|
element.clear
|
|
|
|
element.send_keys( action[:username] )
|
2014-12-09 19:10:38 +00:00
|
|
|
element = instance.find_elements( { :css => '#login input[name="password"]' } )[0]
|
2013-07-25 09:11:20 +00:00
|
|
|
element.clear
|
|
|
|
element.send_keys( action[:password] )
|
2014-12-02 07:22:26 +00:00
|
|
|
if action[:remember_me]
|
2014-12-09 19:10:38 +00:00
|
|
|
instance.find_elements( { :css => '#login [name="remember_me"]' } )[0].click
|
2014-12-02 07:22:26 +00:00
|
|
|
end
|
2014-12-09 19:10:38 +00:00
|
|
|
instance.find_elements( { :css => '#login button' } )[0].click
|
2013-07-25 09:11:20 +00:00
|
|
|
sleep 4
|
2014-12-09 19:10:38 +00:00
|
|
|
login = instance.find_elements( { :css => '.user-menu .user a' } )[0].attribute('title')
|
2014-09-15 09:06:13 +00:00
|
|
|
if login != action[:username]
|
|
|
|
assert( false, "(#{test[:name]}) login failed" )
|
|
|
|
return
|
|
|
|
end
|
|
|
|
assert( true, "(#{test[:name]}) login success" )
|
2013-07-25 09:11:20 +00:00
|
|
|
return
|
|
|
|
elsif action[:execute] == 'logout'
|
2014-12-09 19:10:38 +00:00
|
|
|
instance.find_elements( { :css => 'a[href="#current_user"]' } )[0].click
|
2013-07-25 09:11:20 +00:00
|
|
|
sleep 0.1
|
2014-12-09 19:10:38 +00:00
|
|
|
instance.find_elements( { :css => 'a[href="#logout"]' } )[0].click
|
2013-08-27 21:05:33 +00:00
|
|
|
(1..6).each {|loop|
|
2014-12-09 19:10:38 +00:00
|
|
|
login = instance.find_elements( { :css => '#login' } )[0]
|
2013-08-27 21:05:33 +00:00
|
|
|
if login
|
|
|
|
assert( true, "(#{test[:name]}) logout" )
|
|
|
|
return
|
|
|
|
end
|
|
|
|
}
|
|
|
|
assert( false, "(#{test[:name]}) no login box found!" )
|
|
|
|
return
|
|
|
|
elsif action[:execute] == 'watch_for'
|
2014-11-18 14:51:44 +00:00
|
|
|
timeout = 16
|
|
|
|
if action[:timeout]
|
|
|
|
timeout = action[:timeout]
|
|
|
|
end
|
2015-01-24 09:05:02 +00:00
|
|
|
loops = (timeout).to_i
|
2013-08-28 06:39:24 +00:00
|
|
|
text = ''
|
2014-11-18 14:51:44 +00:00
|
|
|
(1..loops).each { |loop|
|
2014-12-09 19:10:38 +00:00
|
|
|
element = instance.find_elements( { :css => action[:area] } )[0]
|
|
|
|
if element #&& element.displayed?
|
2015-01-24 09:05:02 +00:00
|
|
|
begin
|
|
|
|
text = element.text
|
|
|
|
if text =~ /#{action[:value]}/i
|
|
|
|
assert( true, "(#{test[:name]}) '#{action[:value]}' found in '#{text}'" )
|
|
|
|
return
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
# just try again
|
2014-11-16 23:46:39 +00:00
|
|
|
end
|
2013-08-27 21:05:33 +00:00
|
|
|
end
|
2015-01-24 09:05:02 +00:00
|
|
|
sleep 1
|
2014-08-15 08:59:40 +00:00
|
|
|
}
|
2013-08-27 21:05:33 +00:00
|
|
|
assert( false, "(#{test[:name]}) '#{action[:value]}' found in '#{text}'" )
|
2013-07-25 09:11:20 +00:00
|
|
|
return
|
2014-12-03 10:01:04 +00:00
|
|
|
elsif action[:execute] == 'watch_for_disappear'
|
|
|
|
timeout = 16
|
|
|
|
if action[:timeout]
|
|
|
|
timeout = action[:timeout]
|
|
|
|
end
|
2014-12-09 19:10:38 +00:00
|
|
|
loops = (timeout / 2).to_i
|
2014-12-03 10:01:04 +00:00
|
|
|
text = ''
|
|
|
|
(1..loops).each { |loop|
|
2014-12-09 19:10:38 +00:00
|
|
|
element = instance.find_elements( { :css => action[:area] } )[0]
|
|
|
|
if !element #|| element.displayed?
|
2014-12-03 10:01:04 +00:00
|
|
|
assert( true, "(#{test[:name]}) not found" )
|
2014-12-09 19:10:38 +00:00
|
|
|
sleep 0.2
|
2014-12-03 10:01:04 +00:00
|
|
|
return
|
|
|
|
end
|
2014-12-09 19:10:38 +00:00
|
|
|
sleep 2
|
2014-12-03 10:01:04 +00:00
|
|
|
}
|
|
|
|
assert( false, "(#{test[:name]} / #{test[:area]}) still exsists" )
|
|
|
|
return
|
2015-02-20 23:17:49 +00:00
|
|
|
|
|
|
|
# create user
|
2014-08-15 08:59:40 +00:00
|
|
|
elsif action[:execute] == 'create_user'
|
2014-12-09 19:10:38 +00:00
|
|
|
instance.find_elements( { :css => 'a[href="#manage"]' } )[0].click
|
|
|
|
instance.find_elements( { :css => 'a[href="#manage/users"]' } )[0].click
|
2014-08-15 08:59:40 +00:00
|
|
|
sleep 2
|
2014-12-09 19:10:38 +00:00
|
|
|
instance.find_elements( { :css => 'a[data-type="new"]' } )[0].click
|
2014-08-15 08:59:40 +00:00
|
|
|
sleep 2
|
2014-10-11 23:35:53 +00:00
|
|
|
#element = instance.find_element( { :css => '.modal input[name=login]' } )
|
|
|
|
#element.clear
|
|
|
|
#element.send_keys( action[:login] )
|
2014-12-09 19:10:38 +00:00
|
|
|
element = instance.find_elements( { :css => '.modal input[name=firstname]' } )[0]
|
2014-08-15 08:59:40 +00:00
|
|
|
element.clear
|
|
|
|
element.send_keys( action[:firstname] )
|
2014-12-09 19:10:38 +00:00
|
|
|
element = instance.find_elements( { :css => '.modal input[name=lastname]' } )[0]
|
2014-08-15 08:59:40 +00:00
|
|
|
element.clear
|
|
|
|
element.send_keys( action[:lastname] )
|
2014-12-09 19:10:38 +00:00
|
|
|
element = instance.find_elements( { :css => '.modal input[name=email]' } )[0]
|
2014-08-15 08:59:40 +00:00
|
|
|
element.clear
|
|
|
|
element.send_keys( action[:email] )
|
2014-12-09 19:10:38 +00:00
|
|
|
element = instance.find_elements( { :css => '.modal input[name=password]' } )[0]
|
2014-08-15 08:59:40 +00:00
|
|
|
element.clear
|
|
|
|
element.send_keys( action[:password] )
|
2014-12-09 19:10:38 +00:00
|
|
|
element = instance.find_elements( { :css => '.modal input[name=password_confirm]' } )[0]
|
2014-08-15 08:59:40 +00:00
|
|
|
element.clear
|
|
|
|
element.send_keys( action[:password] )
|
2014-12-09 19:10:38 +00:00
|
|
|
instance.find_elements( { :css => '.modal input[name="role_ids"][value="3"]' } )[0].click
|
|
|
|
instance.find_elements( { :css => '.modal button.js-submit' } )[0].click
|
2014-08-15 08:59:40 +00:00
|
|
|
(1..14).each {|loop|
|
2014-12-09 19:10:38 +00:00
|
|
|
element = instance.find_elements( { :css => 'body' } )[0]
|
2014-08-15 08:59:40 +00:00
|
|
|
text = element.text
|
|
|
|
if text =~ /#{Regexp.quote(action[:lastname])}/
|
|
|
|
assert( true, "(#{test[:name]}) user created" )
|
|
|
|
return
|
|
|
|
end
|
|
|
|
sleep 0.5
|
|
|
|
}
|
|
|
|
assert( true, "(#{test[:name]}) user creation failed" )
|
|
|
|
return
|
2014-10-11 23:35:53 +00:00
|
|
|
|
2015-02-20 23:17:49 +00:00
|
|
|
# overview remember
|
2015-02-20 13:40:51 +00:00
|
|
|
elsif action[:execute] == 'overview_count_remember'
|
|
|
|
instance.find_elements( { :css => '#navigation li.overviews a' } )[0].click
|
|
|
|
sleep 2
|
|
|
|
overviews = {}
|
|
|
|
instance.find_elements( { :css => '.content.active .sidebar a[href]' } ).each {|element|
|
|
|
|
url = element.attribute('href')
|
|
|
|
url.gsub!(/(http|https):\/\/.+?\/(.+?)$/, "\\2")
|
|
|
|
overviews[url] = 0
|
|
|
|
#puts url.inspect
|
|
|
|
#puts element.inspect
|
|
|
|
}
|
|
|
|
overviews.each {|url, value|
|
|
|
|
count = instance.find_elements( { :css => ".content.active .sidebar a[href=\"#{url}\"] .badge" } )[0].text
|
|
|
|
overviews[url] = count
|
|
|
|
}
|
|
|
|
@overview_count_remember = overviews
|
|
|
|
assert( !overviews.empty?, "(#{test[:name]}) overview_count_remember" )
|
|
|
|
return
|
2015-02-20 23:17:49 +00:00
|
|
|
|
|
|
|
# overview verify
|
2015-02-20 13:40:51 +00:00
|
|
|
elsif action[:execute] == 'overview_count_verify'
|
|
|
|
instance.find_elements( { :css => '#navigation li.overviews a' } )[0].click
|
|
|
|
sleep 2
|
|
|
|
overviews = {}
|
|
|
|
instance.find_elements( { :css => '.content.active .sidebar a[href]' } ).each {|element|
|
|
|
|
url = element.attribute('href')
|
|
|
|
url.gsub!(/(http|https):\/\/.+?\/(.+?)$/, "\\2")
|
|
|
|
overviews[url] = 0
|
|
|
|
}
|
|
|
|
overviews.each {|url, value|
|
|
|
|
count = instance.find_elements( { :css => ".content.active .sidebar a[href=\"#{url}\"] .badge" } )[0].text
|
|
|
|
overviews[url] = count
|
|
|
|
}
|
|
|
|
#puts "ov #{overviews.inspect}"
|
|
|
|
#puts "@ov #{@overview_count_remember.inspect}"
|
|
|
|
#puts "data #{action[:data].inspect}"
|
|
|
|
action[:data].each {|url,count|
|
|
|
|
if @overview_count_remember.has_key?(url)
|
|
|
|
count_is = overviews[url].to_i
|
|
|
|
count_should = @overview_count_remember[url].to_i + count.to_i
|
|
|
|
assert_equal( count_should, count_is, "(#{test[:name]}) expected count of url #{url} is different overview_count_remember" )
|
|
|
|
else
|
|
|
|
assert( false, "(#{test[:name]}) no url #{url} exists in overview_count_remember" )
|
|
|
|
end
|
|
|
|
}
|
|
|
|
return
|
2015-02-20 23:17:49 +00:00
|
|
|
|
|
|
|
# create signature
|
2015-01-23 22:24:03 +00:00
|
|
|
elsif action[:execute] == 'create_signature'
|
|
|
|
instance.find_elements( { :css => 'a[href="#manage"]' } )[0].click
|
|
|
|
instance.find_elements( { :css => 'a[href="#channels/email"]' } )[0].click
|
|
|
|
instance.find_elements( { :css => 'a[href="#c-signature"]' } )[0].click
|
|
|
|
sleep 8
|
|
|
|
instance.find_elements( { :css => '#content #c-signature a[data-type="new"]' } )[0].click
|
|
|
|
sleep 2
|
|
|
|
element = instance.find_elements( { :css => '.modal input[name=name]' } )[0]
|
|
|
|
element.clear
|
|
|
|
element.send_keys( action[:name] )
|
|
|
|
element = instance.find_elements( { :css => '.modal textarea[name=body]' } )[0]
|
|
|
|
element.clear
|
|
|
|
element.send_keys( action[:body] )
|
|
|
|
instance.find_elements( { :css => '.modal button.js-submit' } )[0].click
|
|
|
|
(1..12).each {|loop|
|
|
|
|
element = instance.find_elements( { :css => 'body' } )[0]
|
|
|
|
text = element.text
|
|
|
|
if text =~ /#{Regexp.quote(action[:name])}/
|
|
|
|
assert( true, "(#{test[:name]}) signature created" )
|
|
|
|
return
|
|
|
|
end
|
|
|
|
sleep 1
|
|
|
|
}
|
|
|
|
assert( true, "(#{test[:name]}) signature creation failed" )
|
|
|
|
return
|
|
|
|
|
2015-02-20 23:17:49 +00:00
|
|
|
# create overview
|
|
|
|
elsif action[:execute] == 'create_overview'
|
|
|
|
instance.find_elements( { :css => 'a[href="#manage"]' } )[0].click
|
|
|
|
instance.find_elements( { :css => 'a[href="#manage/overviews"]' } )[0].click
|
|
|
|
instance.find_elements( { :css => '#content a[data-type="new"]' } )[0].click
|
|
|
|
sleep 2
|
|
|
|
element = instance.find_elements( { :css => '.modal input[name=name]' } )[0]
|
|
|
|
element.clear
|
|
|
|
element.send_keys( action[:name] )
|
|
|
|
element = instance.find_elements( { :css => '.modal input[name=link]' } )[0]
|
|
|
|
element.clear
|
|
|
|
element.send_keys( action[:link] )
|
|
|
|
|
|
|
|
element = instance.find_elements( { :css => '.modal select[name="role_id"]' } )[0]
|
|
|
|
dropdown = Selenium::WebDriver::Support::Select.new(element)
|
|
|
|
dropdown.select_by( :text, action[:role])
|
|
|
|
sleep 0.2
|
|
|
|
|
|
|
|
element = instance.find_elements( { :css => '.modal input[name=prio]' } )[0]
|
|
|
|
element.clear
|
|
|
|
element.send_keys( action[:prio] )
|
|
|
|
|
|
|
|
element = instance.find_elements( { :css => '.modal select[name="order::direction"]' } )[0]
|
|
|
|
dropdown = Selenium::WebDriver::Support::Select.new(element)
|
|
|
|
dropdown.select_by( :text, action['order::direction'])
|
|
|
|
sleep 0.2
|
|
|
|
|
|
|
|
instance.find_elements( { :css => '.modal button.js-submit' } )[0].click
|
|
|
|
(1..12).each {|loop|
|
|
|
|
element = instance.find_elements( { :css => 'body' } )[0]
|
|
|
|
text = element.text
|
|
|
|
if text =~ /#{Regexp.quote(action[:name])}/
|
|
|
|
assert( true, "(#{test[:name]}) overview created" )
|
|
|
|
return
|
|
|
|
end
|
|
|
|
sleep 1
|
|
|
|
}
|
|
|
|
assert( true, "(#{test[:name]}) overview creation failed" )
|
|
|
|
return
|
|
|
|
|
|
|
|
# create group
|
2015-01-23 22:24:03 +00:00
|
|
|
elsif action[:execute] == 'create_group'
|
|
|
|
instance.find_elements( { :css => 'a[href="#manage"]' } )[0].click
|
|
|
|
instance.find_elements( { :css => 'a[href="#manage/groups"]' } )[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( action[:name] )
|
|
|
|
element = instance.find_elements( { :css => '.modal select[name="email_address_id"]' } )[0]
|
|
|
|
dropdown = Selenium::WebDriver::Support::Select.new(element)
|
|
|
|
dropdown.select_by( :index, 1 )
|
|
|
|
#dropdown.select_by( :text, action[:group])
|
|
|
|
if action[:signature]
|
|
|
|
element = instance.find_elements( { :css => '.modal select[name="signature_id"]' } )[0]
|
|
|
|
dropdown = Selenium::WebDriver::Support::Select.new(element)
|
|
|
|
dropdown.select_by( :text, action[:signature])
|
|
|
|
end
|
|
|
|
instance.find_elements( { :css => '.modal button.js-submit' } )[0].click
|
|
|
|
(1..12).each {|loop|
|
|
|
|
element = instance.find_elements( { :css => 'body' } )[0]
|
|
|
|
text = element.text
|
|
|
|
if text =~ /#{Regexp.quote(action[:name])}/
|
|
|
|
assert( true, "(#{test[:name]}) group created" )
|
|
|
|
|
|
|
|
# add member
|
|
|
|
if action[:member]
|
|
|
|
action[:member].each {|login|
|
|
|
|
instance.find_elements( { :css => 'a[href="#manage"]' } )[0].click
|
|
|
|
instance.find_elements( { :css => 'a[href="#manage/users"]' } )[0].click
|
|
|
|
sleep 2
|
|
|
|
element = instance.find_elements( { :css => '#content [name="search"]' } )[0]
|
|
|
|
element.clear
|
|
|
|
element.send_keys( login )
|
|
|
|
sleep 2
|
|
|
|
#instance.find_elements( { :css => '#content table [data-id]' } )[0].click
|
|
|
|
instance.execute_script( '$("#content table [data-id] td").first().click()' )
|
|
|
|
sleep 2
|
|
|
|
#instance.find_elements( { :css => 'label:contains(" ' + action[:name] + '")' } )[0].click
|
|
|
|
instance.execute_script( '$(\'label:contains(" ' + action[:name] + '")\').first().click()' )
|
|
|
|
instance.find_elements( { :css => '.modal button.js-submit' } )[0].click
|
|
|
|
}
|
|
|
|
end
|
|
|
|
return
|
|
|
|
end
|
|
|
|
sleep 1
|
|
|
|
}
|
|
|
|
assert( true, "(#{test[:name]}) group creation failed" )
|
|
|
|
return
|
|
|
|
|
2014-10-11 23:35:53 +00:00
|
|
|
elsif action[:execute] == 'verify_task_attributes'
|
|
|
|
if action[:title]
|
2014-12-09 19:10:38 +00:00
|
|
|
text = instance.find_elements( { :css => '.tasks .active' } )[0].text.strip
|
2015-02-20 13:40:51 +00:00
|
|
|
assert_equal( action[:title], text )
|
2014-10-11 23:35:53 +00:00
|
|
|
end
|
|
|
|
return
|
|
|
|
elsif action[:execute] == 'verify_ticket_attributes'
|
|
|
|
if action[:title]
|
2014-12-09 19:10:38 +00:00
|
|
|
text = instance.find_elements( { :css => '.content.active .page-header .ticket-title-update' } )[0].text.strip
|
2015-02-20 13:40:51 +00:00
|
|
|
assert_equal( action[:title], text )
|
2014-10-11 23:35:53 +00:00
|
|
|
end
|
|
|
|
if action[:body]
|
2014-12-09 19:10:38 +00:00
|
|
|
text = instance.find_elements( { :css => '.content.active [data-name="body"]' } )[0].text.strip
|
2015-02-20 13:40:51 +00:00
|
|
|
assert_equal( action[:body], text )
|
2014-10-11 23:35:53 +00:00
|
|
|
end
|
|
|
|
return
|
|
|
|
elsif action[:execute] == 'set_ticket_attributes'
|
|
|
|
if action[:title]
|
2014-12-09 19:10:38 +00:00
|
|
|
#element = instance.find_elements( { :css => '.content.active .page-header .ticket-title-update' } )[0]
|
|
|
|
#element.clear
|
|
|
|
#sleep 0.5
|
|
|
|
#element = instance.find_elements( { :css => '.content.active .page-header .ticket-title-update' } )[0]
|
|
|
|
#element.send_keys( action[:title] )
|
|
|
|
#sleep 0.5
|
|
|
|
#element.send_keys( :tab )
|
|
|
|
|
2014-10-11 23:35:53 +00:00
|
|
|
instance.execute_script( '$(".content.active .page-header .ticket-title-update").focus()' )
|
|
|
|
instance.execute_script( '$(".content.active .page-header .ticket-title-update").text("' + action[:title] + '")' )
|
|
|
|
instance.execute_script( '$(".content.active .page-header .ticket-title-update").blur()' )
|
|
|
|
instance.execute_script( '$(".content.active .page-header .ticket-title-update").trigger("blur")' )
|
|
|
|
# {
|
|
|
|
# :where => :instance2,
|
|
|
|
# :execute => 'sendkey',
|
|
|
|
# :css => '.content.active .page-header .ticket-title-update',
|
|
|
|
# :value => 'TTT',
|
|
|
|
# },
|
|
|
|
# {
|
|
|
|
# :where => :instance2,
|
|
|
|
# :execute => 'sendkey',
|
|
|
|
# :css => '.content.active .page-header .ticket-title-update',
|
|
|
|
# :value => :tab,
|
|
|
|
# },
|
|
|
|
end
|
|
|
|
if action[:body]
|
2014-12-09 19:10:38 +00:00
|
|
|
#instance.execute_script( '$(".content.active div[data-name=body]").focus()' )
|
2014-12-08 09:39:05 +00:00
|
|
|
sleep 0.5
|
2014-12-09 19:10:38 +00:00
|
|
|
element = instance.find_elements( { :css => '.content.active div[data-name=body]' } )[0]
|
2014-10-11 23:35:53 +00:00
|
|
|
element.clear
|
|
|
|
element.send_keys( action[:body] )
|
|
|
|
end
|
|
|
|
return
|
2015-02-20 13:40:51 +00:00
|
|
|
|
|
|
|
# create ticket
|
2013-07-25 09:11:20 +00:00
|
|
|
elsif action[:execute] == 'create_ticket'
|
2014-12-09 19:10:38 +00:00
|
|
|
instance.find_elements( { :css => 'a[href="#new"]' } )[0].click
|
|
|
|
instance.find_elements( { :css => 'a[href="#ticket/create"]' } )[0].click
|
|
|
|
element = instance.find_elements( { :css => '.active .newTicket' } )[0]
|
2013-07-25 09:11:20 +00:00
|
|
|
if !element
|
|
|
|
assert( false, "(#{test[:name]}) no ticket create screen found!" )
|
|
|
|
return
|
|
|
|
end
|
2013-08-27 21:05:33 +00:00
|
|
|
sleep 2
|
2015-01-24 10:15:52 +00:00
|
|
|
|
|
|
|
# check count of agents, should be only 1 / - selection on init screen
|
|
|
|
count = instance.find_elements( { :css => '.active .newTicket select[name="owner_id"] option' } ).count
|
|
|
|
assert_equal( 1, count, 'check if owner selection is empty per default' )
|
|
|
|
|
2014-10-14 00:13:19 +00:00
|
|
|
if action[:group]
|
2014-12-09 19:10:38 +00:00
|
|
|
element = instance.find_elements( { :css => '.active .newTicket select[name="group_id"]' } )[0]
|
2014-10-14 00:13:19 +00:00
|
|
|
dropdown = Selenium::WebDriver::Support::Select.new(element)
|
|
|
|
dropdown.select_by( :text, action[:group])
|
|
|
|
sleep 0.2
|
|
|
|
end
|
|
|
|
if action[:subject]
|
2014-12-09 19:10:38 +00:00
|
|
|
element = instance.find_elements( { :css => '.active .newTicket input[name="title"]' } )[0]
|
2014-10-14 00:13:19 +00:00
|
|
|
element.clear
|
|
|
|
element.send_keys( action[:subject] )
|
|
|
|
sleep 0.2
|
|
|
|
end
|
|
|
|
if action[:body]
|
2014-12-09 19:10:38 +00:00
|
|
|
#instance.execute_script( '$(".active .newTicket div[data-name=body]").focus()' )
|
2014-12-08 09:39:05 +00:00
|
|
|
sleep 0.5
|
2014-12-09 19:10:38 +00:00
|
|
|
element = instance.find_elements( { :css => '.active .newTicket div[data-name=body]' } )[0]
|
2014-10-14 00:13:19 +00:00
|
|
|
element.clear
|
|
|
|
element.send_keys( action[:body] )
|
2014-12-09 19:10:38 +00:00
|
|
|
end
|
|
|
|
if action[:customer] == nil
|
|
|
|
element = instance.find_elements( { :css => '.active .newTicket input[name="customer_id_completion"]' } )[0]
|
|
|
|
element.click
|
|
|
|
element.clear
|
|
|
|
element.send_keys( 'nico*' )
|
|
|
|
sleep 4
|
|
|
|
element.send_keys( :arrow_down )
|
|
|
|
sleep 0.1
|
|
|
|
instance.find_elements( { :css => '.active .newTicket .recipientList-entry.js-user.is-active' } )[0].click
|
|
|
|
sleep 0.3
|
2014-10-11 23:35:53 +00:00
|
|
|
end
|
2013-07-25 09:11:20 +00:00
|
|
|
if action[:do_not_submit]
|
|
|
|
assert( true, "(#{test[:name]}) ticket created without submit" )
|
|
|
|
return
|
|
|
|
end
|
2014-09-09 23:42:20 +00:00
|
|
|
sleep 0.8
|
2014-12-09 19:10:38 +00:00
|
|
|
#instance.execute_script( '$(".content.active .newTicket form").submit();' )
|
|
|
|
instance.find_elements( { :css => '.active .newTicket button.submit' } )[0].click
|
2014-09-09 23:42:20 +00:00
|
|
|
sleep 1
|
2014-12-02 21:34:46 +00:00
|
|
|
(1..16).each {|loop|
|
2013-08-27 21:05:33 +00:00
|
|
|
if instance.current_url =~ /#{Regexp.quote('#ticket/zoom/')}/
|
|
|
|
assert( true, "(#{test[:name]}) ticket created" )
|
2014-12-02 12:23:22 +00:00
|
|
|
sleep 1
|
2013-08-27 21:05:33 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
sleep 0.5
|
|
|
|
}
|
2014-09-09 23:42:20 +00:00
|
|
|
assert( false, "(#{test[:name]}) ticket creation failed, can't get zoom url" )
|
2013-07-25 09:11:20 +00:00
|
|
|
return
|
2015-02-20 13:40:51 +00:00
|
|
|
|
|
|
|
# udpate ticket
|
|
|
|
elsif action[:execute] == 'update_ticket'
|
|
|
|
|
|
|
|
if action[:group]
|
|
|
|
element = instance.find_elements( { :css => '.active .sidebar select[name="group_id"]' } )[0]
|
|
|
|
dropdown = Selenium::WebDriver::Support::Select.new(element)
|
|
|
|
dropdown.select_by( :text, action[:group])
|
|
|
|
sleep 0.2
|
|
|
|
end
|
|
|
|
|
|
|
|
if action[:state]
|
|
|
|
element = instance.find_elements( { :css => '.active .sidebar select[name="state_id"]' } )[0]
|
|
|
|
dropdown = Selenium::WebDriver::Support::Select.new(element)
|
|
|
|
dropdown.select_by( :text, action[:state])
|
|
|
|
sleep 0.2
|
|
|
|
end
|
|
|
|
|
|
|
|
found = nil
|
|
|
|
(1..5).each {|loop|
|
|
|
|
if !found
|
|
|
|
text = instance.find_elements( { :css => '.content.active .js-reset' } )[0].text
|
|
|
|
if text =~ /(Discard your unsaved changes.|Verwerfen der)/
|
|
|
|
assert( true, "(#{test[:name]}) discard message found" )
|
|
|
|
found = true
|
|
|
|
end
|
|
|
|
sleep 1
|
|
|
|
end
|
|
|
|
}
|
|
|
|
if !found
|
|
|
|
assert( false, "(#{test[:name]}) no discard message found" )
|
|
|
|
end
|
|
|
|
|
|
|
|
if action[:do_not_submit]
|
|
|
|
assert( true, "(#{test[:name]}) ticket updated without submit" )
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
instance.find_elements( { :css => '.content.active button.js-submit' } )[0].click
|
|
|
|
|
|
|
|
(1..10).each {|loop|
|
|
|
|
text = instance.find_elements( { :css => '.content.active .js-reset' } )[0].text
|
|
|
|
if !text || text.empty?
|
|
|
|
assert( true, "(#{test[:name]}) ticket updated" )
|
|
|
|
return
|
|
|
|
end
|
|
|
|
sleep 1
|
|
|
|
}
|
|
|
|
assert( false, "(#{test[:name]}) unable to update ticket" )
|
|
|
|
return
|
|
|
|
|
|
|
|
# search user
|
2015-02-06 15:23:22 +00:00
|
|
|
elsif action[:execute] == 'search_user'
|
|
|
|
element = instance.find_elements( { :css => '#global-search' } )[0]
|
|
|
|
element.click
|
|
|
|
element.clear
|
|
|
|
if @stack
|
|
|
|
action[:term].gsub! '###stack###', @stack
|
|
|
|
end
|
|
|
|
element.send_keys( action[:term] )
|
|
|
|
sleep 3
|
|
|
|
element = instance.find_element( { :partial_link_text => action[:term] } ).click
|
|
|
|
name = instance.find_elements( { :css => '.active h1' } )[0].text
|
|
|
|
if name !~ /#{action[:term]}/
|
|
|
|
assert( false, "(#{test[:name]}) unable to search/find user #{action[:term]}!" )
|
|
|
|
return
|
|
|
|
end
|
|
|
|
assert( true, "(#{test[:name]}) user #{action[:term]} found" )
|
|
|
|
return
|
2015-02-20 13:40:51 +00:00
|
|
|
|
|
|
|
# search org
|
2015-02-06 15:23:22 +00:00
|
|
|
elsif action[:execute] == 'search_organization'
|
|
|
|
element = instance.find_elements( { :css => '#global-search' } )[0]
|
|
|
|
element.click
|
|
|
|
element.clear
|
|
|
|
if @stack
|
|
|
|
action[:term].gsub! '###stack###', @stack
|
|
|
|
end
|
|
|
|
element.send_keys( action[:term] )
|
|
|
|
sleep 3
|
|
|
|
instance.find_elements( { :css => '.search .empty-search' } )[0].click
|
|
|
|
sleep 0.5
|
|
|
|
text = instance.find_elements( { :css => '#global-search' } )[0].attribute('value')
|
|
|
|
if !text
|
|
|
|
assert( false, "(#{test[:name]}) #global-search is not empty!" )
|
|
|
|
return
|
|
|
|
end
|
|
|
|
element = instance.find_elements( { :css => '#global-search' } )[0]
|
|
|
|
element.click
|
|
|
|
element.clear
|
|
|
|
if @stack
|
|
|
|
action[:term].gsub! '###stack###', @stack
|
|
|
|
end
|
|
|
|
element.send_keys( action[:term] )
|
|
|
|
sleep 2
|
|
|
|
element = instance.find_element( { :partial_link_text => action[:term] } ).click
|
|
|
|
name = instance.find_elements( { :css => '.active h1' } )[0].text
|
|
|
|
if name !~ /#{action[:term]}/
|
|
|
|
assert( false, "(#{test[:name]}) unable to search/find org #{action[:term]}!" )
|
|
|
|
return
|
|
|
|
end
|
|
|
|
assert( true, "(#{test[:name]}) org #{action[:term]} found" )
|
|
|
|
return
|
2015-02-20 13:40:51 +00:00
|
|
|
|
|
|
|
# search ticket
|
2014-12-31 23:38:56 +00:00
|
|
|
elsif action[:execute] == 'search_ticket'
|
|
|
|
element = instance.find_elements( { :css => '#global-search' } )[0]
|
|
|
|
element.click
|
|
|
|
element.clear
|
|
|
|
action[:number].gsub! '###stack###', @stack
|
|
|
|
element.send_keys( action[:number] )
|
|
|
|
sleep 3
|
|
|
|
instance.find_elements( { :css => '.search .empty-search' } )[0].click
|
|
|
|
sleep 0.5
|
|
|
|
text = instance.find_elements( { :css => '#global-search' } )[0].attribute('value')
|
|
|
|
if !text
|
|
|
|
assert( false, "(#{test[:name]}) #global-search is not empty!" )
|
|
|
|
return
|
|
|
|
end
|
|
|
|
element = instance.find_elements( { :css => '#global-search' } )[0]
|
|
|
|
element.click
|
|
|
|
element.clear
|
|
|
|
action[:number].gsub! '###stack###', @stack
|
|
|
|
element.send_keys( action[:number] )
|
2015-02-06 15:23:22 +00:00
|
|
|
sleep 2
|
2014-12-31 23:38:56 +00:00
|
|
|
element = instance.find_element( { :partial_link_text => action[:number] } ).click
|
|
|
|
number = instance.find_elements( { :css => '.active .page-header .ticket-number' } )[0].text
|
|
|
|
if number !~ /#{action[:number]}/
|
|
|
|
assert( false, "(#{test[:name]}) unable to search/find ticket #{action[:number]}!" )
|
|
|
|
return
|
|
|
|
end
|
|
|
|
assert( true, "(#{test[:name]}) ticket #{action[:number]} found" )
|
|
|
|
return
|
2015-02-20 23:17:49 +00:00
|
|
|
|
|
|
|
# overview ticket
|
|
|
|
elsif action[:execute] == 'overview_ticket'
|
|
|
|
instance.find_elements( { :css => '#navigation li.overviews a' } )[0].click
|
|
|
|
sleep 1
|
|
|
|
instance.find_elements( { :css => ".content.active .sidebar a[href=##{action[:link]}]" } ).click
|
|
|
|
sleep 1
|
|
|
|
|
|
|
|
action[:number].gsub! '###stack###', @stack
|
|
|
|
|
|
|
|
element = instance.find_element( { :partial_link_text => action[:number] } ).click
|
|
|
|
number = instance.find_elements( { :css => '.active .page-header .ticket-number' } )[0].text
|
|
|
|
if number !~ /#{action[:number]}/
|
|
|
|
assert( false, "(#{test[:name]}) unable to search/find ticket #{action[:number]}!" )
|
|
|
|
return
|
|
|
|
end
|
|
|
|
assert( true, "(#{test[:name]}) ticket #{action[:number]} found" )
|
|
|
|
return
|
|
|
|
|
|
|
|
# close all tasks
|
2013-06-08 22:35:18 +00:00
|
|
|
elsif action[:execute] == 'close_all_tasks'
|
2013-07-25 09:11:20 +00:00
|
|
|
for i in 1..100
|
2014-12-09 19:10:38 +00:00
|
|
|
sleep 1
|
|
|
|
if instance.find_elements( { :css => '.navigation .tasks .task:first-child' } )[0]
|
|
|
|
instance.mouse.move_to( instance.find_elements( { :css => '.navigation .tasks .task:first-child' } )[0] )
|
|
|
|
sleep 0.2
|
|
|
|
|
|
|
|
click_element = instance.find_elements( { :css => '.navigation .tasks .task:first-child .js-close' } )[0]
|
|
|
|
if click_element
|
2014-09-16 18:57:55 +00:00
|
|
|
sleep 0.1
|
2014-12-09 19:10:38 +00:00
|
|
|
click_element.click
|
|
|
|
|
|
|
|
# accept task close warning
|
|
|
|
if action[:discard_changes]
|
|
|
|
sleep 1
|
|
|
|
instance.find_elements( { :css => '.modal button.js-submit' } )[0].click
|
2014-09-15 09:06:13 +00:00
|
|
|
end
|
2013-06-08 22:35:18 +00:00
|
|
|
end
|
2014-12-09 19:10:38 +00:00
|
|
|
else
|
2013-06-08 22:35:18 +00:00
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
2013-07-25 09:11:20 +00:00
|
|
|
assert( true, "(#{test[:name]}) all tasks closed" )
|
|
|
|
return
|
2013-06-17 05:38:17 +00:00
|
|
|
elsif action[:execute] == 'navigate'
|
|
|
|
instance.navigate.to( action[:to] )
|
2013-07-25 09:11:20 +00:00
|
|
|
return
|
2013-06-18 20:58:29 +00:00
|
|
|
elsif action[:execute] == 'reload'
|
|
|
|
instance.navigate.refresh
|
2013-07-25 09:11:20 +00:00
|
|
|
return
|
2013-06-23 21:32:45 +00:00
|
|
|
elsif action[:execute] == 'js'
|
|
|
|
result = instance.execute_script( action[:value] )
|
2014-10-14 00:13:19 +00:00
|
|
|
elsif action[:execute] == 'sendkey'
|
|
|
|
if action[:value].class == Array
|
|
|
|
action[:value].each {|key|
|
|
|
|
instance.action.send_keys(key).perform
|
|
|
|
}
|
|
|
|
else
|
|
|
|
instance.action.send_keys(action[:value]).perform
|
|
|
|
#instance.action.send_keys(:enter).perform
|
|
|
|
end
|
|
|
|
# element.send_keys( action[:value] )
|
2013-06-18 20:58:29 +00:00
|
|
|
elsif action[:link]
|
|
|
|
if action[:link].match '###stack###'
|
|
|
|
action[:link].gsub! '###stack###', @stack
|
|
|
|
end
|
|
|
|
element = instance.find_element( { :partial_link_text => action[:link] } )
|
2012-12-14 12:16:04 +00:00
|
|
|
else
|
|
|
|
assert( false, "(#{test[:name]}) unknow selector for '#{action[:element]}'" )
|
|
|
|
end
|
2013-07-17 09:02:07 +00:00
|
|
|
if action[:execute] == 'setCheck'
|
|
|
|
checked = element.attribute('checked')
|
|
|
|
if !checked
|
|
|
|
element.click
|
|
|
|
end
|
|
|
|
elsif action[:execute] == 'setUncheck'
|
|
|
|
checked = element.attribute('checked')
|
|
|
|
if checked
|
|
|
|
element.click
|
|
|
|
end
|
|
|
|
elsif action[:execute] == 'set'
|
2013-03-22 08:29:44 +00:00
|
|
|
element.clear
|
2013-04-23 18:36:09 +00:00
|
|
|
if action[:value] == '###stack###'
|
|
|
|
element.send_keys( @stack )
|
|
|
|
else
|
2014-12-03 18:53:42 +00:00
|
|
|
if !action[:slow]
|
|
|
|
element.send_keys( action[:value] )
|
|
|
|
else
|
|
|
|
element.send_keys( '' )
|
|
|
|
keys = action[:value].to_s.split('')
|
|
|
|
keys.each {|key|
|
|
|
|
instance.action.send_keys(key).perform
|
|
|
|
}
|
|
|
|
end
|
2014-10-14 00:13:19 +00:00
|
|
|
sleep 0.3
|
2013-04-23 18:36:09 +00:00
|
|
|
end
|
2013-02-21 21:09:36 +00:00
|
|
|
elsif action[:execute] == 'select'
|
2013-02-23 22:54:48 +00:00
|
|
|
dropdown = Selenium::WebDriver::Support::Select.new(element)
|
|
|
|
dropdown.select_by(:text, action[:value])
|
2012-12-14 12:16:04 +00:00
|
|
|
elsif action[:execute] == 'click'
|
2013-06-10 11:59:16 +00:00
|
|
|
if element.class == Array
|
|
|
|
element.each {|item|
|
|
|
|
item.click
|
|
|
|
}
|
|
|
|
else
|
|
|
|
element.click
|
2013-06-08 22:35:18 +00:00
|
|
|
end
|
2013-03-22 08:29:44 +00:00
|
|
|
elsif action[:execute] == 'accept'
|
|
|
|
element.accept
|
|
|
|
elsif action[:execute] == 'dismiss'
|
|
|
|
element.dismiss
|
2012-12-14 12:16:04 +00:00
|
|
|
elsif action[:execute] == 'send_key'
|
|
|
|
element.send_keys action[:value]
|
|
|
|
elsif action[:execute] == 'match'
|
2013-02-22 10:36:00 +00:00
|
|
|
if action[:css] =~ /select/
|
2013-02-23 22:54:48 +00:00
|
|
|
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
|
2012-12-14 12:16:04 +00:00
|
|
|
if action[:match_result]
|
2013-02-22 10:36:00 +00:00
|
|
|
if success
|
|
|
|
assert( true, "(#{test[:name]}) matching '#{action[:value]}' in select list" )
|
|
|
|
else
|
|
|
|
assert( false, "(#{test[:name]}) not matching '#{action[:value]}' in select list" )
|
|
|
|
end
|
2012-12-14 12:16:04 +00:00
|
|
|
else
|
2013-02-22 10:36:00 +00:00
|
|
|
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
|
2012-12-14 12:16:04 +00:00
|
|
|
end
|
|
|
|
else
|
2014-09-15 09:06:13 +00:00
|
|
|
if action[:attribute]
|
|
|
|
text = element.attribute( action[:attribute] )
|
|
|
|
elsif action[:css] =~ /(input|textarea)/i
|
2013-02-23 22:54:48 +00:00
|
|
|
text = element.attribute('value')
|
2012-12-14 12:16:04 +00:00
|
|
|
else
|
2013-02-22 10:36:00 +00:00
|
|
|
text = element.text
|
|
|
|
end
|
2013-04-23 18:36:09 +00:00
|
|
|
if action[:value] == '###stack###'
|
|
|
|
action[:value] = @stack
|
|
|
|
end
|
|
|
|
match = false
|
|
|
|
if action[:no_quote]
|
2014-10-14 00:13:19 +00:00
|
|
|
#puts "aaaa #{text}/#{action[:value]}"
|
2015-02-06 15:23:22 +00:00
|
|
|
if text =~ /#{action[:value]}/i
|
2013-04-23 18:36:09 +00:00
|
|
|
if $1
|
|
|
|
@stack = $1
|
|
|
|
end
|
|
|
|
match = $1 || true
|
|
|
|
end
|
|
|
|
else
|
2015-02-06 15:23:22 +00:00
|
|
|
if text =~ /#{Regexp.quote(action[:value])}/i
|
2013-04-23 18:36:09 +00:00
|
|
|
match = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if match
|
2013-02-22 10:36:00 +00:00
|
|
|
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 '#{text}'" )
|
|
|
|
else
|
|
|
|
assert( false, "(#{test[:name]}) not matching '#{action[:value]}' in content '#{text}' but should not!" )
|
|
|
|
end
|
2012-12-14 12:16:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
elsif action[:execute] == 'check'
|
2013-06-23 21:32:45 +00:00
|
|
|
elsif action[:execute] == 'js'
|
2014-10-14 00:13:19 +00:00
|
|
|
elsif action[:execute] == 'sendkey'
|
2012-12-14 12:16:04 +00:00
|
|
|
else
|
|
|
|
assert( false, "(#{test[:name]}) unknow action '#{action[:execute]}'" )
|
|
|
|
end
|
|
|
|
end
|
2012-12-14 10:14:48 +00:00
|
|
|
end
|