browser_test_helper.rb 99 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842
  1. ENV['RAILS_ENV'] = 'test'
  2. # rubocop:disable HandleExceptions, NonLocalExitFromIterator, Style/GuardClause, Lint/MissingCopEnableDirective
  3. require File.expand_path('../config/environment', __dir__)
  4. require 'selenium-webdriver'
  5. class TestCase < Test::Unit::TestCase
  6. DEBUG = true
  7. def browser
  8. ENV['BROWSER'] || 'firefox'
  9. end
  10. def profile
  11. browser_profile = nil
  12. if browser == 'firefox'
  13. browser_profile = Selenium::WebDriver::Firefox::Profile.new
  14. browser_profile['intl.locale.matchOS'] = false
  15. browser_profile['intl.accept_languages'] = 'en-US'
  16. browser_profile['general.useragent.locale'] = 'en-US'
  17. # currently console log not working for firefox
  18. # https://github.com/SeleniumHQ/selenium/issues/1161
  19. #browser_profile['loggingPref'] = { browser: :all }
  20. elsif browser == 'chrome'
  21. # profile are only working on remote selenium
  22. if ENV['REMOTE_URL']
  23. browser_profile = Selenium::WebDriver::Chrome::Profile.new
  24. browser_profile['intl.accept_languages'] = 'en'
  25. browser_profile['loggingPref'] = { browser: :all }
  26. end
  27. end
  28. browser_profile
  29. end
  30. def browser_support_cookies
  31. if browser.match?(/(internet_explorer|ie)/i)
  32. return false
  33. end
  34. true
  35. end
  36. def browser_url
  37. ENV['BROWSER_URL'] || 'http://localhost:3000'
  38. end
  39. def browser_instance
  40. @browsers ||= {}
  41. if ENV['REMOTE_URL'].blank?
  42. local_browser = Selenium::WebDriver.for(browser.to_sym, profile: profile)
  43. @browsers[local_browser.hash] = local_browser
  44. browser_instance_preferences(local_browser)
  45. return local_browser
  46. end
  47. # avoid "Cannot read property 'get_Current' of undefined" issues
  48. (1..5).each do |count|
  49. begin
  50. local_browser = browser_instance_remote
  51. break
  52. rescue
  53. wait_until_ready = rand(5..13)
  54. sleep wait_until_ready
  55. log('browser_instance', { rescure: true, count: count, sleep: wait_until_ready })
  56. end
  57. end
  58. local_browser
  59. end
  60. def browser_instance_remote
  61. caps = Selenium::WebDriver::Remote::Capabilities.send(browser)
  62. if ENV['BROWSER_OS']
  63. caps.platform = ENV['BROWSER_OS']
  64. end
  65. if ENV['BROWSER_VERSION']
  66. caps.version = ENV['BROWSER_VERSION']
  67. end
  68. local_browser = Selenium::WebDriver.for(
  69. :remote,
  70. url: ENV['REMOTE_URL'],
  71. desired_capabilities: caps,
  72. )
  73. @browsers[local_browser.hash] = local_browser
  74. browser_instance_preferences(local_browser)
  75. # upload files from remote dir
  76. local_browser.file_detector = lambda do |args|
  77. str = args.first.to_s
  78. str if File.file?(str)
  79. end
  80. local_browser
  81. end
  82. def browser_instance_close(local_browser)
  83. return if !@browsers[local_browser.hash]
  84. @browsers.delete(local_browser.hash)
  85. local_browser.quit
  86. end
  87. def browser_instance_preferences(local_browser)
  88. browser_width = ENV['BROWSER_WIDTH'] || 1024
  89. browser_height = ENV['BROWSER_HEIGHT'] || 800
  90. local_browser.manage.window.resize_to(browser_width, browser_height)
  91. if !ENV['REMOTE_URL']&.match?(/saucelabs|(grid|ci)\.(zammad\.org|znuny\.com)/i)
  92. if @browsers.count == 1
  93. local_browser.manage.window.move_to(0, 0)
  94. else
  95. local_browser.manage.window.move_to(browser_width, 0)
  96. end
  97. end
  98. local_browser.manage.timeouts.implicit_wait = 3 # seconds
  99. end
  100. def teardown
  101. return if !@browsers
  102. @browsers.each_value do |local_browser|
  103. screenshot(browser: local_browser, comment: 'teardown')
  104. browser_instance_close(local_browser)
  105. end
  106. end
  107. def screenshot(params)
  108. instance = params[:browser] || @browser
  109. comment = params[:comment] || ''
  110. filename = "tmp/#{Time.zone.now.strftime('screenshot_%Y_%m_%d__%H_%M_%S_%L')}_#{comment}#{instance.hash}.png"
  111. log('screenshot', { filename: filename })
  112. instance.save_screenshot(filename)
  113. end
  114. =begin
  115. username = login(
  116. browser: browser1,
  117. username: 'someuser',
  118. password: 'somepassword',
  119. url: 'some url', # optional, in case of aleady opened brower a reload is done because url is called again
  120. remember_me: true, # optional
  121. auto_wizard: false, # optional, in case of auto wizard, skip login
  122. success: false, #optional
  123. )
  124. =end
  125. def login(params)
  126. switch_window_focus(params)
  127. log('login', params)
  128. instance = params[:browser] || @browser
  129. if params[:url]
  130. instance.get(params[:url])
  131. end
  132. # submit logs anyway
  133. instance.execute_script('App.Track.force()')
  134. element = instance.find_elements(css: '#login input[name="username"]')[0]
  135. if !element
  136. if params[:auto_wizard]
  137. watch_for(
  138. browser: instance,
  139. css: 'body',
  140. value: 'auto wizard is enabled',
  141. timeout: 10,
  142. )
  143. location(url: "#{browser_url}/#getting_started/auto_wizard")
  144. sleep 10
  145. login = instance.find_elements(css: '.user-menu .user a')[0].attribute('title')
  146. if login != params[:username]
  147. screenshot(browser: instance, comment: 'auto wizard login failed')
  148. raise 'auto wizard login failed'
  149. end
  150. assert(true, 'auto wizard login ok')
  151. clues_close(
  152. browser: instance,
  153. optional: true,
  154. )
  155. return
  156. end
  157. screenshot(browser: instance, comment: 'login_failed')
  158. raise 'No login box found'
  159. end
  160. element.clear
  161. element.send_keys(params[:username])
  162. element = instance.find_elements(css: '#login input[name="password"]')[0]
  163. element.clear
  164. element.send_keys(params[:password])
  165. if params[:remember_me]
  166. instance.find_elements(css: '#login .checkbox-replacement')[0].click
  167. end
  168. instance.find_elements(css: '#login button')[0].click
  169. sleep 4
  170. login_failed = false
  171. if !instance.find_elements(css: '.user-menu .user a')[0]
  172. login_failed = true
  173. else
  174. login = instance.find_elements(css: '.user-menu .user a')[0].attribute('title')
  175. if login != params[:username]
  176. login_failed = true
  177. end
  178. end
  179. if login_failed
  180. if params[:success] == false
  181. assert(true, 'login not successfull, like wanted')
  182. return true
  183. end
  184. screenshot(browser: instance, comment: 'login_failed')
  185. raise 'login failed'
  186. end
  187. if params[:success] == false
  188. raise 'login successfull but should not'
  189. end
  190. clues_close(
  191. browser: instance,
  192. optional: true,
  193. )
  194. assert(true, 'login ok')
  195. login
  196. end
  197. =begin
  198. logout(
  199. browser: browser1
  200. )
  201. =end
  202. def logout(params = {})
  203. switch_window_focus(params)
  204. log('logout', params)
  205. instance = params[:browser] || @browser
  206. click(
  207. browser: instance,
  208. css: 'a[href="#current_user"]',
  209. mute_log: true,
  210. )
  211. click(
  212. browser: instance,
  213. css: 'a[href="#logout"]',
  214. mute_log: true,
  215. )
  216. 5.times do
  217. sleep 1
  218. login = instance.find_elements(css: '#login')[0]
  219. next if !login
  220. assert(true, 'logout ok')
  221. return
  222. end
  223. screenshot(browser: instance, comment: 'logout_failed')
  224. raise 'no login box found, seems logout was not successfully!'
  225. end
  226. =begin
  227. clues_close(
  228. browser: browser1,
  229. optional: false,
  230. )
  231. =end
  232. def clues_close(params = {})
  233. switch_window_focus(params)
  234. log('clues_close', params)
  235. instance = params[:browser] || @browser
  236. clues = instance.find_elements(css: '.js-modal--clue .js-close')[0]
  237. if !params[:optional] && !clues
  238. screenshot(browser: instance, comment: 'no_clues')
  239. raise 'Unable to closes clues, no clues found!'
  240. end
  241. return if !clues
  242. instance.execute_script("$('.js-modal--clue .js-close').click()")
  243. assert(true, 'clues closed')
  244. sleep 1
  245. end
  246. =begin
  247. notify_close(
  248. browser: browser1,
  249. optional: false,
  250. )
  251. =end
  252. def notify_close(params = {})
  253. switch_window_focus(params)
  254. log('notify_close', params)
  255. instance = params[:browser] || @browser
  256. notify = instance.find_elements(css: '.noty_inline_layout_container.i-am-new')[0]
  257. if !params[:optional] && !notify
  258. screenshot(browser: instance, comment: 'no_notify')
  259. raise 'Unable to closes notify, no notify found!'
  260. end
  261. return if !notify
  262. notify.click
  263. assert(true, 'notify closed')
  264. sleep 1
  265. end
  266. =begin
  267. location(
  268. browser: browser1,
  269. url: 'http://someurl',
  270. )
  271. =end
  272. def location(params)
  273. switch_window_focus(params)
  274. log('location', params)
  275. instance = params[:browser] || @browser
  276. instance.get(params[:url])
  277. # check if reload was successfull
  278. if !instance.find_elements(css: 'body')[0] || instance.find_elements(css: 'body')[0].text =~ /unavailable or too busy/i
  279. instance.navigate.refresh
  280. end
  281. end
  282. =begin
  283. location_check(
  284. browser: browser1,
  285. url: 'http://someurl',
  286. )
  287. =end
  288. def location_check(params)
  289. switch_window_focus(params)
  290. log('location_check', params)
  291. instance = params[:browser] || @browser
  292. sleep 0.7
  293. current_url = instance.current_url
  294. if !current_url.match?(/#{Regexp.quote(params[:url])}/)
  295. screenshot(browser: instance, comment: 'location_check_failed')
  296. raise "url #{current_url} is not matching #{params[:url]}"
  297. end
  298. assert(true, "url #{current_url} is matching #{params[:url]}")
  299. end
  300. =begin
  301. reload(
  302. browser: browser1,
  303. )
  304. =end
  305. def reload(params = {})
  306. switch_window_focus(params)
  307. log('reload', params)
  308. instance = params[:browser] || @browser
  309. instance.navigate.refresh
  310. # check if reload was successfull
  311. if !instance.find_elements(css: 'body')[0] || instance.find_elements(css: 'body')[0].text =~ /unavailable or too busy/i
  312. instance.navigate.refresh
  313. end
  314. screenshot(browser: instance, comment: 'reload_after')
  315. end
  316. =begin
  317. click(
  318. browser: browser1,
  319. css: '.some_class',
  320. fast: false, # do not wait
  321. wait: 1, # wait 1 sec.
  322. )
  323. click(
  324. browser: browser1,
  325. text: '.partial_link_text',
  326. fast: false, # do not wait
  327. wait: 1, # wait 1 sec.
  328. )
  329. =end
  330. def click(params)
  331. switch_window_focus(params)
  332. log('click', params)
  333. instance = params[:browser] || @browser
  334. if params.include?(:css)
  335. param_key = :css
  336. find_element_key = :css
  337. else
  338. param_key = :text
  339. find_element_key = :partial_link_text
  340. sleep 0.5
  341. end
  342. begin
  343. elements = instance.find_elements(find_element_key => params[param_key])
  344. .tap { |e| e.slice!(1..-1) unless params[:all] }
  345. if elements.empty?
  346. return if params[:only_if_exists] == true
  347. raise "No such element '#{params[param_key]}'"
  348. end
  349. # a clumsy substitute for elements.each(&:click)
  350. # (we need to refresh element references after each element.click
  351. # because if clicks alter page content,
  352. # subsequent element.clicks will raise a StaleElementReferenceError)
  353. elements.length.times do |i|
  354. instance.find_elements(find_element_key => params[param_key])[i].try(:click)
  355. end
  356. rescue => e
  357. raise e if (fail_count ||= 0).positive?
  358. fail_count += 1
  359. log('click', { rescure: true })
  360. sleep 0.5
  361. retry
  362. end
  363. sleep 0.2 if !params[:fast]
  364. sleep params[:wait] if params[:wait]
  365. end
  366. =begin
  367. scroll_to(
  368. browser: browser1,
  369. position: 'top', # botton
  370. css: '.some_class',
  371. )
  372. =end
  373. def scroll_to(params)
  374. switch_window_focus(params)
  375. log('scroll_to', params)
  376. instance = params[:browser] || @browser
  377. position = 'true'
  378. if params[:position] == 'botton'
  379. position = 'false'
  380. end
  381. execute(
  382. browser: instance,
  383. js: "\$('#{params[:css]}').get(0).scrollIntoView(#{position})",
  384. mute_log: params[:mute_log]
  385. )
  386. sleep 0.3
  387. screenshot(browser: instance, comment: 'scroll_to_after')
  388. end
  389. =begin
  390. modal_close(
  391. browser: browser1,
  392. )
  393. =end
  394. def modal_close(params = {})
  395. switch_window_focus(params)
  396. log('modal_close', params)
  397. instance = params[:browser] || @browser
  398. element = instance.find_elements(css: '.modal .js-close')[0]
  399. raise "No such modal to close #{params.inspect}" if !element
  400. element.click
  401. end
  402. =begin
  403. modal_ready(
  404. browser: browser1,
  405. )
  406. =end
  407. def modal_ready(params = {})
  408. switch_window_focus(params)
  409. log('modal_ready', params)
  410. instance = params[:browser] || @browser
  411. sleep 3
  412. end
  413. =begin
  414. modal_disappear(
  415. browser: browser1,
  416. timeout: 12, # default 8
  417. )
  418. =end
  419. def modal_disappear(params = {})
  420. switch_window_focus(params)
  421. log('modal_disappear', params)
  422. instance = params[:browser] || @browser
  423. watch_for_disappear(
  424. browser: instance,
  425. css: '.modal',
  426. timeout: params[:timeout] || 8,
  427. )
  428. end
  429. =begin
  430. execute(
  431. browser: browser1,
  432. js: '.some_class',
  433. )
  434. =end
  435. def execute(params)
  436. switch_window_focus(params)
  437. log('js', params)
  438. instance = params[:browser] || @browser
  439. if params[:js]
  440. return instance.execute_script(params[:js])
  441. end
  442. raise "Invalid execute params #{params.inspect}"
  443. end
  444. =begin
  445. exists(
  446. browser: browser1,
  447. css: '.some_class',
  448. )
  449. exists(
  450. displayed: false, # true|false
  451. browser: browser1,
  452. css: '.some_class',
  453. )
  454. =end
  455. def exists(params)
  456. switch_window_focus(params)
  457. log('exists', params)
  458. instance = params[:browser] || @browser
  459. if !instance.find_elements(css: params[:css])[0]
  460. screenshot(browser: instance, comment: 'exists_failed')
  461. raise "#{params[:css]} dosn't exist, but should"
  462. end
  463. if params.key?(:displayed)
  464. if params[:displayed] == true && !instance.find_elements(css: params[:css])[0].displayed?
  465. raise "#{params[:css]} is not displayed, but should"
  466. end
  467. if params[:displayed] == false && instance.find_elements(css: params[:css])[0].displayed?
  468. raise "#{params[:css]} is displayed, but should not"
  469. end
  470. end
  471. true
  472. end
  473. =begin
  474. exists_not(
  475. browser: browser1,
  476. css: '.some_class',
  477. )
  478. =end
  479. def exists_not(params)
  480. switch_window_focus(params)
  481. log('exists_not', params)
  482. instance = params[:browser] || @browser
  483. if instance.find_elements(css: params[:css])[0]
  484. screenshot(browser: instance, comment: 'exists_not_failed')
  485. raise "#{params[:css]} exists but should not"
  486. end
  487. true
  488. end
  489. =begin
  490. set(
  491. browser: browser1,
  492. css: '.some_class',
  493. value: true,
  494. slow: false,
  495. blur: true, # default false
  496. clear: true, # todo | default: true
  497. no_click: true,
  498. )
  499. =end
  500. def set(params)
  501. switch_window_focus(params)
  502. log('set', params)
  503. instance = params[:browser] || @browser
  504. element = instance.find_elements(css: params[:css])[0]
  505. if !params[:no_click]
  506. element.click
  507. end
  508. element.clear
  509. begin
  510. if !params[:slow]
  511. element.send_keys(params[:value])
  512. else
  513. element.send_keys('')
  514. keys = params[:value].to_s.split('')
  515. keys.each do |key|
  516. instance.action.send_keys(key).perform
  517. end
  518. end
  519. rescue => e
  520. sleep 0.5
  521. # just try again
  522. log('set', { rescure: true })
  523. element = instance.find_elements(css: params[:css])[0]
  524. raise "No such element '#{params[:css]}'" if !element
  525. if !params[:slow]
  526. element.send_keys(params[:value])
  527. else
  528. element.send_keys('')
  529. keys = params[:value].to_s.split('')
  530. keys.each do |key|
  531. instance.action.send_keys(key).perform
  532. end
  533. end
  534. end
  535. # it's not working stable with ff via selenium, use js
  536. if browser =~ /firefox/i && params[:css] =~ /\[data-name=/
  537. log('set_ff_trigger_workaround', params)
  538. instance.execute_script("$('#{params[:css]}').trigger('focusout')")
  539. end
  540. if params[:blur]
  541. instance.execute_script("$('#{params[:css]}').blur()")
  542. end
  543. sleep 0.2
  544. end
  545. =begin
  546. select(
  547. browser: browser1,
  548. css: '.some_class',
  549. value: 'Some Value',
  550. deselect_all: false, # default false
  551. )
  552. =end
  553. def select(params)
  554. switch_window_focus(params)
  555. log('select', params)
  556. instance = params[:browser] || @browser
  557. # searchable select
  558. element = instance.find_elements(css: "#{params[:css]}.js-shadow")[0]
  559. if element
  560. element = instance.find_elements(css: "#{params[:css]}.js-shadow + .js-input")[0]
  561. element.click
  562. element.clear
  563. sleep 0.2
  564. element.send_keys(params[:value])
  565. sleep 0.2
  566. element.send_keys(:enter)
  567. sleep 0.2
  568. return
  569. end
  570. # native select
  571. begin
  572. element = instance.find_elements(css: params[:css])[0]
  573. dropdown = Selenium::WebDriver::Support::Select.new(element)
  574. if params[:deselect_all]
  575. dropdown.deselect_all
  576. end
  577. dropdown.select_by(:text, params[:value])
  578. #puts "select - #{params.inspect}"
  579. rescue
  580. sleep 0.4
  581. # just try again
  582. log('select', { rescure: true })
  583. element = instance.find_elements(css: params[:css])[0]
  584. dropdown = Selenium::WebDriver::Support::Select.new(element)
  585. if params[:deselect_all]
  586. dropdown.deselect_all
  587. end
  588. dropdown.select_by(:text, params[:value])
  589. #puts "select2 - #{params.inspect}"
  590. end
  591. end
  592. =begin
  593. switch(
  594. browser: browser1,
  595. css: '.some_class',
  596. type: 'on', # 'off'
  597. no_check: true, # do not check is switch has changed, in case if js alert
  598. )
  599. =end
  600. def switch(params)
  601. switch_window_focus(params)
  602. log('switch', params)
  603. instance = params[:browser] || @browser
  604. element = instance.find_elements(css: "#{params[:css]} input[type=checkbox]")[0]
  605. checked = element.attribute('checked')
  606. if !checked
  607. if params[:type] == 'on'
  608. instance.find_elements(css: "#{params[:css]} label")[0].click
  609. sleep 2
  610. if params[:no_check] != true
  611. element = instance.find_elements(css: "#{params[:css]} input[type=checkbox]")[0]
  612. checked = element.attribute('checked')
  613. raise 'Switch not on!' if !checked
  614. end
  615. end
  616. elsif params[:type] == 'off'
  617. instance.find_elements(css: "#{params[:css]} label")[0].click
  618. sleep 2
  619. if params[:no_check] != true
  620. element = instance.find_elements(css: "#{params[:css]} input[type=checkbox]")[0]
  621. checked = element.attribute('checked')
  622. raise 'Switch not off!' if checked
  623. end
  624. end
  625. end
  626. =begin
  627. check(
  628. browser: browser1,
  629. css: '.some_class',
  630. )
  631. =end
  632. def check(params)
  633. switch_window_focus(params)
  634. log('check', params)
  635. instance = params[:browser] || @browser
  636. instance.execute_script("$('#{params[:css]}:not(:checked)').click()")
  637. #element = instance.find_elements(css: params[:css])[0]
  638. #checked = element.attribute('checked')
  639. #element.click if !checked
  640. end
  641. =begin
  642. uncheck(
  643. browser: browser1,
  644. css: '.some_class',
  645. )
  646. =end
  647. def uncheck(params)
  648. switch_window_focus(params)
  649. log('uncheck', params)
  650. instance = params[:browser] || @browser
  651. instance.execute_script("$('#{params[:css]}:checked').click()")
  652. #element = instance.find_elements(css: params[:css])[0]
  653. #checked = element.attribute('checked')
  654. #element.click if checked
  655. end
  656. =begin
  657. sendkey(
  658. browser: browser1,
  659. value: :enter,
  660. slow: false, # default false
  661. )
  662. =end
  663. def sendkey(params)
  664. switch_window_focus(params)
  665. log('sendkey', params)
  666. instance = params[:browser] || @browser
  667. element = nil
  668. if params[:css]
  669. element = instance.find_elements(css: params[:css])[0]
  670. end
  671. if params[:value].class == Array
  672. params[:value].each do |key|
  673. if element
  674. element.send_keys(key)
  675. else
  676. instance.action.send_keys(key).perform
  677. end
  678. end
  679. return
  680. end
  681. if element
  682. element.send_keys(params[:value])
  683. else
  684. instance.action.send_keys(params[:value]).perform
  685. end
  686. if params[:slow]
  687. sleep 1.5
  688. else
  689. sleep 0.2
  690. end
  691. end
  692. =begin
  693. match(
  694. browser: browser1,
  695. css: '#content .text-1',
  696. value: 'some test for browser and some other for browser',
  697. attribute: 'some_attribute', # match on attribute
  698. should_not_match: true,
  699. no_quote: false, # use regex
  700. )
  701. =end
  702. def match(params, fallback = false)
  703. switch_window_focus(params)
  704. log('match', params)
  705. instance = params[:browser] || @browser
  706. element = instance.find_elements(css: params[:css])[0]
  707. if params[:css].match?(/select/)
  708. dropdown = Selenium::WebDriver::Support::Select.new(element)
  709. success = false
  710. dropdown.selected_options&.each do |option|
  711. if option.text == params[:value]
  712. success = true
  713. end
  714. end
  715. if params[:should_not_match]
  716. if success
  717. screenshot(browser: instance, comment: 'match_failed')
  718. raise "should not match '#{params[:value]}' in select list, but is matching"
  719. end
  720. elsif !success
  721. screenshot(browser: instance, comment: 'match_failed')
  722. raise "not matching '#{params[:value]}' in select list"
  723. end
  724. return true
  725. end
  726. # match on attribute
  727. begin
  728. text = if params[:attribute]
  729. element.attribute(params[:attribute])
  730. elsif params[:css].match?(/(input|textarea)/i)
  731. element.attribute('value')
  732. else
  733. element.text
  734. end
  735. rescue => e
  736. # just try again
  737. if !fallback
  738. return match(params, true)
  739. end
  740. raise e.inspect
  741. end
  742. # do cleanups (needed for richtext tests)
  743. if params[:cleanup]
  744. text.gsub!(/\s+$/m, '')
  745. params[:value].gsub!(/\s+$/m, '')
  746. end
  747. match = false
  748. if params[:no_quote]
  749. #puts "aaaa #{text}/#{params[:value]}"
  750. if text =~ /#{params[:value]}/i
  751. match = $1 || true
  752. end
  753. elsif text.match?(/#{Regexp.quote(params[:value])}/i)
  754. match = true
  755. end
  756. if match
  757. if params[:should_not_match]
  758. screenshot(browser: instance, comment: 'match_failed')
  759. raise "matching '#{params[:value]}' in content '#{text}' but should not!"
  760. end
  761. elsif !params[:should_not_match]
  762. screenshot(browser: instance, comment: 'match_failed')
  763. raise "not matching '#{params[:value]}' in content '#{text}' but should!"
  764. end
  765. sleep 0.2
  766. match
  767. end
  768. =begin
  769. match_not(
  770. browser: browser1,
  771. css: '#content .text-1',
  772. value: 'some test for browser and some other for browser',
  773. attribute: 'some_attribute', # match on attribute
  774. should_not_match: true,
  775. no_quote: false, # use regex
  776. )
  777. =end
  778. def match_not(params)
  779. switch_window_focus(params)
  780. log('match_not', params)
  781. params[:should_not_match] = true
  782. match(params)
  783. end
  784. =begin
  785. set type of task (closeTab, closeNextInOverview, stayOnTab)
  786. task_type(
  787. browser: browser1,
  788. type: 'stayOnTab',
  789. )
  790. =end
  791. def task_type(params)
  792. switch_window_focus(params)
  793. log('task_type', params)
  794. instance = params[:browser] || @browser
  795. if params[:type]
  796. instance.find_elements(css: '.content.active .js-secondaryActionButtonLabel')[0].click
  797. instance.find_elements(css: ".content.active .js-secondaryActionLabel[data-type=#{params[:type]}]")[0].click
  798. return
  799. end
  800. raise "Unknown params for task_type: #{params.inspect}"
  801. end
  802. =begin
  803. cookie(
  804. browser: browser1,
  805. name: '^_zammad.+?',
  806. value: '.+?',
  807. expires: nil,
  808. )
  809. cookie(
  810. browser: browser1,
  811. name: '^_zammad.+?',
  812. should_not_exist: true,
  813. )
  814. =end
  815. def cookie(params)
  816. switch_window_focus(params)
  817. log('cookie', params)
  818. instance = params[:browser] || @browser
  819. if !browser_support_cookies
  820. assert(true, "'#{params[:value]}' ups browser is not supporting reading cookies, go ahead")
  821. return true
  822. end
  823. cookies = instance.manage.all_cookies
  824. cookies.each do |cookie|
  825. # :name=>"_zammad_session_c25832f4de2", :value=>"adc31cd21615cb0a7ab269184ec8b76f", :path=>"/", :domain=>"localhost", :expires=>nil, :secure=>false}
  826. next if cookie[:name] !~ /#{params[:name]}/i
  827. if params.key?(:value) && cookie[:value].to_s =~ /#{params[:value]}/i
  828. assert(true, "matching value '#{params[:value]}' in cookie '#{cookie}'")
  829. else
  830. raise "not matching value '#{params[:value]}' in cookie '#{cookie}'"
  831. end
  832. if params.key?(:expires) && cookie[:expires].to_s =~ /#{params[:expires]}/i
  833. assert(true, "matching expires '#{params[:expires].inspect}' in cookie '#{cookie}'")
  834. else
  835. raise "not matching expires '#{params[:expires]}' in cookie '#{cookie}'"
  836. end
  837. return if !params[:should_not_exist]
  838. raise "cookie with name '#{params[:name]}' should not exist, but exists '#{cookies}'"
  839. end
  840. if params[:should_not_exist]
  841. assert(true, "cookie with name '#{params[:name]}' is not existing")
  842. return
  843. end
  844. raise "not matching name '#{params[:name]}' in cookie '#{cookies}'"
  845. end
  846. =begin
  847. verify_title(
  848. browser: browser1,
  849. value: 'some title',
  850. )
  851. =end
  852. def verify_title(params = {})
  853. switch_window_focus(params)
  854. log('verify_title', params)
  855. instance = params[:browser] || @browser
  856. title = instance.title
  857. if title.match?(/#{params[:value]}/i)
  858. assert(true, "matching '#{params[:value]}' in title '#{title}'")
  859. else
  860. raise "not matching '#{params[:value]}' in title '#{title}'"
  861. end
  862. end
  863. =begin
  864. verify_task(
  865. browser: browser1,
  866. data: {
  867. title: 'some title',
  868. modified: true, # optional
  869. }
  870. )
  871. =end
  872. def verify_task(params = {}, fallback = false)
  873. switch_window_focus(params)
  874. log('verify_task', params)
  875. instance = params[:browser] || @browser
  876. data = params[:data]
  877. sleep 1
  878. begin
  879. # verify title
  880. if data[:title]
  881. title = instance.find_elements(css: '.tasks .is-active')[0].text.strip
  882. if title.match?(/#{data[:title]}/i)
  883. assert(true, "matching '#{data[:title]}' in title '#{title}'")
  884. else
  885. screenshot(browser: instance, comment: 'verify_task_failed')
  886. raise "not matching '#{data[:title]}' in title '#{title}'"
  887. end
  888. end
  889. # verify modified
  890. if data.key?(:modified)
  891. exists = instance.find_elements(css: '.tasks .is-active')[0]
  892. is_modified = instance.find_elements(css: '.tasks .is-modified')[0]
  893. puts "m #{data[:modified].inspect}"
  894. if exists
  895. puts ' exists'
  896. end
  897. if is_modified
  898. puts ' is_modified'
  899. end
  900. if data[:modified] == true
  901. if is_modified
  902. assert(true, "task '#{data[:title]}' is modifed")
  903. elsif !exists
  904. screenshot(browser: instance, comment: 'verify_task_failed')
  905. raise "task '#{data[:title]}' not exists, should not modified"
  906. else
  907. screenshot(browser: instance, comment: 'verify_task_failed')
  908. raise "task '#{data[:title]}' is not modifed"
  909. end
  910. elsif !is_modified
  911. assert(true, "task '#{data[:title]}' is modifed")
  912. elsif !exists
  913. screenshot(browser: instance, comment: 'verify_task_failed')
  914. raise "task '#{data[:title]}' not exists, should be not modified"
  915. else
  916. screenshot(browser: instance, comment: 'verify_task_failed')
  917. raise "task '#{data[:title]}' is modifed, but should not"
  918. end
  919. end
  920. rescue => e
  921. # just try again
  922. if !fallback
  923. verify_task(params, true)
  924. end
  925. raise 'ERROR: ' + e.inspect
  926. end
  927. true
  928. end
  929. =begin
  930. open_task(
  931. browser: browser1,
  932. data: {
  933. title: 'some title',
  934. }
  935. )
  936. =end
  937. def open_task(params = {})
  938. switch_window_focus(params)
  939. log('open_task', params)
  940. instance = params[:browser] || @browser
  941. data = params[:data]
  942. element = instance.find_element(css: '#navigation').find_element(partial_link_text: data[:title])
  943. if !element
  944. screenshot(browser: instance, comment: 'open_task_failed')
  945. raise "no task with title '#{data[:title]}' found"
  946. end
  947. # firefix/marionette issue with Selenium::WebDriver::Error::ElementNotInteractableError: could not be scrolled into view
  948. # use js workaround instead of native click
  949. instance.execute_script("$('#navigation .tasks .task:contains(\"#{data[:title]}\") .nav-tab-name').click()")
  950. #element.click
  951. true
  952. end
  953. =begin
  954. close_task(
  955. browser: browser1,
  956. data: {
  957. title: 'some title',
  958. },
  959. discard_changes: true,
  960. )
  961. =end
  962. def close_task(params = {})
  963. switch_window_focus(params)
  964. log('close_task', params)
  965. instance = params[:browser] || @browser
  966. data = params[:data]
  967. element = instance.find_element(css: '#navigation').find_element(partial_link_text: data[:title])
  968. if !element
  969. screenshot(browser: instance, comment: 'close_task_failed')
  970. raise "no task with title '#{data[:title]}' found"
  971. end
  972. instance.action.move_to(element).release.perform
  973. sleep 0.1
  974. instance.execute_script("$('#navigation .tasks .task:contains(\"#{data[:title]}\") .js-close').click()")
  975. # accept task close warning
  976. if params[:discard_changes]
  977. modal_ready(browser: instance)
  978. instance.find_elements(css: '.modal button.js-submit')[0].click
  979. modal_disappear(browser: instance)
  980. end
  981. true
  982. end
  983. =begin
  984. file_upload(
  985. browser: browser1,
  986. css: '.content.active .attachmentPlaceholder-inputHolder input'
  987. files: ['path/in/home/some_file.ext'], # 'test/fixtures/test1.pdf'
  988. )
  989. =end
  990. def file_upload(params = {})
  991. switch_window_focus(params)
  992. log('file_upload', params)
  993. instance = params[:browser] || @browser
  994. params[:files].each do |file|
  995. instance.find_elements(css: params[:css])[0].send_keys(Rails.root.join(file))
  996. end
  997. sleep 2 * params[:files].count
  998. end
  999. =begin
  1000. watch_for(
  1001. browser: browser1,
  1002. container: element # optional, defaults to browser, must exist at the time of dispatch
  1003. css: '#content .text-1', # xpath or css required
  1004. xpath: '/content[contains(@class,".text-1")]', # xpath or css required
  1005. value: 'some text',
  1006. attribute: 'some_attribute' # optional
  1007. timeout: 16, # in sec, default 16
  1008. )
  1009. =end
  1010. def watch_for(params = {})
  1011. switch_window_focus(params)
  1012. log('watch_for', params)
  1013. browser = params[:browser] || @browser
  1014. instance = params[:container] || browser
  1015. selector = params[:css] || params[:xpath]
  1016. selector_type = if params.key?(:css)
  1017. :css
  1018. elsif params.key?(:xpath)
  1019. :xpath
  1020. end
  1021. timeout = 16
  1022. if params[:timeout]
  1023. timeout = params[:timeout]
  1024. end
  1025. loops = timeout.to_i * 2
  1026. text = ''
  1027. (1..loops).each do
  1028. element = instance.find_elements(selector_type => selector)[0]
  1029. if element #&& element.displayed?
  1030. begin
  1031. # watch for selector
  1032. if !params[:attribute] && !params[:value]
  1033. assert(true, "'#{selector}' found")
  1034. sleep 0.5
  1035. return true
  1036. # match an attribute
  1037. else
  1038. text = if params[:attribute]
  1039. element.attribute(params[:attribute])
  1040. elsif selector.match?(/(input|textarea)/i)
  1041. element.attribute('value')
  1042. else
  1043. element.text
  1044. end
  1045. if text.match?(/#{params[:value]}/i)
  1046. assert(true, "'#{params[:value]}' found in '#{text}'")
  1047. sleep 0.5
  1048. return true
  1049. end
  1050. end
  1051. rescue
  1052. # try again
  1053. end
  1054. end
  1055. sleep 0.5
  1056. end
  1057. screenshot(browser: browser, comment: 'watch_for_failed')
  1058. if !params[:attribute] && !params[:value]
  1059. raise "'#{selector}' not found"
  1060. end
  1061. raise "'#{params[:value]}' not found in '#{text}'"
  1062. end
  1063. =begin
  1064. wait untill selector disabppears
  1065. watch_for_disappear(
  1066. browser: browser1,
  1067. css: '#content .text-1',
  1068. timeout: 16, # in sec, default 16
  1069. )
  1070. wait untill text in selector disabppears
  1071. watch_for_disappear(
  1072. browser: browser1,
  1073. css: '#content .text-1',
  1074. value: 'some value as regexp',
  1075. timeout: 16, # in sec, default 16
  1076. )
  1077. =end
  1078. def watch_for_disappear(params = {})
  1079. switch_window_focus(params)
  1080. log('watch_for_disappear', params)
  1081. instance = params[:browser] || @browser
  1082. timeout = 16
  1083. if params[:timeout]
  1084. timeout = params[:timeout]
  1085. end
  1086. loops = timeout.to_i
  1087. text = ''
  1088. (1..loops).each do
  1089. element = instance.find_elements(css: params[:css])[0]
  1090. if !element #|| element.displayed?
  1091. assert(true, 'not found')
  1092. sleep 1
  1093. return true
  1094. end
  1095. if params[:value]
  1096. begin
  1097. text = instance.find_elements(css: params[:css])[0].text
  1098. if !text.match?(/#{params[:value]}/i)
  1099. assert(true, "not matching '#{params[:value]}' in text '#{text}'")
  1100. sleep 1
  1101. return true
  1102. end
  1103. rescue
  1104. # try again
  1105. end
  1106. end
  1107. sleep 1
  1108. end
  1109. screenshot(browser: instance, comment: 'disappear_failed')
  1110. raise "#{params[:css]}) still exsists"
  1111. end
  1112. =begin
  1113. shortcut(
  1114. browser: browser1,
  1115. key: 'x',
  1116. )
  1117. =end
  1118. def shortcut(params = {})
  1119. switch_window_focus(params)
  1120. log('shortcut', params)
  1121. instance = params[:browser] || @browser
  1122. screenshot(browser: instance, comment: 'shortcut_before')
  1123. instance.action.key_down(:control)
  1124. .key_down(:shift)
  1125. .send_keys(params[:key])
  1126. .key_up(:shift)
  1127. .key_up(:control)
  1128. .perform
  1129. screenshot(browser: instance, comment: 'shortcut_after')
  1130. end
  1131. =begin
  1132. window_keys(
  1133. browser: browser1,
  1134. value: 'x',
  1135. )
  1136. =end
  1137. def window_keys(params = {})
  1138. switch_window_focus(params)
  1139. log('window_keys', params)
  1140. instance = params[:browser] || @browser
  1141. instance.action.send_keys(params[:value]).perform
  1142. end
  1143. =begin
  1144. tasks_close_all(
  1145. browser: browser1,
  1146. )
  1147. =end
  1148. def tasks_close_all(params = {})
  1149. switch_window_focus(params)
  1150. log('tasks_close_all', params)
  1151. instance = params[:browser] || @browser
  1152. 99.times do
  1153. #sleep 0.5
  1154. begin
  1155. if instance.find_elements(css: '#navigation .tasks .task:first-child')[0]
  1156. instance.action.move_to(instance.find_elements(css: '#navigation .tasks .task:first-child')[0]).release.perform
  1157. click_element = instance.find_elements(css: '#navigation .tasks .task:first-child .js-close')[0]
  1158. if click_element
  1159. click_element.click
  1160. # accept task close warning
  1161. if instance.find_elements(css: '.modal button.js-submit')[0]
  1162. sleep 0.4
  1163. instance.find_elements(css: '.modal button.js-submit')[0].click
  1164. end
  1165. end
  1166. else
  1167. break
  1168. end
  1169. rescue
  1170. # try again
  1171. end
  1172. end
  1173. assert(true, 'all tasks closed')
  1174. end
  1175. =begin
  1176. close_online_notitifcation(
  1177. browser: browser1,
  1178. data: {
  1179. #title: 'some title',
  1180. position: 3,
  1181. },
  1182. )
  1183. =end
  1184. def close_online_notitifcation(params = {})
  1185. switch_window_focus(params)
  1186. log('close_online_notitifcation', params)
  1187. instance = params[:browser] || @browser
  1188. data = params[:data]
  1189. if data[:title]
  1190. element = instance.find_elements(partial_link_text: data[:title])[0]
  1191. if !element
  1192. screenshot(browser: instance, comment: 'close_online_notitifcation')
  1193. raise "no online notification with title '#{data[:title]}' found"
  1194. end
  1195. instance.action.move_to(element).release.perform
  1196. sleep 0.1
  1197. instance.execute_script("$('.js-notificationsContainer .js-items .js-item .activity-text:contains(\"#{data[:title]}\") .js-remove').first().click()")
  1198. else
  1199. css = ".js-notificationsContainer .js-items .js-item:nth-child(#{data[:position]})"
  1200. element = instance.find_elements(css: css)[0]
  1201. if !element
  1202. screenshot(browser: instance, comment: 'close_online_notitifcation')
  1203. raise "no online notification with postion '#{css}' found"
  1204. end
  1205. instance.action.move_to(element).release.perform
  1206. sleep 0.1
  1207. instance.find_elements(css: "#{css} .js-remove")[0].click
  1208. end
  1209. true
  1210. end
  1211. =begin
  1212. online_notitifcation_close_all(
  1213. browser: browser1,
  1214. )
  1215. =end
  1216. def online_notitifcation_close_all(params = {})
  1217. switch_window_focus(params)
  1218. log('online_notitifcation_close_all', params)
  1219. instance = params[:browser] || @browser
  1220. 99.times do
  1221. sleep 0.5
  1222. begin
  1223. if instance.find_elements(css: '.js-notificationsContainer .js-item:first-child')[0]
  1224. instance.action.move_to(instance.find_elements(css: '.js-notificationsContainer .js-item:first-child')[0]).perform
  1225. sleep 0.1
  1226. click_element = instance.find_elements(css: '.js-notificationsContainer .js-item:first-child .js-remove')[0]
  1227. click_element&.click
  1228. else
  1229. break
  1230. end
  1231. rescue
  1232. # try again
  1233. end
  1234. end
  1235. assert(true, 'all online notification closed')
  1236. end
  1237. =begin
  1238. empty_search(
  1239. browser: browser1,
  1240. )
  1241. =end
  1242. def empty_search(params = {})
  1243. switch_window_focus(params)
  1244. log('empty_search', params)
  1245. instance = params[:browser] || @browser
  1246. # empty search box by x
  1247. begin
  1248. instance.find_elements(css: '.search .js-emptySearch')[0].click
  1249. rescue
  1250. # in issues with ff & selenium, sometimes exeption appears
  1251. # "Element is not currently visible and so may not be interacted with"
  1252. log('empty_search via js')
  1253. instance.execute_script('$(".search .js-emptySearch").click()')
  1254. end
  1255. sleep 0.5
  1256. text = instance.find_elements(css: '#global-search')[0].attribute('value')
  1257. if !text
  1258. raise '#global-search is not empty!'
  1259. end
  1260. true
  1261. end
  1262. =begin
  1263. ticket_customer_select(
  1264. browser: browser1,
  1265. css: '#content .text-1',
  1266. customer: '',
  1267. )
  1268. =end
  1269. def ticket_customer_select(params = {})
  1270. switch_window_focus(params)
  1271. log('ticket_customer_select', params)
  1272. instance = params[:browser] || @browser
  1273. element = instance.find_elements(css: params[:css] + ' input[name="customer_id_completion"]')[0]
  1274. element.click
  1275. element.clear
  1276. element.send_keys(params[:customer])
  1277. sleep 2.5
  1278. element.send_keys(:enter)
  1279. #instance.find_elements(css: params[:css] + ' .recipientList-entry.js-object.is-active')[0].click
  1280. sleep 0.4
  1281. assert(true, 'ticket_customer_select')
  1282. end
  1283. =begin
  1284. overview_create(
  1285. browser: browser1,
  1286. data: {
  1287. name: name,
  1288. roles: ['Agent'],
  1289. selector: {
  1290. 'Priority': '1 low',
  1291. },
  1292. 'order::direction' => 'down',
  1293. }
  1294. )
  1295. =end
  1296. def overview_create(params)
  1297. switch_window_focus(params)
  1298. log('overview_create', params)
  1299. instance = params[:browser] || @browser
  1300. data = params[:data]
  1301. click(
  1302. browser: instance,
  1303. css: 'a[href="#manage"]',
  1304. mute_log: true,
  1305. )
  1306. click(
  1307. browser: instance,
  1308. css: '.content.active a[href="#manage/overviews"]',
  1309. mute_log: true,
  1310. )
  1311. click(
  1312. browser: instance,
  1313. css: '.content.active a[data-type="new"]',
  1314. mute_log: true,
  1315. )
  1316. modal_ready(browser: instance)
  1317. if data[:name]
  1318. set(
  1319. browser: instance,
  1320. css: '.modal input[name=name]',
  1321. value: data[:name],
  1322. mute_log: true,
  1323. )
  1324. end
  1325. if data[:roles]
  1326. 99.times do
  1327. begin
  1328. element = instance.find_elements(css: '.modal .js-selected[data-name=role_ids] .js-option:not(.is-hidden)')[0]
  1329. break if !element
  1330. element.click
  1331. sleep 0.1
  1332. end
  1333. end
  1334. data[:roles].each do |role|
  1335. instance.execute_script("$(\".modal [data-name=role_ids] .js-pool .js-option:not(.is-hidden):contains('#{role}')\").first().click()")
  1336. end
  1337. end
  1338. data[:selector]&.each do |key, value|
  1339. select(
  1340. browser: instance,
  1341. css: '.modal .ticket_selector .js-attributeSelector select',
  1342. value: key,
  1343. mute_log: true,
  1344. )
  1345. sleep 0.5
  1346. select(
  1347. browser: instance,
  1348. css: '.modal .ticket_selector .js-value select',
  1349. value: value,
  1350. deselect_all: true,
  1351. mute_log: true,
  1352. )
  1353. end
  1354. if data['order::direction']
  1355. select(
  1356. browser: instance,
  1357. css: '.modal select[name="order::direction"]',
  1358. value: data['order::direction'],
  1359. mute_log: true,
  1360. )
  1361. end
  1362. instance.find_elements(css: '.modal button.js-submit')[0].click
  1363. modal_disappear(browser: instance)
  1364. 11.times do
  1365. element = instance.find_elements(css: 'body')[0]
  1366. text = element.text
  1367. if text.match?(/#{Regexp.quote(data[:name])}/)
  1368. assert(true, 'overview created')
  1369. overview = {
  1370. name: name,
  1371. }
  1372. sleep 1
  1373. return overview
  1374. end
  1375. sleep 1
  1376. end
  1377. screenshot(browser: instance, comment: 'overview_create_failed')
  1378. raise 'overview creation failed'
  1379. end
  1380. =begin
  1381. overview_update(
  1382. browser: browser1,
  1383. data: {
  1384. name: name,
  1385. roles: ['Agent'],
  1386. selector: {
  1387. 'Priority': '1 low',
  1388. },
  1389. 'order::direction' => 'down',
  1390. }
  1391. )
  1392. =end
  1393. def overview_update(params)
  1394. switch_window_focus(params)
  1395. log('overview_create', params)
  1396. instance = params[:browser] || @browser
  1397. data = params[:data]
  1398. click(
  1399. browser: instance,
  1400. css: 'a[href="#manage"]',
  1401. mute_log: true,
  1402. )
  1403. click(
  1404. browser: instance,
  1405. css: '.content.active a[href="#manage/overviews"]',
  1406. mute_log: true,
  1407. )
  1408. instance.execute_script("$(\".content.active td:contains('#{data[:name]}')\").first().click()")
  1409. sleep 2
  1410. if data[:name]
  1411. set(
  1412. browser: instance,
  1413. css: '.modal input[name=name]',
  1414. value: data[:name],
  1415. mute_log: true,
  1416. )
  1417. end
  1418. if data[:roles]
  1419. 99.times do
  1420. begin
  1421. element = instance.find_elements(css: '.modal .js-selected[data-name=role_ids] .js-option:not(.is-hidden)')[0]
  1422. break if !element
  1423. element.click
  1424. sleep 0.1
  1425. end
  1426. end
  1427. data[:roles].each do |role|
  1428. instance.execute_script("$(\".modal [data-name=role_ids] .js-pool .js-option:not(.is-hidden):contains('#{role}')\").first().click()")
  1429. end
  1430. end
  1431. data[:selector]&.each do |key, value|
  1432. select(
  1433. browser: instance,
  1434. css: '.modal .ticket_selector .js-attributeSelector select',
  1435. value: key,
  1436. mute_log: true,
  1437. )
  1438. sleep 0.5
  1439. select(
  1440. browser: instance,
  1441. css: '.modal .ticket_selector .js-value select',
  1442. value: value,
  1443. deselect_all: true,
  1444. mute_log: true,
  1445. )
  1446. end
  1447. if data['order::direction']
  1448. select(
  1449. browser: instance,
  1450. css: '.modal select[name="order::direction"]',
  1451. value: data['order::direction'],
  1452. mute_log: true,
  1453. )
  1454. end
  1455. instance.find_elements(css: '.modal button.js-submit')[0].click
  1456. modal_disappear(browser: instance)
  1457. 11.times do
  1458. element = instance.find_elements(css: 'body')[0]
  1459. text = element.text
  1460. if text.match?(/#{Regexp.quote(data[:name])}/)
  1461. assert(true, 'overview updated')
  1462. overview = {
  1463. name: name,
  1464. }
  1465. sleep 1
  1466. return overview
  1467. end
  1468. sleep 1
  1469. end
  1470. screenshot(browser: instance, comment: 'overview_update_failed')
  1471. raise 'overview update failed'
  1472. end
  1473. =begin
  1474. ticket = ticket_create(
  1475. browser: browser1,
  1476. data: {
  1477. customer: 'nico',
  1478. group: 'Users', # optional / '-NONE-' # if group selection should not be shown
  1479. priority: '2 normal',
  1480. state: 'open',
  1481. title: 'overview #1',
  1482. body: 'overview #1',
  1483. },
  1484. do_not_submit: true,
  1485. )
  1486. returns (in case of submitted)
  1487. {
  1488. id: 123,
  1489. number: '100001',
  1490. title: 'overview #1',
  1491. }
  1492. ticket = ticket_create(
  1493. browser: browser1,
  1494. data: {
  1495. customer: 'nico',
  1496. group: 'Users', # optional / '-NONE-' # if group selection should not be shown
  1497. priority: '2 normal',
  1498. state: 'open',
  1499. title: 'overview #1',
  1500. body: 'overview #1',
  1501. },
  1502. custom_data_select: {
  1503. key1: 'some value',
  1504. },
  1505. custom_data_input: {
  1506. key1: 'some value',
  1507. },
  1508. custom_data_date: {
  1509. key!: '02/28/2018',
  1510. }
  1511. disable_group_check: true,
  1512. )
  1513. =end
  1514. def ticket_create(params)
  1515. switch_window_focus(params)
  1516. log('ticket_create', params)
  1517. instance = params[:browser] || @browser
  1518. data = params[:data]
  1519. click(
  1520. browser: instance,
  1521. css: 'a[href="#new"]',
  1522. mute_log: true,
  1523. only_if_exists: true,
  1524. )
  1525. click(
  1526. browser: instance,
  1527. css: 'a[href="#ticket/create"]',
  1528. mute_log: true,
  1529. )
  1530. found = false
  1531. 7.times do
  1532. element = instance.find_elements(css: '.content.active .newTicket')[0]
  1533. if element
  1534. found = true
  1535. break
  1536. end
  1537. sleep 1
  1538. end
  1539. if !found
  1540. screenshot(browser: instance, comment: 'ticket_create_failed')
  1541. raise 'no ticket create screen found!'
  1542. end
  1543. if data[:group]
  1544. if data[:group] == '-NONE-'
  1545. # check if owner selection exists
  1546. count = instance.find_elements(css: '.content.active .newTicket select[name="group_id"] option').count
  1547. if count.nonzero?
  1548. instance.find_elements(css: '.content.active .newTicket select[name="group_id"] option').each do |element|
  1549. log('ticket_create invalid group count', text: element.text)
  1550. end
  1551. end
  1552. assert_equal(0, count, 'owner selection should not be showm')
  1553. # check count of agents, should be only 3 / - selection + master + agent on init screen
  1554. count = instance.find_elements(css: '.content.active .newTicket select[name="owner_id"] option').count
  1555. if count != 3
  1556. instance.find_elements(css: '.content.active .newTicket select[name="owner_id"] option').each do |element|
  1557. log('ticket_create invalid owner count', text: element.text)
  1558. end
  1559. end
  1560. assert_equal(3, count, 'check if owner selection is - selection + master + agent per default')
  1561. else
  1562. # check count of agents, should be only 1 / - selection on init screen
  1563. if !params[:disable_group_check]
  1564. count = instance.find_elements(css: '.content.active .newTicket select[name="owner_id"] option').count
  1565. if count != 1
  1566. instance.find_elements(css: '.content.active .newTicket select[name="owner_id"] option').each do |element|
  1567. log('ticket_create invalid owner count', text: element.text)
  1568. end
  1569. end
  1570. assert_equal(1, count, 'check if owner selection is empty per default')
  1571. end
  1572. select(
  1573. browser: instance,
  1574. css: '.content.active .newTicket select[name="group_id"]',
  1575. value: data[:group],
  1576. mute_log: true,
  1577. )
  1578. end
  1579. end
  1580. if data[:priority]
  1581. select(
  1582. browser: instance,
  1583. css: '.content.active .newTicket select[name="priority_id"]',
  1584. value: data[:priority],
  1585. mute_log: true,
  1586. )
  1587. end
  1588. if data[:state]
  1589. select(
  1590. browser: instance,
  1591. css: '.content.active .newTicket select[name="state_id"]',
  1592. value: data[:state],
  1593. mute_log: true,
  1594. )
  1595. end
  1596. if data[:title]
  1597. set(
  1598. browser: instance,
  1599. css: '.content.active .newTicket input[name="title"]',
  1600. value: data[:title],
  1601. clear: true,
  1602. mute_log: true,
  1603. )
  1604. end
  1605. if data[:body]
  1606. set(
  1607. browser: instance,
  1608. css: '.content.active .newTicket div[data-name=body]',
  1609. value: data[:body],
  1610. clear: true,
  1611. mute_log: true,
  1612. )
  1613. end
  1614. if data[:customer]
  1615. element = instance.find_elements(css: '.content.active .newTicket input[name="customer_id_completion"]')[0]
  1616. element.click
  1617. element.clear
  1618. # ff issue, sometimes focus event gets dropped
  1619. # if drowdown is not open, try it again
  1620. if !instance.find_elements(css: '.content.active .newTicket .js-recipientDropdown.open')[0]
  1621. instance.execute_script('$(".active .newTicket .js-recipientDropdown").addClass("open")')
  1622. end
  1623. element.send_keys(data[:customer])
  1624. sleep 2.5
  1625. element.send_keys(:enter)
  1626. sleep 0.2
  1627. # ff issue, sometimes enter event gets dropped
  1628. # take user manually
  1629. if instance.find_elements(css: '.content.active .newTicket .js-recipientDropdown.open')[0]
  1630. instance.find_elements(css: '.content.active .newTicket .recipientList-entry.js-object.is-active')[0].click
  1631. sleep 0.4
  1632. end
  1633. end
  1634. params[:custom_data_select]&.each do |local_key, local_value|
  1635. select(
  1636. browser: instance,
  1637. css: ".content.active .newTicket select[name=\"#{local_key}\"]",
  1638. value: local_value,
  1639. )
  1640. end
  1641. params[:custom_data_input]&.each do |local_key, local_value|
  1642. set(
  1643. browser: instance,
  1644. css: ".content.active .newTicket input[name=\"#{local_key}\"]",
  1645. value: local_value,
  1646. clear: true,
  1647. )
  1648. end
  1649. params[:custom_data_date]&.each do |local_key, local_value|
  1650. set(
  1651. browser: instance,
  1652. css: ".content.active .newTicket div[data-name=\"#{local_key}\"] input[data-item=\"date\"]",
  1653. value: local_value,
  1654. clear: true,
  1655. )
  1656. end
  1657. if data[:attachment]
  1658. file_upload(
  1659. browser: instance,
  1660. css: '.content.active .text-1',
  1661. value: 'some text',
  1662. )
  1663. end
  1664. if params[:do_not_submit]
  1665. assert(true, 'ticket created without submit')
  1666. return
  1667. end
  1668. #instance.execute_script('$(".content.active .newTicket form").submit();')
  1669. click(
  1670. browser: instance,
  1671. css: '.content.active .newTicket button.js-submit',
  1672. mute_log: true,
  1673. )
  1674. sleep 1
  1675. 9.times do
  1676. if instance.current_url.match?(/#{Regexp.quote('#ticket/zoom/')}/)
  1677. assert(true, 'ticket created')
  1678. sleep 2
  1679. id = instance.current_url
  1680. id.gsub!(//,)
  1681. id.gsub!(%r{^.+?/(\d+)$}, '\\1')
  1682. element = instance.find_elements(css: '.content.active .ticketZoom-header .ticket-number')[0]
  1683. if element
  1684. number = element.text
  1685. ticket = {
  1686. id: id,
  1687. number: number,
  1688. title: data[:title],
  1689. }
  1690. sleep 2 # wait until notify is gone
  1691. return ticket
  1692. end
  1693. end
  1694. sleep 1
  1695. end
  1696. screenshot(browser: instance, comment: 'ticket_create_failed')
  1697. raise "ticket creation failed, can't get zoom url (current url is '#{instance.current_url}')"
  1698. end
  1699. =begin
  1700. ticket_update(
  1701. browser: browser1,
  1702. data: {
  1703. title: '',
  1704. customer: 'some_customer@example.com',
  1705. body: 'some body',
  1706. group: 'some group', # optional
  1707. priority: '1 low',
  1708. state: 'closed',
  1709. },
  1710. do_not_submit: true,
  1711. )
  1712. ticket_update(
  1713. browser: browser1,
  1714. data: {
  1715. title: '',
  1716. customer: 'some_customer@example.com',
  1717. body: 'some body',
  1718. group: 'some group', # optional
  1719. priority: '1 low',
  1720. state: 'closed',
  1721. },
  1722. custom_data_select: {
  1723. key1: 'some value',
  1724. },
  1725. custom_data_input: {
  1726. key1: 'some value',
  1727. },
  1728. custom_data_date: {
  1729. key1: '02/21/2018',
  1730. },
  1731. do_not_submit: true,
  1732. task_type: 'stayOnTab', # default: stayOnTab / possible: closeTab, closeNextInOverview, stayOnTab
  1733. )
  1734. =end
  1735. def ticket_update(params)
  1736. switch_window_focus(params)
  1737. log('ticket_update', params)
  1738. instance = params[:browser] || @browser
  1739. data = params[:data]
  1740. if data[:title]
  1741. #element = instance.find_elements(:css => '.content.active .ticketZoom-header .js-objectTitle')[0]
  1742. #element.clear
  1743. #sleep 0.5
  1744. #element = instance.find_elements(:css => '.content.active .ticketZoom-header .js-objectTitle')[0]
  1745. #element.send_keys(data[:title])
  1746. #sleep 0.5
  1747. #element.send_keys(:tab)
  1748. instance.execute_script('$(".content.active .ticketZoom-header .js-objectTitle").focus()')
  1749. instance.execute_script('$(".content.active .ticketZoom-header .js-objectTitle").text("' + data[:title] + '")')
  1750. instance.execute_script('$(".content.active .ticketZoom-header .js-objectTitle").blur()')
  1751. instance.execute_script('$(".content.active .ticketZoom-header .js-objectTitle").trigger("blur")')
  1752. # {
  1753. # :where => :instance2,
  1754. # :execute => 'sendkey',
  1755. # :css => '.content.active .ticketZoom-header .js-objectTitle',
  1756. # :value => 'TTT',
  1757. # },
  1758. # {
  1759. # :where => :instance2,
  1760. # :execute => 'sendkey',
  1761. # :css => '.content.active .ticketZoom-header .js-objectTitle',
  1762. # :value => :tab,
  1763. # },
  1764. end
  1765. if data[:customer]
  1766. # select tab
  1767. click(browser: instance, css: '.content.active .tabsSidebar-tab[data-tab="customer"]')
  1768. click(browser: instance, css: '.content.active div[data-tab="customer"] .js-actions .icon-arrow-down')
  1769. click(browser: instance, css: '.content.active div[data-tab="customer"] .js-actions [data-type="customer-change"]')
  1770. watch_for(
  1771. browser: instance,
  1772. css: '.modal',
  1773. value: 'change',
  1774. )
  1775. element = instance.find_elements(css: '.modal input[name="customer_id_completion"]')[0]
  1776. element.click
  1777. element.clear
  1778. element.send_keys(data[:customer])
  1779. sleep 2.5
  1780. element.send_keys(:enter)
  1781. #instance.find_elements(css: '.modal .user_autocompletion .recipientList-entry.js-object.is-active')[0].click
  1782. sleep 0.2
  1783. click(browser: instance, css: '.modal .js-submit')
  1784. modal_disappear(browser: instance)
  1785. watch_for(
  1786. browser: instance,
  1787. css: '.content.active .tabsSidebar',
  1788. value: data[:customer],
  1789. )
  1790. # select tab
  1791. click(browser: instance, css: '.content.active .tabsSidebar-tab[data-tab="ticket"]')
  1792. end
  1793. if data[:body]
  1794. set(
  1795. browser: instance,
  1796. css: '.content.active div[data-name=body]',
  1797. value: data[:body],
  1798. no_click: true,
  1799. mute_log: true,
  1800. )
  1801. # it's not working stable via selenium, use js
  1802. value = instance.find_elements(css: '.content.active div[data-name=body]')[0].text
  1803. if value != data[:body]
  1804. body_quoted = quote(data[:body])
  1805. instance.execute_script("$('.content.active div[data-name=body]').html('#{body_quoted}').trigger('focusout')")
  1806. end
  1807. end
  1808. if data[:group]
  1809. if data[:group] == '-NONE-'
  1810. # check if owner selection exists
  1811. count = instance.find_elements(css: '.content.active .sidebar select[name="group_id"] option').count
  1812. assert_equal(0, count, 'owner selection should not be showm')
  1813. # check count of agents, should be only 3 / - selection + master + agent on init screen
  1814. count = instance.find_elements(css: '.content.active .sidebar select[name="owner_id"] option').count
  1815. assert_equal(3, count, 'check if owner selection is - selection + master + agent per default')
  1816. else
  1817. select(
  1818. browser: instance,
  1819. css: '.content.active .sidebar select[name="group_id"]',
  1820. value: data[:group],
  1821. mute_log: true,
  1822. )
  1823. sleep 0.2
  1824. end
  1825. end
  1826. if data[:priority]
  1827. select(
  1828. browser: instance,
  1829. css: '.content.active .sidebar select[name="priority_id"]',
  1830. value: data[:priority],
  1831. mute_log: true,
  1832. )
  1833. end
  1834. if data[:state]
  1835. select(
  1836. browser: instance,
  1837. css: '.content.active .sidebar select[name="state_id"]',
  1838. value: data[:state],
  1839. mute_log: true,
  1840. )
  1841. end
  1842. params[:custom_data_select]&.each do |local_key, local_value|
  1843. select(
  1844. browser: instance,
  1845. css: ".active .sidebar select[name=\"#{local_key}\"]",
  1846. value: local_value,
  1847. )
  1848. end
  1849. params[:custom_data_input]&.each do |local_key, local_value|
  1850. set(
  1851. browser: instance,
  1852. css: ".active .sidebar input[name=\"#{local_key}\"]",
  1853. value: local_value,
  1854. clear: true,
  1855. )
  1856. end
  1857. params[:custom_data_date]&.each do |local_key, local_value|
  1858. click(
  1859. browser: instance,
  1860. css: ".active .sidebar div[data-name=\"#{local_key}\"] input[data-item=\"date\"]",
  1861. mute_log: true,
  1862. )
  1863. # weird bug where you cannot "clear" for date/time input
  1864. # this is specific chrome problem, chrome bug report: https://bugs.chromium.org/p/chromedriver/issues/detail?id=1319#c2
  1865. # indirect issue: https://github.com/angular/protractor/issues/562#issuecomment-47745263
  1866. 11.times do
  1867. sendkey(
  1868. value: :backspace,
  1869. )
  1870. end
  1871. set(
  1872. browser: instance,
  1873. css: ".active .sidebar div[data-name=\"#{local_key}\"] input[data-item=\"date\"]",
  1874. value: local_value,
  1875. )
  1876. end
  1877. if data[:state] || data[:group] || data[:body] || params[:custom_data_select].present? || params[:custom_data_input].present?
  1878. found = nil
  1879. 9.times do
  1880. break if found
  1881. begin
  1882. text = instance.find_elements(css: '.content.active .js-reset')[0].text
  1883. if text.match?(/(Discard your unsaved changes.|Verwerfen der)/)
  1884. found = true
  1885. end
  1886. rescue
  1887. # try again
  1888. end
  1889. sleep 1
  1890. end
  1891. if !found
  1892. screenshot(browser: instance, comment: 'ticket_update_discard_message_failed')
  1893. raise 'no discard message found'
  1894. end
  1895. end
  1896. task_type(
  1897. browser: instance,
  1898. type: params[:task_type] || 'stayOnTab',
  1899. )
  1900. if params[:do_not_submit]
  1901. assert(true, 'ticket updated without submit')
  1902. return true
  1903. end
  1904. instance.find_elements(css: '.content.active .js-submit')[0].click
  1905. # do not stay on tab
  1906. if params[:task_type] == 'closeTab' || params[:task_type] == 'closeNextInOverview'
  1907. sleep 1
  1908. return
  1909. end
  1910. 9.times do
  1911. begin
  1912. text = instance.find_elements(css: '.content.active .js-reset')[0].text
  1913. if text.blank?
  1914. sleep 1
  1915. return true
  1916. end
  1917. rescue
  1918. # try again
  1919. end
  1920. sleep 1
  1921. end
  1922. screenshot(browser: instance, comment: 'ticket_update_failed')
  1923. raise 'unable to update ticket'
  1924. end
  1925. =begin
  1926. ticket_verify(
  1927. browser: browser1,
  1928. data: {
  1929. title: 'some title',
  1930. body: 'some body',
  1931. ## group: 'some group',
  1932. ## state: 'closed',
  1933. custom_data_select: {
  1934. key1: 'some value',
  1935. },
  1936. custom_data_input: {
  1937. key1: 'some value',
  1938. },
  1939. },
  1940. )
  1941. =end
  1942. def ticket_verify(params)
  1943. switch_window_focus(params)
  1944. log('ticket_verify', params)
  1945. instance = params[:browser] || @browser
  1946. data = params[:data]
  1947. if data[:title]
  1948. title = instance.find_elements(css: '.content.active .ticketZoom-header .js-objectTitle').first.text.strip
  1949. if title.match?(/#{data[:title]}/i)
  1950. assert(true, "matching '#{data[:title]}' in title '#{title}'")
  1951. else
  1952. raise "not matching '#{data[:title]}' in title '#{title}'"
  1953. end
  1954. end
  1955. if data[:body]
  1956. body = instance.find_elements(css: '.content.active [data-name="body"]').first.text.strip
  1957. if body.match?(/#{data[:body]}/i)
  1958. assert(true, "matching '#{data[:body]}' in body '#{body}'")
  1959. else
  1960. raise "not matching '#{data[:body]}' in body '#{body}'"
  1961. end
  1962. end
  1963. params[:custom_data_select]&.each do |local_key, local_value|
  1964. element = instance.find_elements(css: ".active .sidebar select[name=\"#{local_key}\"] option[selected]").first
  1965. value = element.text.strip
  1966. if value.match?(/#{local_value}/i)
  1967. assert(true, "matching '#{value}' in #{local_key} '#{local_value}'")
  1968. else
  1969. raise "not matching '#{value}' in #{local_key} '#{local_value}'"
  1970. end
  1971. end
  1972. params[:custom_data_input]&.each do |local_key, local_value|
  1973. element = instance.find_elements(css: ".active .sidebar input[name=\"#{local_key}\"]").first
  1974. value = element.text.strip
  1975. if value.match?(/#{local_value}/i)
  1976. assert(true, "matching '#{value}' in #{local_key} '#{local_value}'")
  1977. else
  1978. raise "not matching '#{value}' in #{local_key} '#{local_value}'"
  1979. end
  1980. end
  1981. true
  1982. end
  1983. =begin
  1984. ticket_open_by_overview(
  1985. browser: browser2,
  1986. number: ticket1[:number],
  1987. link: "#ticket/view/#{name}",
  1988. )
  1989. ticket_open_by_overview(
  1990. browser: browser2,
  1991. number: ticket1[:number],
  1992. text: title,
  1993. link: "#ticket/view/#{name}",
  1994. )
  1995. =end
  1996. def ticket_open_by_overview(params)
  1997. switch_window_focus(params)
  1998. log('ticket_open_by_overview', params)
  1999. instance = params[:browser] || @browser
  2000. instance.find_elements(css: '.js-overviewsMenuItem')[0].click
  2001. sleep 0.5
  2002. execute(
  2003. browser: instance,
  2004. js: '$(".content.active .sidebar").css("display", "block")',
  2005. )
  2006. instance.find_elements(css: ".content.active .sidebar a[href=\"#{params[:link]}\"]")[0].click
  2007. sleep 0.5
  2008. execute(
  2009. browser: instance,
  2010. js: '$(".content.active .sidebar").css("display", "none")',
  2011. )
  2012. if params[:title]
  2013. element = instance.find_element(css: '.content.active').find_element(partial_link_text: params[:title])
  2014. if !element
  2015. screenshot(browser: instance, comment: 'ticket_open_by_overview_no_ticket_failed')
  2016. raise "unable to find ticket #{params[:title]} in overview #{params[:link]}!"
  2017. end
  2018. else
  2019. element = instance.find_elements(partial_link_text: params[:number])[0]
  2020. if !element
  2021. screenshot(browser: instance, comment: 'ticket_open_by_overview_no_ticket_failed')
  2022. raise "unable to find ticket #{params[:number]} in overview #{params[:link]}!"
  2023. end
  2024. end
  2025. element.click
  2026. sleep 1
  2027. number = instance.find_elements(css: '.content.active .ticketZoom-header .ticket-number')[0].text
  2028. if !number.match?(/#{params[:number]}/)
  2029. screenshot(browser: instance, comment: 'ticket_open_by_overview_open_failed_failed')
  2030. raise "unable to open ticket #{params[:number]}!"
  2031. end
  2032. assert(true, "ticket #{params[:number]} found")
  2033. true
  2034. end
  2035. =begin
  2036. ticket_open_by_search(
  2037. browser: browser2,
  2038. number: ticket1[:number],
  2039. )
  2040. =end
  2041. def ticket_open_by_search(params)
  2042. switch_window_focus(params)
  2043. log('ticket_open_by_search', params)
  2044. instance = params[:browser] || @browser
  2045. # search by number
  2046. element = instance.find_elements(css: '#global-search')[0]
  2047. element.click
  2048. element.clear
  2049. element.send_keys(params[:number])
  2050. sleep 3
  2051. empty_search(browser: instance)
  2052. # search by number again
  2053. element = instance.find_elements(css: '#global-search')[0]
  2054. element.click
  2055. element.clear
  2056. element.send_keys(params[:number])
  2057. sleep 1
  2058. # open ticket
  2059. #instance.find_element(partial_link_text: params[:number] } ).click
  2060. instance.execute_script("$(\".js-global-search-result a:contains('#{params[:number]}') .nav-tab-icon\").first().click()")
  2061. sleep 1
  2062. number = instance.find_elements(css: '.content.active .ticketZoom-header .ticket-number')[0].text
  2063. if !number.match?(/#{params[:number]}/)
  2064. screenshot(browser: instance, comment: 'ticket_open_by_search_failed')
  2065. raise "unable to search/find ticket #{params[:number]}!"
  2066. end
  2067. true
  2068. end
  2069. =begin
  2070. ticket_open_by_title(
  2071. browser: browser2,
  2072. title: ticket1[:title],
  2073. )
  2074. =end
  2075. def ticket_open_by_title(params)
  2076. switch_window_focus(params)
  2077. log('ticket_open_by_title', params)
  2078. instance = params[:browser] || @browser
  2079. # search by number
  2080. element = instance.find_elements(css: '#global-search')[0]
  2081. element.click
  2082. element.clear
  2083. element.send_keys(params[:title])
  2084. sleep 3
  2085. # open ticket
  2086. #instance.find_element(partial_link_text: params[:title] } ).click
  2087. instance.execute_script("$(\".js-global-search-result a:contains('#{params[:title]}') .nav-tab-icon\").click()")
  2088. sleep 1
  2089. title = instance.find_elements(css: '.content.active .ticketZoom-header .js-objectTitle')[0].text
  2090. if !title.match?(/#{params[:title]}/)
  2091. screenshot(browser: instance, comment: 'ticket_open_by_title_failed')
  2092. raise "unable to search/find ticket #{params[:title]}!"
  2093. end
  2094. true
  2095. end
  2096. =begin
  2097. overview_count = overview_counter(
  2098. browser: browser2,
  2099. )
  2100. returns
  2101. {
  2102. '#ticket/view/all_unassigned' => 42,
  2103. }
  2104. =end
  2105. def overview_counter(params = {})
  2106. switch_window_focus(params)
  2107. log('overview_counter', params)
  2108. instance = params[:browser] || @browser
  2109. instance.find_elements(css: '.js-overviewsMenuItem')[0].click
  2110. sleep 2
  2111. execute(
  2112. browser: instance,
  2113. js: '$(".content.active .sidebar").css("display", "block")',
  2114. )
  2115. #execute(
  2116. # browser: instance,
  2117. # js: '$(".content.active .overview-header").css("display", "none")',
  2118. #)
  2119. overviews = {}
  2120. instance.find_elements(css: '.content.active .sidebar a[href]').each do |element|
  2121. url = element.attribute('href')
  2122. url.gsub!(%r{(http|https)://.+?/(.+?)$}, '\\2')
  2123. overviews[url] = 0
  2124. #puts url.inspect
  2125. #puts element.inspect
  2126. end
  2127. overviews.each_key do |url|
  2128. count = instance.find_elements(css: ".content.active .sidebar a[href=\"#{url}\"] .badge")[0].text
  2129. overviews[url] = count.to_i
  2130. end
  2131. log('overview_counter', overviews)
  2132. overviews
  2133. end
  2134. =begin
  2135. organization_open_by_search(
  2136. browser: browser2,
  2137. value: 'some value',
  2138. )
  2139. =end
  2140. def organization_open_by_search(params = {})
  2141. switch_window_focus(params)
  2142. log('organization_open_by_search', params)
  2143. instance = params[:browser] || @browser
  2144. element = instance.find_elements(css: '#global-search')[0]
  2145. element.click
  2146. element.clear
  2147. element.send_keys(params[:value])
  2148. sleep 3
  2149. empty_search(browser: instance)
  2150. element = instance.find_elements(css: '#global-search')[0]
  2151. element.click
  2152. element.clear
  2153. element.send_keys(params[:value])
  2154. sleep 2
  2155. #instance.find_element(partial_link_text: params[:value] } ).click
  2156. instance.execute_script("$(\".js-global-search-result a:contains('#{params[:value]}') .nav-tab-icon\").click()")
  2157. sleep 1
  2158. name = instance.find_elements(css: '.content.active h1')[0].text
  2159. if !name.match?(/#{params[:value]}/)
  2160. screenshot(browser: instance, comment: 'organization_open_by_search_failed')
  2161. raise "unable to search/find org #{params[:value]}!"
  2162. end
  2163. assert(true, "org #{params[:value]} found")
  2164. true
  2165. end
  2166. =begin
  2167. user_open_by_search(
  2168. browser: browser2,
  2169. value: 'some value',
  2170. )
  2171. =end
  2172. def user_open_by_search(params = {})
  2173. switch_window_focus(params)
  2174. log('user_open_by_search', params)
  2175. instance = params[:browser] || @browser
  2176. element = instance.find_elements(css: '#global-search')[0]
  2177. element.click
  2178. element.clear
  2179. element.send_keys(params[:value])
  2180. sleep 3
  2181. #instance.find_element(partial_link_text: params[:value]).click
  2182. instance.execute_script("$(\".js-global-search-result a:contains('#{params[:value]}') .nav-tab-icon\").click()")
  2183. sleep 1
  2184. name = instance.find_elements(css: '.content.active h1')[0].text
  2185. if !name.match?(/#{params[:value]}/)
  2186. screenshot(browser: instance, comment: 'user_open_by_search_failed')
  2187. raise "unable to search/find user #{params[:value]}!"
  2188. end
  2189. assert(true, "user #{params[:term]} found")
  2190. true
  2191. end
  2192. =begin
  2193. user_create(
  2194. browser: browser2,
  2195. data: {
  2196. #login: 'some login' + random,
  2197. firstname: 'Manage Firstname' + random,
  2198. lastname: 'Manage Lastname' + random,
  2199. email: user_email,
  2200. password: 'some-pass',
  2201. },
  2202. )
  2203. =end
  2204. def user_create(params = {})
  2205. switch_window_focus(params)
  2206. log('user_create', params)
  2207. instance = params[:browser] || @browser
  2208. data = params[:data]
  2209. click(
  2210. browser: instance,
  2211. css: 'a[href="#manage"]',
  2212. mute_log: true,
  2213. )
  2214. click(
  2215. browser: instance,
  2216. css: '.content.active a[href="#manage/users"]',
  2217. mute_log: true,
  2218. )
  2219. click(
  2220. browser: instance,
  2221. css: '.content.active a[data-type="new"]',
  2222. mute_log: true,
  2223. )
  2224. modal_ready(browser: instance)
  2225. element = instance.find_elements(css: '.modal input[name=firstname]')[0]
  2226. element.clear
  2227. element.send_keys(data[:firstname])
  2228. element = instance.find_elements(css: '.modal input[name=lastname]')[0]
  2229. element.clear
  2230. element.send_keys(data[:lastname])
  2231. element = instance.find_elements(css: '.modal input[name=email]')[0]
  2232. element.clear
  2233. element.send_keys(data[:email])
  2234. element = instance.find_elements(css: '.modal input[name=password]')[0]
  2235. element.clear
  2236. element.send_keys(data[:password])
  2237. element = instance.find_elements(css: '.modal input[name=password_confirm]')[0]
  2238. element.clear
  2239. element.send_keys(data[:password])
  2240. check(
  2241. browser: instance,
  2242. css: '.modal input[name=role_ids][value=3]',
  2243. )
  2244. instance.find_elements(css: '.modal button.js-submit')[0].click
  2245. modal_disappear(
  2246. browser: instance,
  2247. timeout: 10,
  2248. )
  2249. set(
  2250. browser: instance,
  2251. css: '.content .js-search',
  2252. value: data[:email],
  2253. )
  2254. watch_for(
  2255. browser: instance,
  2256. css: 'body',
  2257. value: data[:lastname],
  2258. )
  2259. assert(true, 'user created')
  2260. end
  2261. =begin
  2262. calendar_create(
  2263. browser: browser2,
  2264. data: {
  2265. name: 'some calendar' + random,
  2266. first_response_time_in_text: 61
  2267. },
  2268. )
  2269. =end
  2270. def calendar_create(params = {})
  2271. switch_window_focus(params)
  2272. log('calendar_create', params)
  2273. instance = params[:browser] || @browser
  2274. data = params[:data]
  2275. click(
  2276. browser: instance,
  2277. css: 'a[href="#manage"]',
  2278. mute_log: true,
  2279. )
  2280. click(
  2281. browser: instance,
  2282. css: '.content.active a[href="#manage/calendars"]',
  2283. mute_log: true,
  2284. )
  2285. sleep 4
  2286. click(
  2287. browser: instance,
  2288. css: '.content.active a.js-new',
  2289. mute_log: true,
  2290. )
  2291. modal_ready(browser: instance)
  2292. element = instance.find_elements(css: '.content.active .modal input[name=name]')[0]
  2293. element.clear
  2294. element.send_keys(data[:name])
  2295. element = instance.find_elements(css: '.content.active .modal .js-input')[0]
  2296. element.clear
  2297. element.send_keys(data[:timezone])
  2298. element.send_keys(:enter)
  2299. instance.find_elements(css: '.modal button.js-submit')[0].click
  2300. modal_disappear(browser: instance)
  2301. 7.times do
  2302. element = instance.find_elements(css: 'body')[0]
  2303. text = element.text
  2304. if text.match?(/#{Regexp.quote(data[:name])}/)
  2305. assert(true, 'calendar created')
  2306. sleep 1
  2307. return true
  2308. end
  2309. sleep 1
  2310. end
  2311. screenshot(browser: instance, comment: 'calendar_create_failed')
  2312. raise 'calendar creation failed'
  2313. end
  2314. =begin
  2315. sla_create(
  2316. browser: browser2,
  2317. data: {
  2318. name: 'some sla' + random,
  2319. calendar: 'some calendar name',
  2320. first_response_time_in_text: 61
  2321. },
  2322. )
  2323. =end
  2324. def sla_create(params = {})
  2325. switch_window_focus(params)
  2326. log('sla_create', params)
  2327. instance = params[:browser] || @browser
  2328. data = params[:data]
  2329. click(
  2330. browser: instance,
  2331. css: 'a[href="#manage"]',
  2332. mute_log: true,
  2333. )
  2334. click(
  2335. browser: instance,
  2336. css: '.content.active a[href="#manage/slas"]',
  2337. mute_log: true,
  2338. )
  2339. click(
  2340. browser: instance,
  2341. css: '.content.active a.js-new',
  2342. mute_log: true,
  2343. )
  2344. modal_ready(browser: instance)
  2345. element = instance.find_elements(css: '.modal input[name=name]')[0]
  2346. element.clear
  2347. element.send_keys(data[:name])
  2348. if data[:calendar].present?
  2349. element = instance.find_elements(css: '.modal select[name="calendar_id"]')[0]
  2350. dropdown = Selenium::WebDriver::Support::Select.new(element)
  2351. dropdown.select_by(:text, data[:calendar])
  2352. end
  2353. element = instance.find_elements(css: '.modal input[name=first_response_time_in_text]')[0]
  2354. element.clear
  2355. element.send_keys(data[:first_response_time_in_text])
  2356. instance.find_elements(css: '.modal button.js-submit')[0].click
  2357. modal_disappear(browser: instance)
  2358. 7.times do
  2359. element = instance.find_elements(css: 'body')[0]
  2360. text = element.text
  2361. if text.match?(/#{Regexp.quote(data[:name])}/)
  2362. assert(true, 'sla created')
  2363. sleep 1
  2364. return true
  2365. end
  2366. sleep 1
  2367. end
  2368. screenshot(browser: instance, comment: 'sla_create_failed')
  2369. raise 'sla creation failed'
  2370. end
  2371. =begin
  2372. text_module_create(
  2373. browser: browser2,
  2374. data: {
  2375. name: 'some sla' + random,
  2376. keywords: 'some keywords',
  2377. content: 'some content',
  2378. },
  2379. )
  2380. =end
  2381. def text_module_create(params = {})
  2382. switch_window_focus(params)
  2383. log('text_module_create', params)
  2384. instance = params[:browser] || @browser
  2385. data = params[:data]
  2386. click(
  2387. browser: instance,
  2388. css: 'a[href="#manage"]',
  2389. mute_log: true,
  2390. )
  2391. click(
  2392. browser: instance,
  2393. css: '.content.active a[href="#manage/text_modules"]',
  2394. mute_log: true,
  2395. )
  2396. click(
  2397. browser: instance,
  2398. css: '.content.active a[data-type="new"]',
  2399. mute_log: true,
  2400. )
  2401. modal_ready(browser: instance)
  2402. set(
  2403. browser: instance,
  2404. css: '.modal input[name=name]',
  2405. value: data[:name],
  2406. )
  2407. set(
  2408. browser: instance,
  2409. css: '.modal input[name=keywords]',
  2410. value: data[:keywords],
  2411. )
  2412. set(
  2413. browser: instance,
  2414. css: '.modal [data-name=content]',
  2415. value: data[:content],
  2416. )
  2417. instance.find_elements(css: '.modal button.js-submit')[0].click
  2418. modal_disappear(browser: instance)
  2419. 7.times do
  2420. element = instance.find_elements(css: 'body')[0]
  2421. text = element.text
  2422. if text.match?(/#{Regexp.quote(data[:name])}/)
  2423. assert(true, 'text module created')
  2424. sleep 1
  2425. return true
  2426. end
  2427. sleep 1
  2428. end
  2429. screenshot(browser: instance, comment: 'text_module_create_failed')
  2430. raise 'text module creation failed'
  2431. end
  2432. =begin
  2433. signature_create(
  2434. browser: browser2,
  2435. data: {
  2436. name: 'some sla' + random,
  2437. body: 'some body',
  2438. },
  2439. )
  2440. =end
  2441. def signature_create(params = {})
  2442. switch_window_focus(params)
  2443. log('signature_create', params)
  2444. instance = params[:browser] || @browser
  2445. data = params[:data]
  2446. click(
  2447. browser: instance,
  2448. css: 'a[href="#manage"]',
  2449. mute_log: true,
  2450. )
  2451. click(
  2452. browser: instance,
  2453. css: '.content.active a[href="#channels/email"]',
  2454. mute_log: true,
  2455. )
  2456. click(
  2457. browser: instance,
  2458. css: '.content.active a[href="#c-signature"]',
  2459. mute_log: true,
  2460. )
  2461. sleep 4
  2462. click(
  2463. browser: instance,
  2464. css: '.content.active #c-signature a[data-type="new"]',
  2465. mute_log: true,
  2466. )
  2467. modal_ready(browser: instance)
  2468. set(
  2469. browser: instance,
  2470. css: '.modal input[name=name]',
  2471. value: data[:name],
  2472. )
  2473. set(
  2474. browser: instance,
  2475. css: '.modal [data-name=body]',
  2476. value: data[:body],
  2477. )
  2478. instance.find_elements(css: '.modal button.js-submit')[0].click
  2479. modal_disappear(browser: instance)
  2480. 11.times do
  2481. element = instance.find_elements(css: 'body')[0]
  2482. text = element.text
  2483. if text.match?(/#{Regexp.quote(data[:name])}/)
  2484. assert(true, 'signature created')
  2485. sleep 1
  2486. return true
  2487. end
  2488. sleep 1
  2489. end
  2490. screenshot(browser: instance, comment: 'signature_create_failed')
  2491. raise 'signature creation failed'
  2492. end
  2493. =begin
  2494. group_create(
  2495. browser: browser2,
  2496. data: {
  2497. name: 'some sla' + random,
  2498. signature: 'some signature bame',
  2499. member: [
  2500. {
  2501. login: 'some_user_login',
  2502. access: 'all',
  2503. },
  2504. ],
  2505. },
  2506. )
  2507. =end
  2508. def group_create(params = {})
  2509. switch_window_focus(params)
  2510. log('group_create', params)
  2511. instance = params[:browser] || @browser
  2512. data = params[:data]
  2513. click(
  2514. browser: instance,
  2515. css: 'a[href="#manage"]',
  2516. mute_log: true,
  2517. )
  2518. click(
  2519. browser: instance,
  2520. css: '.content.active a[href="#manage/groups"]',
  2521. mute_log: true,
  2522. )
  2523. click(
  2524. browser: instance,
  2525. css: '.content.active a[data-type="new"]',
  2526. mute_log: true,
  2527. )
  2528. modal_ready(browser: instance)
  2529. element = instance.find_elements(css: '.modal input[name=name]')[0]
  2530. element.clear
  2531. element.send_keys(data[:name])
  2532. element = instance.find_elements(css: '.modal select[name="email_address_id"]')[0]
  2533. dropdown = Selenium::WebDriver::Support::Select.new(element)
  2534. dropdown.select_by(:index, 1)
  2535. #dropdown.select_by(:text, action[:group])
  2536. if data[:signature]
  2537. element = instance.find_elements(css: '.modal select[name="signature_id"]')[0]
  2538. dropdown = Selenium::WebDriver::Support::Select.new(element)
  2539. dropdown.select_by(:text, data[:signature])
  2540. end
  2541. instance.find_elements(css: '.modal button.js-submit')[0].click
  2542. modal_disappear(browser: instance)
  2543. 11.times do
  2544. element = instance.find_elements(css: 'body')[0]
  2545. text = element.text
  2546. if text.match?(/#{Regexp.quote(data[:name])}/)
  2547. assert(true, 'group created')
  2548. modal_disappear(browser: instance) # wait until modal has gone
  2549. # add member
  2550. data[:member]&.each do |member|
  2551. instance.find_elements(css: 'a[href="#manage"]')[0].click
  2552. sleep 1
  2553. instance.find_elements(css: '.content.active a[href="#manage/users"]')[0].click
  2554. sleep 3
  2555. element = instance.find_elements(css: '.content.active [name="search"]')[0]
  2556. element.clear
  2557. element.send_keys(member[:login])
  2558. sleep 3
  2559. #instance.find_elements(:css => '.content.active table [data-id]')[0].click
  2560. instance.execute_script('$(".content.active table [data-id] td").first().click()')
  2561. modal_ready(browser: instance)
  2562. #instance.find_elements(:css => 'label:contains(" ' + action[:name] + '")')[0].click
  2563. instance.execute_script('$(".js-groupList tr:contains(\"' + data[:name] + '\") .js-groupListItem[value=' + member[:access] + ']").prop("checked", true)')
  2564. instance.find_elements(css: '.modal button.js-submit')[0].click
  2565. modal_disappear(browser: instance)
  2566. end
  2567. end
  2568. sleep 1
  2569. return true
  2570. end
  2571. screenshot(browser: instance, comment: 'group_create_failed')
  2572. raise 'group creation failed'
  2573. end
  2574. =begin
  2575. role_create(
  2576. browser: browser2,
  2577. data: {
  2578. name: 'some role' + random,
  2579. default_at_signup: false,
  2580. permission: {
  2581. 'admin.group' => true,
  2582. 'preferences.password' => true,
  2583. },
  2584. member: [
  2585. 'some_user_login',
  2586. ],
  2587. },
  2588. )
  2589. =end
  2590. def role_create(params = {})
  2591. switch_window_focus(params)
  2592. log('role_create', params)
  2593. instance = params[:browser] || @browser
  2594. data = params[:data]
  2595. click(
  2596. browser: instance,
  2597. css: 'a[href="#manage"]',
  2598. mute_log: true,
  2599. )
  2600. click(
  2601. browser: instance,
  2602. css: '.content.active a[href="#manage/roles"]',
  2603. mute_log: true,
  2604. )
  2605. click(
  2606. browser: instance,
  2607. css: '.content.active a[data-type="new"]',
  2608. mute_log: true,
  2609. )
  2610. modal_ready(browser: instance)
  2611. element = instance.find_elements(css: '.modal input[name=name]')[0]
  2612. element.clear
  2613. element.send_keys(data[:name])
  2614. if data.key?(:default_at_signup)
  2615. element = instance.find_elements(css: '.modal select[name="default_at_signup"]')[0]
  2616. dropdown = Selenium::WebDriver::Support::Select.new(element)
  2617. if data[:default_at_signup] == true
  2618. dropdown.select_by(:text, 'yes')
  2619. else
  2620. dropdown.select_by(:text, 'no')
  2621. end
  2622. end
  2623. if data.key?(:permission)
  2624. data[:permission].each do |permission_name, permission_value|
  2625. if permission_value == false
  2626. uncheck(
  2627. browser: instance,
  2628. css: ".modal [data-permission-name=\"#{permission_name}\"]",
  2629. )
  2630. else
  2631. check(
  2632. browser: instance,
  2633. css: ".modal [data-permission-name=\"#{permission_name}\"]",
  2634. )
  2635. end
  2636. end
  2637. end
  2638. instance.find_elements(css: '.modal button.js-submit')[0].click
  2639. modal_disappear(browser: instance)
  2640. 11.times do
  2641. element = instance.find_elements(css: 'body')[0]
  2642. text = element.text
  2643. if text.match?(/#{Regexp.quote(data[:name])}/)
  2644. assert(true, 'role created')
  2645. modal_disappear(browser: instance) # wait until modal has gone
  2646. # add member
  2647. data[:member]&.each do |login|
  2648. instance.find_elements(css: 'a[href="#manage"]')[0].click
  2649. sleep 1
  2650. instance.find_elements(css: '.content.active a[href="#manage/users"]')[0].click
  2651. sleep 3
  2652. element = instance.find_elements(css: '.content.active [name="search"]')[0]
  2653. element.clear
  2654. element.send_keys(login)
  2655. sleep 3
  2656. #instance.find_elements(:css => '.content.active table [data-id]')[0].click
  2657. instance.execute_script('$(".content.active table [data-id] td").first().click()')
  2658. sleep 3
  2659. #instance.find_elements(:css => 'label:contains(" ' + action[:name] + '")')[0].click
  2660. instance.execute_script('$(\'label:contains(" ' + data[:name] + '")\').first().click()')
  2661. instance.find_elements(css: '.modal button.js-submit')[0].click
  2662. modal_disappear(browser: instance)
  2663. end
  2664. end
  2665. sleep 1
  2666. return true
  2667. end
  2668. screenshot(browser: instance, comment: 'role_create_failed')
  2669. raise 'role creation failed'
  2670. end
  2671. =begin
  2672. role_create(
  2673. browser: browser2,
  2674. data: {
  2675. name: 'some role' + random,
  2676. default_at_signup: false,
  2677. permission: {
  2678. 'admin.group' => true,
  2679. 'preferences.password' => true,
  2680. },
  2681. member: [
  2682. 'some_user_login',
  2683. ],
  2684. },
  2685. )
  2686. =end
  2687. def role_edit(params = {})
  2688. switch_window_focus(params)
  2689. log('role_edit', params)
  2690. instance = params[:browser] || @browser
  2691. data = params[:data]
  2692. click(
  2693. browser: instance,
  2694. css: 'a[href="#manage"]',
  2695. mute_log: true,
  2696. )
  2697. click(
  2698. browser: instance,
  2699. css: '.content.active a[href="#manage/roles"]',
  2700. mute_log: true,
  2701. )
  2702. instance.execute_script('$(\'.content.active table tr td:contains(" ' + data[:name] + '")\').first().click()')
  2703. modal_ready(browser: instance)
  2704. element = instance.find_elements(css: '.modal input[name=name]')[0]
  2705. element.clear
  2706. element.send_keys(data[:name])
  2707. if data.key?(:default_at_signup)
  2708. element = instance.find_elements(css: '.modal select[name="default_at_signup"]')[0]
  2709. dropdown = Selenium::WebDriver::Support::Select.new(element)
  2710. if data[:default_at_signup] == true
  2711. dropdown.select_by(:text, 'yes')
  2712. else
  2713. dropdown.select_by(:text, 'no')
  2714. end
  2715. end
  2716. if data.key?(:permission)
  2717. data[:permission].each do |permission_name, permission_value|
  2718. if permission_value == false
  2719. uncheck(
  2720. browser: instance,
  2721. css: ".modal [data-permission-name=\"#{permission_name}\"]",
  2722. )
  2723. else
  2724. check(
  2725. browser: instance,
  2726. css: ".modal [data-permission-name=\"#{permission_name}\"]",
  2727. )
  2728. end
  2729. end
  2730. end
  2731. if data.key?(:active)
  2732. element = instance.find_elements(css: '.modal select[name="active"]')[0]
  2733. dropdown = Selenium::WebDriver::Support::Select.new(element)
  2734. if data[:active] == true
  2735. dropdown.select_by(:text, 'active')
  2736. else
  2737. dropdown.select_by(:text, 'inactive')
  2738. end
  2739. end
  2740. instance.find_elements(css: '.modal button.js-submit')[0].click
  2741. modal_disappear(browser: instance)
  2742. 11.times do
  2743. element = instance.find_elements(css: 'body')[0]
  2744. text = element.text
  2745. if text.match?(/#{Regexp.quote(data[:name])}/)
  2746. assert(true, 'role created')
  2747. modal_disappear(browser: instance) # wait until modal has gone
  2748. # add member
  2749. data[:member]&.each do |login|
  2750. instance.find_elements(css: 'a[href="#manage"]')[0].click
  2751. sleep 1
  2752. instance.find_elements(css: '.content.active a[href="#manage/users"]')[0].click
  2753. sleep 3
  2754. element = instance.find_elements(css: '.content.active [name="search"]')[0]
  2755. element.clear
  2756. element.send_keys(login)
  2757. sleep 3
  2758. #instance.find_elements(:css => '.content.active table [data-id]')[0].click
  2759. instance.execute_script('$(".content.active table [data-id] td").first().click()')
  2760. sleep 3
  2761. #instance.find_elements(:css => 'label:contains(" ' + action[:name] + '")')[0].click
  2762. instance.execute_script('$(\'label:contains(" ' + data[:name] + '")\').first().click()')
  2763. instance.find_elements(css: '.modal button.js-submit')[0].click
  2764. modal_disappear(browser: instance)
  2765. end
  2766. end
  2767. sleep 1
  2768. return true
  2769. end
  2770. screenshot(browser: instance, comment: 'role_edit_failed')
  2771. raise 'role edit failed'
  2772. end
  2773. =begin
  2774. object_manager_attribute_create(
  2775. browser: browser2,
  2776. data: {
  2777. name: 'field_name' + random,
  2778. display: 'Display Name of Field',
  2779. data_type: 'Select',
  2780. data_option: {
  2781. options: {
  2782. 'aa' => 'AA',
  2783. 'bb' => 'BB',
  2784. },
  2785. default: 'abc',
  2786. },
  2787. },
  2788. error: 'already exists'
  2789. )
  2790. object_manager_attribute_create(
  2791. browser: browser2,
  2792. data: {
  2793. name: 'field_name' + random,
  2794. display: 'Display Name of Field',
  2795. data_type: 'Text',
  2796. data_option: {
  2797. default: 'abc',
  2798. },
  2799. },
  2800. error: 'already exists'
  2801. )
  2802. object_manager_attribute_create(
  2803. browser: browser2,
  2804. data: {
  2805. name: 'field_name' + random,
  2806. display: 'Display Name of Field',
  2807. data_type: 'Integer',
  2808. data_option: {
  2809. default: '15',
  2810. min: 1,
  2811. max: 999999,
  2812. },
  2813. },
  2814. error: 'already exists'
  2815. )
  2816. object_manager_attribute_create(
  2817. browser: browser2,
  2818. data: {
  2819. name: 'field_name' + random,
  2820. display: 'Display Name of Field',
  2821. data_type: 'Datetime',
  2822. data_option: {
  2823. future: true,
  2824. past: true,
  2825. diff: 24,
  2826. },
  2827. },
  2828. error: 'already exists'
  2829. )
  2830. object_manager_attribute_create(
  2831. browser: browser2,
  2832. data: {
  2833. name: 'field_name' + random,
  2834. display: 'Display Name of Field',
  2835. data_type: 'Date',
  2836. data_option: {
  2837. future: true,
  2838. past: true,
  2839. diff: 24,
  2840. },
  2841. },
  2842. error: 'already exists'
  2843. )
  2844. object_manager_attribute_create(
  2845. browser: browser2,
  2846. data: {
  2847. name: 'field_name' + random,
  2848. display: 'Display Name of Field',
  2849. data_type: 'Boolean',
  2850. data_option: {
  2851. options: {
  2852. true: 'YES',
  2853. false: 'NO',
  2854. }
  2855. default: undefined,
  2856. },
  2857. },
  2858. error: 'already exists'
  2859. )
  2860. =end
  2861. def object_manager_attribute_create(params = {})
  2862. switch_window_focus(params)
  2863. log('object_manager_attribute_create', params)
  2864. instance = params[:browser] || @browser
  2865. data = params[:data]
  2866. click(
  2867. browser: instance,
  2868. css: 'a[href="#manage"]',
  2869. mute_log: true,
  2870. )
  2871. click(
  2872. browser: instance,
  2873. css: '.content.active a[href="#system/object_manager"]',
  2874. mute_log: true,
  2875. )
  2876. sleep 4
  2877. click(
  2878. browser: instance,
  2879. css: '.content.active .js-new',
  2880. mute_log: true,
  2881. )
  2882. modal_ready(browser: instance)
  2883. element = instance.find_elements(css: '.modal input[name=name]')[0]
  2884. element.clear
  2885. element.send_keys(data[:name])
  2886. element = instance.find_elements(css: '.modal input[name=display]')[0]
  2887. element.clear
  2888. element.send_keys(data[:display])
  2889. select(
  2890. browser: instance,
  2891. css: '.modal select[name="data_type"]',
  2892. value: data[:data_type],
  2893. mute_log: true,
  2894. )
  2895. if data[:data_option]
  2896. if data[:data_option][:options]
  2897. if data[:data_type] == 'Boolean'
  2898. # rubocop:disable Lint/BooleanSymbol
  2899. element = instance.find_elements(css: '.modal .js-valueTrue').first
  2900. element.clear
  2901. element.send_keys(data[:data_option][:options][:true])
  2902. element = instance.find_elements(css: '.modal .js-valueFalse').first
  2903. element.clear
  2904. element.send_keys(data[:data_option][:options][:false])
  2905. # rubocop:enable Lint/BooleanSymbol
  2906. elsif data[:data_type] == 'Tree Select'
  2907. add_tree_options(
  2908. instance: instance,
  2909. options: data[:data_option][:options],
  2910. )
  2911. else
  2912. data[:data_option][:options].each do |key, value|
  2913. element = instance.find_elements(css: '.modal .js-Table .js-key').last
  2914. element.clear
  2915. element.send_keys(key)
  2916. element = instance.find_elements(css: '.modal .js-Table .js-value').last
  2917. element.clear
  2918. element.send_keys(value)
  2919. element = instance.find_elements(css: '.modal .js-Table .js-add')[0]
  2920. element.click
  2921. end
  2922. end
  2923. end
  2924. %i[default min max diff].each do |key|
  2925. next if !data[:data_option].key?(key)
  2926. element = instance.find_elements(css: ".modal [name=\"data_option::#{key}\"]").first
  2927. element.clear
  2928. element.send_keys(data[:data_option][key])
  2929. end
  2930. %i[future past].each do |key|
  2931. next if !data[:data_option].key?(key)
  2932. select(
  2933. browser: instance,
  2934. css: ".modal select[name=\"data_option::#{key}\"]",
  2935. value: data[:data_option][key],
  2936. mute_log: true,
  2937. )
  2938. end
  2939. end
  2940. instance.find_elements(css: '.modal button.js-submit')[0].click
  2941. if params[:error]
  2942. sleep 4
  2943. watch_for(
  2944. css: '.modal',
  2945. value: params[:error],
  2946. )
  2947. click(
  2948. browser: instance,
  2949. css: '.modal .js-close',
  2950. )
  2951. modal_disappear(browser: instance)
  2952. return
  2953. end
  2954. 11.times do
  2955. element = instance.find_elements(css: 'body')[0]
  2956. text = element.text
  2957. if text.match?(/#{Regexp.quote(data[:name])}/)
  2958. assert(true, 'object manager attribute created')
  2959. sleep 1
  2960. return true
  2961. end
  2962. sleep 1
  2963. end
  2964. screenshot(browser: instance, comment: 'object_manager_attribute_create_failed')
  2965. raise 'object manager attribute creation failed'
  2966. end
  2967. =begin
  2968. object_manager_attribute_update(
  2969. browser: browser2,
  2970. data: {
  2971. name: 'field_name' + random,
  2972. display: 'Display Name of Field',
  2973. data_type: 'Select',
  2974. data_option: {
  2975. options: {
  2976. 'aa' => 'AA',
  2977. 'bb' => 'BB',
  2978. },
  2979. default: 'abc',
  2980. },
  2981. },
  2982. error: 'already exists'
  2983. )
  2984. =end
  2985. def object_manager_attribute_update(params = {})
  2986. switch_window_focus(params)
  2987. log('object_manager_attribute_update', params)
  2988. instance = params[:browser] || @browser
  2989. data = params[:data]
  2990. click(
  2991. browser: instance,
  2992. css: 'a[href="#manage"]',
  2993. mute_log: true,
  2994. )
  2995. click(
  2996. browser: instance,
  2997. css: '.content.active a[href="#system/object_manager"]',
  2998. mute_log: true,
  2999. )
  3000. sleep 4
  3001. instance.execute_script("$(\".content.active td:contains('#{data[:name]}')\").first().click()")
  3002. modal_ready(browser: instance)
  3003. element = instance.find_elements(css: '.modal input[name=display]')[0]
  3004. element.clear
  3005. element.send_keys(data[:display])
  3006. select(
  3007. browser: instance,
  3008. css: '.modal select[name="data_type"]',
  3009. value: data[:data_type],
  3010. mute_log: true,
  3011. )
  3012. if data[:data_option]
  3013. if data[:data_option][:options]
  3014. if data[:data_type] == 'Boolean'
  3015. # rubocop:disable Lint/BooleanSymbol
  3016. element = instance.find_elements(css: '.modal .js-valueTrue').first
  3017. element.clear
  3018. element.send_keys(data[:data_option][:options][:true])
  3019. element = instance.find_elements(css: '.modal .js-valueFalse').first
  3020. element.clear
  3021. element.send_keys(data[:data_option][:options][:false])
  3022. # rubocop:enable Lint/BooleanSymbol
  3023. else
  3024. data[:data_option][:options].each do |key, value|
  3025. element = instance.find_elements(css: '.modal .js-Table .js-key').last
  3026. element.clear
  3027. element.send_keys(key)
  3028. element = instance.find_elements(css: '.modal .js-Table .js-value').last
  3029. element.clear
  3030. element.send_keys(value)
  3031. element = instance.find_elements(css: '.modal .js-Table .js-add')[0]
  3032. element.click
  3033. end
  3034. end
  3035. end
  3036. %i[default min max diff].each do |key|
  3037. next if !data[:data_option].key?(key)
  3038. element = instance.find_elements(css: ".modal [name=\"data_option::#{key}\"]").first
  3039. element.clear
  3040. element.send_keys(data[:data_option][key])
  3041. end
  3042. %i[future past].each do |key|
  3043. next if !data[:data_option].key?(key)
  3044. select(
  3045. browser: instance,
  3046. css: ".modal select[name=\"data_option::#{key}\"]",
  3047. value: data[:data_option][key],
  3048. mute_log: true,
  3049. )
  3050. end
  3051. end
  3052. instance.find_elements(css: '.modal button.js-submit')[0].click
  3053. if params[:error]
  3054. sleep 4
  3055. watch_for(
  3056. css: '.modal',
  3057. value: params[:error],
  3058. )
  3059. click(
  3060. browser: instance,
  3061. css: '.modal .js-close',
  3062. )
  3063. modal_disappear(browser: instance)
  3064. return
  3065. end
  3066. 11.times do
  3067. element = instance.find_elements(css: 'body')[0]
  3068. text = element.text
  3069. if text.match?(/#{Regexp.quote(data[:name])}/)
  3070. assert(true, 'object manager attribute updated')
  3071. sleep 1
  3072. return true
  3073. end
  3074. sleep 1
  3075. end
  3076. screenshot(browser: instance, comment: 'object_manager_attribute_update_failed')
  3077. raise 'object manager attribute update failed'
  3078. end
  3079. =begin
  3080. object_manager_attribute_delete(
  3081. browser: browser2,
  3082. data: {
  3083. name: 'field_name' + random,
  3084. },
  3085. )
  3086. =end
  3087. def object_manager_attribute_delete(params = {})
  3088. switch_window_focus(params)
  3089. log('object_manager_attribute_delete', params)
  3090. instance = params[:browser] || @browser
  3091. data = params[:data]
  3092. click(
  3093. browser: instance,
  3094. css: 'a[href="#manage"]',
  3095. mute_log: true,
  3096. )
  3097. click(
  3098. browser: instance,
  3099. css: '.content.active a[href="#system/object_manager"]',
  3100. mute_log: true,
  3101. )
  3102. sleep 4
  3103. instance = params[:browser] || @browser
  3104. data = params[:data]
  3105. r = instance.execute_script("$(\".content.active td:contains('#{data[:name]}')\").first().closest('tr').find('.js-delete').click()")
  3106. #p "rrr #{r.inspect}"
  3107. end
  3108. =begin
  3109. object_manager_attribute_discard_changes(
  3110. browser: browser2,
  3111. )
  3112. =end
  3113. def object_manager_attribute_discard_changes(params = {})
  3114. switch_window_focus(params)
  3115. log('object_manager_attribute_discard_changes', params)
  3116. instance = params[:browser] || @browser
  3117. click(
  3118. browser: instance,
  3119. css: 'a[href="#manage"]',
  3120. mute_log: true,
  3121. )
  3122. click(
  3123. browser: instance,
  3124. css: '.content.active a[href="#system/object_manager"]',
  3125. mute_log: true,
  3126. )
  3127. sleep 4
  3128. element = instance.find_elements(css: '.content.active .js-discard').first
  3129. element.click
  3130. watch_for_disappear(
  3131. browser: instance,
  3132. css: '.content.active .js-discard',
  3133. )
  3134. end
  3135. =begin
  3136. tags_verify(
  3137. browser: browser2,
  3138. tags: {
  3139. 'tag 1' => true,
  3140. 'tag 2' => true,
  3141. 'tag 3' => false,
  3142. },
  3143. )
  3144. =end
  3145. def tags_verify(params = {})
  3146. switch_window_focus(params)
  3147. log('tags_verify', params)
  3148. instance = params[:browser] || @browser
  3149. tags = instance.find_elements({ css: '.content.active .js-tag' })
  3150. assert(tags)
  3151. assert(tags[0])
  3152. tags_found = {}
  3153. params[:tags].each_key do |key|
  3154. tags_found[key] = false
  3155. end
  3156. tags.each do |element|
  3157. text = element.text
  3158. if tags_found.key?(text)
  3159. tags_found[text] = true
  3160. else
  3161. assert(false, "tag exists but is not in check to verify '#{text}'")
  3162. end
  3163. end
  3164. params[:tags].each do |key, value|
  3165. assert_equal(value, tags_found[key], "tag '#{key}'")
  3166. end
  3167. end
  3168. def quote(string)
  3169. string_quoted = string
  3170. string_quoted.gsub!(/&/, '&amp;')
  3171. string_quoted.gsub!(/</, '&lt;')
  3172. string_quoted.gsub!(/>/, '&gt;')
  3173. string_quoted
  3174. end
  3175. def switch_window_focus(params)
  3176. instance = params[:browser] || @browser
  3177. if instance != @last_used_browser
  3178. log('switch browser window focus', {})
  3179. instance.switch_to.window(instance.window_handles.first)
  3180. end
  3181. @last_used_browser = instance
  3182. end
  3183. def log(method, params = {})
  3184. begin
  3185. instance = params[:browser] || @browser
  3186. if instance
  3187. logs = instance.manage.logs.get(:browser)
  3188. logs.each do |log|
  3189. next if log.level == 'WARNING' && log.message =~ /Declaration\sdropped./ # ignore ff css warnings
  3190. time = Time.zone.parse(Time.zone.at(log.timestamp / 1000).to_datetime.to_s)
  3191. puts "#{time}/#{log.level}: #{log.message}"
  3192. end
  3193. end
  3194. rescue
  3195. # failed to get logs
  3196. end
  3197. return if !DEBUG
  3198. return if params[:mute_log]
  3199. puts "#{Time.zone.now}/#{method}: #{params.inspect}"
  3200. end
  3201. private
  3202. def add_tree_options(instance:, options:)
  3203. # first level entries have to get added in regular order
  3204. options.each_key.with_index do |option, index|
  3205. if index != 0
  3206. element = instance.find_elements(css: '.modal .js-treeTable .js-addRow')[index - 1]
  3207. element.click
  3208. end
  3209. element = instance.find_elements(css: '.modal .js-treeTable .js-key')[index]
  3210. element.clear
  3211. element.send_keys(option)
  3212. end
  3213. add_sub_tree_recursion(
  3214. instance: instance,
  3215. options: options,
  3216. )
  3217. end
  3218. def add_sub_tree_recursion(instance:, options:, offset: 0)
  3219. options.each_value.inject(offset) do |child_offset, children|
  3220. child_offset += 1
  3221. # put your recursion glasses on 8-)
  3222. add_sub_tree_options(
  3223. instance: instance,
  3224. options: children,
  3225. offset: child_offset,
  3226. )
  3227. end
  3228. end
  3229. def add_sub_tree_options(instance:, options:, offset:)
  3230. # sub level entries have to get added in reversed order
  3231. level_options = options.to_a.reverse.to_h.keys
  3232. level_options.each do |option|
  3233. # sub level entries have to get added via 'add child row' link
  3234. click_index = offset - 1
  3235. element = instance.find_elements(css: '.modal .js-treeTable .js-addChild')[click_index]
  3236. element.click
  3237. element = instance.find_elements(css: '.modal .js-treeTable .js-key')[offset]
  3238. element.clear
  3239. element.send_keys(option)
  3240. sleep 0.25
  3241. end
  3242. add_sub_tree_recursion(
  3243. instance: instance,
  3244. options: options,
  3245. offset: offset,
  3246. )
  3247. end
  3248. def token_verify(css, value)
  3249. original_element = @browser.find_element(:css, css)
  3250. elem = original_element.find_element(xpath: '../input[contains(@class, "token-input")]')
  3251. elem.send_keys value
  3252. elem.send_keys :enter
  3253. watch_for(
  3254. xpath: '../*/span[contains(@class,"token-label")]',
  3255. value: value,
  3256. container: original_element
  3257. )
  3258. end
  3259. def toggle_checkbox(scope, value)
  3260. checkbox = scope.find_element(css: "input[value=#{value}]")
  3261. @browser
  3262. .action
  3263. .move_to(checkbox)
  3264. .click
  3265. .perform
  3266. end
  3267. def checkbox_is_selected(scope, value)
  3268. scope.find_element(css: "input[value=#{value}]").property('checked')
  3269. end
  3270. end