2021-06-01 12:20:20 +00:00
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
2015-04-27 12:51:43 +00:00
ENV [ 'RAILS_ENV' ] = 'test'
2020-04-14 08:14:14 +00:00
# rubocop:disable Lint/NonLocalExitFromIterator, Style/GuardClause, Lint/MissingCopEnableDirective
2018-04-12 14:57:37 +00:00
require File . expand_path ( '../config/environment' , __dir__ )
2013-02-23 22:54:48 +00:00
require 'selenium-webdriver'
2018-07-04 14:56:16 +00:00
require 'json'
require 'net/http'
require 'uri'
2012-12-14 10:14:48 +00:00
2019-02-26 12:01:27 +00:00
# This is a workaround for running the browser test suite
# in an alphabetical order
# because `test/browser/aaa_*` tests are required to run first
require 'minitest'
module Minitest
def self . __run ( reporter , options )
Runnable . runnables
. reject { | s | s . runnable_methods . empty? }
. map { | suite | suite . run reporter , options }
end
end
class TestCase < ActiveSupport :: TestCase
2018-04-12 14:57:37 +00:00
DEBUG = true
2021-07-09 13:05:05 +00:00
setup do
2019-02-26 12:01:27 +00:00
# print current test case to STDOUT
# for status reasoning and debugging purposes
source_location = self . class . instance_method ( method_name ) . source_location
test_file_path = source_location [ 0 ] . remove ( " #{ Rails . root } / " ) # rubocop:disable Rails/FilePath
test_method_line = source_location [ 1 ]
puts << ~ HTML
Performing test #{self.class.name}##{method_name} (#{test_file_path}:#{test_method_line}):
HTML
end
2013-06-25 14:00:28 +00:00
def browser
ENV [ 'BROWSER' ] || 'firefox'
end
2015-07-16 13:14:06 +00:00
def profile
browser_profile = nil
2020-07-13 12:46:08 +00:00
case browser
when 'firefox'
2015-07-16 13:14:06 +00:00
browser_profile = Selenium :: WebDriver :: Firefox :: Profile . new
browser_profile [ 'intl.locale.matchOS' ] = false
browser_profile [ 'intl.accept_languages' ] = 'en-US'
browser_profile [ 'general.useragent.locale' ] = 'en-US'
2016-06-20 18:55:31 +00:00
# currently console log not working for firefox
# https://github.com/SeleniumHQ/selenium/issues/1161
2021-07-16 13:44:10 +00:00
# browser_profile['loggingPref'] = { browser: :all }
2020-07-13 12:46:08 +00:00
when 'chrome'
2015-12-18 19:32:00 +00:00
# profile are only working on remote selenium
if ENV [ 'REMOTE_URL' ]
browser_profile = Selenium :: WebDriver :: Chrome :: Profile . new
browser_profile [ 'intl.accept_languages' ] = 'en'
2016-06-14 13:25:01 +00:00
browser_profile [ 'loggingPref' ] = { browser : :all }
2015-12-18 19:32:00 +00:00
end
2015-07-16 13:14:06 +00:00
end
browser_profile
end
2013-06-25 14:00:28 +00:00
def browser_support_cookies
2021-05-12 11:37:44 +00:00
if browser . match? ( %r{ (internet_explorer|ie) }i )
2013-06-25 14:00:28 +00:00
return false
end
2018-10-09 06:17:41 +00:00
2015-04-27 19:56:07 +00:00
true
2013-06-25 14:00:28 +00:00
end
2013-02-23 22:54:48 +00:00
def browser_url
2018-12-14 19:19:46 +00:00
return ENV [ 'BROWSER_URL' ] if ENV [ 'BROWSER_URL' ] . present?
" http:// #{ host } :3000 "
end
def host
return 'localhost' if ENV [ 'CI' ] . blank?
Socket . ip_address_list . detect ( & :ipv4_private? ) . ip_address
2013-02-23 22:54:48 +00:00
end
def browser_instance
2018-04-23 13:12:19 +00:00
@browsers || = { }
2017-11-23 08:09:44 +00:00
if ENV [ 'REMOTE_URL' ] . blank?
2018-08-06 10:21:44 +00:00
params = {
profile : profile ,
}
if ENV [ 'BROWSER_HEADLESS' ] . present?
2020-07-13 12:46:08 +00:00
case browser
when 'firefox'
2018-08-06 10:21:44 +00:00
params [ :options ] = Selenium :: WebDriver :: Firefox :: Options . new
params [ :options ] . add_argument ( '-headless' )
2020-07-13 12:46:08 +00:00
when 'chrome'
2018-08-06 10:21:44 +00:00
params [ :options ] = Selenium :: WebDriver :: Chrome :: Options . new
params [ :options ] . add_argument ( '-headless' )
end
end
local_browser = Selenium :: WebDriver . for ( browser . to_sym , params )
2014-12-14 13:13:46 +00:00
@browsers [ local_browser . hash ] = local_browser
2015-12-17 23:02:31 +00:00
browser_instance_preferences ( local_browser )
2013-06-25 14:00:28 +00:00
return local_browser
2013-02-23 22:54:48 +00:00
end
2016-05-21 15:40:08 +00:00
# avoid "Cannot read property 'get_Current' of undefined" issues
2017-10-01 12:25:52 +00:00
( 1 .. 5 ) . each do | count |
2019-06-27 18:26:28 +00:00
local_browser = browser_instance_remote
break
rescue = > e
wait_until_ready = rand ( 5 .. 13 )
log ( 'browser_instance' , { rescure : true , count : count , sleep : wait_until_ready , exception : e } )
sleep wait_until_ready
2017-10-01 12:25:52 +00:00
end
2016-05-21 15:40:08 +00:00
local_browser
end
def browser_instance_remote
2015-12-14 10:02:49 +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
2018-12-14 17:57:02 +00:00
# (ironically) required for timeout checks
# https://github.com/zalando/zalenium/issues/469#issuecomment-371417340
# https://opensource.zalando.com/zalenium/#usage
caps [ 'idleTimeout' ] = 300
http_client = Selenium :: WebDriver :: Remote :: Http :: Default . new (
open_timeout : 120 ,
read_timeout : 120
)
2013-06-25 14:00:28 +00:00
local_browser = Selenium :: WebDriver . for (
2013-02-23 22:54:48 +00:00
:remote ,
2018-12-19 17:31:51 +00:00
url : ENV [ 'REMOTE_URL' ] ,
2015-04-27 13:42:53 +00:00
desired_capabilities : caps ,
2018-12-19 17:31:51 +00:00
http_client : http_client ,
2013-02-23 22:54:48 +00:00
)
2015-12-14 23:52:26 +00:00
@browsers [ local_browser . hash ] = local_browser
2016-05-21 15:40:08 +00:00
browser_instance_preferences ( local_browser )
2015-12-14 23:52:26 +00:00
2015-12-18 10:48:22 +00:00
# upload files from remote dir
local_browser . file_detector = lambda do | args |
str = args . first . to_s
str if File . file? ( str )
end
2015-04-27 19:56:07 +00:00
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 ]
2018-10-09 06:17:41 +00:00
2015-12-14 23:52:26 +00:00
@browsers . delete ( local_browser . hash )
2014-12-14 13:13:46 +00:00
local_browser . quit
end
2013-07-24 18:09:20 +00:00
def browser_instance_preferences ( local_browser )
2016-06-09 17:52:08 +00:00
browser_width = ENV [ 'BROWSER_WIDTH' ] || 1024
browser_height = ENV [ 'BROWSER_HEIGHT' ] || 800
local_browser . manage . window . resize_to ( browser_width , browser_height )
2021-05-12 11:37:44 +00:00
if ! ENV [ 'REMOTE_URL' ] & . match? ( %r{ saucelabs|(grid|ci) \ .(zammad \ .org|znuny \ .com) }i )
2015-12-17 23:02:31 +00:00
if @browsers . count == 1
2013-07-24 18:09:20 +00:00
local_browser . manage . window . move_to ( 0 , 0 )
else
2016-06-09 17:52:08 +00:00
local_browser . manage . window . move_to ( browser_width , 0 )
2013-07-24 18:09:20 +00:00
end
end
local_browser . manage . timeouts . implicit_wait = 3 # seconds
end
2013-02-23 22:54:48 +00:00
def teardown
return if ! @browsers
2018-10-09 06:17:41 +00:00
2017-11-23 08:09:44 +00:00
@browsers . each_value do | local_browser |
2015-12-14 23:52:26 +00:00
screenshot ( browser : local_browser , comment : 'teardown' )
2014-12-14 13:13:46 +00:00
browser_instance_close ( local_browser )
2017-10-01 12:25:52 +00:00
end
2013-02-23 22:54:48 +00:00
end
2012-12-14 10:14:48 +00:00
2018-06-27 09:45:13 +00:00
def screenshot ( params = { } )
2015-05-04 06:13:14 +00:00
instance = params [ :browser ] || @browser
comment = params [ :comment ] || ''
2016-09-08 19:18:26 +00:00
filename = " tmp/ #{ Time . zone . now . strftime ( 'screenshot_%Y_%m_%d__%H_%M_%S_%L' ) } _ #{ comment } #{ instance . hash } .png "
2015-05-04 14:17:36 +00:00
log ( 'screenshot' , { filename : filename } )
2015-05-04 06:13:14 +00:00
instance . save_screenshot ( filename )
end
2015-02-22 12:28:34 +00:00
= begin
username = login (
2015-11-17 09:03:51 +00:00
browser : browser1 ,
username : 'someuser' ,
password : 'somepassword' ,
2018-04-23 13:12:19 +00:00
url : 'some url' , # optional, in case of aleady opened brower a reload is done because url is called again
2015-11-17 09:03:51 +00:00
remember_me : true , # optional
2015-12-31 01:04:45 +00:00
auto_wizard : false , # optional, in case of auto wizard, skip login
2016-05-25 07:19:45 +00:00
success : false , #optional
2015-02-22 12:28:34 +00:00
)
= end
def login ( params )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'login' , params )
2015-02-22 12:28:34 +00:00
instance = params [ :browser ] || @browser
if params [ :url ]
2015-12-18 10:48:22 +00:00
instance . get ( params [ :url ] )
2015-02-22 12:28:34 +00:00
end
2016-06-15 08:52:38 +00:00
# submit logs anyway
instance . execute_script ( 'App.Track.force()' )
2016-02-25 12:45:46 +00:00
element = instance . find_elements ( css : '#login input[name="username"]' ) [ 0 ]
2015-02-22 12:28:34 +00:00
if ! element
2015-12-31 01:04:45 +00:00
if params [ :auto_wizard ]
2015-12-31 01:29:49 +00:00
watch_for (
browser : instance ,
css : 'body' ,
value : 'auto wizard is enabled' ,
timeout : 10 ,
)
2016-03-21 19:10:01 +00:00
location ( url : " #{ browser_url } / # getting_started/auto_wizard " )
2015-12-31 01:04:45 +00:00
sleep 10
2016-02-25 12:45:46 +00:00
login = instance . find_elements ( css : '.user-menu .user a' ) [ 0 ] . attribute ( 'title' )
2015-12-31 01:04:45 +00:00
if login != params [ :username ]
screenshot ( browser : instance , comment : 'auto wizard login failed' )
2016-03-01 14:26:46 +00:00
raise 'auto wizard login failed'
2015-12-31 01:04:45 +00:00
end
assert ( true , 'auto wizard login ok' )
2016-02-03 11:50:30 +00:00
2016-02-03 14:21:59 +00:00
clues_close (
2018-12-19 17:31:51 +00:00
browser : instance ,
2016-02-03 14:21:59 +00:00
optional : true ,
)
2016-02-03 11:50:30 +00:00
2015-12-31 01:04:45 +00:00
return
end
2015-12-18 10:48:22 +00:00
screenshot ( browser : instance , comment : 'login_failed' )
2016-03-01 14:26:46 +00:00
raise 'No login box found'
2015-02-22 12:28:34 +00:00
end
2015-05-04 06:13:14 +00:00
2015-02-22 12:28:34 +00:00
element . clear
2015-12-18 10:48:22 +00:00
element . send_keys ( params [ :username ] )
2015-02-22 12:28:34 +00:00
2016-02-25 12:45:46 +00:00
element = instance . find_elements ( css : '#login input[name="password"]' ) [ 0 ]
2015-02-22 12:28:34 +00:00
element . clear
2015-12-18 10:48:22 +00:00
element . send_keys ( params [ :password ] )
2015-02-22 12:28:34 +00:00
if params [ :remember_me ]
2016-02-25 12:45:46 +00:00
instance . find_elements ( css : '#login .checkbox-replacement' ) [ 0 ] . click
2015-02-22 12:28:34 +00:00
end
2016-02-25 12:45:46 +00:00
instance . find_elements ( css : '#login button' ) [ 0 ] . click
2015-02-22 12:28:34 +00:00
2016-04-04 13:54:37 +00:00
sleep 4
2016-05-25 07:19:45 +00:00
login_failed = false
2020-11-05 16:31:00 +00:00
if instance . find_elements ( css : '.user-menu .user a' ) [ 0 ]
2016-05-25 07:19:45 +00:00
login = instance . find_elements ( css : '.user-menu .user a' ) [ 0 ] . attribute ( 'title' )
if login != params [ :username ]
login_failed = true
end
2020-11-05 16:31:00 +00:00
else
login_failed = true
2016-05-25 07:19:45 +00:00
end
if login_failed
if params [ :success ] == false
assert ( true , 'login not successfull, like wanted' )
return true
end
2015-12-18 10:48:22 +00:00
screenshot ( browser : instance , comment : 'login_failed' )
2016-03-01 14:26:46 +00:00
raise 'login failed'
2015-02-22 12:28:34 +00:00
end
2016-02-03 11:50:30 +00:00
2016-05-25 07:19:45 +00:00
if params [ :success ] == false
raise 'login successfull but should not'
end
2016-02-03 14:21:59 +00:00
clues_close (
2018-12-19 17:31:51 +00:00
browser : instance ,
2016-02-03 14:21:59 +00:00
optional : true ,
)
2016-02-03 11:50:30 +00:00
2015-12-18 10:48:22 +00:00
assert ( true , 'login ok' )
2015-02-22 12:28:34 +00:00
login
end
= begin
logout (
2015-11-17 09:03:51 +00:00
browser : browser1
2015-02-22 12:28:34 +00:00
)
= end
def logout ( params = { } )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'logout' , params )
2015-02-22 12:28:34 +00:00
instance = params [ :browser ] || @browser
2016-03-21 19:10:01 +00:00
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : 'a[href="#current_user"]' ,
2016-03-21 19:10:01 +00:00
mute_log : true ,
)
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : 'a[href="#logout"]' ,
2016-03-21 19:10:01 +00:00
mute_log : true ,
)
2017-10-01 12:25:52 +00:00
5 . times do
2015-03-03 09:14:57 +00:00
sleep 1
2016-02-25 12:45:46 +00:00
login = instance . find_elements ( css : '#login' ) [ 0 ]
2015-07-03 17:36:13 +00:00
next if ! login
2018-10-09 06:17:41 +00:00
2015-12-18 10:48:22 +00:00
assert ( true , 'logout ok' )
2015-07-03 17:36:13 +00:00
return
2017-10-01 12:25:52 +00:00
end
2015-12-18 10:48:22 +00:00
screenshot ( browser : instance , comment : 'logout_failed' )
2016-03-01 14:26:46 +00:00
raise 'no login box found, seems logout was not successfully!'
2015-02-22 12:28:34 +00:00
end
2016-02-03 14:21:59 +00:00
= begin
clues_close (
browser : browser1 ,
optional : false ,
)
= end
2016-02-03 20:44:47 +00:00
def clues_close ( params = { } )
2016-02-03 14:21:59 +00:00
switch_window_focus ( params )
log ( 'clues_close' , params )
instance = params [ :browser ] || @browser
2016-02-25 12:45:46 +00:00
clues = instance . find_elements ( css : '.js-modal--clue .js-close' ) [ 0 ]
2016-02-03 14:21:59 +00:00
if ! params [ :optional ] && ! clues
screenshot ( browser : instance , comment : 'no_clues' )
2016-03-01 14:26:46 +00:00
raise 'Unable to closes clues, no clues found!'
2016-02-03 14:21:59 +00:00
end
return if ! clues
2018-10-09 06:17:41 +00:00
2020-02-02 15:40:13 +00:00
checks = 25
previous = clues . location
( checks + 1 ) . times do | check |
raise " Element still moving after #{ checks } checks " if check == checks
current = clues . location
sleep 0 . 2 if ENV [ 'CI' ]
break if previous == current
previous = current
end
clues . click
watch_for_disappear (
browser : instance ,
css : 'modal-backdrop js-backdrop' ,
)
2016-02-03 14:21:59 +00:00
assert ( true , 'clues closed' )
end
2016-06-13 08:19:44 +00:00
= begin
notify_close (
browser : browser1 ,
2016-06-14 13:25:01 +00:00
optional : false ,
2016-06-13 08:19:44 +00:00
)
= end
def notify_close ( params = { } )
switch_window_focus ( params )
log ( 'notify_close' , params )
instance = params [ :browser ] || @browser
notify = instance . find_elements ( css : '.noty_inline_layout_container.i-am-new' ) [ 0 ]
if ! params [ :optional ] && ! notify
screenshot ( browser : instance , comment : 'no_notify' )
raise 'Unable to closes notify, no notify found!'
end
return if ! notify
2018-10-09 06:17:41 +00:00
2016-06-13 08:19:44 +00:00
notify . click
assert ( true , 'notify closed' )
sleep 1
end
2015-02-22 12:28:34 +00:00
= begin
location (
2015-11-17 09:03:51 +00:00
browser : browser1 ,
url : 'http://someurl' ,
2015-02-22 12:28:34 +00:00
)
= end
def location ( params )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'location' , params )
2015-02-22 12:28:34 +00:00
instance = params [ :browser ] || @browser
2015-12-14 23:52:26 +00:00
instance . get ( params [ :url ] )
2015-12-05 13:38:24 +00:00
# check if reload was successfull
2021-05-12 11:37:44 +00:00
if ! instance . find_elements ( css : 'body' ) [ 0 ] || instance . find_elements ( css : 'body' ) [ 0 ] . text =~ %r{ unavailable or too busy }i
2015-12-05 13:38:24 +00:00
instance . navigate . refresh
end
2015-02-22 12:28:34 +00:00
end
2015-02-22 22:20:05 +00:00
= begin
location_check (
2015-11-17 09:03:51 +00:00
browser : browser1 ,
url : 'http://someurl' ,
2015-02-22 22:20:05 +00:00
)
= end
def location_check ( params )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'location_check' , params )
2015-02-22 22:20:05 +00:00
instance = params [ :browser ] || @browser
2016-02-25 14:20:22 +00:00
sleep 0 . 7
current_url = instance . current_url
2021-05-12 11:37:44 +00:00
if ! current_url . match? ( %r{ #{ Regexp . quote ( params [ :url ] ) } } )
2015-12-14 23:52:26 +00:00
screenshot ( browser : instance , comment : 'location_check_failed' )
2016-03-01 14:26:46 +00:00
raise " url #{ current_url } is not matching #{ params [ :url ] } "
2015-02-22 22:20:05 +00:00
end
2016-02-25 14:20:22 +00:00
assert ( true , " url #{ current_url } is matching #{ params [ :url ] } " )
2015-02-22 22:20:05 +00:00
end
2015-02-22 12:28:34 +00:00
= begin
reload (
2015-11-17 09:03:51 +00:00
browser : browser1 ,
2015-02-22 12:28:34 +00:00
)
= end
def reload ( params = { } )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'reload' , params )
2015-02-22 12:28:34 +00:00
instance = params [ :browser ] || @browser
instance . navigate . refresh
2015-12-05 13:38:24 +00:00
# check if reload was successfull
2021-05-12 11:37:44 +00:00
if ! instance . find_elements ( css : 'body' ) [ 0 ] || instance . find_elements ( css : 'body' ) [ 0 ] . text =~ %r{ unavailable or too busy }i
2015-12-05 13:38:24 +00:00
instance . navigate . refresh
end
2015-12-14 23:52:26 +00:00
screenshot ( browser : instance , comment : 'reload_after' )
2015-02-22 12:28:34 +00:00
end
= begin
click (
2015-11-17 09:03:51 +00:00
browser : browser1 ,
2018-06-27 09:43:50 +00:00
css : '.some_class' ,
fast : false , # do not wait
wait : 1 , # wait 1 sec.
)
click (
browser : browser1 ,
xpath : '//a[contains(@class,".text-1")]' ,
fast : false , # do not wait
wait : 1 , # wait 1 sec.
2015-02-22 12:28:34 +00:00
)
2015-04-05 22:39:01 +00:00
click (
2015-11-17 09:03:51 +00:00
browser : browser1 ,
2018-06-27 09:43:50 +00:00
text : '.partial_link_text' ,
fast : false , # do not wait
wait : 1 , # wait 1 sec.
2015-04-05 22:39:01 +00:00
)
2015-02-22 12:28:34 +00:00
= end
def click ( params )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'click' , params )
2015-02-22 12:28:34 +00:00
instance = params [ :browser ] || @browser
2018-05-28 06:42:04 +00:00
if params . include? ( :css )
2018-06-27 09:43:50 +00:00
param_key = :css
2018-05-28 06:42:04 +00:00
find_element_key = :css
2018-06-27 09:43:50 +00:00
elsif params . include? ( :xpath )
param_key = :xpath
find_element_key = :xpath
2018-05-28 06:42:04 +00:00
else
2018-06-27 09:43:50 +00:00
param_key = :text
2018-05-28 06:42:04 +00:00
find_element_key = :partial_link_text
sleep 0 . 5
end
2015-11-17 09:03:51 +00:00
2018-05-28 06:42:04 +00:00
begin
elements = instance . find_elements ( find_element_key = > params [ param_key ] )
2020-08-18 13:01:18 +00:00
. tap { | e | e . slice! ( 1 .. - 1 ) if ! params [ :all ] }
2018-05-28 06:42:04 +00:00
if elements . empty?
return if params [ :only_if_exists ] == true
2018-10-09 06:17:41 +00:00
2018-05-28 06:42:04 +00:00
raise " No such element ' #{ params [ param_key ] } ' "
2016-03-21 19:10:01 +00:00
end
2015-05-14 14:59:35 +00:00
2018-05-28 06:42:04 +00:00
# a clumsy substitute for elements.each(&:click)
# (we need to refresh element references after each element.click
# because if clicks alter page content,
# subsequent element.clicks will raise a StaleElementReferenceError)
elements . length . times do | i |
instance . find_elements ( find_element_key = > params [ param_key ] ) [ i ] . try ( :click )
2016-05-29 00:51:58 +00:00
end
2018-05-28 06:42:04 +00:00
rescue = > e
raise e if ( fail_count || = 0 ) . positive?
fail_count += 1
log ( 'click' , { rescure : true } )
sleep 0 . 5
retry
2015-04-05 22:39:01 +00:00
end
2018-05-28 06:42:04 +00:00
2016-03-22 12:58:48 +00:00
sleep 0 . 2 if ! params [ :fast ]
2015-12-05 13:38:24 +00:00
sleep params [ :wait ] if params [ :wait ]
2021-06-15 06:26:52 +00:00
if params [ :expect_alert ]
check_alert ( params )
else
await_empty_ajax_queue ( params )
end
2015-02-22 12:28:34 +00:00
end
2018-06-27 09:43:50 +00:00
= begin
perform_macro ( 'Close & Tag as Spam' )
# or
perform_macro (
name : 'Close & Tag as Spam' ,
browser : browser1 ,
)
= end
def perform_macro ( params )
switch_window_focus ( params )
log ( 'perform_macro' , params )
instance = params [ :browser ] || @browser
click (
browser : instance ,
css : '.active.content .js-submitDropdown .js-openDropdownMacro'
)
click (
browser : instance ,
xpath : " //div[contains(@class, 'content') and contains(@class, 'active')]//li[contains(@class, 'js-dropdownActionMacro') and contains(text(), ' #{ params [ :name ] } ')] "
)
end
2015-11-17 09:03:51 +00:00
= begin
scroll_to (
2015-11-17 18:57:15 +00:00
browser : browser1 ,
position : 'top' , # botton
css : '.some_class' ,
2015-11-17 09:03:51 +00:00
)
= end
def scroll_to ( params )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-11-17 09:03:51 +00:00
log ( 'scroll_to' , params )
instance = params [ :browser ] || @browser
2015-11-17 18:57:15 +00:00
position = 'true'
if params [ :position ] == 'botton'
position = 'false'
end
2015-11-17 09:03:51 +00:00
execute (
browser : instance ,
2015-11-17 18:57:15 +00:00
js : " \ $(' #{ params [ :css ] } ').get(0).scrollIntoView( #{ position } ) " ,
2015-11-17 09:03:51 +00:00
mute_log : params [ :mute_log ]
)
2016-03-22 23:12:50 +00:00
sleep 0 . 3
2017-06-16 20:43:09 +00:00
screenshot ( browser : instance , comment : 'scroll_to_after' )
2015-11-17 09:03:51 +00:00
end
2018-05-11 08:09:24 +00:00
= begin
modal_close (
browser : browser1 ,
)
= end
def modal_close ( params = { } )
switch_window_focus ( params )
log ( 'modal_close' , params )
instance = params [ :browser ] || @browser
element = instance . find_elements ( css : '.modal .js-close' ) [ 0 ]
raise " No such modal to close #{ params . inspect } " if ! element
element . click
end
2016-03-23 07:24:25 +00:00
= begin
modal_ready (
2016-06-10 07:21:47 +00:00
browser : browser1 ,
2016-03-23 07:24:25 +00:00
)
= end
2016-03-23 07:40:05 +00:00
def modal_ready ( params = { } )
2016-03-23 07:24:25 +00:00
switch_window_focus ( params )
log ( 'modal_ready' , params )
instance = params [ :browser ] || @browser
2018-07-24 16:06:09 +00:00
watch_for (
browser : instance ,
css : '.modal.in' ,
timeout : params [ :timeout ] || 4 ,
)
2016-03-23 07:24:25 +00:00
end
2016-06-10 06:09:47 +00:00
= begin
modal_disappear (
2016-06-10 07:21:47 +00:00
browser : browser1 ,
2016-09-12 06:53:25 +00:00
timeout : 12 , # default 8
2016-06-10 06:09:47 +00:00
)
= end
def modal_disappear ( params = { } )
switch_window_focus ( params )
log ( 'modal_disappear' , params )
instance = params [ :browser ] || @browser
watch_for_disappear (
browser : instance ,
css : '.modal' ,
2016-09-12 06:53:25 +00:00
timeout : params [ :timeout ] || 8 ,
2016-06-10 06:09:47 +00:00
)
end
2015-11-05 12:34:22 +00:00
= begin
execute (
2015-11-17 09:03:51 +00:00
browser : browser1 ,
js : '.some_class' ,
2015-11-05 12:34:22 +00:00
)
= end
def execute ( params )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-11-05 12:34:22 +00:00
log ( 'js' , params )
instance = params [ :browser ] || @browser
if params [ :js ]
2015-12-18 16:18:09 +00:00
return instance . execute_script ( params [ :js ] )
2015-11-05 12:34:22 +00:00
end
2018-10-09 06:17:41 +00:00
2016-03-01 14:26:46 +00:00
raise " Invalid execute params #{ params . inspect } "
2015-11-05 12:34:22 +00:00
end
2015-02-22 12:28:34 +00:00
= begin
exists (
2015-11-29 15:39:56 +00:00
browser : browser1 ,
css : '.some_class' ,
2015-02-22 12:28:34 +00:00
)
2016-12-14 14:48:41 +00:00
exists (
displayed : false , # true|false
browser : browser1 ,
css : '.some_class' ,
2018-06-05 12:57:00 +00:00
displayed : true , # true|false
2016-12-14 14:48:41 +00:00
)
2015-02-22 12:28:34 +00:00
= end
def exists ( params )
2018-06-03 15:10:22 +00:00
retries || = 0
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'exists' , params )
2015-02-22 22:20:05 +00:00
instance = params [ :browser ] || @browser
2016-02-25 12:45:46 +00:00
if ! instance . find_elements ( css : params [ :css ] ) [ 0 ]
2015-12-14 23:52:26 +00:00
screenshot ( browser : instance , comment : 'exists_failed' )
2016-03-01 14:26:46 +00:00
raise " #{ params [ :css ] } dosn't exist, but should "
2015-02-22 22:20:05 +00:00
end
2016-12-14 14:48:41 +00:00
if params . key? ( :displayed )
if params [ :displayed ] == true && ! instance . find_elements ( css : params [ :css ] ) [ 0 ] . displayed?
raise " #{ params [ :css ] } is not displayed, but should "
end
if params [ :displayed ] == false && instance . find_elements ( css : params [ :css ] ) [ 0 ] . displayed?
raise " #{ params [ :css ] } is displayed, but should not "
end
end
2015-02-22 22:20:05 +00:00
true
2021-02-18 16:08:40 +00:00
rescue
2018-06-03 15:10:22 +00:00
sleep retries
retries += 1
retry if retries < 3
2015-02-22 22:20:05 +00:00
end
= begin
exists_not (
2015-11-29 15:39:56 +00:00
browser : browser1 ,
css : '.some_class' ,
2015-02-22 22:20:05 +00:00
)
= end
def exists_not ( params )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'exists_not' , params )
2015-02-22 12:28:34 +00:00
instance = params [ :browser ] || @browser
2016-02-25 12:45:46 +00:00
if instance . find_elements ( css : params [ :css ] ) [ 0 ]
2015-12-14 23:52:26 +00:00
screenshot ( browser : instance , comment : 'exists_not_failed' )
2016-03-01 14:26:46 +00:00
raise " #{ params [ :css ] } exists but should not "
2015-02-22 12:28:34 +00:00
end
2015-02-22 22:20:05 +00:00
true
2015-02-22 12:28:34 +00:00
end
= begin
set (
2015-12-05 19:44:43 +00:00
browser : browser1 ,
css : '.some_class' ,
value : true ,
slow : false ,
2016-09-12 22:14:10 +00:00
blur : true , # default false
2015-12-05 19:44:43 +00:00
clear : true , # todo | default: true
no_click : true ,
2015-02-22 12:28:34 +00:00
)
= end
def set ( params )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'set' , params )
2015-02-22 12:28:34 +00:00
instance = params [ :browser ] || @browser
2020-02-02 15:40:13 +00:00
begin
retries || = 0
element = instance . find_elements ( css : params [ :css ] ) [ 0 ]
if ! params [ :no_click ]
element . click
end
element . clear
rescue Selenium :: WebDriver :: Error :: StaleElementReferenceError
sleep retries
retries += 1
retry if retries < 3
2015-12-05 19:44:43 +00:00
end
2015-02-22 12:28:34 +00:00
2018-03-28 05:33:41 +00:00
begin
2020-11-05 16:31:00 +00:00
if params [ :slow ]
2018-03-28 05:33:41 +00:00
element . send_keys ( '' )
2021-05-28 11:25:36 +00:00
keys = params [ :value ] . to_s . chars
2018-03-28 05:33:41 +00:00
keys . each do | key |
instance . action . send_keys ( key ) . perform
end
2020-11-05 16:31:00 +00:00
else
element . send_keys ( params [ :value ] )
2018-03-28 05:33:41 +00:00
end
2019-06-28 11:38:49 +00:00
rescue
2018-03-28 05:33:41 +00:00
sleep 0 . 5
# just try again
log ( 'set' , { rescure : true } )
element = instance . find_elements ( css : params [ :css ] ) [ 0 ]
raise " No such element ' #{ params [ :css ] } ' " if ! element
2018-10-09 06:17:41 +00:00
2020-11-05 16:31:00 +00:00
if params [ :slow ]
2018-03-28 05:33:41 +00:00
element . send_keys ( '' )
2021-05-28 11:25:36 +00:00
keys = params [ :value ] . to_s . chars
2018-03-28 05:33:41 +00:00
keys . each do | key |
instance . action . send_keys ( key ) . perform
end
2020-11-05 16:31:00 +00:00
else
element . send_keys ( params [ :value ] )
2017-10-01 12:25:52 +00:00
end
2015-02-22 12:28:34 +00:00
end
2015-02-26 12:41:09 +00:00
2016-09-08 19:18:26 +00:00
# it's not working stable with ff via selenium, use js
2021-05-12 11:37:44 +00:00
if browser =~ %r{ firefox }i && params [ :css ] . include? ( '[data-name=' )
2018-03-28 05:33:41 +00:00
log ( 'set_ff_trigger_workaround' , params )
instance . execute_script ( " $(' #{ params [ :css ] } ').trigger('focusout') " )
2016-09-08 19:18:26 +00:00
end
2015-02-26 12:41:09 +00:00
if params [ :blur ]
2015-12-14 23:52:26 +00:00
instance . execute_script ( " $(' #{ params [ :css ] } ').blur() " )
2015-02-26 12:41:09 +00:00
end
2015-02-28 10:40:23 +00:00
2016-03-22 12:58:48 +00:00
sleep 0 . 2
2021-06-15 06:26:52 +00:00
await_empty_ajax_queue ( params )
2015-02-22 12:28:34 +00:00
end
2015-02-22 22:20:05 +00:00
= begin
select (
2016-03-21 12:51:55 +00:00
browser : browser1 ,
css : '.some_class' ,
value : 'Some Value' ,
deselect_all : false , # default false
2015-02-22 22:20:05 +00:00
)
= end
def select ( params )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'select' , params )
2015-02-22 22:20:05 +00:00
instance = params [ :browser ] || @browser
2016-02-09 20:02:57 +00:00
# searchable select
2016-02-25 12:45:46 +00:00
element = instance . find_elements ( css : " #{ params [ :css ] } .js-shadow " ) [ 0 ]
2016-02-09 20:02:57 +00:00
if element
2016-02-25 12:45:46 +00:00
element = instance . find_elements ( css : " #{ params [ :css ] } .js-shadow + .js-input " ) [ 0 ]
2016-02-09 20:02:57 +00:00
element . click
element . clear
2018-05-21 22:58:50 +00:00
sleep 0 . 2
2016-03-22 12:58:48 +00:00
element . send_keys ( params [ :value ] )
sleep 0 . 2
2016-02-09 20:02:57 +00:00
element . send_keys ( :enter )
2016-03-22 12:58:48 +00:00
sleep 0 . 2
2016-02-09 20:02:57 +00:00
return
end
# native select
2015-02-24 01:31:17 +00:00
begin
2016-02-25 12:45:46 +00:00
element = instance . find_elements ( css : params [ :css ] ) [ 0 ]
2015-02-24 01:31:17 +00:00
dropdown = Selenium :: WebDriver :: Support :: Select . new ( element )
2016-03-21 12:51:55 +00:00
if params [ :deselect_all ]
dropdown . deselect_all
end
2015-02-24 01:31:17 +00:00
dropdown . select_by ( :text , params [ :value ] )
2021-07-16 13:44:10 +00:00
# puts "select - #{params.inspect}"
2015-02-24 01:31:17 +00:00
rescue
2016-03-23 07:24:25 +00:00
sleep 0 . 4
2016-03-21 13:39:18 +00:00
2015-02-24 01:31:17 +00:00
# just try again
2016-03-21 19:10:01 +00:00
log ( 'select' , { rescure : true } )
2016-02-25 12:45:46 +00:00
element = instance . find_elements ( css : params [ :css ] ) [ 0 ]
2015-02-24 01:31:17 +00:00
dropdown = Selenium :: WebDriver :: Support :: Select . new ( element )
2016-03-21 12:51:55 +00:00
if params [ :deselect_all ]
dropdown . deselect_all
end
2015-02-24 01:31:17 +00:00
dropdown . select_by ( :text , params [ :value ] )
2021-07-16 13:44:10 +00:00
# puts "select2 - #{params.inspect}"
2015-02-24 01:31:17 +00:00
end
2021-06-15 06:26:52 +00:00
await_empty_ajax_queue ( params )
2015-02-22 22:20:05 +00:00
end
2015-12-05 13:38:24 +00:00
= begin
switch (
browser : browser1 ,
css : '.some_class' ,
type : 'on' , # 'off'
2016-08-16 06:31:54 +00:00
no_check : true , # do not check is switch has changed, in case if js alert
2015-12-05 13:38:24 +00:00
)
= end
def switch ( params )
switch_window_focus ( params )
log ( 'switch' , params )
instance = params [ :browser ] || @browser
2016-02-25 12:45:46 +00:00
element = instance . find_elements ( css : " #{ params [ :css ] } input[type=checkbox] " ) [ 0 ]
2015-12-05 13:38:24 +00:00
checked = element . attribute ( 'checked' )
2016-08-16 06:31:54 +00:00
2015-12-05 13:38:24 +00:00
if ! checked
if params [ :type ] == 'on'
2016-02-25 12:45:46 +00:00
instance . find_elements ( css : " #{ params [ :css ] } label " ) [ 0 ] . click
2016-06-09 22:25:13 +00:00
sleep 2
2016-08-16 00:10:41 +00:00
2016-08-16 06:31:54 +00:00
if params [ :no_check ] != true
element = instance . find_elements ( css : " #{ params [ :css ] } input[type=checkbox] " ) [ 0 ]
checked = element . attribute ( 'checked' )
raise 'Switch not on!' if ! checked
end
2015-12-05 13:38:24 +00:00
end
2016-01-15 17:22:57 +00:00
elsif params [ :type ] == 'off'
2016-02-25 12:45:46 +00:00
instance . find_elements ( css : " #{ params [ :css ] } label " ) [ 0 ] . click
2016-06-09 22:25:13 +00:00
sleep 2
2016-08-16 00:10:41 +00:00
2016-08-16 06:31:54 +00:00
if params [ :no_check ] != true
element = instance . find_elements ( css : " #{ params [ :css ] } input[type=checkbox] " ) [ 0 ]
checked = element . attribute ( 'checked' )
raise 'Switch not off!' if checked
end
2015-12-05 13:38:24 +00:00
end
end
2015-02-23 06:56:45 +00:00
= begin
check (
2015-11-27 14:47:56 +00:00
browser : browser1 ,
css : '.some_class' ,
2015-02-23 06:56:45 +00:00
)
= end
def check ( params )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'check' , params )
2015-02-23 06:56:45 +00:00
instance = params [ :browser ] || @browser
2018-06-05 08:31:59 +00:00
instance . execute_script ( " $(' #{ params [ :css ] } :not(:checked)').click() " )
2021-07-16 13:44:10 +00:00
# element = instance.find_elements(css: params[:css])[0]
# checked = element.attribute('checked')
# element.click if !checked
2015-02-23 06:56:45 +00:00
end
= begin
uncheck (
2015-11-27 14:47:56 +00:00
browser : browser1 ,
css : '.some_class' ,
2015-02-23 06:56:45 +00:00
)
= end
def uncheck ( params )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'uncheck' , params )
2015-02-23 06:56:45 +00:00
instance = params [ :browser ] || @browser
2018-06-05 08:31:59 +00:00
instance . execute_script ( " $(' #{ params [ :css ] } :checked').click() " )
2021-07-16 13:44:10 +00:00
# element = instance.find_elements(css: params[:css])[0]
# checked = element.attribute('checked')
# element.click if checked
2015-02-23 06:56:45 +00:00
end
2015-02-22 12:28:34 +00:00
= begin
sendkey (
2015-11-27 14:47:56 +00:00
browser : browser1 ,
value : :enter ,
2016-09-12 22:14:10 +00:00
slow : false , # default false
2015-02-22 12:28:34 +00:00
)
= end
def sendkey ( params )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'sendkey' , params )
2015-02-22 12:28:34 +00:00
instance = params [ :browser ] || @browser
2016-09-12 22:14:10 +00:00
element = nil
if params [ :css ]
element = instance . find_elements ( css : params [ :css ] ) [ 0 ]
end
2020-10-22 13:57:01 +00:00
if params [ :value ] . instance_of? ( Array )
2017-10-01 12:25:52 +00:00
params [ :value ] . each do | key |
2016-09-12 22:14:10 +00:00
if element
element . send_keys ( key )
else
instance . action . send_keys ( key ) . perform
end
2017-10-01 12:25:52 +00:00
end
2015-02-22 12:28:34 +00:00
return
end
2016-09-12 22:14:10 +00:00
if element
element . send_keys ( params [ :value ] )
else
instance . action . send_keys ( params [ :value ] ) . perform
end
2015-11-27 14:47:56 +00:00
if params [ :slow ]
2016-03-22 12:58:48 +00:00
sleep 1 . 5
2015-11-27 14:47:56 +00:00
else
2016-03-22 12:58:48 +00:00
sleep 0 . 2
2015-11-27 14:47:56 +00:00
end
2015-02-22 12:28:34 +00:00
end
= begin
match (
2015-11-29 15:39:56 +00:00
browser : browser1 ,
css : '#content .text-1' ,
value : 'some test for browser and some other for browser' ,
attribute : 'some_attribute' , # match on attribute
should_not_match : true ,
no_quote : false , # use regex
2015-02-22 12:28:34 +00:00
)
= end
2015-03-01 23:16:36 +00:00
def match ( params , fallback = false )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'match' , params )
2015-02-22 12:28:34 +00:00
instance = params [ :browser ] || @browser
2016-02-25 12:45:46 +00:00
element = instance . find_elements ( css : params [ :css ] ) [ 0 ]
2015-02-22 12:28:34 +00:00
2020-07-07 06:30:20 +00:00
if params [ :css ] . include? ( 'select' )
2015-02-22 12:28:34 +00:00
dropdown = Selenium :: WebDriver :: Support :: Select . new ( element )
success = false
2017-11-23 08:09:44 +00:00
dropdown . selected_options & . each do | option |
if option . text == params [ :value ]
success = true
2017-10-01 12:25:52 +00:00
end
2015-02-22 12:28:34 +00:00
end
if params [ :should_not_match ]
if success
2016-09-08 19:18:26 +00:00
screenshot ( browser : instance , comment : 'match_failed' )
2016-03-01 14:26:46 +00:00
raise " should not match ' #{ params [ :value ] } ' in select list, but is matching "
2015-02-22 12:28:34 +00:00
end
2016-01-15 17:22:57 +00:00
elsif ! success
2016-09-08 19:18:26 +00:00
screenshot ( browser : instance , comment : 'match_failed' )
2016-03-01 14:26:46 +00:00
raise " not matching ' #{ params [ :value ] } ' in select list "
2015-02-22 12:28:34 +00:00
end
2016-01-15 17:22:57 +00:00
return true
2015-02-22 12:28:34 +00:00
end
2015-02-24 01:31:17 +00:00
# match on attribute
2015-02-28 10:40:23 +00:00
begin
2016-01-15 17:22:57 +00:00
text = if params [ :attribute ]
element . attribute ( params [ :attribute ] )
2021-05-12 11:37:44 +00:00
elsif params [ :css ] . match? ( %r{ (input|textarea) }i )
2016-01-15 17:22:57 +00:00
element . attribute ( 'value' )
else
element . text
end
2015-03-08 01:06:57 +00:00
rescue = > e
2015-02-28 10:40:23 +00:00
# just try again
2015-03-01 23:16:36 +00:00
if ! fallback
return match ( params , true )
2015-02-28 10:40:23 +00:00
end
2016-01-15 17:22:57 +00:00
raise e . inspect
2015-02-22 12:28:34 +00:00
end
2015-04-14 14:29:26 +00:00
# do cleanups (needed for richtext tests)
2015-04-14 21:49:46 +00:00
if params [ :cleanup ]
2021-05-12 11:37:44 +00:00
text . gsub! ( %r{ \ s+$ }m , '' )
params [ :value ] . gsub! ( %r{ \ s+$ }m , '' )
2015-04-14 21:49:46 +00:00
end
2015-04-14 14:29:26 +00:00
2015-02-22 12:28:34 +00:00
match = false
if params [ :no_quote ]
2021-07-16 13:44:10 +00:00
# puts "aaaa #{text}/#{params[:value]}"
2021-05-12 11:37:44 +00:00
if text =~ %r{ #{ params [ :value ] } }i
2015-02-22 12:28:34 +00:00
match = $1 || true
end
2021-05-12 11:37:44 +00:00
elsif text . match? ( %r{ #{ Regexp . quote ( params [ :value ] ) } }i )
2016-01-15 17:22:57 +00:00
match = true
2015-02-22 12:28:34 +00:00
end
2016-01-15 17:22:57 +00:00
2015-02-22 12:28:34 +00:00
if match
if params [ :should_not_match ]
2016-09-08 19:18:26 +00:00
screenshot ( browser : instance , comment : 'match_failed' )
2016-03-01 14:26:46 +00:00
raise " matching ' #{ params [ :value ] } ' in content ' #{ text } ' but should not! "
2015-02-22 12:28:34 +00:00
end
2016-01-15 17:22:57 +00:00
elsif ! params [ :should_not_match ]
2016-09-08 19:18:26 +00:00
screenshot ( browser : instance , comment : 'match_failed' )
2016-03-01 14:26:46 +00:00
raise " not matching ' #{ params [ :value ] } ' in content ' #{ text } ' but should! "
2015-02-22 12:28:34 +00:00
end
2016-03-22 12:58:48 +00:00
sleep 0 . 2
2015-02-28 10:40:23 +00:00
match
2015-02-22 12:28:34 +00:00
end
2015-02-22 22:20:05 +00:00
= begin
match_not (
2015-11-29 15:39:56 +00:00
browser : browser1 ,
css : '#content .text-1' ,
value : 'some test for browser and some other for browser' ,
attribute : 'some_attribute' , # match on attribute
should_not_match : true ,
no_quote : false , # use regex
2015-02-22 22:20:05 +00:00
)
= end
def match_not ( params )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'match_not' , params )
2015-02-22 22:20:05 +00:00
params [ :should_not_match ] = true
match ( params )
end
2015-11-06 01:08:06 +00:00
= begin
2018-07-12 07:18:39 +00:00
Get the on - screen pixel coordinates of a given DOM element . Can be used to compare
the relative location of table rows before and after sort , for example .
Returns a Selenium :: WebDriver :: Point object . Use result . x and result . y to access
its X and Y coordinates respectively .
get_location (
browser : browser1 ,
css : '.some_class' ,
)
= end
def get_location ( params )
switch_window_focus ( params )
log ( 'exists' , params )
instance = params [ :browser ] || @browser
if params [ :css ]
query = { css : params [ :css ] }
end
if params [ :xpath ]
query = { xpath : params [ :xpath ] }
end
if ! instance . find_elements ( query ) [ 0 ]
screenshot ( browser : instance , comment : 'exists_failed' )
raise " #{ query } dosn't exist, but should "
end
instance . find_elements ( query ) [ 0 ] . location
end
= begin
2017-02-05 18:24:48 +00:00
set type of task ( closeTab , closeNextInOverview , stayOnTab )
2015-11-06 01:08:06 +00:00
task_type (
2015-11-29 15:39:56 +00:00
browser : browser1 ,
type : 'stayOnTab' ,
2015-11-06 01:08:06 +00:00
)
= end
def task_type ( params )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-11-06 01:08:06 +00:00
log ( 'task_type' , params )
instance = params [ :browser ] || @browser
if params [ :type ]
2016-02-25 12:45:46 +00:00
instance . find_elements ( css : '.content.active .js-secondaryActionButtonLabel' ) [ 0 ] . click
instance . find_elements ( css : " .content.active .js-secondaryActionLabel[data-type= #{ params [ :type ] } ] " ) [ 0 ] . click
2015-11-06 01:08:06 +00:00
return
end
2016-03-01 14:26:46 +00:00
raise " Unknown params for task_type: #{ params . inspect } "
2015-11-06 01:08:06 +00:00
end
2015-02-22 12:28:34 +00:00
= begin
cookie (
2015-11-29 15:39:56 +00:00
browser : browser1 ,
name : '^_zammad.+?' ,
value : '.+?' ,
expires : nil ,
2015-02-22 12:28:34 +00:00
)
cookie (
2015-11-29 15:39:56 +00:00
browser : browser1 ,
name : '^_zammad.+?' ,
should_not_exist : true ,
2015-02-22 12:28:34 +00:00
)
= end
def cookie ( params )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'cookie' , params )
2015-02-22 12:28:34 +00:00
instance = params [ :browser ] || @browser
if ! browser_support_cookies
2015-12-14 23:52:26 +00:00
assert ( true , " ' #{ params [ :value ] } ' ups browser is not supporting reading cookies, go ahead " )
2015-02-22 12:28:34 +00:00
return true
end
cookies = instance . manage . all_cookies
2017-10-01 12:25:52 +00:00
cookies . each do | cookie |
2015-02-22 12:28:34 +00:00
# :name=>"_zammad_session_c25832f4de2", :value=>"adc31cd21615cb0a7ab269184ec8b76f", :path=>"/", :domain=>"localhost", :expires=>nil, :secure=>false}
2021-05-12 11:37:44 +00:00
next if ! cookie [ :name ] . match? ( %r{ #{ params [ :name ] } }i )
2015-02-22 12:28:34 +00:00
2021-05-12 11:37:44 +00:00
if params . key? ( :value ) && cookie [ :value ] . to_s =~ %r{ #{ params [ :value ] } }i
2015-12-14 23:52:26 +00:00
assert ( true , " matching value ' #{ params [ :value ] } ' in cookie ' #{ cookie } ' " )
2015-07-03 17:36:13 +00:00
else
2016-03-01 14:26:46 +00:00
raise " not matching value ' #{ params [ :value ] } ' in cookie ' #{ cookie } ' "
2015-07-03 17:36:13 +00:00
end
2021-05-12 11:37:44 +00:00
if params . key? ( :expires ) && cookie [ :expires ] . to_s =~ %r{ #{ params [ :expires ] } }i
2015-12-14 23:52:26 +00:00
assert ( true , " matching expires ' #{ params [ :expires ] . inspect } ' in cookie ' #{ cookie } ' " )
2015-07-03 17:36:13 +00:00
else
2016-03-01 14:26:46 +00:00
raise " not matching expires ' #{ params [ :expires ] } ' in cookie ' #{ cookie } ' "
2015-02-22 12:28:34 +00:00
end
2015-07-03 17:36:13 +00:00
return if ! params [ :should_not_exist ]
2016-03-01 14:26:46 +00:00
raise " cookie with name ' #{ params [ :name ] } ' should not exist, but exists ' #{ cookies } ' "
2017-10-01 12:25:52 +00:00
end
2015-02-22 12:28:34 +00:00
if params [ :should_not_exist ]
2015-12-14 23:52:26 +00:00
assert ( true , " cookie with name ' #{ params [ :name ] } ' is not existing " )
2015-02-22 12:28:34 +00:00
return
end
2016-03-01 14:26:46 +00:00
raise " not matching name ' #{ params [ :name ] } ' in cookie ' #{ cookies } ' "
2015-02-22 12:28:34 +00:00
end
2015-02-28 18:51:40 +00:00
= begin
verify_title (
2015-11-29 15:39:56 +00:00
browser : browser1 ,
value : 'some title' ,
2015-02-28 18:51:40 +00:00
)
= end
def verify_title ( params = { } )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'verify_title' , params )
2015-02-28 18:51:40 +00:00
instance = params [ :browser ] || @browser
title = instance . title
2021-05-12 11:37:44 +00:00
if title . match? ( %r{ #{ params [ :value ] } }i )
2015-12-14 23:52:26 +00:00
assert ( true , " matching ' #{ params [ :value ] } ' in title ' #{ title } ' " )
2015-02-28 18:51:40 +00:00
else
2016-03-01 14:26:46 +00:00
raise " not matching ' #{ params [ :value ] } ' in title ' #{ title } ' "
2015-02-28 18:51:40 +00:00
end
end
= begin
verify_task (
2015-11-29 15:39:56 +00:00
browser : browser1 ,
data : {
title : 'some title' ,
modified : true , # optional
2015-02-28 18:51:40 +00:00
}
)
= end
2021-06-15 06:26:52 +00:00
def verify_task ( params = { } )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'verify_task' , params )
2015-02-28 18:51:40 +00:00
instance = params [ :browser ] || @browser
data = params [ :data ]
2015-03-01 23:16:36 +00:00
begin
2021-06-15 06:26:52 +00:00
retries || = 0
sleep 1
2015-03-08 01:06:57 +00:00
# verify title
2015-03-01 23:16:36 +00:00
if data [ :title ]
2016-02-25 12:45:46 +00:00
title = instance . find_elements ( css : '.tasks .is-active' ) [ 0 ] . text . strip
2021-05-12 11:37:44 +00:00
if title . match? ( %r{ #{ data [ :title ] } }i )
2015-12-14 23:52:26 +00:00
assert ( true , " matching ' #{ data [ :title ] } ' in title ' #{ title } ' " )
2015-03-01 23:16:36 +00:00
else
2016-09-08 19:18:26 +00:00
screenshot ( browser : instance , comment : 'verify_task_failed' )
2016-03-01 14:26:46 +00:00
raise " not matching ' #{ data [ :title ] } ' in title ' #{ title } ' "
2015-03-01 23:16:36 +00:00
end
end
2016-09-08 19:18:26 +00:00
2015-03-08 01:06:57 +00:00
# verify modified
2015-04-27 19:56:07 +00:00
if data . key? ( :modified )
2016-02-25 12:45:46 +00:00
exists = instance . find_elements ( css : '.tasks .is-active' ) [ 0 ]
is_modified = instance . find_elements ( css : '.tasks .is-modified' ) [ 0 ]
2015-03-08 01:06:57 +00:00
puts " m #{ data [ :modified ] . inspect } "
if exists
2015-06-01 10:38:10 +00:00
puts ' exists'
2015-03-08 01:06:57 +00:00
end
if is_modified
2015-04-27 12:51:43 +00:00
puts ' is_modified'
2015-03-08 01:06:57 +00:00
end
if data [ :modified ] == true
if is_modified
2015-12-14 23:52:26 +00:00
assert ( true , " task ' #{ data [ :title ] } ' is modifed " )
2015-03-08 01:06:57 +00:00
elsif ! exists
2016-09-08 19:18:26 +00:00
screenshot ( browser : instance , comment : 'verify_task_failed' )
2016-03-01 14:26:46 +00:00
raise " task ' #{ data [ :title ] } ' not exists, should not modified "
2015-03-08 01:06:57 +00:00
else
2016-09-08 19:18:26 +00:00
screenshot ( browser : instance , comment : 'verify_task_failed' )
2016-03-01 14:26:46 +00:00
raise " task ' #{ data [ :title ] } ' is not modifed "
2015-03-08 01:06:57 +00:00
end
2016-01-15 17:22:57 +00:00
elsif ! is_modified
assert ( true , " task ' #{ data [ :title ] } ' is modifed " )
elsif ! exists
2016-09-08 19:18:26 +00:00
screenshot ( browser : instance , comment : 'verify_task_failed' )
2016-03-01 14:26:46 +00:00
raise " task ' #{ data [ :title ] } ' not exists, should be not modified "
2015-03-08 01:06:57 +00:00
else
2016-09-08 19:18:26 +00:00
screenshot ( browser : instance , comment : 'verify_task_failed' )
2016-03-01 14:26:46 +00:00
raise " task ' #{ data [ :title ] } ' is modifed, but should not "
2015-03-08 01:06:57 +00:00
end
end
rescue = > e
2021-06-15 06:26:52 +00:00
retries += 1
retry if retries < 5
2020-09-30 09:07:01 +00:00
raise " ERROR: #{ e . inspect } "
2015-02-28 18:51:40 +00:00
end
true
end
2015-03-02 13:39:27 +00:00
= begin
open_task (
2015-11-29 15:39:56 +00:00
browser : browser1 ,
data : {
title : 'some title' ,
2015-03-02 13:39:27 +00:00
}
)
= end
2016-02-29 15:00:11 +00:00
def open_task ( params = { } )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'open_task' , params )
2015-03-02 13:39:27 +00:00
instance = params [ :browser ] || @browser
data = params [ :data ]
2018-03-28 05:33:41 +00:00
element = instance . find_element ( css : '#navigation' ) . find_element ( partial_link_text : data [ :title ] )
2015-03-02 13:39:27 +00:00
if ! element
2015-12-14 23:52:26 +00:00
screenshot ( browser : instance , comment : 'open_task_failed' )
2016-03-01 14:26:46 +00:00
raise " no task with title ' #{ data [ :title ] } ' found "
2015-03-02 13:39:27 +00:00
end
2018-03-28 05:33:41 +00:00
# firefix/marionette issue with Selenium::WebDriver::Error::ElementNotInteractableError: could not be scrolled into view
# use js workaround instead of native click
instance . execute_script ( " $(' # navigation .tasks .task:contains( \" #{ data [ :title ] } \" ) .nav-tab-name').click() " )
2021-07-16 13:44:10 +00:00
# element.click
2015-03-02 13:39:27 +00:00
true
end
2016-02-29 15:00:11 +00:00
= begin
close_task (
browser : browser1 ,
data : {
title : 'some title' ,
} ,
discard_changes : true ,
)
= end
def close_task ( params = { } )
switch_window_focus ( params )
log ( 'close_task' , params )
instance = params [ :browser ] || @browser
data = params [ :data ]
2018-03-28 05:33:41 +00:00
element = instance . find_element ( css : '#navigation' ) . find_element ( partial_link_text : data [ :title ] )
2016-02-29 15:00:11 +00:00
if ! element
screenshot ( browser : instance , comment : 'close_task_failed' )
2016-03-01 14:26:46 +00:00
raise " no task with title ' #{ data [ :title ] } ' found "
2016-02-29 15:00:11 +00:00
end
2018-03-28 05:33:41 +00:00
instance . action . move_to ( element ) . release . perform
2016-02-29 15:00:11 +00:00
sleep 0 . 1
2018-03-28 05:33:41 +00:00
instance . execute_script ( " $(' # navigation .tasks .task:contains( \" #{ data [ :title ] } \" ) .js-close').click() " )
2016-02-29 15:00:11 +00:00
# accept task close warning
if params [ :discard_changes ]
2016-06-10 07:21:47 +00:00
modal_ready ( browser : instance )
2016-02-29 15:00:11 +00:00
instance . find_elements ( css : '.modal button.js-submit' ) [ 0 ] . click
2016-06-10 06:09:47 +00:00
modal_disappear ( browser : instance )
2016-02-29 15:00:11 +00:00
end
true
end
2015-02-28 10:40:23 +00:00
= begin
file_upload (
2015-11-29 15:39:56 +00:00
browser : browser1 ,
2016-09-27 17:46:23 +00:00
css : '.content.active .attachmentPlaceholder-inputHolder input'
2018-06-05 03:28:12 +00:00
files : [ 'path/in/home/some_file.ext' ] , # 'test/data/pdf/test1.pdf'
2015-02-28 10:40:23 +00:00
)
= end
def file_upload ( params = { } )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'file_upload' , params )
2015-02-28 10:40:23 +00:00
instance = params [ :browser ] || @browser
2017-10-01 12:25:52 +00:00
params [ :files ] . each do | file |
2017-11-23 08:09:44 +00:00
instance . find_elements ( css : params [ :css ] ) [ 0 ] . send_keys ( Rails . root . join ( file ) )
2017-10-01 12:25:52 +00:00
end
2018-07-10 14:07:11 +00:00
return if params [ :no_sleep ]
2018-10-09 06:17:41 +00:00
2015-12-17 18:38:42 +00:00
sleep 2 * params [ :files ] . count
2015-02-28 10:40:23 +00:00
end
2015-02-22 12:28:34 +00:00
= begin
watch_for (
2015-11-29 15:39:56 +00:00
browser : browser1 ,
2018-05-14 09:24:54 +00:00
container : element # optional, defaults to browser, must exist at the time of dispatch
css : '#content .text-1' , # xpath or css required
2018-06-27 09:43:50 +00:00
xpath : '/content[contains(@class,".text-1")]' , # xpath or css required
2015-11-29 15:39:56 +00:00
value : 'some text' ,
attribute : 'some_attribute' # optional
2016-02-02 19:17:40 +00:00
timeout : 16 , # in sec, default 16
2015-02-22 12:28:34 +00:00
)
= end
def watch_for ( params = { } )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'watch_for' , params )
2018-05-14 09:24:54 +00:00
browser = params [ :browser ] || @browser
instance = params [ :container ] || browser
selector = params [ :css ] || params [ :xpath ]
selector_type = if params . key? ( :css )
:css
elsif params . key? ( :xpath )
:xpath
end
2015-02-22 12:28:34 +00:00
timeout = 16
if params [ :timeout ]
timeout = params [ :timeout ]
end
2016-01-15 17:22:57 +00:00
loops = timeout . to_i * 2
2015-02-22 12:28:34 +00:00
text = ''
2017-10-01 12:25:52 +00:00
( 1 .. loops ) . each do
2018-05-14 09:24:54 +00:00
element = instance . find_elements ( selector_type = > selector ) [ 0 ]
2021-07-16 13:44:10 +00:00
if element # && element.displayed?
2015-02-22 12:28:34 +00:00
begin
2016-12-02 11:24:00 +00:00
# watch for selector
if ! params [ :attribute ] && ! params [ :value ]
2018-05-14 09:24:54 +00:00
assert ( true , " ' #{ selector } ' found " )
2015-02-23 22:58:05 +00:00
sleep 0 . 5
2015-02-22 12:28:34 +00:00
return true
2016-12-02 11:24:00 +00:00
2017-11-24 15:54:56 +00:00
# match an attribute
2016-12-02 11:24:00 +00:00
else
text = if params [ :attribute ]
element . attribute ( params [ :attribute ] )
2021-05-12 11:37:44 +00:00
elsif selector . match? ( %r{ (input|textarea) }i )
2016-12-02 11:24:00 +00:00
element . attribute ( 'value' )
else
element . text
end
2021-05-12 11:37:44 +00:00
if text . match? ( %r{ #{ params [ :value ] } }i )
2016-12-02 11:24:00 +00:00
assert ( true , " ' #{ params [ :value ] } ' found in ' #{ text } ' " )
sleep 0 . 5
return true
end
2015-02-22 12:28:34 +00:00
end
2020-04-14 08:14:14 +00:00
rescue
2015-04-28 20:44:31 +00:00
# try again
2015-02-22 12:28:34 +00:00
end
end
2015-03-03 13:44:19 +00:00
sleep 0 . 5
2017-10-01 12:25:52 +00:00
end
2018-05-14 09:24:54 +00:00
screenshot ( browser : browser , comment : 'watch_for_failed' )
2016-12-02 11:24:00 +00:00
if ! params [ :attribute ] && ! params [ :value ]
2018-05-14 09:24:54 +00:00
raise " ' #{ selector } ' not found "
2016-12-02 11:24:00 +00:00
end
2018-10-09 06:17:41 +00:00
2016-12-02 11:24:00 +00:00
raise " ' #{ params [ :value ] } ' not found in ' #{ text } ' "
2015-02-22 12:28:34 +00:00
end
2015-02-23 22:37:00 +00:00
= begin
2015-02-28 18:51:40 +00:00
wait untill selector disabppears
2015-02-23 22:37:00 +00:00
watch_for_disappear (
2015-11-29 15:39:56 +00:00
browser : browser1 ,
css : '#content .text-1' ,
2016-02-02 19:17:40 +00:00
timeout : 16 , # in sec, default 16
2015-02-23 22:37:00 +00:00
)
2015-02-28 18:51:40 +00:00
wait untill text in selector disabppears
watch_for_disappear (
2015-11-29 15:39:56 +00:00
browser : browser1 ,
css : '#content .text-1' ,
value : 'some value as regexp' ,
2016-02-02 19:17:40 +00:00
timeout : 16 , # in sec, default 16
2015-02-28 18:51:40 +00:00
)
2015-02-23 22:37:00 +00:00
= end
def watch_for_disappear ( params = { } )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'watch_for_disappear' , params )
2015-02-23 22:37:00 +00:00
instance = params [ :browser ] || @browser
timeout = 16
2015-02-24 00:11:10 +00:00
if params [ :timeout ]
2015-02-23 22:37:00 +00:00
timeout = params [ :timeout ]
end
2016-01-15 17:22:57 +00:00
loops = timeout . to_i
2015-02-28 10:40:23 +00:00
text = ''
2017-10-01 12:25:52 +00:00
( 1 .. loops ) . each do
2016-02-25 12:45:46 +00:00
element = instance . find_elements ( css : params [ :css ] ) [ 0 ]
2021-07-16 13:44:10 +00:00
if ! element # || element.displayed?
2015-12-14 23:52:26 +00:00
assert ( true , 'not found' )
2015-02-23 22:58:05 +00:00
sleep 1
2015-02-23 22:37:00 +00:00
return true
end
2015-02-28 18:51:40 +00:00
if params [ :value ]
begin
2016-02-25 12:45:46 +00:00
text = instance . find_elements ( css : params [ :css ] ) [ 0 ] . text
2021-05-12 11:37:44 +00:00
if ! text . match? ( %r{ #{ params [ :value ] } }i )
2015-12-14 23:52:26 +00:00
assert ( true , " not matching ' #{ params [ :value ] } ' in text ' #{ text } ' " )
2015-02-28 18:51:40 +00:00
sleep 1
return true
end
2020-04-14 08:14:14 +00:00
rescue
2015-04-28 20:44:31 +00:00
# try again
2015-02-28 18:51:40 +00:00
end
end
2015-02-23 22:37:00 +00:00
sleep 1
2017-10-01 12:25:52 +00:00
end
2015-12-14 23:52:26 +00:00
screenshot ( browser : instance , comment : 'disappear_failed' )
2016-03-01 14:26:46 +00:00
raise " #{ params [ :css ] } ) still exsists "
2015-02-23 22:37:00 +00:00
end
2015-02-22 12:28:34 +00:00
2016-02-25 12:45:46 +00:00
= begin
shortcut (
browser : browser1 ,
key : 'x' ,
)
= end
def shortcut ( params = { } )
switch_window_focus ( params )
log ( 'shortcut' , params )
instance = params [ :browser ] || @browser
2016-09-08 19:18:26 +00:00
screenshot ( browser : instance , comment : 'shortcut_before' )
2016-02-25 12:45:46 +00:00
instance . action . key_down ( :control )
2017-04-10 06:08:18 +00:00
. key_down ( :shift )
2016-02-25 12:45:46 +00:00
. send_keys ( params [ :key ] )
2017-04-10 06:08:18 +00:00
. key_up ( :shift )
2016-02-25 12:45:46 +00:00
. key_up ( :control )
. perform
2016-09-08 19:18:26 +00:00
screenshot ( browser : instance , comment : 'shortcut_after' )
2021-06-15 06:26:52 +00:00
await_empty_ajax_queue ( params )
2016-02-25 12:45:46 +00:00
end
= begin
window_keys (
browser : browser1 ,
value : 'x' ,
)
= end
def window_keys ( params = { } )
switch_window_focus ( params )
log ( 'window_keys' , params )
instance = params [ :browser ] || @browser
instance . action . send_keys ( params [ :value ] ) . perform
2021-06-15 06:26:52 +00:00
await_empty_ajax_queue ( params )
2016-02-25 12:45:46 +00:00
end
2015-02-22 12:28:34 +00:00
= begin
tasks_close_all (
2015-11-20 14:10:50 +00:00
browser : browser1 ,
2015-02-22 12:28:34 +00:00
)
= end
def tasks_close_all ( params = { } )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'tasks_close_all' , params )
2015-02-22 12:28:34 +00:00
instance = params [ :browser ] || @browser
2016-06-30 20:04:48 +00:00
99 . times do
2021-07-16 13:44:10 +00:00
# sleep 0.5
2019-06-27 18:26:28 +00:00
if instance . find_elements ( css : '#navigation .tasks .task:first-child' ) [ 0 ]
instance . action . move_to ( instance . find_elements ( css : '#navigation .tasks .task:first-child' ) [ 0 ] ) . release . perform
click_element = instance . find_elements ( css : '#navigation .tasks .task:first-child .js-close' ) [ 0 ]
if click_element
click_element . click
# accept task close warning
if instance . find_elements ( css : '.modal button.js-submit' ) [ 0 ]
sleep 0 . 4
instance . find_elements ( css : '.modal button.js-submit' ) [ 0 ] . click
2015-02-22 12:28:34 +00:00
end
end
2019-06-27 18:26:28 +00:00
else
break
2015-02-22 12:28:34 +00:00
end
2019-06-27 18:26:28 +00:00
rescue
2020-02-02 15:40:13 +00:00
# Firefox doesn't move the mouse if it's already at the position.
# Therefore the hover event is not triggered in all cases.
# That's why we move the mouse a bit as a workaround and try again.
# The last working selenium version was: https://github.com/elgalu/docker-selenium/releases/tag/3.14.0-p17
instance . action . move_by ( 100 , 100 ) . perform
2019-06-27 18:26:28 +00:00
2020-02-02 15:40:13 +00:00
# try again
2015-02-22 12:28:34 +00:00
end
2015-12-14 23:52:26 +00:00
assert ( true , 'all tasks closed' )
2015-02-22 12:28:34 +00:00
end
2016-04-04 13:54:37 +00:00
= begin
close_online_notitifcation (
browser : browser1 ,
data : {
#title: 'some title',
position : 3 ,
} ,
)
= end
def close_online_notitifcation ( params = { } )
switch_window_focus ( params )
log ( 'close_online_notitifcation' , params )
instance = params [ :browser ] || @browser
data = params [ :data ]
if data [ :title ]
element = instance . find_elements ( partial_link_text : data [ :title ] ) [ 0 ]
if ! element
screenshot ( browser : instance , comment : 'close_online_notitifcation' )
raise " no online notification with title ' #{ data [ :title ] } ' found "
end
2018-03-28 05:33:41 +00:00
instance . action . move_to ( element ) . release . perform
2016-04-04 13:54:37 +00:00
sleep 0 . 1
instance . execute_script ( " $('.js-notificationsContainer .js-items .js-item .activity-text:contains( \" #{ data [ :title ] } \" ) .js-remove').first().click() " )
else
css = " .js-notificationsContainer .js-items .js-item:nth-child( #{ data [ :position ] } ) "
element = instance . find_elements ( css : css ) [ 0 ]
if ! element
screenshot ( browser : instance , comment : 'close_online_notitifcation' )
raise " no online notification with postion ' #{ css } ' found "
end
2018-03-28 05:33:41 +00:00
instance . action . move_to ( element ) . release . perform
2016-04-04 13:54:37 +00:00
sleep 0 . 1
instance . find_elements ( css : " #{ css } .js-remove " ) [ 0 ] . click
end
true
end
= begin
online_notitifcation_close_all (
browser : browser1 ,
)
= end
def online_notitifcation_close_all ( params = { } )
switch_window_focus ( params )
log ( 'online_notitifcation_close_all' , params )
instance = params [ :browser ] || @browser
2016-06-30 20:04:48 +00:00
99 . times do
2016-04-04 13:54:37 +00:00
sleep 0 . 5
begin
if instance . find_elements ( css : '.js-notificationsContainer .js-item:first-child' ) [ 0 ]
2018-03-28 05:33:41 +00:00
instance . action . move_to ( instance . find_elements ( css : '.js-notificationsContainer .js-item:first-child' ) [ 0 ] ) . perform
2016-04-04 13:54:37 +00:00
sleep 0 . 1
click_element = instance . find_elements ( css : '.js-notificationsContainer .js-item:first-child .js-remove' ) [ 0 ]
2017-11-23 08:09:44 +00:00
click_element & . click
2016-04-04 13:54:37 +00:00
else
break
end
2020-04-14 08:14:14 +00:00
rescue
2016-04-04 13:54:37 +00:00
# try again
end
end
assert ( true , 'all online notification closed' )
end
2016-03-15 10:24:42 +00:00
= begin
empty_search (
browser : browser1 ,
)
= end
def empty_search ( params = { } )
switch_window_focus ( params )
log ( 'empty_search' , params )
instance = params [ :browser ] || @browser
# empty search box by x
begin
2016-06-09 17:52:08 +00:00
instance . find_elements ( css : '.search .js-emptySearch' ) [ 0 ] . click
2016-03-15 10:24:42 +00:00
rescue
# in issues with ff & selenium, sometimes exeption appears
# "Element is not currently visible and so may not be interacted with"
log ( 'empty_search via js' )
2016-06-09 17:52:08 +00:00
instance . execute_script ( '$(".search .js-emptySearch").click()' )
2016-03-15 10:24:42 +00:00
end
sleep 0 . 5
text = instance . find_elements ( css : '#global-search' ) [ 0 ] . attribute ( 'value' )
if ! text
raise '#global-search is not empty!'
end
true
end
2015-11-29 15:39:56 +00:00
= begin
ticket_customer_select (
browser : browser1 ,
css : '#content .text-1' ,
customer : '' ,
)
= end
def ticket_customer_select ( params = { } )
switch_window_focus ( params )
log ( 'ticket_customer_select' , params )
instance = params [ :browser ] || @browser
2020-09-30 09:07:01 +00:00
element = instance . find_elements ( css : %( #{ params [ :css ] } input[name="customer_id_completion"] ) ) [ 0 ]
2015-11-29 15:39:56 +00:00
element . click
element . clear
2016-03-14 22:29:39 +00:00
element . send_keys ( params [ :customer ] )
2016-03-22 12:58:48 +00:00
sleep 2 . 5
2015-11-29 15:39:56 +00:00
2015-12-14 23:52:26 +00:00
element . send_keys ( :enter )
2021-07-16 13:44:10 +00:00
# instance.find_elements(css: params[:css] + ' .recipientList-entry.js-object.is-active')[0].click
2016-03-22 12:58:48 +00:00
sleep 0 . 4
2015-12-14 23:52:26 +00:00
assert ( true , 'ticket_customer_select' )
2015-11-29 15:39:56 +00:00
end
2015-02-22 12:28:34 +00:00
= begin
2016-03-13 23:25:05 +00:00
overview_create (
2015-11-29 15:39:56 +00:00
browser : browser1 ,
data : {
2017-04-19 19:54:04 +00:00
name : name ,
roles : [ 'Agent' ] ,
2015-11-29 15:39:56 +00:00
selector : {
2015-09-21 20:51:10 +00:00
'Priority' : '1 low' ,
} ,
2015-02-22 12:28:34 +00:00
'order::direction' = > 'down' ,
}
)
= end
def overview_create ( params )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'overview_create' , params )
2015-02-22 12:28:34 +00:00
instance = params [ :browser ] || @browser
data = params [ :data ]
2016-03-21 19:10:01 +00:00
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : 'a[href="#manage"]' ,
2016-03-21 19:10:01 +00:00
mute_log : true ,
)
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.content.active a[href="#manage/overviews"]' ,
2016-03-21 19:10:01 +00:00
mute_log : true ,
)
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.content.active a[data-type="new"]' ,
2016-03-21 19:10:01 +00:00
mute_log : true ,
)
2016-06-10 07:21:47 +00:00
modal_ready ( browser : instance )
2015-02-22 12:28:34 +00:00
if data [ :name ]
2016-03-21 12:51:55 +00:00
set (
browser : instance ,
css : '.modal input[name=name]' ,
value : data [ :name ] ,
mute_log : true ,
)
2015-02-22 12:28:34 +00:00
end
2017-04-19 19:54:04 +00:00
if data [ :roles ]
99 . times do
2018-10-09 06:17:41 +00:00
2019-06-27 18:26:28 +00:00
element = instance . find_elements ( css : '.modal .js-selected[data-name=role_ids] .js-option:not(.is-hidden)' ) [ 0 ]
break if ! element
element . click
sleep 0 . 1
2017-04-19 19:54:04 +00:00
end
2017-10-01 12:25:52 +00:00
data [ :roles ] . each do | role |
2017-04-19 19:54:04 +00:00
instance . execute_script ( " $( \" .modal [data-name=role_ids] .js-pool .js-option:not(.is-hidden):contains(' #{ role } ') \" ).first().click() " )
2017-10-01 12:25:52 +00:00
end
2015-02-22 12:28:34 +00:00
end
2015-09-21 20:51:10 +00:00
2018-12-19 05:40:32 +00:00
data [ :attributes ] & . each do | key , value |
if value
check (
browser : instance ,
css : " .modal .checkbox input[value= \" #{ key } \" ] " ,
)
else
uncheck (
browser : instance ,
css : " .modal .checkbox input[value= \" #{ key } \" ] " ,
)
end
end
2017-11-23 08:09:44 +00:00
data [ :selector ] & . each do | key , value |
select (
browser : instance ,
css : '.modal .ticket_selector .js-attributeSelector select' ,
value : key ,
mute_log : true ,
)
sleep 0 . 5
2018-06-20 12:13:35 +00:00
if data . key? ( 'text_input' )
set (
browser : instance ,
css : '.modal .ticket_selector .js-value input' ,
value : value ,
mute_log : true ,
)
2018-12-19 05:40:32 +00:00
elsif value . instance_of? Array
value . each do | item |
select (
browser : instance ,
css : '.modal .ticket_selector .js-value select' ,
value : item ,
mute_log : true ,
)
end
2018-06-20 12:13:35 +00:00
else
select (
browser : instance ,
css : '.modal .ticket_selector .js-value select' ,
value : value ,
deselect_all : true ,
mute_log : true ,
)
end
2015-09-21 20:51:10 +00:00
end
2015-02-22 12:28:34 +00:00
if data [ 'order::direction' ]
2016-03-21 12:51:55 +00:00
select (
browser : instance ,
css : '.modal select[name="order::direction"]' ,
value : data [ 'order::direction' ] ,
mute_log : true ,
)
2015-02-22 12:28:34 +00:00
end
2018-06-20 22:33:44 +00:00
if data [ :group_by ]
select (
browser : instance ,
css : '.modal select[name="group_by"]' ,
value : data [ :group_by ] ,
mute_log : true ,
)
end
2018-07-12 07:18:39 +00:00
if data [ :group_direction ]
select (
browser : instance ,
css : '.modal select[name="group_direction"]' ,
value : data [ :group_direction ] ,
mute_log : true ,
)
end
2016-02-25 12:45:46 +00:00
instance . find_elements ( css : '.modal button.js-submit' ) [ 0 ] . click
2016-06-10 06:09:47 +00:00
modal_disappear ( browser : instance )
2017-10-01 12:25:52 +00:00
11 . times do
2016-02-25 12:45:46 +00:00
element = instance . find_elements ( css : 'body' ) [ 0 ]
2015-02-22 12:28:34 +00:00
text = element . text
2021-05-12 11:37:44 +00:00
if text . match? ( %r{ #{ Regexp . quote ( data [ :name ] ) } } )
2015-12-14 23:52:26 +00:00
assert ( true , 'overview created' )
2015-02-22 12:28:34 +00:00
overview = {
2015-04-27 13:42:53 +00:00
name : name ,
2015-02-22 12:28:34 +00:00
}
2016-03-03 14:13:06 +00:00
sleep 1
2015-02-22 12:28:34 +00:00
return overview
end
sleep 1
2017-10-01 12:25:52 +00:00
end
2015-12-14 23:52:26 +00:00
screenshot ( browser : instance , comment : 'overview_create_failed' )
2016-03-01 14:26:46 +00:00
raise 'overview creation failed'
2015-02-22 12:28:34 +00:00
end
2016-03-13 23:25:05 +00:00
= begin
overview_update (
browser : browser1 ,
data : {
2017-04-19 19:54:04 +00:00
name : name ,
roles : [ 'Agent' ] ,
2016-03-13 23:25:05 +00:00
selector : {
'Priority' : '1 low' ,
} ,
'order::direction' = > 'down' ,
}
)
= end
def overview_update ( params )
switch_window_focus ( params )
log ( 'overview_create' , params )
instance = params [ :browser ] || @browser
data = params [ :data ]
2016-03-21 19:10:01 +00:00
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : 'a[href="#manage"]' ,
2016-03-21 19:10:01 +00:00
mute_log : true ,
)
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.content.active a[href="#manage/overviews"]' ,
2016-03-21 19:10:01 +00:00
mute_log : true ,
)
2016-03-13 23:25:05 +00:00
2016-09-27 17:46:23 +00:00
instance . execute_script ( " $( \" .content.active td:contains(' #{ data [ :name ] } ') \" ).first().click() " )
2016-03-13 23:25:05 +00:00
sleep 2
if data [ :name ]
2016-03-21 12:51:55 +00:00
set (
browser : instance ,
css : '.modal input[name=name]' ,
value : data [ :name ] ,
mute_log : true ,
)
2016-03-13 23:25:05 +00:00
end
2017-04-19 19:54:04 +00:00
if data [ :roles ]
99 . times do
2018-10-09 06:17:41 +00:00
2019-06-27 18:26:28 +00:00
element = instance . find_elements ( css : '.modal .js-selected[data-name=role_ids] .js-option:not(.is-hidden)' ) [ 0 ]
break if ! element
element . click
sleep 0 . 1
2017-04-19 19:54:04 +00:00
end
2017-10-01 12:25:52 +00:00
data [ :roles ] . each do | role |
2017-04-19 19:54:04 +00:00
instance . execute_script ( " $( \" .modal [data-name=role_ids] .js-pool .js-option:not(.is-hidden):contains(' #{ role } ') \" ).first().click() " )
2017-10-01 12:25:52 +00:00
end
2016-03-13 23:25:05 +00:00
end
2017-11-23 08:09:44 +00:00
data [ :selector ] & . each do | key , value |
select (
browser : instance ,
css : '.modal .ticket_selector .js-attributeSelector select' ,
value : key ,
mute_log : true ,
)
sleep 0 . 5
select (
browser : instance ,
css : '.modal .ticket_selector .js-value select' ,
value : value ,
deselect_all : true ,
mute_log : true ,
)
2016-03-13 23:25:05 +00:00
end
if data [ 'order::direction' ]
2016-03-21 12:51:55 +00:00
select (
browser : instance ,
css : '.modal select[name="order::direction"]' ,
value : data [ 'order::direction' ] ,
mute_log : true ,
)
2016-03-13 23:25:05 +00:00
end
2018-07-12 07:18:39 +00:00
if data [ :group_direction ]
select (
browser : instance ,
css : '.modal select[name="group_direction"]' ,
value : data [ :group_direction ] ,
mute_log : true ,
)
end
2016-03-13 23:25:05 +00:00
instance . find_elements ( css : '.modal button.js-submit' ) [ 0 ] . click
2016-06-10 06:09:47 +00:00
modal_disappear ( browser : instance )
2017-10-01 12:25:52 +00:00
11 . times do
2016-03-13 23:25:05 +00:00
element = instance . find_elements ( css : 'body' ) [ 0 ]
text = element . text
2021-05-12 11:37:44 +00:00
if text . match? ( %r{ #{ Regexp . quote ( data [ :name ] ) } } )
2016-03-13 23:25:05 +00:00
assert ( true , 'overview updated' )
overview = {
name : name ,
}
sleep 1
return overview
end
sleep 1
2017-10-01 12:25:52 +00:00
end
2016-03-13 23:25:05 +00:00
screenshot ( browser : instance , comment : 'overview_update_failed' )
raise 'overview update failed'
end
2015-02-22 12:28:34 +00:00
= begin
ticket = ticket_create (
2015-11-29 15:39:56 +00:00
browser : browser1 ,
data : {
customer : 'nico' ,
2016-03-07 03:24:08 +00:00
group : 'Users' , # optional / '-NONE-' # if group selection should not be shown
2015-11-29 15:39:56 +00:00
priority : '2 normal' ,
2016-04-04 13:54:37 +00:00
state : 'open' ,
2015-11-29 15:39:56 +00:00
title : 'overview #1' ,
body : 'overview #1' ,
2015-02-22 12:28:34 +00:00
} ,
2015-11-29 15:39:56 +00:00
do_not_submit : true ,
2015-02-22 12:28:34 +00:00
)
returns ( in case of submitted )
{
2015-11-29 15:39:56 +00:00
id : 123 ,
number : '100001' ,
2016-01-27 21:24:54 +00:00
title : 'overview #1' ,
2015-02-22 12:28:34 +00:00
}
2016-05-24 07:47:53 +00:00
ticket = ticket_create (
browser : browser1 ,
data : {
customer : 'nico' ,
group : 'Users' , # optional / '-NONE-' # if group selection should not be shown
priority : '2 normal' ,
state : 'open' ,
title : 'overview #1' ,
body : 'overview #1' ,
} ,
custom_data_select : {
key1 : 'some value' ,
} ,
custom_data_input : {
key1 : 'some value' ,
} ,
2018-03-28 10:24:57 +00:00
custom_data_date : {
key! : '02/28/2018' ,
}
2016-05-24 07:47:53 +00:00
disable_group_check : true ,
)
2018-12-19 05:40:32 +00:00
ticket = ticket_create (
browser : browser1 ,
data : {
customer : 'nico' ,
priority : '2 normal' ,
state : 'pending close' ,
pending_date : '11/24/2018' ,
pending_time : '08:00' ,
title : 'overview #1' ,
body : 'overview #1' ,
} ,
do_not_submit : true ,
)
2015-02-22 12:28:34 +00:00
= end
def ticket_create ( params )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'ticket_create' , params )
2015-02-22 12:28:34 +00:00
instance = params [ :browser ] || @browser
data = params [ :data ]
2016-03-21 19:10:01 +00:00
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : 'a[href="#new"]' ,
mute_log : true ,
2018-03-06 05:30:12 +00:00
only_if_exists : true ,
2016-03-21 19:10:01 +00:00
)
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : 'a[href="#ticket/create"]' ,
2016-03-21 19:10:01 +00:00
mute_log : true ,
)
2021-06-15 06:26:52 +00:00
watch_for (
browser : instance ,
css : '.content.active .newTicket' ,
timeout : 30 ,
)
# Rumors say there is a modal reaper which will kill your modals if you dont sleep before a new ticket create
sleep 3
2015-02-22 12:28:34 +00:00
if data [ :group ]
2016-03-07 03:24:08 +00:00
if data [ :group ] == '-NONE-'
# check if owner selection exists
2016-09-27 17:46:23 +00:00
count = instance . find_elements ( css : '.content.active .newTicket select[name="group_id"] option' ) . count
2017-06-16 20:43:09 +00:00
if count . nonzero?
2017-10-01 12:25:52 +00:00
instance . find_elements ( css : '.content.active .newTicket select[name="group_id"] option' ) . each do | element |
2017-06-16 20:43:09 +00:00
log ( 'ticket_create invalid group count' , text : element . text )
2017-10-01 12:25:52 +00:00
end
2017-06-16 20:43:09 +00:00
end
2016-03-07 03:24:08 +00:00
assert_equal ( 0 , count , 'owner selection should not be showm' )
# check count of agents, should be only 3 / - selection + master + agent on init screen
2016-09-27 17:46:23 +00:00
count = instance . find_elements ( css : '.content.active .newTicket select[name="owner_id"] option' ) . count
2017-06-16 20:43:09 +00:00
if count != 3
2017-10-01 12:25:52 +00:00
instance . find_elements ( css : '.content.active .newTicket select[name="owner_id"] option' ) . each do | element |
2017-06-16 20:43:09 +00:00
log ( 'ticket_create invalid owner count' , text : element . text )
2017-10-01 12:25:52 +00:00
end
2017-06-16 20:43:09 +00:00
end
2016-03-07 03:24:08 +00:00
assert_equal ( 3 , count , 'check if owner selection is - selection + master + agent per default' )
else
2018-08-06 10:21:44 +00:00
# check count of agents, should be only 1 selection, the "-" selection on init screen
2016-05-24 07:47:53 +00:00
if ! params [ :disable_group_check ]
2016-09-27 17:46:23 +00:00
count = instance . find_elements ( css : '.content.active .newTicket select[name="owner_id"] option' ) . count
2017-06-16 20:43:09 +00:00
if count != 1
2017-10-01 12:25:52 +00:00
instance . find_elements ( css : '.content.active .newTicket select[name="owner_id"] option' ) . each do | element |
2017-06-16 20:43:09 +00:00
log ( 'ticket_create invalid owner count' , text : element . text )
2017-10-01 12:25:52 +00:00
end
2017-06-16 20:43:09 +00:00
end
2016-05-24 07:47:53 +00:00
assert_equal ( 1 , count , 'check if owner selection is empty per default' )
end
2016-03-21 12:51:55 +00:00
select (
browser : instance ,
2016-09-27 17:46:23 +00:00
css : '.content.active .newTicket select[name="group_id"]' ,
2016-03-21 12:51:55 +00:00
value : data [ :group ] ,
mute_log : true ,
)
2016-03-07 03:24:08 +00:00
end
2015-02-22 12:28:34 +00:00
end
2015-09-21 20:51:10 +00:00
if data [ :priority ]
2016-03-21 12:51:55 +00:00
select (
browser : instance ,
2016-09-27 17:46:23 +00:00
css : '.content.active .newTicket select[name="priority_id"]' ,
2016-03-21 12:51:55 +00:00
value : data [ :priority ] ,
mute_log : true ,
)
2015-09-21 20:51:10 +00:00
end
2016-04-04 13:54:37 +00:00
if data [ :state ]
select (
browser : instance ,
2016-09-27 17:46:23 +00:00
css : '.content.active .newTicket select[name="state_id"]' ,
2016-04-04 13:54:37 +00:00
value : data [ :state ] ,
mute_log : true ,
)
2018-12-19 05:40:32 +00:00
if [ 'pending close' , 'pending reminder' ] . include? ( data [ :state ] ) &&
data [ :pending_date ] &&
data [ :pending_time ]
set (
browser : instance ,
css : '.content.active .newTicket input.js-datepicker' ,
value : data [ :pending_date ] ,
clear : true ,
mute_log : true ,
)
set (
browser : instance ,
css : '.content.active .newTicket input.js-timepicker' ,
value : data [ :pending_time ] ,
clear : true ,
mute_log : true ,
)
end
2016-04-04 13:54:37 +00:00
end
2015-02-22 12:28:34 +00:00
if data [ :title ]
2016-03-21 12:51:55 +00:00
set (
browser : instance ,
2016-09-27 17:46:23 +00:00
css : '.content.active .newTicket input[name="title"]' ,
2016-03-21 12:51:55 +00:00
value : data [ :title ] ,
clear : true ,
mute_log : true ,
)
2015-02-22 12:28:34 +00:00
end
if data [ :body ]
2016-03-21 12:51:55 +00:00
set (
browser : instance ,
2016-09-27 17:46:23 +00:00
css : '.content.active .newTicket div[data-name=body]' ,
2016-03-21 12:51:55 +00:00
value : data [ :body ] ,
clear : true ,
mute_log : true ,
)
2015-02-22 12:28:34 +00:00
end
if data [ :customer ]
2016-09-27 17:46:23 +00:00
element = instance . find_elements ( css : '.content.active .newTicket input[name="customer_id_completion"]' ) [ 0 ]
2015-02-22 12:28:34 +00:00
element . click
element . clear
2015-02-28 10:40:23 +00:00
2016-06-21 18:42:55 +00:00
# ff issue, sometimes focus event gets dropped
# if drowdown is not open, try it again
2016-09-27 17:46:23 +00:00
if ! instance . find_elements ( css : '.content.active .newTicket .js-recipientDropdown.open' ) [ 0 ]
2016-06-21 18:42:55 +00:00
instance . execute_script ( '$(".active .newTicket .js-recipientDropdown").addClass("open")' )
end
2016-03-14 22:29:39 +00:00
element . send_keys ( data [ :customer ] )
2016-03-22 12:58:48 +00:00
sleep 2 . 5
2015-02-28 10:40:23 +00:00
2015-12-14 23:52:26 +00:00
element . send_keys ( :enter )
2018-05-21 22:58:50 +00:00
sleep 0 . 2
2016-06-21 18:42:55 +00:00
# ff issue, sometimes enter event gets dropped
# take user manually
2016-09-27 17:46:23 +00:00
if instance . find_elements ( css : '.content.active .newTicket .js-recipientDropdown.open' ) [ 0 ]
2017-04-10 09:02:08 +00:00
instance . find_elements ( css : '.content.active .newTicket .recipientList-entry.js-object.is-active' ) [ 0 ] . click
2016-06-21 18:42:55 +00:00
sleep 0 . 4
end
2015-02-22 12:28:34 +00:00
end
2015-02-28 10:40:23 +00:00
2017-11-23 08:09:44 +00:00
params [ :custom_data_select ] & . each do | local_key , local_value |
select (
browser : instance ,
css : " .content.active .newTicket select[name= \" #{ local_key } \" ] " ,
value : local_value ,
)
2016-05-24 07:47:53 +00:00
end
2017-11-23 08:09:44 +00:00
params [ :custom_data_input ] & . each do | local_key , local_value |
set (
browser : instance ,
css : " .content.active .newTicket input[name= \" #{ local_key } \" ] " ,
value : local_value ,
clear : true ,
)
2016-05-24 07:47:53 +00:00
end
2018-03-28 10:24:57 +00:00
params [ :custom_data_date ] & . each do | local_key , local_value |
set (
browser : instance ,
css : " .content.active .newTicket div[data-name= \" #{ local_key } \" ] input[data-item= \" date \" ] " ,
value : local_value ,
clear : true ,
)
end
2016-05-24 07:47:53 +00:00
2015-02-28 18:51:40 +00:00
if data [ :attachment ]
file_upload (
2015-04-27 13:42:53 +00:00
browser : instance ,
2018-12-19 17:31:51 +00:00
css : '.content.active .text-1' ,
value : 'some text' ,
2015-02-28 18:51:40 +00:00
)
end
2015-02-28 10:40:23 +00:00
2015-02-22 12:28:34 +00:00
if params [ :do_not_submit ]
2015-12-14 23:52:26 +00:00
assert ( true , 'ticket created without submit' )
2015-02-22 12:28:34 +00:00
return
end
2018-05-21 22:58:50 +00:00
2021-07-16 13:44:10 +00:00
# instance.execute_script('$(".content.active .newTicket form").submit();')
2016-03-21 19:10:01 +00:00
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.content.active .newTicket button.js-submit' ,
2016-03-21 19:10:01 +00:00
mute_log : true ,
)
2015-02-22 12:28:34 +00:00
sleep 1
2017-10-01 12:25:52 +00:00
9 . times do
2021-05-12 11:37:44 +00:00
if instance . current_url . match? ( %r{ #{ Regexp . quote ( '#ticket/zoom/' ) } } )
2015-12-14 23:52:26 +00:00
assert ( true , 'ticket created' )
2018-05-21 22:58:50 +00:00
sleep 2
2015-02-22 12:28:34 +00:00
id = instance . current_url
2021-05-12 11:37:44 +00:00
id . gsub! ( %r{ } , )
2015-04-27 20:49:17 +00:00
id . gsub! ( %r{ ^.+?/( \ d+)$ } , '\\1' )
2015-02-22 12:28:34 +00:00
2016-09-27 17:46:23 +00:00
element = instance . find_elements ( css : '.content.active .ticketZoom-header .ticket-number' ) [ 0 ]
2015-03-01 23:16:36 +00:00
if element
number = element . text
ticket = {
2018-12-19 17:31:51 +00:00
id : id ,
2015-04-27 13:42:53 +00:00
number : number ,
2018-12-19 17:31:51 +00:00
title : data [ :title ] ,
2015-03-01 23:16:36 +00:00
}
2018-06-04 12:57:53 +00:00
sleep 2 # wait until notify is gone
2015-03-01 23:16:36 +00:00
return ticket
end
2015-02-22 12:28:34 +00:00
end
2015-03-01 23:16:36 +00:00
sleep 1
2017-10-01 12:25:52 +00:00
end
2015-12-14 23:52:26 +00:00
screenshot ( browser : instance , comment : 'ticket_create_failed' )
2016-03-01 14:26:46 +00:00
raise " ticket creation failed, can't get zoom url (current url is ' #{ instance . current_url } ') "
2015-02-22 12:28:34 +00:00
end
= begin
ticket_update (
2015-11-29 15:39:56 +00:00
browser : browser1 ,
data : {
title : '' ,
customer : 'some_customer@example.com' ,
body : 'some body' ,
2016-03-07 03:24:08 +00:00
group : 'some group' , # optional
2015-11-29 15:39:56 +00:00
priority : '1 low' ,
state : 'closed' ,
2015-02-22 12:28:34 +00:00
} ,
2015-11-29 15:39:56 +00:00
do_not_submit : true ,
2015-02-22 12:28:34 +00:00
)
2016-05-24 07:47:53 +00:00
ticket_update (
browser : browser1 ,
data : {
title : '' ,
customer : 'some_customer@example.com' ,
body : 'some body' ,
group : 'some group' , # optional
priority : '1 low' ,
state : 'closed' ,
} ,
custom_data_select : {
key1 : 'some value' ,
} ,
custom_data_input : {
key1 : 'some value' ,
} ,
2018-03-28 10:24:57 +00:00
custom_data_date : {
key1 : '02/21/2018' ,
} ,
2016-05-24 07:47:53 +00:00
do_not_submit : true ,
2017-02-05 18:24:48 +00:00
task_type : 'stayOnTab' , # default: stayOnTab / possible: closeTab, closeNextInOverview, stayOnTab
2016-05-24 07:47:53 +00:00
)
2015-02-22 12:28:34 +00:00
= end
def ticket_update ( params )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'ticket_update' , params )
2015-02-22 12:28:34 +00:00
instance = params [ :browser ] || @browser
data = params [ :data ]
2015-02-23 15:35:48 +00:00
if data [ :title ]
2021-07-16 13:44:10 +00:00
# element = instance.find_elements(:css => '.content.active .ticketZoom-header .js-objectTitle')[0]
# element.clear
# sleep 0.5
# element = instance.find_elements(:css => '.content.active .ticketZoom-header .js-objectTitle')[0]
# element.send_keys(data[:title])
# sleep 0.5
# element.send_keys(:tab)
2015-02-23 15:35:48 +00:00
2016-05-23 13:23:18 +00:00
instance . execute_script ( '$(".content.active .ticketZoom-header .js-objectTitle").focus()' )
2020-09-30 09:07:01 +00:00
instance . execute_script ( %( $ ( ".content.active .ticketZoom-header .js-objectTitle" ) .text ( " #{ data [ :title ] } " ) ) )
2016-05-23 13:23:18 +00:00
instance . execute_script ( '$(".content.active .ticketZoom-header .js-objectTitle").blur()' )
instance . execute_script ( '$(".content.active .ticketZoom-header .js-objectTitle").trigger("blur")' )
2015-04-27 20:49:17 +00:00
# {
# :where => :instance2,
# :execute => 'sendkey',
2016-05-23 13:23:18 +00:00
# :css => '.content.active .ticketZoom-header .js-objectTitle',
2015-04-27 20:49:17 +00:00
# :value => 'TTT',
# },
# {
# :where => :instance2,
# :execute => 'sendkey',
2016-05-23 13:23:18 +00:00
# :css => '.content.active .ticketZoom-header .js-objectTitle',
2015-04-27 20:49:17 +00:00
# :value => :tab,
# },
2015-03-08 21:34:14 +00:00
end
if data [ :customer ]
# select tab
2016-09-27 17:46:23 +00:00
click ( browser : instance , css : '.content.active .tabsSidebar-tab[data-tab="customer"]' )
2015-03-08 21:34:14 +00:00
2016-09-27 17:46:23 +00:00
click ( browser : instance , css : '.content.active div[data-tab="customer"] .js-actions .icon-arrow-down' )
click ( browser : instance , css : '.content.active div[data-tab="customer"] .js-actions [data-type="customer-change"]' )
2015-03-08 21:34:14 +00:00
watch_for (
2015-04-27 13:42:53 +00:00
browser : instance ,
2018-12-19 17:31:51 +00:00
css : '.modal' ,
value : 'change' ,
2015-03-08 21:34:14 +00:00
)
2016-02-25 12:45:46 +00:00
element = instance . find_elements ( css : '.modal input[name="customer_id_completion"]' ) [ 0 ]
2015-03-08 21:34:14 +00:00
element . click
element . clear
2015-12-14 23:52:26 +00:00
element . send_keys ( data [ :customer ] )
2016-03-22 12:58:48 +00:00
sleep 2 . 5
2015-03-08 21:34:14 +00:00
2015-12-14 23:52:26 +00:00
element . send_keys ( :enter )
2021-07-16 13:44:10 +00:00
# instance.find_elements(css: '.modal .user_autocompletion .recipientList-entry.js-object.is-active')[0].click
2016-03-22 12:58:48 +00:00
sleep 0 . 2
2015-03-08 21:34:14 +00:00
2015-12-14 23:52:26 +00:00
click ( browser : instance , css : '.modal .js-submit' )
2015-03-08 21:34:14 +00:00
2016-06-10 06:09:47 +00:00
modal_disappear ( browser : instance )
2015-03-08 21:34:14 +00:00
watch_for (
2015-04-27 13:42:53 +00:00
browser : instance ,
2018-12-19 17:31:51 +00:00
css : '.content.active .tabsSidebar' ,
value : data [ :customer ] ,
2015-03-08 21:34:14 +00:00
)
# select tab
2016-09-27 17:46:23 +00:00
click ( browser : instance , css : '.content.active .tabsSidebar-tab[data-tab="ticket"]' )
2015-03-08 21:34:14 +00:00
2015-02-23 15:35:48 +00:00
end
if data [ :body ]
2016-03-21 12:51:55 +00:00
set (
browser : instance ,
css : '.content.active div[data-name=body]' ,
value : data [ :body ] ,
2016-03-21 13:39:18 +00:00
no_click : true ,
2016-03-21 12:51:55 +00:00
mute_log : true ,
)
2015-02-28 10:40:23 +00:00
# it's not working stable via selenium, use js
2016-02-25 12:45:46 +00:00
value = instance . find_elements ( css : '.content.active div[data-name=body]' ) [ 0 ] . text
2015-02-28 10:40:23 +00:00
if value != data [ :body ]
2015-12-14 23:52:26 +00:00
body_quoted = quote ( data [ :body ] )
instance . execute_script ( " $('.content.active div[data-name=body]').html(' #{ body_quoted } ').trigger('focusout') " )
2015-02-28 10:40:23 +00:00
end
2015-02-23 15:35:48 +00:00
end
2015-02-22 12:28:34 +00:00
if data [ :group ]
2016-03-07 03:24:08 +00:00
if data [ :group ] == '-NONE-'
# check if owner selection exists
2016-09-27 17:46:23 +00:00
count = instance . find_elements ( css : '.content.active .sidebar select[name="group_id"] option' ) . count
2016-03-07 03:24:08 +00:00
assert_equal ( 0 , count , 'owner selection should not be showm' )
# check count of agents, should be only 3 / - selection + master + agent on init screen
2016-09-27 17:46:23 +00:00
count = instance . find_elements ( css : '.content.active .sidebar select[name="owner_id"] option' ) . count
2016-03-07 03:24:08 +00:00
assert_equal ( 3 , count , 'check if owner selection is - selection + master + agent per default' )
else
2016-03-21 12:51:55 +00:00
select (
browser : instance ,
2016-09-27 17:46:23 +00:00
css : '.content.active .sidebar select[name="group_id"]' ,
2016-03-21 12:51:55 +00:00
value : data [ :group ] ,
mute_log : true ,
)
2016-03-07 03:24:08 +00:00
sleep 0 . 2
end
2015-02-22 12:28:34 +00:00
end
2015-09-21 20:51:10 +00:00
if data [ :priority ]
2016-03-21 12:51:55 +00:00
select (
browser : instance ,
2016-09-27 17:46:23 +00:00
css : '.content.active .sidebar select[name="priority_id"]' ,
2016-03-21 12:51:55 +00:00
value : data [ :priority ] ,
mute_log : true ,
)
2015-09-21 20:51:10 +00:00
end
2015-02-22 12:28:34 +00:00
if data [ :state ]
2016-03-21 12:51:55 +00:00
select (
browser : instance ,
2016-09-27 17:46:23 +00:00
css : '.content.active .sidebar select[name="state_id"]' ,
2016-03-21 12:51:55 +00:00
value : data [ :state ] ,
mute_log : true ,
)
2015-02-22 12:28:34 +00:00
end
2018-07-04 14:56:16 +00:00
if data [ :files ]
file_upload (
css : '.content.active .attachmentPlaceholder-inputHolder input' ,
files : data [ :files ] ,
)
end
2017-11-23 08:09:44 +00:00
params [ :custom_data_select ] & . each do | local_key , local_value |
select (
browser : instance ,
css : " .active .sidebar select[name= \" #{ local_key } \" ] " ,
value : local_value ,
)
2016-05-24 07:47:53 +00:00
end
2017-11-23 08:09:44 +00:00
params [ :custom_data_input ] & . each do | local_key , local_value |
set (
browser : instance ,
css : " .active .sidebar input[name= \" #{ local_key } \" ] " ,
value : local_value ,
clear : true ,
)
2016-05-24 07:47:53 +00:00
end
2018-03-28 10:24:57 +00:00
params [ :custom_data_date ] & . each do | local_key , local_value |
click (
browser : instance ,
css : " .active .sidebar div[data-name= \" #{ local_key } \" ] input[data-item= \" date \" ] " ,
mute_log : true ,
)
# weird bug where you cannot "clear" for date/time input
# this is specific chrome problem, chrome bug report: https://bugs.chromium.org/p/chromedriver/issues/detail?id=1319#c2
# indirect issue: https://github.com/angular/protractor/issues/562#issuecomment-47745263
11 . times do
sendkey (
value : :backspace ,
)
end
set (
browser : instance ,
css : " .active .sidebar div[data-name= \" #{ local_key } \" ] input[data-item= \" date \" ] " ,
value : local_value ,
)
end
2016-05-24 07:47:53 +00:00
2017-11-23 08:09:44 +00:00
if data [ :state ] || data [ :group ] || data [ :body ] || params [ :custom_data_select ] . present? || params [ :custom_data_input ] . present?
2015-03-08 21:34:14 +00:00
found = nil
2017-10-01 12:25:52 +00:00
9 . times do
2015-07-03 17:36:13 +00:00
2015-07-16 15:19:46 +00:00
break if found
2015-07-03 17:36:13 +00:00
begin
2016-02-25 12:45:46 +00:00
text = instance . find_elements ( css : '.content.active .js-reset' ) [ 0 ] . text
2021-05-12 11:37:44 +00:00
if text . match? ( %r{ (Discard your unsaved changes.|Verwerfen der) } )
2015-07-03 17:36:13 +00:00
found = true
2015-02-22 22:51:44 +00:00
end
2020-04-14 08:14:14 +00:00
rescue
2015-07-03 17:36:13 +00:00
# try again
2015-02-22 12:28:34 +00:00
end
2015-07-03 17:36:13 +00:00
sleep 1
2017-10-01 12:25:52 +00:00
end
2015-03-08 21:34:14 +00:00
if ! found
2015-12-14 23:52:26 +00:00
screenshot ( browser : instance , comment : 'ticket_update_discard_message_failed' )
2016-03-01 14:26:46 +00:00
raise 'no discard message found'
2015-02-22 12:28:34 +00:00
end
end
2019-09-16 09:08:44 +00:00
# avoid accessing a stale element when accessing task type
sleep 1
2015-11-06 01:08:06 +00:00
task_type (
browser : instance ,
2017-02-05 18:24:48 +00:00
type : params [ :task_type ] || 'stayOnTab' ,
2015-11-06 01:08:06 +00:00
)
2015-02-22 12:28:34 +00:00
if params [ :do_not_submit ]
2015-12-14 23:52:26 +00:00
assert ( true , 'ticket updated without submit' )
2015-02-22 12:28:34 +00:00
return true
end
2016-02-25 12:45:46 +00:00
instance . find_elements ( css : '.content.active .js-submit' ) [ 0 ] . click
2021-06-15 06:26:52 +00:00
await_empty_ajax_queue ( params )
2015-02-22 12:28:34 +00:00
2017-02-05 18:24:48 +00:00
# do not stay on tab
if params [ :task_type ] == 'closeTab' || params [ :task_type ] == 'closeNextInOverview'
sleep 1
return
end
2017-10-01 12:25:52 +00:00
9 . times do
2015-02-24 00:11:10 +00:00
begin
2016-02-25 12:45:46 +00:00
text = instance . find_elements ( css : '.content.active .js-reset' ) [ 0 ] . text
2017-07-05 05:18:19 +00:00
if text . blank?
2016-03-03 16:42:19 +00:00
sleep 1
2015-02-24 00:11:10 +00:00
return true
end
2020-04-14 08:14:14 +00:00
rescue
2015-04-28 20:44:31 +00:00
# try again
2015-02-22 12:28:34 +00:00
end
sleep 1
2017-10-01 12:25:52 +00:00
end
2015-12-14 23:52:26 +00:00
screenshot ( browser : instance , comment : 'ticket_update_failed' )
2016-03-01 14:26:46 +00:00
raise 'unable to update ticket'
2015-02-22 12:28:34 +00:00
end
2015-02-28 18:51:40 +00:00
= begin
ticket_verify (
2015-11-29 15:39:56 +00:00
browser : browser1 ,
data : {
title : 'some title' ,
body : 'some body' ,
## group: 'some group',
## state: 'closed',
2016-05-28 22:04:26 +00:00
custom_data_select : {
key1 : 'some value' ,
} ,
custom_data_input : {
key1 : 'some value' ,
} ,
2015-02-28 18:51:40 +00:00
} ,
)
= end
def ticket_verify ( params )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'ticket_verify' , params )
2015-02-28 18:51:40 +00:00
instance = params [ :browser ] || @browser
data = params [ :data ]
if data [ :title ]
2016-05-28 22:04:26 +00:00
title = instance . find_elements ( css : '.content.active .ticketZoom-header .js-objectTitle' ) . first . text . strip
2021-05-12 11:37:44 +00:00
if title . match? ( %r{ #{ data [ :title ] } }i )
2015-12-14 23:52:26 +00:00
assert ( true , " matching ' #{ data [ :title ] } ' in title ' #{ title } ' " )
2015-02-28 18:51:40 +00:00
else
2016-03-01 14:26:46 +00:00
raise " not matching ' #{ data [ :title ] } ' in title ' #{ title } ' "
2015-02-28 18:51:40 +00:00
end
end
if data [ :body ]
2016-05-28 22:04:26 +00:00
body = instance . find_elements ( css : '.content.active [data-name="body"]' ) . first . text . strip
2021-05-12 11:37:44 +00:00
if body . match? ( %r{ #{ data [ :body ] } }i )
2015-12-14 23:52:26 +00:00
assert ( true , " matching ' #{ data [ :body ] } ' in body ' #{ body } ' " )
2015-02-28 18:51:40 +00:00
else
2016-03-01 14:26:46 +00:00
raise " not matching ' #{ data [ :body ] } ' in body ' #{ body } ' "
2015-02-28 18:51:40 +00:00
end
end
2016-05-28 22:04:26 +00:00
2017-11-23 08:09:44 +00:00
params [ :custom_data_select ] & . each do | local_key , local_value |
element = instance . find_elements ( css : " .active .sidebar select[name= \" #{ local_key } \" ] option[selected] " ) . first
value = element . text . strip
2021-05-12 11:37:44 +00:00
if value . match? ( %r{ #{ local_value } }i )
2017-11-23 08:09:44 +00:00
assert ( true , " matching ' #{ value } ' in #{ local_key } ' #{ local_value } ' " )
else
raise " not matching ' #{ value } ' in #{ local_key } ' #{ local_value } ' "
2017-10-01 12:25:52 +00:00
end
2016-05-28 22:04:26 +00:00
end
2017-11-23 08:09:44 +00:00
params [ :custom_data_input ] & . each do | local_key , local_value |
element = instance . find_elements ( css : " .active .sidebar input[name= \" #{ local_key } \" ] " ) . first
value = element . text . strip
2021-05-12 11:37:44 +00:00
if value . match? ( %r{ #{ local_value } }i )
2017-11-23 08:09:44 +00:00
assert ( true , " matching ' #{ value } ' in #{ local_key } ' #{ local_value } ' " )
else
raise " not matching ' #{ value } ' in #{ local_key } ' #{ local_value } ' "
2017-10-01 12:25:52 +00:00
end
2016-05-28 22:04:26 +00:00
end
2015-02-28 18:51:40 +00:00
true
end
2015-02-22 12:28:34 +00:00
= begin
2018-07-20 12:04:05 +00:00
overview_open (
2015-11-29 15:39:56 +00:00
browser : browser2 ,
2018-07-20 12:04:05 +00:00
name : overview_name ,
2015-02-22 12:28:34 +00:00
)
2018-07-20 12:04:05 +00:00
overview_open (
2017-02-05 18:24:48 +00:00
browser : browser2 ,
2018-07-20 12:04:05 +00:00
link : " # ticket/view/some_special_name " ,
2017-02-05 18:24:48 +00:00
)
2015-02-22 12:28:34 +00:00
= end
2018-07-20 12:04:05 +00:00
def overview_open ( params )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2018-07-20 12:04:05 +00:00
log ( 'overview_open' , params )
2015-03-08 01:06:57 +00:00
2015-02-22 12:28:34 +00:00
instance = params [ :browser ] || @browser
2018-07-20 12:04:05 +00:00
# click on overview task in sidebar
2016-02-25 12:45:46 +00:00
instance . find_elements ( css : '.js-overviewsMenuItem' ) [ 0 ] . click
2018-07-20 12:04:05 +00:00
# show larger overview selection list
2018-05-21 22:58:50 +00:00
sleep 0 . 5
2015-11-05 12:34:22 +00:00
execute (
browser : instance ,
2018-12-19 17:31:51 +00:00
js : '$(".content.active .sidebar").css("display", "block")' ,
2015-11-05 12:34:22 +00:00
)
2018-07-20 12:04:05 +00:00
link = if params [ :link ]
params [ :link ]
elsif params [ :name ]
" \# ticket/view/ #{ params [ :name ] } "
end
# switch to overview
2019-10-02 13:57:08 +00:00
element = nil
6 . times do
element = instance . find_elements ( css : " .content.active .sidebar a[href= \" #{ link } \" ] " ) [ 0 ]
break if element
sleep 1
end
element . click
2018-07-20 12:04:05 +00:00
# hide larger overview selection list again
2018-05-21 22:58:50 +00:00
sleep 0 . 5
2015-11-17 23:53:19 +00:00
execute (
browser : instance ,
2018-12-19 17:31:51 +00:00
js : '$(".content.active .sidebar").css("display", "none")' ,
2015-11-17 23:53:19 +00:00
)
2018-07-20 12:04:05 +00:00
end
= begin
ticket_open_by_overview (
browser : browser2 ,
number : ticket1 [ :number ] ,
link : " # ticket/view/ #{ name } " ,
)
ticket_open_by_overview (
browser : browser2 ,
number : ticket1 [ :number ] ,
text : title ,
link : " # ticket/view/ #{ name } " ,
)
= end
def ticket_open_by_overview ( params )
switch_window_focus ( params )
log ( 'ticket_open_by_overview' , params )
instance = params [ :browser ] || @browser
overview_open ( params )
2019-10-02 13:57:08 +00:00
element = nil
2017-02-05 18:24:48 +00:00
if params [ :title ]
2019-10-02 13:57:08 +00:00
6 . times do
element = instance . find_element ( css : '.content.active' ) . find_element ( partial_link_text : params [ :title ] )
break if element
sleep 1
end
2017-02-05 18:24:48 +00:00
if ! element
screenshot ( browser : instance , comment : 'ticket_open_by_overview_no_ticket_failed' )
raise " unable to find ticket #{ params [ :title ] } in overview #{ params [ :link ] } ! "
end
else
2019-10-02 13:57:08 +00:00
6 . times do
2019-11-28 06:59:22 +00:00
# prefere find_elements ofer find_element because of exception handling
2019-10-02 13:57:08 +00:00
element = instance . find_elements ( partial_link_text : params [ :number ] ) [ 0 ]
break if element
sleep 1
end
2017-02-05 18:24:48 +00:00
if ! element
screenshot ( browser : instance , comment : 'ticket_open_by_overview_no_ticket_failed' )
raise " unable to find ticket #{ params [ :number ] } in overview #{ params [ :link ] } ! "
end
end
element . click
2015-02-22 12:28:34 +00:00
sleep 1
2019-11-28 06:59:22 +00:00
number = instance . find_element ( css : '.content.active .ticketZoom-header .ticket-number' ) . text
2021-05-12 11:37:44 +00:00
if ! number . match? ( %r{ #{ params [ :number ] } } )
2017-02-05 18:24:48 +00:00
screenshot ( browser : instance , comment : 'ticket_open_by_overview_open_failed_failed' )
raise " unable to open ticket #{ params [ :number ] } ! "
2015-02-22 12:28:34 +00:00
end
2015-12-14 23:52:26 +00:00
assert ( true , " ticket #{ params [ :number ] } found " )
2015-02-28 10:40:23 +00:00
true
2015-02-22 12:28:34 +00:00
end
= begin
ticket_open_by_search (
2015-11-29 15:39:56 +00:00
browser : browser2 ,
number : ticket1 [ :number ] ,
2015-02-22 12:28:34 +00:00
)
= end
def ticket_open_by_search ( params )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'ticket_open_by_search' , params )
2015-02-22 12:28:34 +00:00
instance = params [ :browser ] || @browser
# search by number
2016-02-25 12:45:46 +00:00
element = instance . find_elements ( css : '#global-search' ) [ 0 ]
2015-02-22 12:28:34 +00:00
element . click
element . clear
2015-12-14 23:52:26 +00:00
element . send_keys ( params [ :number ] )
2015-02-22 12:28:34 +00:00
sleep 3
# open ticket
2021-07-16 13:44:10 +00:00
# instance.find_element(partial_link_text: params[:number] } ).click
2019-01-08 22:14:47 +00:00
instance . execute_script ( " $( \" .js-global-search-result a:contains(' #{ params [ :number ] } ') .nav-tab-name \" ).first().click() " )
2018-09-17 07:01:17 +00:00
watch_for (
browser : instance ,
2018-12-19 17:31:51 +00:00
css : '.content.active .ticketZoom-header .ticket-number'
2018-09-17 07:01:17 +00:00
)
2016-09-27 17:46:23 +00:00
number = instance . find_elements ( css : '.content.active .ticketZoom-header .ticket-number' ) [ 0 ] . text
2021-05-12 11:37:44 +00:00
if ! number . match? ( %r{ #{ params [ :number ] } } )
2015-12-14 23:52:26 +00:00
screenshot ( browser : instance , comment : 'ticket_open_by_search_failed' )
2016-03-01 14:26:46 +00:00
raise " unable to search/find ticket #{ params [ :number ] } ! "
2015-02-22 12:28:34 +00:00
end
2015-02-28 10:40:23 +00:00
true
2015-02-22 12:28:34 +00:00
end
2016-01-13 23:33:34 +00:00
= begin
ticket_open_by_title (
browser : browser2 ,
title : ticket1 [ :title ] ,
)
= end
def ticket_open_by_title ( params )
switch_window_focus ( params )
log ( 'ticket_open_by_title' , params )
instance = params [ :browser ] || @browser
# search by number
2016-02-25 12:45:46 +00:00
element = instance . find_elements ( css : '#global-search' ) [ 0 ]
2016-01-13 23:33:34 +00:00
element . click
element . clear
element . send_keys ( params [ :title ] )
sleep 3
# open ticket
2021-07-16 13:44:10 +00:00
# instance.find_element(partial_link_text: params[:title] } ).click
2019-01-08 22:14:47 +00:00
instance . execute_script ( " $( \" .js-global-search-result a:contains(' #{ params [ :title ] } ') .nav-tab-name \" ).first().click() " )
2016-03-15 15:01:28 +00:00
sleep 1
2016-09-27 17:46:23 +00:00
title = instance . find_elements ( css : '.content.active .ticketZoom-header .js-objectTitle' ) [ 0 ] . text
2021-05-12 11:37:44 +00:00
if ! title . match? ( %r{ #{ params [ :title ] } } )
2016-01-13 23:33:34 +00:00
screenshot ( browser : instance , comment : 'ticket_open_by_title_failed' )
2016-03-01 14:26:46 +00:00
raise " unable to search/find ticket #{ params [ :title ] } ! "
2016-01-13 23:33:34 +00:00
end
true
end
2015-02-22 12:28:34 +00:00
= begin
overview_count = overview_counter (
2015-11-29 15:39:56 +00:00
browser : browser2 ,
2015-02-22 12:28:34 +00:00
)
returns
{
'#ticket/view/all_unassigned' = > 42 ,
}
= end
def overview_counter ( params = { } )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'overview_counter' , params )
2015-02-22 12:28:34 +00:00
instance = params [ :browser ] || @browser
2016-02-25 12:45:46 +00:00
instance . find_elements ( css : '.js-overviewsMenuItem' ) [ 0 ] . click
2021-06-15 06:26:52 +00:00
await_empty_ajax_queue ( params )
2015-11-05 12:34:22 +00:00
execute (
browser : instance ,
2018-12-19 17:31:51 +00:00
js : '$(".content.active .sidebar").css("display", "block")' ,
2015-11-05 12:34:22 +00:00
)
2021-07-16 13:44:10 +00:00
# execute(
2015-11-17 09:03:51 +00:00
# browser: instance,
# js: '$(".content.active .overview-header").css("display", "none")',
2021-07-16 13:44:10 +00:00
# )
2015-11-05 12:34:22 +00:00
2021-06-15 06:26:52 +00:00
begin
overviews = { }
instance . find_elements ( css : '.content.active .sidebar a[href]' ) . each do | element |
url = element . attribute ( 'href' )
url . gsub! ( %r{ (http|https)://.+?/(.+?)$ } , '\\2' )
overviews [ url ] = 0
2021-07-16 13:44:10 +00:00
# puts url.inspect
# puts element.inspect
2021-06-15 06:26:52 +00:00
end
overviews . each_key do | url |
count = instance . find_elements ( css : " .content.active .sidebar a[href= \" #{ url } \" ] .badge " ) [ 0 ] . text
overviews [ url ] = count . to_i
end
rescue = > e
retries || = 0
retries += 1
sleep 0 . 5
retry if retries < 5
raise e
2017-10-01 12:25:52 +00:00
end
2021-06-15 06:26:52 +00:00
2015-11-05 12:34:22 +00:00
log ( 'overview_counter' , overviews )
2015-02-22 12:28:34 +00:00
overviews
end
2015-02-23 13:49:40 +00:00
= begin
organization_open_by_search (
2015-11-29 15:39:56 +00:00
browser : browser2 ,
value : 'some value' ,
2015-02-23 13:49:40 +00:00
)
= end
def organization_open_by_search ( params = { } )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'organization_open_by_search' , params )
2015-02-23 13:49:40 +00:00
instance = params [ :browser ] || @browser
2016-02-25 12:45:46 +00:00
element = instance . find_elements ( css : '#global-search' ) [ 0 ]
2015-02-23 13:49:40 +00:00
element . click
element . clear
2015-12-14 23:52:26 +00:00
element . send_keys ( params [ :value ] )
2015-02-23 13:49:40 +00:00
sleep 3
2016-03-15 10:24:42 +00:00
empty_search ( browser : instance )
2016-02-25 12:45:46 +00:00
element = instance . find_elements ( css : '#global-search' ) [ 0 ]
2015-02-23 13:49:40 +00:00
element . click
element . clear
2015-12-14 23:52:26 +00:00
element . send_keys ( params [ :value ] )
2015-02-23 13:49:40 +00:00
sleep 2
2020-01-29 15:42:12 +00:00
watch_for_disappear (
browser : instance ,
css : '.navigation .search.loading'
)
2021-07-16 13:44:10 +00:00
# instance.find_element(partial_link_text: params[:value] } ).click
2019-01-08 22:14:47 +00:00
instance . execute_script ( " $( \" .js-global-search-result a:contains(' #{ params [ :value ] } ') .nav-tab-name \" ).first().click() " )
2018-09-17 07:01:17 +00:00
watch_for (
browser : instance ,
2018-12-19 17:31:51 +00:00
css : '.content.active h1'
2018-09-17 07:01:17 +00:00
)
2016-09-27 17:46:23 +00:00
name = instance . find_elements ( css : '.content.active h1' ) [ 0 ] . text
2021-05-12 11:37:44 +00:00
if ! name . match? ( %r{ #{ params [ :value ] } } )
2015-12-14 23:52:26 +00:00
screenshot ( browser : instance , comment : 'organization_open_by_search_failed' )
2016-03-01 14:26:46 +00:00
raise " unable to search/find org #{ params [ :value ] } ! "
2015-02-23 13:49:40 +00:00
end
2015-12-14 23:52:26 +00:00
assert ( true , " org #{ params [ :value ] } found " )
2015-02-23 13:49:40 +00:00
true
end
2015-02-23 13:02:46 +00:00
= begin
user_open_by_search (
2015-11-29 15:39:56 +00:00
browser : browser2 ,
value : 'some value' ,
2015-02-23 13:02:46 +00:00
)
= end
def user_open_by_search ( params = { } )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'user_open_by_search' , params )
2015-02-23 13:02:46 +00:00
instance = params [ :browser ] || @browser
2016-02-25 12:45:46 +00:00
element = instance . find_elements ( css : '#global-search' ) [ 0 ]
2015-02-23 13:02:46 +00:00
element . click
element . clear
2015-12-14 23:52:26 +00:00
element . send_keys ( params [ :value ] )
2015-02-23 13:02:46 +00:00
sleep 3
2016-09-08 19:18:26 +00:00
2021-07-16 13:44:10 +00:00
# instance.find_element(partial_link_text: params[:value]).click
2019-01-08 22:14:47 +00:00
instance . execute_script ( " $( \" .js-global-search-result a:contains(' #{ params [ :value ] } ') .nav-tab-name \" ).first().click() " )
2018-09-17 07:01:17 +00:00
watch_for (
browser : instance ,
2018-12-19 17:31:51 +00:00
css : '.content.active h1'
2018-09-17 07:01:17 +00:00
)
2016-09-27 17:46:23 +00:00
name = instance . find_elements ( css : '.content.active h1' ) [ 0 ] . text
2021-05-12 11:37:44 +00:00
if ! name . match? ( %r{ #{ params [ :value ] } } )
2015-12-14 23:52:26 +00:00
screenshot ( browser : instance , comment : 'user_open_by_search_failed' )
2016-03-01 14:26:46 +00:00
raise " unable to search/find user #{ params [ :value ] } ! "
2015-02-23 13:02:46 +00:00
end
2015-12-14 23:52:26 +00:00
assert ( true , " user #{ params [ :term ] } found " )
2015-02-23 13:02:46 +00:00
true
end
= begin
user_create (
2015-11-29 15:39:56 +00:00
browser : browser2 ,
data : {
2015-11-27 19:58:27 +00:00
#login: 'some login' + random,
firstname : 'Manage Firstname' + random ,
lastname : 'Manage Lastname' + random ,
email : user_email ,
password : 'some-pass' ,
2018-08-07 12:15:53 +00:00
role : 'Admin' , # optional, choose among [Admin, Agent, Customer]
# defaults to Customer if not provided
} ,
)
user_create (
browser : browser2 ,
data : {
#login: 'some login' + random,
firstname : 'Manage Firstname' + random ,
lastname : 'Manage Lastname' + random ,
email : user_email ,
password : 'some-pass' ,
role : 'Agent' , # when the role is Agent an array of permissions for each group is optionally accepted
permissions : { 1 = > %w[ read create overview ] ,
2 = > [ 'full' ] , }
2015-02-23 13:02:46 +00:00
} ,
)
= end
def user_create ( params = { } )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'user_create' , params )
2015-02-23 13:02:46 +00:00
instance = params [ :browser ] || @browser
data = params [ :data ]
2018-09-17 07:01:17 +00:00
raise 'user_create() requires either email or phone' if data [ :email ] . blank? && data [ :phone ] . blank?
2016-03-21 19:10:01 +00:00
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : 'a[href="#manage"]' ,
2016-03-21 19:10:01 +00:00
mute_log : true ,
)
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.content.active a[href="#manage/users"]' ,
2016-03-21 19:10:01 +00:00
mute_log : true ,
)
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.content.active a[data-type="new"]' ,
2016-03-21 19:10:01 +00:00
mute_log : true ,
)
2016-06-10 07:21:47 +00:00
modal_ready ( browser : instance )
2016-02-25 12:45:46 +00:00
element = instance . find_elements ( css : '.modal input[name=firstname]' ) [ 0 ]
2015-02-23 13:02:46 +00:00
element . clear
2015-12-14 23:52:26 +00:00
element . send_keys ( data [ :firstname ] )
2016-02-25 12:45:46 +00:00
element = instance . find_elements ( css : '.modal input[name=lastname]' ) [ 0 ]
2015-02-23 13:02:46 +00:00
element . clear
2015-12-14 23:52:26 +00:00
element . send_keys ( data [ :lastname ] )
2016-02-25 12:45:46 +00:00
element = instance . find_elements ( css : '.modal input[name=email]' ) [ 0 ]
2015-02-23 13:02:46 +00:00
element . clear
2015-12-14 23:52:26 +00:00
element . send_keys ( data [ :email ] )
2016-02-25 12:45:46 +00:00
element = instance . find_elements ( css : '.modal input[name=password]' ) [ 0 ]
2015-02-23 13:02:46 +00:00
element . clear
2015-12-14 23:52:26 +00:00
element . send_keys ( data [ :password ] )
2016-02-25 12:45:46 +00:00
element = instance . find_elements ( css : '.modal input[name=password_confirm]' ) [ 0 ]
2015-02-23 13:02:46 +00:00
element . clear
2015-12-14 23:52:26 +00:00
element . send_keys ( data [ :password ] )
2018-08-20 09:13:18 +00:00
element = instance . find_elements ( css : '.modal input[name=phone]' ) [ 0 ]
element . clear
element . send_keys ( data [ :phone ] )
if data [ :active ] == false
select ( css : 'select[name="active"]' , value : 'inactive' )
end
2018-06-20 22:33:44 +00:00
if data [ :organization ]
2018-06-27 14:46:45 +00:00
begin
2018-10-08 13:51:58 +00:00
target = nil
2018-06-27 14:46:45 +00:00
retries || = 0
2018-10-08 13:51:58 +00:00
5 . times do
element = instance . find_elements ( css : '.modal input.searchableSelect-main' ) [ 0 ]
element . clear
element . send_keys ( data [ :organization ] )
10 . times do
sleep 0 . 5
target = instance . find_elements ( css : " .modal li[title=' #{ data [ :organization ] } '] " ) [ 0 ]
break if target
end
break if target
2018-06-27 14:46:45 +00:00
end
2018-10-08 13:51:58 +00:00
raise " Can't find organization #{ data [ :organization ] } " if target . blank?
2018-10-09 06:22:20 +00:00
2021-07-16 13:29:38 +00:00
target . click
2018-06-27 14:46:45 +00:00
rescue Selenium :: WebDriver :: Error :: StaleElementReferenceError
sleep retries
retries += 1
retry if retries < 3
2018-06-20 22:33:44 +00:00
end
end
2018-08-07 12:15:53 +00:00
if data [ :role ]
2020-07-13 12:46:08 +00:00
case data [ :role ]
when 'Admin'
2018-08-07 12:15:53 +00:00
check (
browser : instance ,
css : '.modal input[name=role_ids][value=1]' ,
)
2020-07-13 12:46:08 +00:00
when 'Customer'
2018-08-07 12:15:53 +00:00
check (
browser : instance ,
css : '.modal input[name=role_ids][value=3]' ,
)
2020-07-13 12:46:08 +00:00
when 'Agent'
2018-08-07 12:15:53 +00:00
check (
browser : instance ,
css : '.modal input[name=role_ids][value=2]' ,
)
data [ :permissions ] . each do | key , value |
value . each do | permission |
check (
browser : instance ,
css : " .modal input[name= \" group_ids:: #{ key } \" ][value= \" #{ permission } \" ] " ,
)
end
end
else
raise " Unknown :role \" #{ data [ :role ] } \" in user_create() "
end
else
check (
browser : instance ,
css : '.modal input[name=role_ids][value=3]' ,
)
end
click (
2016-03-14 20:03:51 +00:00
browser : instance ,
2018-08-07 12:15:53 +00:00
css : '.modal .js-submit' ,
2016-03-14 20:03:51 +00:00
)
2018-08-07 12:15:53 +00:00
2016-09-12 06:53:25 +00:00
modal_disappear (
browser : instance ,
timeout : 10 ,
)
2018-09-17 07:01:17 +00:00
if data [ :email ]
search_query = data [ :email ]
search_target = data [ :email ]
search_css = '.content.active .user-list .js-tableBody td:first-child'
else
search_query = data [ :phone ]
search_target = data [ :firstname ]
search_css = '.content.active .user-list .js-tableBody td:nth-child(2)'
end
60 . times do | i |
if ( i % 10 ) . zero?
set (
browser : instance ,
2018-12-19 17:31:51 +00:00
css : '.content.active .js-search' ,
value : search_query ,
2018-09-17 07:01:17 +00:00
)
end
sleep 1
search_result = instance . find_elements ( css : search_css ) . map ( & :text ) . map ( & :strip )
break if search_result . include? search_target
raise 'user creation failed' if i > = 19
2018-10-09 06:17:41 +00:00
2018-09-17 07:01:17 +00:00
log " new user #{ search_query } not found on the #{ i . ordinalize } try, retrying "
end
2015-02-23 13:02:46 +00:00
2015-12-14 23:52:26 +00:00
assert ( true , 'user created' )
2015-02-23 13:02:46 +00:00
end
2018-08-07 12:15:53 +00:00
= begin
user_edit (
browser : browser2 ,
data : {
login : 'some login' + random ,
firstname : 'Manage Firstname' + random ,
lastname : 'Manage Lastname' + random ,
email : user_email ,
password : 'some-pass' ,
role : 'Agent' , # when the role is Agent an array of permissions for each group is optionally accepted
permissions : { 1 = > %w[ read create overview ] ,
2 = > [ 'full' ] , }
} ,
)
= end
def user_edit ( params = { } )
switch_window_focus ( params )
log ( 'user_edit' , params )
instance = params [ :browser ] || @browser
data = params [ :data ]
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : 'a[href="#manage"]' ,
2018-08-07 12:15:53 +00:00
mute_log : true ,
)
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.content.active a[href="#manage/users"]' ,
2018-08-07 12:15:53 +00:00
mute_log : true ,
)
instance . find_elements ( css : '.content.active .user-list td:first-child' ) . each do | element |
next if element . text . strip != data [ :login ]
2018-10-09 06:17:41 +00:00
2018-08-07 12:15:53 +00:00
element . click
break
end
modal_ready ( browser : instance )
if data [ :firstname ]
element = instance . find_elements ( css : '.modal input[name=firstname]' ) [ 0 ]
element . clear
element . send_keys ( data [ :firstname ] )
end
if data [ :lastname ]
element = instance . find_elements ( css : '.modal input[name=lastname]' ) [ 0 ]
element . clear
element . send_keys ( data [ :lastname ] )
end
if data [ :email ]
element = instance . find_elements ( css : '.modal input[name=email]' ) [ 0 ]
element . clear
element . send_keys ( data [ :email ] )
end
if data [ :password ]
element = instance . find_elements ( css : '.modal input[name=password]' ) [ 0 ]
element . clear
element . send_keys ( data [ :password ] )
element = instance . find_elements ( css : '.modal input[name=password_confirm]' ) [ 0 ]
element . clear
element . send_keys ( data [ :password ] )
end
if data [ :phone ]
element = instance . find_elements ( css : '.modal input[name=phone]' ) [ 0 ]
element . clear
element . send_keys ( data [ :phone ] )
end
if data [ :active ] . present?
2021-07-16 13:38:01 +00:00
select ( css : 'select[name="active"]' , value : data [ :active ] ? 'active' : 'inactive' )
2018-08-07 12:15:53 +00:00
end
if data [ :organization ]
element = instance . find_elements ( css : '.modal input.searchableSelect-main' ) [ 0 ]
element . clear
element . send_keys ( data [ :organization ] )
begin
retries || = 0
target = nil
until target
sleep 0 . 5
target = instance . find_elements ( css : " .modal li[title=' #{ data [ :organization ] } '] " ) [ 0 ]
end
2021-07-16 13:29:38 +00:00
target . click
2018-08-07 12:15:53 +00:00
rescue Selenium :: WebDriver :: Error :: StaleElementReferenceError
sleep retries
retries += 1
retry if retries < 3
end
end
if data [ :role ]
2020-07-13 12:46:08 +00:00
case data [ :role ]
when 'Admin'
2018-08-07 12:15:53 +00:00
check (
browser : instance ,
css : '.modal input[name=role_ids][value=1]' ,
)
2020-07-13 12:46:08 +00:00
when 'Customer'
2018-08-07 12:15:53 +00:00
check (
browser : instance ,
css : '.modal input[name=role_ids][value=3]' ,
)
2020-07-13 12:46:08 +00:00
when 'Agent'
2018-08-07 12:15:53 +00:00
check (
browser : instance ,
css : '.modal input[name=role_ids][value=2]' ,
)
else
raise " Unknown :role \" #{ data [ :role ] } \" in user_create() "
end
end
if data [ :permissions ] . present?
data [ :permissions ] . each do | key , value |
value . each do | permission |
check (
browser : instance ,
css : " .modal input[name= \" group_ids:: #{ key } \" ][value= \" #{ permission } \" ] " ,
)
end
end
end
click (
browser : instance ,
css : '.modal .js-submit' ,
)
modal_disappear (
browser : instance ,
timeout : 10 ,
)
assert ( true , 'user updated' )
end
2018-06-20 22:33:44 +00:00
= begin
organization_create (
browser : browser2 ,
data : {
name : 'Test Organization' ,
}
)
= end
def organization_create ( params = { } )
switch_window_focus ( params )
log ( 'organization_create' , params )
instance = params [ :browser ] || @browser
data = params [ :data ]
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : 'a[href="#manage"]' ,
2018-06-20 22:33:44 +00:00
mute_log : true ,
)
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.content.active a[href="#manage/organizations"]' ,
2018-06-20 22:33:44 +00:00
mute_log : true ,
)
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.content.active a[data-type="new"]' ,
2018-06-20 22:33:44 +00:00
mute_log : true ,
)
modal_ready ( browser : instance )
element = instance . find_elements ( css : '.modal input[name=name]' ) [ 0 ]
element . clear
element . send_keys ( data [ :name ] )
instance . find_elements ( css : '.modal button.js-submit' ) [ 0 ] . click
2021-06-15 06:26:52 +00:00
await_empty_ajax_queue ( params )
2018-06-20 22:33:44 +00:00
modal_disappear (
browser : instance ,
timeout : 5 ,
)
watch_for (
browser : instance ,
2018-12-19 17:31:51 +00:00
css : 'body' ,
value : data [ :name ] ,
2018-06-20 22:33:44 +00:00
)
end
2018-05-11 08:09:24 +00:00
= begin
calendar_create (
browser : browser2 ,
data : {
name : 'some calendar' + random ,
first_response_time_in_text : 61
} ,
)
= end
def calendar_create ( params = { } )
switch_window_focus ( params )
log ( 'calendar_create' , params )
instance = params [ :browser ] || @browser
data = params [ :data ]
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : 'a[href="#manage"]' ,
2018-05-11 08:09:24 +00:00
mute_log : true ,
)
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.content.active a[href="#manage/calendars"]' ,
2018-05-11 08:09:24 +00:00
mute_log : true ,
)
sleep 4
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.content.active a.js-new' ,
2018-05-11 08:09:24 +00:00
mute_log : true ,
)
modal_ready ( browser : instance )
element = instance . find_elements ( css : '.content.active .modal input[name=name]' ) [ 0 ]
element . clear
element . send_keys ( data [ :name ] )
element = instance . find_elements ( css : '.content.active .modal .js-input' ) [ 0 ]
element . clear
element . send_keys ( data [ :timezone ] )
element . send_keys ( :enter )
instance . find_elements ( css : '.modal button.js-submit' ) [ 0 ] . click
modal_disappear ( browser : instance )
7 . times do
element = instance . find_elements ( css : 'body' ) [ 0 ]
text = element . text
2021-05-12 11:37:44 +00:00
if text . match? ( %r{ #{ Regexp . quote ( data [ :name ] ) } } )
2018-05-11 08:09:24 +00:00
assert ( true , 'calendar created' )
sleep 1
return true
end
sleep 1
end
screenshot ( browser : instance , comment : 'calendar_create_failed' )
raise 'calendar creation failed'
end
2015-02-23 13:02:46 +00:00
= begin
sla_create (
2015-11-29 15:39:56 +00:00
browser : browser2 ,
data : {
name : 'some sla' + random ,
2018-05-11 08:09:24 +00:00
calendar : 'some calendar name' ,
2015-11-29 15:39:56 +00:00
first_response_time_in_text : 61
2015-02-23 13:02:46 +00:00
} ,
)
= end
def sla_create ( params = { } )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'sla_create' , params )
2015-02-23 13:02:46 +00:00
instance = params [ :browser ] || @browser
data = params [ :data ]
2016-03-21 19:10:01 +00:00
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : 'a[href="#manage"]' ,
2016-03-21 19:10:01 +00:00
mute_log : true ,
)
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.content.active a[href="#manage/slas"]' ,
2016-03-21 19:10:01 +00:00
mute_log : true ,
)
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.content.active a.js-new' ,
2016-03-21 19:10:01 +00:00
mute_log : true ,
)
2016-06-10 07:21:47 +00:00
modal_ready ( browser : instance )
2016-02-25 12:45:46 +00:00
element = instance . find_elements ( css : '.modal input[name=name]' ) [ 0 ]
2015-02-23 13:02:46 +00:00
element . clear
2015-12-14 23:52:26 +00:00
element . send_keys ( data [ :name ] )
2018-05-11 08:09:24 +00:00
if data [ :calendar ] . present?
element = instance . find_elements ( css : '.modal select[name="calendar_id"]' ) [ 0 ]
dropdown = Selenium :: WebDriver :: Support :: Select . new ( element )
dropdown . select_by ( :text , data [ :calendar ] )
end
2016-02-25 12:45:46 +00:00
element = instance . find_elements ( css : '.modal input[name=first_response_time_in_text]' ) [ 0 ]
2015-02-23 13:02:46 +00:00
element . clear
2015-12-14 23:52:26 +00:00
element . send_keys ( data [ :first_response_time_in_text ] )
2016-02-25 12:45:46 +00:00
instance . find_elements ( css : '.modal button.js-submit' ) [ 0 ] . click
2021-06-15 06:26:52 +00:00
await_empty_ajax_queue ( params )
2016-06-10 06:09:47 +00:00
modal_disappear ( browser : instance )
2017-10-01 12:25:52 +00:00
7 . times do
2016-02-25 12:45:46 +00:00
element = instance . find_elements ( css : 'body' ) [ 0 ]
2015-02-23 13:02:46 +00:00
text = element . text
2021-05-12 11:37:44 +00:00
if text . match? ( %r{ #{ Regexp . quote ( data [ :name ] ) } } )
2015-12-14 23:52:26 +00:00
assert ( true , 'sla created' )
2016-03-03 14:13:06 +00:00
sleep 1
2015-02-23 13:02:46 +00:00
return true
end
sleep 1
2017-10-01 12:25:52 +00:00
end
2015-12-14 23:52:26 +00:00
screenshot ( browser : instance , comment : 'sla_create_failed' )
2016-03-01 14:26:46 +00:00
raise 'sla creation failed'
2015-02-23 13:02:46 +00:00
end
2015-02-23 22:37:00 +00:00
= begin
text_module_create (
2015-11-29 15:39:56 +00:00
browser : browser2 ,
data : {
name : 'some sla' + random ,
keywords : 'some keywords' ,
content : 'some content' ,
2015-02-23 22:37:00 +00:00
} ,
)
= end
def text_module_create ( params = { } )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'text_module_create' , params )
2015-02-23 22:37:00 +00:00
instance = params [ :browser ] || @browser
data = params [ :data ]
2016-03-21 19:10:01 +00:00
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : 'a[href="#manage"]' ,
2016-03-21 19:10:01 +00:00
mute_log : true ,
)
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.content.active a[href="#manage/text_modules"]' ,
2016-03-21 19:10:01 +00:00
mute_log : true ,
)
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.content.active a[data-type="new"]' ,
2016-03-21 19:10:01 +00:00
mute_log : true ,
)
2016-06-10 07:21:47 +00:00
modal_ready ( browser : instance )
2016-09-12 06:53:25 +00:00
set (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.modal input[name=name]' ,
value : data [ :name ] ,
2016-09-12 06:53:25 +00:00
)
set (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.modal input[name=keywords]' ,
value : data [ :keywords ] ,
2016-09-12 06:53:25 +00:00
)
set (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.modal [data-name=content]' ,
value : data [ :content ] ,
2016-09-12 06:53:25 +00:00
)
2016-02-25 12:45:46 +00:00
instance . find_elements ( css : '.modal button.js-submit' ) [ 0 ] . click
2016-06-10 06:09:47 +00:00
modal_disappear ( browser : instance )
2017-10-01 12:25:52 +00:00
7 . times do
2016-02-25 12:45:46 +00:00
element = instance . find_elements ( css : 'body' ) [ 0 ]
2015-02-23 22:37:00 +00:00
text = element . text
2021-05-12 11:37:44 +00:00
if text . match? ( %r{ #{ Regexp . quote ( data [ :name ] ) } } )
2015-12-14 23:52:26 +00:00
assert ( true , 'text module created' )
2016-03-03 14:13:06 +00:00
sleep 1
2015-02-23 22:37:00 +00:00
return true
end
sleep 1
2017-10-01 12:25:52 +00:00
end
2015-12-14 23:52:26 +00:00
screenshot ( browser : instance , comment : 'text_module_create_failed' )
2016-03-01 14:26:46 +00:00
raise 'text module creation failed'
2015-02-23 22:37:00 +00:00
end
2015-03-01 23:16:36 +00:00
= begin
2012-12-14 10:14:48 +00:00
2015-03-01 23:16:36 +00:00
signature_create (
2015-11-29 15:39:56 +00:00
browser : browser2 ,
data : {
name : 'some sla' + random ,
body : 'some body' ,
2015-03-01 23:16:36 +00:00
} ,
)
2014-12-09 19:10:38 +00:00
2015-03-01 23:16:36 +00:00
= end
2014-12-09 19:10:38 +00:00
2015-03-01 23:16:36 +00:00
def signature_create ( params = { } )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'signature_create' , params )
2015-03-01 23:16:36 +00:00
instance = params [ :browser ] || @browser
data = params [ :data ]
2012-12-14 12:16:04 +00:00
2016-03-21 19:10:01 +00:00
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : 'a[href="#manage"]' ,
2016-03-21 19:10:01 +00:00
mute_log : true ,
)
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.content.active a[href="#channels/email"]' ,
2016-03-21 19:10:01 +00:00
mute_log : true ,
)
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.content.active a[href="#c-signature"]' ,
2016-03-21 19:10:01 +00:00
mute_log : true ,
)
sleep 4
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.content.active #c-signature a[data-type="new"]' ,
2016-03-21 19:10:01 +00:00
mute_log : true ,
)
2016-06-10 07:21:47 +00:00
modal_ready ( browser : instance )
2016-09-12 06:53:25 +00:00
set (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.modal input[name=name]' ,
value : data [ :name ] ,
2016-09-12 06:53:25 +00:00
)
set (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.modal [data-name=body]' ,
value : data [ :body ] ,
2016-09-12 06:53:25 +00:00
)
2016-02-25 12:45:46 +00:00
instance . find_elements ( css : '.modal button.js-submit' ) [ 0 ] . click
2016-06-10 06:09:47 +00:00
modal_disappear ( browser : instance )
2017-10-01 12:25:52 +00:00
11 . times do
2016-02-25 12:45:46 +00:00
element = instance . find_elements ( css : 'body' ) [ 0 ]
2015-03-01 23:16:36 +00:00
text = element . text
2021-05-12 11:37:44 +00:00
if text . match? ( %r{ #{ Regexp . quote ( data [ :name ] ) } } )
2015-11-30 12:13:27 +00:00
assert ( true , 'signature created' )
2016-03-03 14:13:06 +00:00
sleep 1
2015-03-01 23:16:36 +00:00
return true
2012-12-14 10:14:48 +00:00
end
2015-03-01 23:16:36 +00:00
sleep 1
2017-10-01 12:25:52 +00:00
end
2015-11-30 12:13:27 +00:00
screenshot ( browser : instance , comment : 'signature_create_failed' )
2016-03-01 14:26:46 +00:00
raise 'signature creation failed'
2012-12-14 10:14:48 +00:00
end
2013-06-08 22:35:18 +00:00
2015-03-01 23:16:36 +00:00
= begin
2013-08-27 21:05:33 +00:00
2015-03-01 23:16:36 +00:00
group_create (
2015-11-29 15:39:56 +00:00
browser : browser2 ,
data : {
name : 'some sla' + random ,
signature : 'some signature bame' ,
member : [
2017-06-16 20:43:09 +00:00
{
login : 'some_user_login' ,
access : 'all' ,
} ,
2015-03-01 23:16:36 +00:00
] ,
} ,
)
2015-02-20 23:17:49 +00:00
2015-03-01 23:16:36 +00:00
= end
2014-10-11 23:35:53 +00:00
2015-03-01 23:16:36 +00:00
def group_create ( params = { } )
2015-11-29 15:39:56 +00:00
switch_window_focus ( params )
2015-03-08 01:06:57 +00:00
log ( 'group_create' , params )
2015-03-01 23:16:36 +00:00
instance = params [ :browser ] || @browser
data = params [ :data ]
2015-01-23 22:24:03 +00:00
2016-03-21 19:10:01 +00:00
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : 'a[href="#manage"]' ,
2016-03-21 19:10:01 +00:00
mute_log : true ,
)
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.content.active a[href="#manage/groups"]' ,
2016-03-21 19:10:01 +00:00
mute_log : true ,
)
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.content.active a[data-type="new"]' ,
2016-03-21 19:10:01 +00:00
mute_log : true ,
)
2016-06-10 07:21:47 +00:00
modal_ready ( browser : instance )
2016-02-25 12:45:46 +00:00
element = instance . find_elements ( css : '.modal input[name=name]' ) [ 0 ]
2015-03-01 23:16:36 +00:00
element . clear
2015-11-30 12:13:27 +00:00
element . send_keys ( data [ :name ] )
2016-02-25 12:45:46 +00:00
element = instance . find_elements ( css : '.modal select[name="email_address_id"]' ) [ 0 ]
2015-03-01 23:16:36 +00:00
dropdown = Selenium :: WebDriver :: Support :: Select . new ( element )
2015-11-30 12:13:27 +00:00
dropdown . select_by ( :index , 1 )
2021-07-16 13:44:10 +00:00
# dropdown.select_by(:text, action[:group])
2015-03-01 23:16:36 +00:00
if data [ :signature ]
2016-02-25 12:45:46 +00:00
element = instance . find_elements ( css : '.modal select[name="signature_id"]' ) [ 0 ]
2015-01-23 22:24:03 +00:00
dropdown = Selenium :: WebDriver :: Support :: Select . new ( element )
2015-11-30 12:13:27 +00:00
dropdown . select_by ( :text , data [ :signature ] )
2012-12-14 12:16:04 +00:00
end
2016-02-25 12:45:46 +00:00
instance . find_elements ( css : '.modal button.js-submit' ) [ 0 ] . click
2021-06-15 06:26:52 +00:00
await_empty_ajax_queue ( params )
2016-06-10 06:09:47 +00:00
modal_disappear ( browser : instance )
2015-03-01 23:16:36 +00:00
2020-09-30 09:07:01 +00:00
element = instance . find_elements ( css : 'body' ) [ 0 ]
text = element . text
2021-05-12 11:37:44 +00:00
if text . match? ( %r{ #{ Regexp . quote ( data [ :name ] ) } } )
2020-09-30 09:07:01 +00:00
assert ( true , 'group created' )
modal_disappear ( browser : instance ) # wait until modal has gone
# add member
data [ :member ] & . each do | member |
instance . find_elements ( css : 'a[href="#manage"]' ) [ 0 ] . click
sleep 1
2021-06-15 06:26:52 +00:00
scroll_to ( params . merge ( css : '.content.active a[href="#manage/users"]' ) )
2020-09-30 09:07:01 +00:00
instance . find_elements ( css : '.content.active a[href="#manage/users"]' ) [ 0 ] . click
sleep 3
element = instance . find_elements ( css : '.content.active [name="search"]' ) [ 0 ]
element . clear
element . send_keys ( member [ :login ] )
sleep 3
2021-07-16 13:44:10 +00:00
# instance.find_elements(:css => '.content.active table [data-id]')[0].click
2020-09-30 09:07:01 +00:00
instance . execute_script ( '$(".content.active table [data-id] td").first().click()' )
modal_ready ( browser : instance )
2021-07-16 13:44:10 +00:00
# instance.find_elements(:css => 'label:contains(" ' + action[:name] + '")')[0].click
2020-09-30 09:07:01 +00:00
instance . execute_script ( %( $ ( ".js-groupList tr:contains ( \\ " #{ data [ :name ] } \\ " ) .js-groupListItem[value= #{ member [ :access ] } ]" ) .prop ( "checked", true ) ) )
instance . find_elements ( css : '.modal button.js-submit' ) [ 0 ] . click
2021-06-15 06:26:52 +00:00
await_empty_ajax_queue ( params )
2020-09-30 09:07:01 +00:00
modal_disappear ( browser : instance )
2012-12-14 12:16:04 +00:00
end
2017-10-01 12:25:52 +00:00
end
2020-09-30 09:07:01 +00:00
sleep 1
true
2012-12-14 12:16:04 +00:00
end
2015-03-01 23:16:36 +00:00
2018-06-27 09:43:50 +00:00
= begin
macro_create (
browser : browser1 ,
name : 'Emmanuel Macro' ,
ux_flow_next_up : 'Stay on tab' , # possible: 'Stay on tab', 'Close tab', 'Advance to next ticket from overview'
actions : {
'Tags' = > { # currently only 'Tags' is supported
operator : 'add' ,
value : 'spam' ,
}
}
)
= end
def macro_create ( params )
switch_window_focus ( params )
log ( 'macro_create' , params )
instance = params [ :browser ] || @browser
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : 'a[href="#manage"]' ,
2018-06-27 09:43:50 +00:00
mute_log : true ,
)
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.sidebar a[href="#manage/macros"]' ,
2018-06-27 09:43:50 +00:00
mute_log : true ,
)
click (
browser : instance ,
css : '.page-header-meta > a[data-type="new"]'
)
sendkey (
browser : instance ,
css : '.modal-body input[name="name"]' ,
value : params [ :name ]
)
params [ :actions ] & . each do | attribute , changes |
select (
browser : instance ,
css : '.modal .ticket_perform_action .js-filterElement .js-attributeSelector select' ,
value : attribute ,
mute_log : true ,
)
next if attribute != 'Tags'
select (
browser : instance ,
css : '.modal .ticket_perform_action .js-filterElement .js-operator select' ,
value : changes [ :operator ] ,
mute_log : true ,
)
sendkey (
browser : instance ,
css : '.modal .ticket_perform_action .js-filterElement .js-value .token-input' ,
value : changes [ :value ] ,
mute_log : true ,
)
sendkey (
browser : instance ,
value : :enter ,
)
end
select (
browser : instance ,
css : '.modal-body select[name="ux_flow_next_up"]' ,
value : params [ :ux_flow_next_up ]
)
click (
browser : instance ,
css : '.modal-footer button[type="submit"]'
)
watch_for (
browser : instance ,
css : 'body' ,
value : params [ :name ] ,
)
assert ( true , 'macro created' )
end
2016-09-07 06:47:31 +00:00
= begin
role_create (
browser : browser2 ,
data : {
name : 'some role' + random ,
default_at_signup : false ,
2017-04-10 06:08:18 +00:00
permission : {
'admin.group' = > true ,
'preferences.password' = > true ,
} ,
2016-09-07 06:47:31 +00:00
member : [
'some_user_login' ,
] ,
} ,
)
= end
def role_create ( params = { } )
switch_window_focus ( params )
log ( 'role_create' , params )
instance = params [ :browser ] || @browser
data = params [ :data ]
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : 'a[href="#manage"]' ,
2016-09-07 06:47:31 +00:00
mute_log : true ,
)
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.content.active a[href="#manage/roles"]' ,
2016-09-07 06:47:31 +00:00
mute_log : true ,
)
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.content.active a[data-type="new"]' ,
2016-09-07 06:47:31 +00:00
mute_log : true ,
)
modal_ready ( browser : instance )
element = instance . find_elements ( css : '.modal input[name=name]' ) [ 0 ]
element . clear
element . send_keys ( data [ :name ] )
if data . key? ( :default_at_signup )
element = instance . find_elements ( css : '.modal select[name="default_at_signup"]' ) [ 0 ]
dropdown = Selenium :: WebDriver :: Support :: Select . new ( element )
if data [ :default_at_signup ] == true
dropdown . select_by ( :text , 'yes' )
else
dropdown . select_by ( :text , 'no' )
end
end
if data . key? ( :permission )
2017-10-01 12:25:52 +00:00
data [ :permission ] . each do | permission_name , permission_value |
2017-04-10 06:08:18 +00:00
if permission_value == false
uncheck (
browser : instance ,
css : " .modal [data-permission-name= \" #{ permission_name } \" ] " ,
)
else
check (
browser : instance ,
css : " .modal [data-permission-name= \" #{ permission_name } \" ] " ,
)
end
2017-10-01 12:25:52 +00:00
end
2016-09-07 06:47:31 +00:00
end
2018-11-09 13:06:21 +00:00
if data [ :active ] == false
select ( css : 'select[name="active"]' , value : 'inactive' )
end
2016-09-07 06:47:31 +00:00
instance . find_elements ( css : '.modal button.js-submit' ) [ 0 ] . click
modal_disappear ( browser : instance )
2020-09-30 09:07:01 +00:00
element = instance . find_elements ( css : 'body' ) [ 0 ]
text = element . text
2021-05-12 11:37:44 +00:00
if text . match? ( %r{ #{ Regexp . quote ( data [ :name ] ) } } )
2020-09-30 09:07:01 +00:00
assert ( true , 'role created' )
modal_disappear ( browser : instance ) # wait until modal has gone
# add member
data [ :member ] & . each do | login |
instance . find_elements ( css : 'a[href="#manage"]' ) [ 0 ] . click
sleep 1
instance . find_elements ( css : '.content.active a[href="#manage/users"]' ) [ 0 ] . click
sleep 3
element = instance . find_elements ( css : '.content.active [name="search"]' ) [ 0 ]
element . clear
element . send_keys ( login )
sleep 3
2021-07-16 13:44:10 +00:00
# instance.find_elements(:css => '.content.active table [data-id]')[0].click
2020-09-30 09:07:01 +00:00
instance . execute_script ( '$(".content.active table [data-id] td").first().click()' )
sleep 3
2021-07-16 13:44:10 +00:00
# instance.find_elements(:css => 'label:contains(" ' + action[:name] + '")')[0].click
2020-09-30 09:07:01 +00:00
instance . execute_script ( %( $ ( 'label:contains ( " #{ data [ :name ] } " ) ' ) .first ( ) .click ( ) ) )
instance . find_elements ( css : '.modal button.js-submit' ) [ 0 ] . click
modal_disappear ( browser : instance )
2016-09-07 06:47:31 +00:00
end
2017-10-01 12:25:52 +00:00
end
2020-09-30 09:07:01 +00:00
sleep 1
true
2016-09-07 06:47:31 +00:00
end
= begin
role_create (
browser : browser2 ,
data : {
name : 'some role' + random ,
default_at_signup : false ,
2017-04-10 06:08:18 +00:00
permission : {
'admin.group' = > true ,
'preferences.password' = > true ,
} ,
2016-09-07 06:47:31 +00:00
member : [
'some_user_login' ,
] ,
} ,
)
= end
def role_edit ( params = { } )
switch_window_focus ( params )
log ( 'role_edit' , params )
instance = params [ :browser ] || @browser
data = params [ :data ]
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : 'a[href="#manage"]' ,
2016-09-07 06:47:31 +00:00
mute_log : true ,
)
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.content.active a[href="#manage/roles"]' ,
2016-09-07 06:47:31 +00:00
mute_log : true ,
)
2021-06-15 06:26:52 +00:00
await_text ( container : '.content.active table tr td' , text : data [ :name ] )
2020-09-30 09:07:01 +00:00
instance . execute_script ( %( $ ( '.content.active table tr td:contains ( " #{ data [ :name ] } " ) ' ) .first ( ) .click ( ) ) )
2016-09-07 06:47:31 +00:00
modal_ready ( browser : instance )
element = instance . find_elements ( css : '.modal input[name=name]' ) [ 0 ]
element . clear
element . send_keys ( data [ :name ] )
if data . key? ( :default_at_signup )
element = instance . find_elements ( css : '.modal select[name="default_at_signup"]' ) [ 0 ]
dropdown = Selenium :: WebDriver :: Support :: Select . new ( element )
if data [ :default_at_signup ] == true
dropdown . select_by ( :text , 'yes' )
else
dropdown . select_by ( :text , 'no' )
end
end
if data . key? ( :permission )
2017-10-01 12:25:52 +00:00
data [ :permission ] . each do | permission_name , permission_value |
2017-04-10 06:08:18 +00:00
if permission_value == false
uncheck (
browser : instance ,
css : " .modal [data-permission-name= \" #{ permission_name } \" ] " ,
)
else
check (
browser : instance ,
css : " .modal [data-permission-name= \" #{ permission_name } \" ] " ,
)
end
2017-10-01 12:25:52 +00:00
end
2016-09-07 06:47:31 +00:00
end
2018-10-12 08:28:37 +00:00
if data . key? ( :group_permissions )
data [ :group_permissions ] . each do | key , value |
value . each do | permission |
check (
browser : instance ,
css : " .modal input[name= \" group_ids:: #{ key } \" ][value= \" #{ permission } \" ] " ,
)
end
end
end
2016-09-07 06:47:31 +00:00
if data . key? ( :active )
element = instance . find_elements ( css : '.modal select[name="active"]' ) [ 0 ]
dropdown = Selenium :: WebDriver :: Support :: Select . new ( element )
if data [ :active ] == true
dropdown . select_by ( :text , 'active' )
else
dropdown . select_by ( :text , 'inactive' )
end
end
instance . find_elements ( css : '.modal button.js-submit' ) [ 0 ] . click
modal_disappear ( browser : instance )
2020-09-30 09:07:01 +00:00
element = instance . find_elements ( css : 'body' ) [ 0 ]
text = element . text
2021-05-12 11:37:44 +00:00
if text . match? ( %r{ #{ Regexp . quote ( data [ :name ] ) } } )
2020-09-30 09:07:01 +00:00
assert ( true , 'role created' )
modal_disappear ( browser : instance ) # wait until modal has gone
# add member
data [ :member ] & . each do | login |
instance . find_elements ( css : 'a[href="#manage"]' ) [ 0 ] . click
sleep 1
instance . find_elements ( css : '.content.active a[href="#manage/users"]' ) [ 0 ] . click
sleep 3
element = instance . find_elements ( css : '.content.active [name="search"]' ) [ 0 ]
element . clear
element . send_keys ( login )
sleep 3
2021-07-16 13:44:10 +00:00
# instance.find_elements(:css => '.content.active table [data-id]')[0].click
2020-09-30 09:07:01 +00:00
instance . execute_script ( '$(".content.active table [data-id] td").first().click()' )
sleep 3
2021-07-16 13:44:10 +00:00
# instance.find_elements(:css => 'label:contains(" ' + action[:name] + '")')[0].click
2020-09-30 09:07:01 +00:00
instance . execute_script ( %( $ ( 'label:contains ( " #{ data [ :name ] } " ) ' ) .first ( ) .click ( ) ) )
instance . find_elements ( css : '.modal button.js-submit' ) [ 0 ] . click
modal_disappear ( browser : instance )
2016-09-07 06:47:31 +00:00
end
2017-10-01 12:25:52 +00:00
end
2020-09-30 09:07:01 +00:00
sleep 1
true
2016-09-07 06:47:31 +00:00
end
2018-09-17 07:01:17 +00:00
= begin
report_profile_create (
browser : browser2 ,
data : {
name : 'some profile' + random ,
active : true
} ,
)
= end
def report_profile_create ( params = { } )
switch_window_focus ( params )
log ( 'report_profile_create' , params )
instance = params [ :browser ] || @browser
data = params [ :data ]
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : 'a[href="#manage"]' ,
2018-09-17 07:01:17 +00:00
mute_log : true ,
)
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.content.active a[href="#manage/report_profiles"]' ,
2018-09-17 07:01:17 +00:00
mute_log : true ,
)
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.content.active a.btn.primary[data-type="new"]' ,
2018-09-17 07:01:17 +00:00
mute_log : true ,
)
set (
browser : instance ,
css : '.modal input[name=name]' ,
value : data [ :name ] ,
mute_log : true ,
)
if data [ :active ] == false
select ( css : '.content.active .modal select[name="active"]' , value : 'inactive' )
end
sleep 0 . 5
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.content.active .modal .js-submit' ,
2018-09-17 07:01:17 +00:00
mute_log : true ,
)
modal_disappear
end
2016-05-25 07:19:45 +00:00
= begin
object_manager_attribute_create (
browser : browser2 ,
data : {
2018-09-15 16:22:56 +00:00
object : 'Ticket' , # optional, defaults to Ticket
2016-05-25 07:19:45 +00:00
name : 'field_name' + random ,
display : 'Display Name of Field' ,
2016-05-28 22:04:26 +00:00
data_type : 'Select' ,
2016-05-26 08:14:51 +00:00
data_option : {
options : {
'aa' = > 'AA' ,
'bb' = > 'BB' ,
} ,
2016-05-28 22:04:26 +00:00
default : 'abc' ,
} ,
} ,
error : 'already exists'
)
object_manager_attribute_create (
browser : browser2 ,
data : {
2018-09-15 16:22:56 +00:00
object : 'Ticket' , # optional, defaults to Ticket
2016-05-28 22:04:26 +00:00
name : 'field_name' + random ,
display : 'Display Name of Field' ,
data_type : 'Text' ,
data_option : {
default : 'abc' ,
2018-07-26 09:16:34 +00:00
maxlength : 20 ,
2016-05-28 22:04:26 +00:00
} ,
} ,
error : 'already exists'
)
object_manager_attribute_create (
browser : browser2 ,
data : {
2018-09-15 16:22:56 +00:00
object : 'Ticket' , # optional, defaults to Ticket
2016-05-28 22:04:26 +00:00
name : 'field_name' + random ,
display : 'Display Name of Field' ,
data_type : 'Integer' ,
data_option : {
default : '15' ,
min : 1 ,
max : 999999 ,
} ,
} ,
error : 'already exists'
)
object_manager_attribute_create (
browser : browser2 ,
data : {
2018-09-15 16:22:56 +00:00
object : 'Ticket' , # optional, defaults to Ticket
2016-05-28 22:04:26 +00:00
name : 'field_name' + random ,
display : 'Display Name of Field' ,
data_type : 'Datetime' ,
data_option : {
future : true ,
past : true ,
diff : 24 ,
} ,
} ,
error : 'already exists'
)
object_manager_attribute_create (
browser : browser2 ,
data : {
2018-09-15 16:22:56 +00:00
object : 'Ticket' , # optional, defaults to Ticket
2016-05-28 22:04:26 +00:00
name : 'field_name' + random ,
display : 'Display Name of Field' ,
data_type : 'Date' ,
data_option : {
future : true ,
past : true ,
diff : 24 ,
} ,
} ,
error : 'already exists'
)
object_manager_attribute_create (
browser : browser2 ,
data : {
2018-09-15 16:22:56 +00:00
object : 'Ticket' , # optional, defaults to Ticket
2016-05-28 22:04:26 +00:00
name : 'field_name' + random ,
display : 'Display Name of Field' ,
data_type : 'Boolean' ,
data_option : {
options : {
true : 'YES' ,
false : 'NO' ,
}
default : undefined ,
2016-05-26 08:14:51 +00:00
} ,
2016-05-25 07:19:45 +00:00
} ,
error : 'already exists'
)
= end
def object_manager_attribute_create ( params = { } )
switch_window_focus ( params )
log ( 'object_manager_attribute_create' , params )
instance = params [ :browser ] || @browser
data = params [ :data ]
2018-09-15 16:22:56 +00:00
data [ :object ] = data [ :object ] || 'Ticket'
raise 'invalid object parameter in object_manager_attribute_create' if %w[ Ticket User Organization Group ] . exclude? data [ :object ]
2018-07-26 09:16:34 +00:00
# make sure that required params are supplied
% i [ name display data_type ] . each do | s |
next if data . key? s
2018-10-09 06:17:41 +00:00
2018-07-26 09:16:34 +00:00
raise " missing required param #{ s } in object_manager_attribute_create() "
end
2016-05-25 07:19:45 +00:00
click (
2018-06-29 06:14:18 +00:00
browser : instance ,
css : 'a[href="#manage"]' ,
2016-05-25 07:19:45 +00:00
mute_log : true ,
)
click (
2018-06-29 06:14:18 +00:00
browser : instance ,
css : '.content.active a[href="#system/object_manager"]' ,
2016-05-25 07:19:45 +00:00
mute_log : true ,
)
2018-06-29 06:14:18 +00:00
watch_for (
2016-05-25 07:19:45 +00:00
browser : instance ,
2018-06-29 06:14:18 +00:00
css : '.content.active .js-new' ,
)
click (
browser : instance ,
2018-09-15 16:22:56 +00:00
css : " .content.active a[href=' # c- #{ data [ :object ] } '] " ,
mute_log : true ,
)
click (
browser : instance ,
css : " .content.active # c- #{ data [ :object ] } .js-new " ,
2016-05-25 07:19:45 +00:00
mute_log : true ,
)
2016-05-28 22:04:26 +00:00
2018-07-26 09:16:34 +00:00
object_manager_attribute_perform ( 'create' , params )
2016-05-25 07:19:45 +00:00
end
2017-04-30 13:14:17 +00:00
= begin
object_manager_attribute_update (
browser : browser2 ,
data : {
2018-09-15 16:22:56 +00:00
object : 'Ticket' , # optional, defaults to Ticket
2017-04-30 13:14:17 +00:00
name : 'field_name' + random ,
display : 'Display Name of Field' ,
data_type : 'Select' ,
data_option : {
options : {
'aa' = > 'AA' ,
'bb' = > 'BB' ,
} ,
default : 'abc' ,
} ,
} ,
error : 'already exists'
)
= end
def object_manager_attribute_update ( params = { } )
switch_window_focus ( params )
log ( 'object_manager_attribute_update' , params )
instance = params [ :browser ] || @browser
data = params [ :data ]
2018-09-15 16:22:56 +00:00
data [ :object ] = data [ :object ] || 'Ticket'
raise 'invalid object parameter in object_manager_attribute_update' if %w[ Ticket User Organization Group ] . exclude? data [ :object ]
2017-04-30 13:14:17 +00:00
click (
2018-06-29 06:14:18 +00:00
browser : instance ,
css : 'a[href="#manage"]' ,
2017-04-30 13:14:17 +00:00
mute_log : true ,
)
click (
2018-06-29 06:14:18 +00:00
browser : instance ,
css : '.content.active a[href="#system/object_manager"]' ,
2017-04-30 13:14:17 +00:00
mute_log : true ,
)
2018-06-29 06:14:18 +00:00
watch_for (
browser : instance ,
css : '.content.active .js-new' ,
)
2018-09-15 16:22:56 +00:00
click (
browser : instance ,
css : " .content.active a[href=' # c- #{ data [ :object ] } '] " ,
mute_log : true ,
)
instance . execute_script ( " $( \" .content.active # c- #{ data [ :object ] } td:contains(' #{ data [ :name ] } ') \" ).first().click() " )
2017-04-30 13:14:17 +00:00
2018-07-26 09:16:34 +00:00
object_manager_attribute_perform ( 'update' , params )
2017-04-30 13:14:17 +00:00
end
2016-05-26 08:14:51 +00:00
= begin
object_manager_attribute_delete (
browser : browser2 ,
data : {
2018-09-15 16:22:56 +00:00
object : 'Ticket' , # optional, defaults to Ticket
2016-05-26 08:14:51 +00:00
name : 'field_name' + random ,
} ,
)
= end
def object_manager_attribute_delete ( params = { } )
switch_window_focus ( params )
log ( 'object_manager_attribute_delete' , params )
2016-05-28 22:04:26 +00:00
instance = params [ :browser ] || @browser
data = params [ :data ]
2018-09-15 16:22:56 +00:00
data [ :object ] = data [ :object ] || 'Ticket'
raise 'invalid object parameter in object_manager_attribute_delete' if %w[ Ticket User Organization Group ] . exclude? data [ :object ]
2016-05-26 08:14:51 +00:00
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : 'a[href="#manage"]' ,
2016-05-26 08:14:51 +00:00
mute_log : true ,
)
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.content.active a[href="#system/object_manager"]' ,
2016-05-26 08:14:51 +00:00
mute_log : true ,
)
2018-09-15 16:22:56 +00:00
watch_for (
browser : instance ,
css : '.content.active .js-new' ,
)
click (
browser : instance ,
css : " .content.active a[href=' # c- #{ data [ :object ] } '] " ,
mute_log : true ,
)
2016-05-26 08:14:51 +00:00
sleep 4
2019-06-28 11:38:49 +00:00
instance . execute_script ( " $( \" .content.active # c- #{ data [ :object ] } td:contains(' #{ data [ :name ] } ') \" ).first().closest('tr').find('.js-delete').click() " )
2016-05-26 08:14:51 +00:00
end
= begin
object_manager_attribute_discard_changes (
browser : browser2 ,
)
= end
def object_manager_attribute_discard_changes ( params = { } )
switch_window_focus ( params )
log ( 'object_manager_attribute_discard_changes' , params )
instance = params [ :browser ] || @browser
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : 'a[href="#manage"]' ,
2016-05-26 08:14:51 +00:00
mute_log : true ,
)
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.content.active a[href="#system/object_manager"]' ,
2016-05-26 08:14:51 +00:00
mute_log : true ,
)
sleep 4
2016-09-27 17:46:23 +00:00
element = instance . find_elements ( css : '.content.active .js-discard' ) . first
2016-05-26 08:14:51 +00:00
element . click
watch_for_disappear (
browser : instance ,
2016-09-27 17:46:23 +00:00
css : '.content.active .js-discard' ,
2016-05-26 08:14:51 +00:00
)
end
2018-07-26 09:16:34 +00:00
= begin
Execute any pending migrations in the object attribute manager
object_manager_attribute_migrate (
browser : browser2 ,
)
= end
def object_manager_attribute_migrate ( params = { } )
switch_window_focus ( params )
log ( 'object_manager_attribute_migrate' , params )
instance = params [ :browser ] || @browser
watch_for (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.content.active' ,
value : 'Database Update required' ,
2018-07-26 09:16:34 +00:00
mute_log : true ,
)
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.content.active .tab-pane.active div.js-execute' ,
2018-07-26 09:16:34 +00:00
mute_log : true ,
)
modal_ready (
browser : instance ,
)
title_text = instance . find_elements ( css : '.modal .modal-title' ) . first . text
2018-10-15 13:43:16 +00:00
if [ 'Zammad is restarting...' , 'Zammad need a restart!' ] . include? ( title_text )
2018-07-26 09:16:34 +00:00
# in the complex case, wait for server to restart
modal_disappear (
browser : instance ,
timeout : 7 . minutes ,
)
elsif title_text == 'Config has changed'
# in the simple case, just click the submit button
click (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.modal .js-submit' ,
2018-07-26 09:16:34 +00:00
mute_log : true ,
)
else
raise " Unknown title text \" #{ title_text } \" found when trying to update database "
end
sleep 5
watch_for (
2018-12-19 17:31:51 +00:00
browser : instance ,
css : '.content.active' ,
2018-07-26 09:16:34 +00:00
mute_log : true ,
)
end
2016-06-02 06:58:10 +00:00
= begin
tags_verify (
browser : browser2 ,
tags : {
'tag 1' = > true ,
'tag 2' = > true ,
'tag 3' = > false ,
} ,
)
= end
def tags_verify ( params = { } )
switch_window_focus ( params )
log ( 'tags_verify' , params )
instance = params [ :browser ] || @browser
tags = instance . find_elements ( { css : '.content.active .js-tag' } )
assert ( tags )
assert ( tags [ 0 ] )
tags_found = { }
2017-11-23 08:09:44 +00:00
params [ :tags ] . each_key do | key |
2016-06-02 06:58:10 +00:00
tags_found [ key ] = false
2017-10-01 12:25:52 +00:00
end
2016-06-02 06:58:10 +00:00
2017-10-01 12:25:52 +00:00
tags . each do | element |
2016-06-02 06:58:10 +00:00
text = element . text
if tags_found . key? ( text )
tags_found [ text ] = true
else
assert ( false , " tag exists but is not in check to verify ' #{ text } ' " )
end
2017-10-01 12:25:52 +00:00
end
params [ :tags ] . each do | key , value |
2016-06-02 06:58:10 +00:00
assert_equal ( value , tags_found [ key ] , " tag ' #{ key } ' " )
2017-10-01 12:25:52 +00:00
end
2016-06-02 06:58:10 +00:00
end
2015-03-01 23:16:36 +00:00
def quote ( string )
string_quoted = string
2021-05-12 11:37:44 +00:00
string_quoted . gsub! ( %r{ & } , '&' )
string_quoted . gsub! ( %r{ < } , '<' )
string_quoted . gsub! ( %r{ > } , '>' )
2015-03-01 23:16:36 +00:00
string_quoted
end
2015-11-29 15:39:56 +00:00
def switch_window_focus ( params )
instance = params [ :browser ] || @browser
if instance != @last_used_browser
log ( 'switch browser window focus' , { } )
instance . switch_to . window ( instance . window_handles . first )
end
@last_used_browser = instance
end
2016-03-15 11:47:26 +00:00
def log ( method , params = { } )
2016-06-14 13:58:16 +00:00
begin
instance = params [ :browser ] || @browser
if instance
logs = instance . manage . logs . get ( :browser )
2017-10-01 12:25:52 +00:00
logs . each do | log |
2021-05-12 11:37:44 +00:00
next if log . level == 'WARNING' && log . message =~ %r{ Declaration \ sdropped. } # ignore ff css warnings
2018-10-09 06:17:41 +00:00
2016-06-14 13:58:16 +00:00
time = Time . zone . parse ( Time . zone . at ( log . timestamp / 1000 ) . to_datetime . to_s )
puts " #{ time } / #{ log . level } : #{ log . message } "
2017-10-01 12:25:52 +00:00
end
2016-06-14 13:58:16 +00:00
end
2020-04-14 08:14:14 +00:00
rescue
2017-03-03 05:12:02 +00:00
# failed to get logs
2016-06-14 13:25:01 +00:00
end
2018-04-12 14:57:37 +00:00
return if ! DEBUG
2015-11-17 09:03:51 +00:00
return if params [ :mute_log ]
2018-10-09 06:17:41 +00:00
2015-04-27 19:56:07 +00:00
puts " #{ Time . zone . now } / #{ method } : #{ params . inspect } "
2015-03-08 01:06:57 +00:00
end
2018-03-29 11:58:39 +00:00
private
def add_tree_options ( instance : , options : )
# first level entries have to get added in regular order
options . each_key . with_index do | option , index |
if index != 0
element = instance . find_elements ( css : '.modal .js-treeTable .js-addRow' ) [ index - 1 ]
element . click
end
element = instance . find_elements ( css : '.modal .js-treeTable .js-key' ) [ index ]
element . clear
element . send_keys ( option )
end
add_sub_tree_recursion (
instance : instance ,
2018-12-19 17:31:51 +00:00
options : options ,
2018-03-29 11:58:39 +00:00
)
end
def add_sub_tree_recursion ( instance : , options : , offset : 0 )
options . each_value . inject ( offset ) do | child_offset , children |
child_offset += 1
# put your recursion glasses on 8-)
add_sub_tree_options (
instance : instance ,
options : children ,
offset : child_offset ,
)
end
end
def add_sub_tree_options ( instance : , options : , offset : )
# sub level entries have to get added in reversed order
level_options = options . to_a . reverse . to_h . keys
level_options . each do | option |
# sub level entries have to get added via 'add child row' link
click_index = offset - 1
element = instance . find_elements ( css : '.modal .js-treeTable .js-addChild' ) [ click_index ]
element . click
element = instance . find_elements ( css : '.modal .js-treeTable .js-key' ) [ offset ]
element . clear
element . send_keys ( option )
sleep 0 . 25
end
add_sub_tree_recursion (
instance : instance ,
options : options ,
offset : offset ,
)
end
2018-05-14 09:24:54 +00:00
def token_verify ( css , value )
original_element = @browser . find_element ( :css , css )
elem = original_element . find_element ( xpath : '../input[contains(@class, "token-input")]' )
elem . send_keys value
elem . send_keys :enter
watch_for (
2018-12-19 17:31:51 +00:00
xpath : '../*/span[contains(@class,"token-label")]' ,
value : value ,
2018-05-14 09:24:54 +00:00
container : original_element
)
end
2018-05-15 16:15:38 +00:00
def toggle_checkbox ( scope , value )
checkbox = scope . find_element ( css : " input[value= #{ value } ] " )
@browser
. action
. move_to ( checkbox )
. click
. perform
end
def checkbox_is_selected ( scope , value )
scope . find_element ( css : " input[value= #{ value } ] " ) . property ( 'checked' )
end
2018-07-04 14:56:16 +00:00
2018-11-28 16:12:24 +00:00
= begin
Switch the current logged in user ' s profile language to a new language
switch_language (
browser : browser2 ,
data : {
language : 'Deutsch'
} ,
)
IMPORTANT REMINDER ! At the end of tests , the caller must manually set the language back to English again :
switch_language (
browser : browser2 ,
data : {
language : 'English (United States)'
} ,
)
Failure to switch back to English will cause large amounts of subsequent tests to fail due to the UI language differences .
= end
def switch_language ( params = { } )
switch_window_focus ( params )
log ( 'switch_language' , params )
instance = params [ :browser ] || @browser
data = params [ :data ]
click ( browser : instance , css : '#navigation .user-menu .js-avatar' )
click ( browser : instance , css : '#navigation .user-menu a[href="#profile"]' )
select (
browser : instance ,
2018-12-19 17:31:51 +00:00
css : '.content.active .searchableSelect-shadow' ,
value : data [ :language ] ,
2018-11-28 16:12:24 +00:00
)
click ( browser : instance , css : '.content.active .btn--primary' )
watch_for (
browser : instance ,
2018-12-19 17:31:51 +00:00
css : '#notify' ,
2018-11-28 16:12:24 +00:00
)
end
2018-07-04 14:56:16 +00:00
= begin
Retrieve a hash of all the avaiable Zammad settings and their current values .
settings = fetch_settings ( )
= end
def fetch_settings
url = URI . parse ( browser_url )
2020-09-30 09:07:01 +00:00
req = Net :: HTTP :: Get . new ( " #{ browser_url } /api/v1/settings/ " )
2021-08-17 12:10:02 +00:00
req . basic_auth ( 'admin@example.com' , 'test' )
2018-07-04 14:56:16 +00:00
res = Net :: HTTP . start ( url . host , url . port ) do | http |
http . request ( req )
end
raise " HTTP error #{ res . code } while fetching #{ browser_url } /api/v1/settings/ " if res . code != '200'
2018-10-09 06:17:41 +00:00
2018-07-04 14:56:16 +00:00
JSON . parse ( res . body )
end
= begin
Enable or disable Zammad experiemental features remotely .
set_setting ( 'ui_ticket_zoom_attachments_preview' , true )
= end
def set_setting ( name , value )
name_to_id = fetch_settings . map { | s | [ s [ 'name' ] , s [ 'id' ] ] } . to_h
id = name_to_id [ name ]
url = URI . parse ( browser_url )
req = Net :: HTTP :: Put . new ( " #{ browser_url } /api/v1/settings/ #{ id } " )
req [ 'Content-Type' ] = 'application/json'
2021-08-17 12:10:02 +00:00
req . basic_auth ( 'admin@example.com' , 'test' )
2018-07-04 14:56:16 +00:00
req . body = { 'state_current' = > { 'value' = > value } } . to_json
res = Net :: HTTP . start ( url . host , url . port ) do | http |
http . request ( req )
end
raise " HTTP error #{ res . code } while POSTing to #{ browser_url } /api/v1/settings/ " if res . code != '200'
end
2018-07-26 09:16:34 +00:00
= begin
Helper method for both object_manager_attribute_create and object_manager_attribute_update
= end
def object_manager_attribute_perform ( action = 'create' , params = { } )
instance = params [ :browser ] || @browser
data = params [ :data ]
modal_ready ( browser : instance )
if action == 'create'
set (
browser : instance ,
css : '.modal input[name=name]' ,
value : data [ :name ] ,
mute_log : true ,
)
end
if data [ :display ]
set (
browser : instance ,
css : '.modal input[name=display]' ,
value : data [ :display ] ,
mute_log : true ,
)
end
if data [ :data_type ]
select (
browser : instance ,
css : '.modal select[name="data_type"]' ,
value : data [ :data_type ] ,
mute_log : true ,
)
end
if data [ :data_option ]
if data [ :data_option ] [ :options ]
2020-07-13 12:46:08 +00:00
case data [ :data_type ]
when 'Boolean'
2018-07-26 09:16:34 +00:00
# rubocop:disable Lint/BooleanSymbol
element = instance . find_elements ( css : '.modal .js-valueTrue' ) . first
element . clear
element . send_keys ( data [ :data_option ] [ :options ] [ :true ] )
element = instance . find_elements ( css : '.modal .js-valueFalse' ) . first
element . clear
element . send_keys ( data [ :data_option ] [ :options ] [ :false ] )
# rubocop:enable Lint/BooleanSymbol
2020-07-13 12:46:08 +00:00
when 'Tree Select'
2018-07-26 09:16:34 +00:00
add_tree_options (
instance : instance ,
options : data [ :data_option ] [ :options ] ,
)
else
2018-08-23 07:44:32 +00:00
if action == 'update'
# first clear all existing entries
loop do
target = {
browser : instance ,
2018-12-19 17:31:51 +00:00
css : '.modal .js-Table .js-remove' ,
2018-08-23 07:44:32 +00:00
mute_log : true ,
}
break if ! instance . find_elements ( css : target [ :css ] ) [ 0 ]
2018-10-09 06:17:41 +00:00
2018-08-23 07:44:32 +00:00
click ( target )
end
sleep 1
2018-07-26 09:16:34 +00:00
end
# then populate the table with the new values
data [ :data_option ] [ :options ] . each do | key , value |
element = instance . find_elements ( css : '.modal .js-Table .js-key' ) . last
element . clear
element . send_keys ( key )
element = instance . find_elements ( css : '.modal .js-Table .js-value' ) . last
element . clear
element . send_keys ( value )
element = instance . find_elements ( css : '.modal .js-Table .js-add' ) [ 0 ]
element . click
end
end
end
% i [ default min max diff ] . each do | key |
next if ! data [ :data_option ] . key? ( key )
2018-10-09 06:17:41 +00:00
2018-07-26 09:16:34 +00:00
element = instance . find_elements ( css : " .modal [name= \" data_option:: #{ key } \" ] " ) . first
element . clear
element . send_keys ( data [ :data_option ] [ key ] )
end
% i [ future past ] . each do | key |
next if ! data [ :data_option ] . key? ( key )
2018-10-09 06:17:41 +00:00
2018-07-26 09:16:34 +00:00
select (
browser : instance ,
css : " .modal select[name= \" data_option:: #{ key } \" ] " ,
value : data [ :data_option ] [ key ] ,
mute_log : true ,
)
end
% i [ maxlength ] . each do | key |
next if ! data [ :data_option ] . key? ( key )
2018-10-09 06:17:41 +00:00
2018-07-26 09:16:34 +00:00
set (
browser : instance ,
css : " .modal input[name= \" data_option:: #{ key } \" ] " ,
value : data [ :data_option ] [ key ] ,
mute_log : true ,
)
end
end
if params [ :do_not_submit ]
assert ( true , " attribute #{ action } d without submit " )
return true
end
instance . find_elements ( css : '.modal button.js-submit' ) [ 0 ] . click
if params [ :error ]
sleep 4
watch_for (
2018-12-19 17:31:51 +00:00
css : '.modal' ,
2018-07-26 09:16:34 +00:00
value : params [ :error ] ,
)
click (
browser : instance ,
2018-12-19 17:31:51 +00:00
css : '.modal .js-close' ,
2018-07-26 09:16:34 +00:00
)
modal_disappear ( browser : instance )
return
end
2018-10-15 13:43:16 +00:00
modal_disappear ( browser : instance )
2018-07-26 09:16:34 +00:00
11 . times do
element = instance . find_elements ( css : 'body' ) [ 0 ]
text = element . text
2021-05-12 11:37:44 +00:00
if text . match? ( %r{ #{ Regexp . quote ( data [ :name ] ) } } )
2018-07-26 09:16:34 +00:00
assert ( true , 'object manager attribute updated' )
sleep 1
return true
end
sleep 1
end
screenshot ( browser : instance , comment : " object_manager_attribute_ #{ action } _failed " )
raise " object_manager_attribute_ #{ action } _failed "
end
2021-06-15 06:26:52 +00:00
def check_alert ( params = { } )
instance = params [ :browser ] || @browser
tries = 5
begin
alert = instance . switch_to . alert
2021-07-16 13:29:38 +00:00
alert . dismiss
2021-06-15 06:26:52 +00:00
rescue e
tries -= 1
sleep 0 . 5
retry if tries . positive?
raise e
end
end
= begin
This function waits for ajax requests and object form flow to be done
await_empty_ajax_queue
= end
def await_empty_ajax_queue ( params = { } )
return if params [ :ajax ] == false
instance = params [ :browser ] || @browser
10 . times do
sleep 0 . 5
break if instance . execute_script ( 'return typeof(App) === "undefined"' )
break if instance . execute_script ( 'return App.Ajax.queue().length' ) . zero?
end
end
= begin
This function waits for a text to be ready in the dom . By default it searches in the active content .
await_text ( text : 'New Ticket' )
await_text ( text : 'New Ticket' , container : 'body' )
= end
def await_text ( params )
return if params [ :ajax ] == false
instance = params [ :browser ] || @browser
container = '.content.active'
if params [ :container ]
container = params [ :container ]
end
20 . times do
log ( 'await_text' , params )
break if instance . execute_script ( " return $( \" #{ container } :contains(' #{ params [ :text ] } ') \" ).length " ) . positive?
sleep 0 . 5
end
end
= begin
This function waits for the overview_counter to return a specific result .
await_overview_counter ( view : '#ticket/view/all_unassigned' , count : overview_counter_before [ '#ticket/view/all_unassigned' ] - 2 )
= end
def await_overview_counter ( params )
result = nil
40 . times do
result = overview_counter
if result [ params [ :view ] ] != params [ :count ]
sleep 0 . 5
next
end
break
end
assert_equal ( params [ :count ] , result [ params [ :view ] ] )
end
= begin
This function waits for a search result to be available in the global search .
It can help to verify if a user is indexed in elastic search .
await_global_search ( query : 'customer 1 firstname' )
= end
def await_global_search ( params )
instance = params [ :browser ] || @browser
30 . times do
log ( 'await_global_search' , params )
set (
css : 'input#global-search' ,
value : params [ :query ] ,
)
break if instance . execute_script ( " return $( \" ul.global-search-result:visible:contains(' #{ params [ :query ] } ') \" ).length " ) == 1
sleep 0 . 5
end
set (
css : 'input#global-search' ,
value : '' ,
)
end
2015-04-27 14:15:29 +00:00
end