-
Notifications
You must be signed in to change notification settings - Fork 174
/
navigation_steps.rb
1225 lines (1015 loc) · 43 KB
/
navigation_steps.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright (c) 2010-2024 SUSE LLC.
# Licensed under the terms of the MIT license.
### This file contains the definitions for all steps concerning navigation through the Web UI
### as well as validating the UI output.
#
# Texts and links
#
Then(/^I should see a "(.*)" text in the content area$/) do |text|
within('#spacewalk-content') do
raise ScriptError, "Text '#{text}' not found" unless check_text_and_catch_request_timeout_popup?(text)
end
end
Then(/^I should not see a "(.*)" text in the content area$/) do |text|
within('#spacewalk-content') do
raise ScriptError, "Text '#{text}' found" unless has_no_content?(text)
end
end
When(/^I click on "([^"]+)" in row "([^"]+)"$/) do |link, item|
within(:xpath, "//tr[td[contains(.,'#{item}')]]") do
click_link_or_button_and_wait(link)
end
end
When(/^I click on "([^"]+)" in tree item "(.*?)"$/) do |button, item|
within(:xpath, "//span[contains(text(), '#{item}')]/ancestor::div[contains(@class, 'product-details-wrapper')]") do
click_link_or_button_and_wait(button)
end
end
Then(/^the current path is "([^"]*)"$/) do |arg1|
raise ScriptError, "Path #{current_path} different than #{arg1}" unless current_path == arg1
end
When(/^I wait until I see "([^"]*)" text$/) do |text|
raise ScriptError, "Text '#{text}' not found" unless check_text_and_catch_request_timeout_popup?(text, timeout: DEFAULT_TIMEOUT)
end
When(/^I wait until I do not see "([^"]*)" text$/) do |text|
raise ScriptError, "Text '#{text}' found" unless has_no_text?(text, wait: DEFAULT_TIMEOUT)
end
When(/^I wait at most (\d+) seconds until I see "([^"]*)" text$/) do |seconds, text|
raise ScriptError, "Text '#{text}' not found" unless check_text_and_catch_request_timeout_popup?(text, timeout: seconds.to_i)
end
When(/^I wait until I see "([^"]*)" text or "([^"]*)" text$/) do |text1, text2|
raise ScriptError, "Text '#{text1}' or '#{text2}' not found" unless check_text_and_catch_request_timeout_popup?(text1, text2: text2, timeout: DEFAULT_TIMEOUT)
end
When(/^I wait until I see "([^"]*)" (text|regex), refreshing the page$/) do |text, type|
text = Regexp.new(text) if type == 'regex'
next if has_content?(text, wait: 3)
repeat_until_timeout(message: "Couldn't find text '#{text}'") do
break if has_content?(text, wait: 3)
refresh_page
end
end
When(/^I wait at most (\d+) seconds until I do not see "([^"]*)" text, refreshing the page$/) do |seconds, text|
next if has_no_text?(text, wait: 3)
repeat_until_timeout(message: "I still see text '#{text}'", timeout: seconds.to_i) do
break if has_no_text?(text, wait: 3)
refresh_page
end
end
When(/^I wait at most "([^"]*)" seconds until I do not see "([^"]*)" text$/) do |seconds, text|
next if has_no_text?(text, wait: 3)
repeat_until_timeout(message: "I still see text '#{text}'", timeout: seconds.to_i) do
break if has_no_text?(text, wait: 3)
end
end
When(/^I wait at most (\d+) seconds until the event is completed, refreshing the page$/) do |timeout|
last = Time.now
next if has_content?('This action\'s status is: Completed.', wait: 3)
repeat_until_timeout(timeout: timeout.to_i, message: 'Event not yet completed') do
break if has_content?('This action\'s status is: Completed.', wait: 3)
raise SystemCallError, 'Event failed' if has_content?('This action\'s status is: Failed.', wait: 3)
current = Time.now
if current - last > 150
log "#{current} Still waiting for action to complete..."
last = current
end
refresh_page
end
end
When(/^I wait until I see the name of "([^"]*)", refreshing the page$/) do |host|
raise ScriptError, 'Overview System page didn\'t load' unless has_content?('Download CSV') || has_content?('Keys')
system_name = get_system_name(host)
step %(I wait until I see the "#{system_name}" system, refreshing the page)
end
When(/^I wait until I see the "([^"]*)" system, refreshing the page$/) do |system_name|
steps %(
And I wait until I do not see "Loading..." text
And I wait until I see "#{system_name}" text, refreshing the page
)
end
When(/^I wait until I do not see "([^"]*)" text, refreshing the page$/) do |text|
next unless has_content?(text, wait: 3)
repeat_until_timeout(message: "Text '#{text}' is still visible") do
break unless has_content?(text, wait: 3)
refresh_page
end
end
When(/^I wait until I do not see the name of "([^"]*)", refreshing the page$/) do |host|
system_name = get_system_name(host)
step %(I wait until I do not see "#{system_name}" text, refreshing the page)
end
Then(/^I wait until I see the (VNC|spice) graphical console$/) do |type|
repeat_until_timeout(message: "The #{type} graphical console didn't load") do
break if find(:xpath, '//canvas')
# If the connection failed try reloading since the VM may not have been ready
if find(:xpath, '//*[contains(@class, "modal-title") and text() = "Failed to connect"]')
refresh_page
end
end
end
When(/^I switch to last opened window$/) do
page.driver.browser.switch_to.window(page.driver.browser.window_handles.last)
end
When(/^I close the last opened window$/) do
page.driver.browser.close
page.driver.browser.switch_to.window(page.driver.browser.window_handles.first)
end
#
# Check a checkbox of the given id
#
When(/^I check "([^"]*)"$/) do |identifier|
check(identifier)
raise ScriptError, "Checkbox #{identifier} not checked." unless has_checked_field?(identifier)
end
When(/^I uncheck "([^"]*)"$/) do |identifier|
uncheck(identifier)
raise ScriptError, "Checkbox #{identifier} not unchecked." if has_checked_field?(identifier)
end
When(/^I select "([^"]*)" from "([^"]*)"$/) do |option, field|
if has_select?(field, with_options: [option], wait: 1)
select(option, from: field)
else
# Custom React selector
xpath_field = "//*[contains(@class, 'data-testid-#{field}-child__control')]"
xpath_option = ".//*[contains(@class, 'data-testid-#{field}-child__option') and contains(text(), '#{option}')]"
find(:xpath, xpath_field).click
find(:xpath, xpath_option, match: :first).click
end
end
When(/^I select the parent channel for the "([^"]*)" from "([^"]*)"$/) do |client, from|
product_key = $is_gh_validation && !$build_validation ? 'Fake' : product
select(BASE_CHANNEL_BY_CLIENT[product_key][client], from: from, exact: false)
end
When(/^I select "([^"]*)" from drop-down in table line with "([^"]*)"$/) do |value, line|
select = find(:xpath, ".//div[@class='table-responsive']/table/tbody/tr[contains(td/a,'#{line}')]//select")
select(value, from: select[:id])
end
When(/^I choose radio button "([^"]*)" for child channel "([^"]*)"$/) do |radio, channel|
label = find(:xpath, "//dt[contains(.//div, '#{channel}')]//label[text()='#{radio}']")
choose(label[:for])
end
When(/^I wait for child channels to appear$/) do
steps %(
And I wait until I do not see "Loading..." text
And I wait until I do not see "Loading child channels.." text
And I wait until I do not see "Loading dependencies.." text
)
end
When(/^I (include|exclude) the recommended child channels$/) do |action|
toggle = "//span[@class='pointer']"
step 'I wait at most 10 seconds until I see "include recommended" text'
raise ScriptError, 'The toggle is not present' unless page.has_xpath?(toggle, wait: 5)
if action == 'include'
toggle_off = '//i[contains(@class, \'fa-toggle-off\')]'
find(:xpath, toggle).click if page.has_xpath?(toggle_off, wait: 5)
else
toggle_on = '//i[contains(@class, \'fa-toggle-on\')]'
find(:xpath, toggle).click if page.has_xpath?(toggle_on, wait: 5)
end
end
When(/^I choose "([^"]*)"$/) do |arg1|
find(:xpath, "//input[@type='radio' and @value='#{arg1}']").set(true)
end
#
# Enter a text into a textfield
#
When(/^I enter "([^"]*)" as "([^"]*)"$/) do |text, field|
fill_in(field, with: text, fill_options: { clear: :backspace })
end
When(/^I enter (\d+) minutes from now as "([^"]*)"$/) do |minutes_to_add, field|
future_time = get_future_time(minutes_to_add)
fill_in(field, with: future_time, fill_options: { clear: :backspace })
log "Execution time: #{future_time}"
end
When(/^I enter "([^"]*)" as "([^"]*)" text area$/) do |arg1, arg2|
execute_script("document.getElementsByName('#{arg2}')[0].value = '#{arg1}'")
end
When(/^I enter "(.*?)" as "(.*?)" in the content area$/) do |text, field|
within(:xpath, '//section') do
fill_in(field, with: text, fill_options: { clear: :backspace })
end
end
When(/^I enter the URI of the registry as "([^"]*)"$/) do |field|
fill_in(field, with: $no_auth_registry, fill_options: { clear: :backspace })
end
When(/^I enter "([^"]*)" on the search field$/) do |search_text|
step %(I enter "#{search_text}" as "search_string")
end
# Go back in the browser history
When(/^I go back$/) do
page.driver.go_back
end
#
# Click on a button
#
When(/^I click on "([^"]*)"$/) do |text|
click_button_and_wait(text, match: :first)
end
#
# Click on a button which appears inside of <div> with
# the given "id"
When(/^I click on "([^"]*)" in element "([^"]*)"$/) do |text, element_id|
within(:xpath, "//div[@id=\"#{element_id}\"]") do
click_button_and_wait(text, match: :first)
end
end
#
# Click on a button and confirm in alert box
When(/^I click on "([^"]*)" and confirm$/) do |text|
begin
accept_alert do
step %(I click on "#{text}")
end
rescue Capybara::ModalNotFound
warn 'Modal not found'
end
end
#
# Click on a link
#
When(/^I follow "([^"]*)"$/) do |text|
click_link_and_wait(text)
end
#
# Click on the first link
#
When(/^I follow first "([^"]*)"$/) do |text|
click_link_and_wait(text, match: :first)
end
#
# Click on a link which appears inside of <div> with
# the given "id"
When(/^I follow "([^"]*)" in the (.+)$/) do |arg1, arg2|
tag =
case arg2
when /tab bar|tabs/ then 'header'
when /content area/ then 'section'
else raise ScriptError, "Unknown element with description '#{arg2}'"
end
within(:xpath, "//#{tag}") do
step %(I follow "#{arg1}")
end
end
When(/^I follow first "([^"]*)" in the (.+)$/) do |arg1, arg2|
tag =
case arg2
when /tab bar|tabs/ then 'header'
when /content area/ then 'section'
else raise ScriptError, "Unknown element with description '#{arg2}'"
end
within(:xpath, "//#{tag}") do
step "I follow first \"#{arg1}\""
end
end
When(/^I follow "([^"]*)" on "(.*?)" row$/) do |text, host|
system_name = get_system_name(host)
xpath_query = "//tr[td[contains(.,'#{system_name}')]]//a[contains(., '#{text}')]"
element = find_and_wait_click(:xpath, xpath_query)
element.click
end
When(/^I enter "(.*?)" in the editor$/) do |arg1|
execute_script("ace.edit('contents-editor').insert('#{arg1}')")
end
#
# Menu links
#
# Menu path link
When(/^I follow the left menu "([^"]*)"$/) do |menu_path|
# split menu levels separated by '>' character
menu_levels = menu_path.split('>').map(&:strip)
# define reusable patterns
prefix_path = '//aside/div[@id=\'nav\']/nav'
link_path = '/ul/li/div/a[contains(.,\'%s\')]'
parent_wrapper_path = '/parent::div'
parent_level_path = '/parent::li'
# point the target to the nav menu
target_link_path = prefix_path
menu_levels.each_with_index do |menu_level, index|
# append the current target link and replace the placeholder with the current level value
target_link_path += (link_path % menu_level)
# if this is the last element of the path
break if index == (menu_levels.count - 1)
# open the submenu if needed
begin
unless find(:xpath, target_link_path + parent_wrapper_path + parent_level_path)[:class].include?('open')
find(:xpath, target_link_path + parent_wrapper_path).click
end
rescue NoMethodError
warn 'The browser session seems broken. See debug details below:'
warn "target_link_path=#{target_link_path}, parent_wrapper_path=#{parent_wrapper_path}, parent_level_path=#{parent_level_path}"
step 'I am authorized for the "Admin" section'
end
# point the target to the current menu level
target_link_path += parent_wrapper_path + parent_level_path
end
# finally go to the target page
find_and_wait_click(:xpath, target_link_path).click
end
#
# End of Menu links
#
Given(/^I am not authorized$/) do
begin
page.reset!
rescue NoMethodError
log 'The browser session could not be cleaned.'
capybara_register_driver
ensure
visit Capybara.app_host
end
raise ScriptError, 'Button \'Sign In\' not visible' unless find_button('Sign In').visible?
end
When(/^I go to the home page$/) do
visit Capybara.app_host
end
Given(/^I access the host the first time$/) do
visit Capybara.app_host
raise ScriptError, "Text 'Create #{product} Administrator' not found" unless check_text_and_catch_request_timeout_popup?("Create #{product} Administrator")
end
# Menu permission check
Given(/^I am authorized for the "([^"]*)" section$/) do |section|
case section
when 'Admin'
step 'I am authorized as "admin" with password "admin"'
when 'Images'
step 'I am authorized as "kiwikiwi" with password "kiwikiwi"'
else
log "Section #{section} not supported"
end
end
# access the clients
Given(/^I am on the Systems overview page of this "([^"]*)"$/) do |host|
node = get_target(host)
system_id = get_system_id(node)
visit("/rhn/systems/details/Overview.do?sid=#{system_id}")
end
Given(/^I navigate to the Systems overview page of this "([^"]*)"$/) do |host|
system_name = get_system_name(host)
steps %(
Given I am on the Systems page
When I enter "#{system_name}" as "criteria"
And I wait until I do not see "Loading..." text
And I follow "#{system_name}"
And I wait until I see "System Status" text
)
end
Given(/^I am on the "([^"]*)" page of this "([^"]*)"$/) do |page, host|
steps %(
Given I am on the Systems overview page of this "#{host}"
And I follow "#{page}" in the content area
)
end
When(/^I enter the hostname of "([^"]*)" as "([^"]*)"$/) do |host, field|
system_name = get_system_name(host)
log "The hostname of #{host} is #{system_name}"
step %(I enter "#{system_name}" as "#{field}")
end
When(/^I select the hostname of "([^"]*)" from "([^"]*)"((?: if present)?)$/) do |host, field, if_present|
begin
system_name = get_system_name(host)
rescue StandardError
raise KeyError, "Host #{host} not found" if if_present.empty?
log "Host #{host} is not deployed, not trying to select it"
next
end
step %(I select "#{system_name}" from "#{field}")
end
When(/^I follow this "([^"]*)" link$/) do |host|
system_name = get_system_name(host)
step %(I follow "#{system_name}")
end
When(/^I check the "([^"]*)" client$/) do |host|
system_name = get_system_name(host)
step %(I check "#{system_name}" in the list)
end
Then(/^table row for "([^"]*)" should contain "([^"]*)"$/) do |arg1, arg2|
step %(I wait until table row for "#{arg1}" contains "#{arg2}")
end
Then(/^I wait until table row for "([^"]*)" contains "([^"]*)"$/) do |arg1, arg2|
xpath_query = "//div[@class=\"table-responsive\"]/table/tbody/tr[.//*[contains(.,'#{arg1}')]]"
within(:xpath, xpath_query) do
raise ScriptError, "xpath: #{xpath_query} has no content #{arg2}" unless check_text_and_catch_request_timeout_popup?(arg2, timeout: DEFAULT_TIMEOUT)
end
end
Then(/^the table row for "([^"]*)" should( not)? contain "([^"]*)" icon$/) do |row, should_not, icon|
case icon
when 'retracted'
content_selector = 'i[class*=\'errata-retracted\']'
else
raise ScriptError, "Unsupported icon '#{icon}' in the step definition"
end
xpath_query = "//div[@class=\"table-responsive\"]/table/tbody/tr[.//*[contains(.,'#{row}')]]"
within(:xpath, xpath_query) do
if should_not
raise ScriptError, "xpath: #{xpath_query} has no icon #{icon}" unless has_no_css?(content_selector, wait: 2)
else
raise ScriptError, "xpath: #{xpath_query} has no icon #{icon}" unless has_css?(content_selector, wait: 2)
end
end
end
When(/^I wait at most ([0-9]+) seconds until table row for "([^"]*)" contains button "([^"]*)"$/) do |timeout, text, button|
xpath_query = "//tr[td[contains(., '#{text}')]]/td/descendant::*[self::a or self::button][@title='#{button}']"
raise ScriptError, "xpath: #{xpath_query} not found" unless find(:xpath, xpath_query, wait: timeout.to_f)
end
When(/^I wait until table row for "([^"]*)" contains button "([^"]*)"$/) do |text, button|
step %(I wait at most #{DEFAULT_TIMEOUT} seconds until table row for "#{text}" contains button "#{button}")
end
When(/^I wait until table row contains a "([^"]*)" text$/) do |text|
xpath_query = "//div[@class=\"table-responsive\"]/table/tbody/tr[.//td[contains(.,'#{text}')]]"
raise ScriptError, "xpath: #{xpath_query} not found" unless find(:xpath, xpath_query, wait: DEFAULT_TIMEOUT)
end
When(/^I wait until button "([^"]*)" becomes enabled$/) do |text|
raise ScriptError, "Button '#{text}' still disabled after #{DEFAULT_TIMEOUT} seconds" unless find_button(text, disabled: false, wait: DEFAULT_TIMEOUT)
end
# login, logout steps
Given(/^I am authorized as "([^"]*)" with password "([^"]*)"$/) do |user, passwd|
begin
page.reset!
rescue NoMethodError => e
log "The browser session could not be cleaned because there is no browser available: #{e.message}"
capybara_register_driver
rescue StandardError => e
log "The browser session could not be cleaned for unknown issue: #{e.message}"
capybara_register_driver
ensure
visit Capybara.app_host
end
next if all(:xpath, "//header//span[text()='#{user}']", wait: 0).any?
begin
find(:xpath, '//header//i[@class=\'fa fa-sign-out\']').click
rescue Capybara::ElementNotFound, NoMethodError
# No need to logout
end
raise ScriptError, 'Login page is not correctly loaded' unless has_field?('username')
fill_in('username', with: user)
fill_in('password', with: passwd)
click_button_and_wait('Sign In', match: :first)
step 'I should be logged in'
end
Given(/^I am authorized$/) do
step 'I am authorized as "testing" with password "testing"'
end
When(/^I sign out$/) do
find(:xpath, '//a[@href=\'/rhn/Logout.do\']').click
end
Then(/^I should not be authorized$/) do
raise ScriptError, 'User is authorized' if has_xpath?('//a[@href=\'/rhn/Logout.do\']')
end
Then(/^I should be logged in$/) do
xpath_query = '//a[@href=\'/rhn/Logout.do\']'
# Check if the user is logged in, using the specified wait_time
raise ScriptError, 'User is not logged in' unless has_selector?(:xpath, xpath_query, wait: Capybara.default_max_wait_time * 3)
end
Then(/^I am logged in$/) do
raise ScriptError, 'User is not logged in' unless find(:xpath, '//a[@href=\'/rhn/Logout.do\']').visible?
# text = "You have just created your first #{product} user. To finalize your installation please use the Setup Wizard"
# Workaround: Ignore the fact that the message is not shown
# TODO: restore this as soon as the related issue is fixed: https://github.com/SUSE/spacewalk/issues/19369
# raise ScriptError, 'The welcome message is not shown' unless has_content?(text)
end
Then(/^I should see an update in the list$/) do
xpath_query = '//div[@class="table-responsive"]/table/tbody/tr/td/a'
raise ScriptError, "xpath: #{xpath_query} not found" unless has_xpath?(xpath_query)
end
When(/^I check test channel$/) do
step 'I check "Fake-Base-Channel-SUSE-like" in the list'
end
When(/^I check "([^"]*)" patch$/) do |arg1|
step %(I check "#{arg1}" in the list)
end
Then(/^I should see "([^"]*)" systems selected for SSM$/) do |arg|
within(:xpath, '//span[@id="spacewalk-set-system_list-counter"]') do
raise ScriptError, "There are not #{arg} systems selected" unless check_text_and_catch_request_timeout_popup?(arg)
end
end
#
# Test for a text in the whole page
#
Then(/^I should see a "([^"]*)" text$/) do |text|
raise ScriptError, "Text '#{text}' not found" unless check_text_and_catch_request_timeout_popup?(text)
end
Then(/^I should see a "([^"]*)" text or "([^"]*)" text$/) do |text1, text2|
raise ScriptError, "Text '#{text1}' and '#{text2}' not found" unless check_text_and_catch_request_timeout_popup?(text1, text2: text2)
end
Then(/^I should see "([^"]*)" short hostname$/) do |host|
system_name = get_system_name(host).partition('.').first
raise ScriptError, "Hostname #{system_name} is not present" unless check_text_and_catch_request_timeout_popup?(system_name)
end
Then(/^I should see "([^"]*)" hostname$/) do |host|
system_name = get_system_name(host)
raise ScriptError, "Hostname #{system_name} is not present" unless check_text_and_catch_request_timeout_popup?(system_name)
end
Then(/^I should not see "([^"]*)" hostname$/) do |host|
system_name = get_system_name(host)
raise ScriptError, "Hostname #{system_name} is present" if check_text_and_catch_request_timeout_popup?(system_name)
end
#
# Test for text in a snippet textarea
#
Then(/^I should see "([^"]*)" in the textarea$/) do |text|
within('textarea') do
raise ScriptError, "Text '#{text}' not found" unless check_text_and_catch_request_timeout_popup?(text)
end
end
Then(/^I should see "([^"]*)" or "([^"]*)" in the textarea$/) do |text1, text2|
within('textarea') do
raise ScriptError, "Text '#{text1}' and '#{text2}' not found" unless check_text_and_catch_request_timeout_popup?(text1, text2: text2)
end
end
Then(/^I should see "([^"]*)" in the ([^ ]+) textarea$/) do |text, id|
within(:xpath, ".//textarea[@data-testid='#{id}']") do
raise ScriptError, "Text '#{text}' not found" unless check_text_and_catch_request_timeout_popup?(text)
end
end
Then(/^I should see "([^"]*)" or "([^"]*)" in the ([^ ]+) textarea$/) do |text1, text2, id|
within(:xpath, ".//textarea[@data-testid='#{id}']") do
raise ScriptError, "Text '#{text1}' and '#{text2}' not found" unless check_text_and_catch_request_timeout_popup?(text1, text2: text2)
end
end
#
# Test for a text in the whole page using regexp
#
Then(/^I should see a text like "([^"]*)"$/) do |title|
raise ScriptError, "Regular expression '#{title}' not found" unless has_content?(Regexp.new(title))
end
#
# Test for a text not allowed in the whole page
#
Then(/^I should not see a "([^"]*)" text$/) do |text|
raise ScriptError, "Text '#{text}' found on the page" unless has_no_content?(text)
end
#
# Test for a visible link in the whole page
#
Then(/^I should see a "([^"]*)" link$/) do |text|
raise ScriptError, "Link #{text} is not visible" unless has_link?(text)
end
#
# Validate link is gone
#
Then(/^I should not see a "([^"]*)" link$/) do |arg1|
raise ScriptError, "Link #{arg1} is present" unless has_no_link?(arg1)
end
Then(/^I should see a "([^"]*)" button$/) do |arg1|
raise ScriptError, "Link #{arg1} is not visible" unless find_button(arg1).visible?
end
Then(/^I should see a "(.*?)" link in the text$/) do |linktext, text|
within(:xpath, "//p/strong[contains(normalize-space(string(.)), '#{text}')]") do
assert has_xpath?("//a[text() = '#{linktext}']")
end
end
Then(/^I should see a "([^"]*)" text in element "([^"]*)"$/) do |text, element|
within(:xpath, "//div[@id=\"#{element}\" or @class=\"#{element}\"]") do
raise ScriptError, "Text '#{text}' not found in #{element}" unless check_text_and_catch_request_timeout_popup?(text)
end
end
Then(/^I should not see a "([^"]*)" text in element "([^"]*)"$/) do |text, element|
within(:xpath, "//div[@id=\"#{element}\" or @class=\"#{element}\"]") do
raise ScriptError, "Text '#{text}' found in #{element}" if check_text_and_catch_request_timeout_popup?(text)
end
end
Then(/^I should see a "([^"]*)" or "([^"]*)" text in element "([^"]*)"$/) do |text1, text2, element|
within(:xpath, "//div[@id=\"#{element}\" or @class=\"#{element}\"]") do
raise ScriptError, "Texts #{text1} and #{text2} not found in #{element}" unless check_text_and_catch_request_timeout_popup?(text1, text2: text2)
end
end
Then(/^I should see a "([^"]*)" link in the table (.*) column$/) do |link, column|
idx = %w[first second third fourth].index(column)
unless idx
# try column by name
# unquote if neeeded
colname = column.gsub(/\A['"]+|['"]+\Z/, '')
cols = all(:xpath, '//table//thead/tr[1]/th').map(&:text)
idx = cols.index(colname)
end
raise("Unknown column '#{column}'") unless idx
# find(:xpath, "//table//thead//tr/td[#{idx + 1}]/a[text()='#{link}']")
raise unless has_xpath?("//table//tr/td[#{idx + 1}]//a[text()='#{link}']")
end
When(/^I wait until the table contains "FINISHED" or "SKIPPED" followed by "FINISHED" in its first rows$/) do
# this step is used for long operations like refreshing caches, repositories, etc.
# therefore we use a non-standard timeout
repeat_until_timeout(timeout: 800, message: 'Task does not look FINISHED yet') do
visit current_url
# get all texts in the table column under the "Status" header
status_tds = '//tr/td[count(//th[contains(*/text(), \'Status\')]/preceding-sibling::*) + 1]'
statuses = all(:xpath, status_tds).map(&:text)
# get all texts in the table column under the "Start time" header
start_time_tds = '//tr/td[count(//th[contains(*/text(), \'Start Time\')]/preceding-sibling::*) + 1]'
start_times = all(:xpath, start_time_tds).map(&:text)
# disregard any number of initial unimportant rows, that is:
# - INTERRUPTED rows with no start time (expected when Taskomatic had been restarted)
# - SKIPPED rows (expected when Taskomatic triggers the same task concurrently)
result =
statuses.zip(start_times).drop_while do |status, start_time|
(status == 'INTERRUPTED' && (start_time.empty? || start_time == 'Task never started')) || status == 'SKIPPED'
end
first_non_skipped = result.first.first
# halt in case we are done, or if an error is detected
break if first_non_skipped == 'FINISHED'
raise('Taskomatic task was INTERRUPTED') if first_non_skipped == 'INTERRUPTED'
# otherwise either no row is shown yet, or the task is still RUNNING
# continue waiting
sleep 1
end
end
Then(/^I should see a "([^"]*)" link in the (left menu|tab bar|tabs|content area)$/) do |arg1, arg2|
tag =
case arg2
when /left menu/ then 'aside'
when /tab bar|tabs/ then 'header'
when /content area/ then 'section'
else raise ScriptError, "Unknown element with description '#{arg2}'"
end
within(:xpath, "//#{tag}") do
step "I should see a \"#{arg1}\" link"
end
end
Then(/^I should not see a "([^"]*)" link in the (.+)$/) do |arg1, arg2|
tag =
case arg2
when /left menu/ then 'aside'
when /tab bar|tabs/ then 'header'
when /content area/ then 'section'
else raise ScriptError, "Unknown element with description '#{arg2}'"
end
within(:xpath, "//#{tag}") do
step "I should not see a \"#{arg1}\" link"
end
end
Then(/^I should see a "([^"]*)" link in row ([0-9]+) of the content menu$/) do |arg1, arg2|
within(:xpath, '//section') do
within(:xpath, "//div[@class=\"spacewalk-content-nav\"]/ul[#{arg2}]") do
step %(I should see a "#{arg1}" link)
end
end
end
Then(/^I should see a "([^"]*)" button in "([^"]*)" form$/) do |arg1, arg2|
within(:xpath, "//form[@id='#{arg2}' or @name=\"#{arg2}\"]") do
raise ScriptError, "Button #{arg1} not found" unless find_button(arg1)
end
end
Then(/^I should not see a warning nor an error sign$/) do
raise ScriptError, 'Warning detected' unless page.has_no_xpath?('//*[contains(@class, \'fa-exclamation-triangle\')]')
raise ScriptError, 'Error detected' unless page.has_no_xpath?('//*[contains(@class, \'fa-exclamation-circle\')]')
end
Then(/^I select the "([^"]*)" repo$/) do |repo|
step %(I check "#{repo}" in the list)
end
Then(/^I check the row with the "([^"]*)" link$/) do |text|
step %(I check "#{text}" in the list)
end
Then(/^I check the row with the "([^"]*)" text$/) do |text|
step %(I check "#{text}" in the list)
end
When(/^I check the first patch in the list, that does not require a reboot$/) do
row = find(:xpath, '//section//div[@class=\'table-responsive\']/table/tbody/tr', match: :first)
reboot_required = row.has_xpath?('.//*[contains(@title,\'Reboot Required\')]')
if reboot_required
step 'I check the second row in the list'
else
step 'I check the first row in the list'
end
end
When(/^I click on the red confirmation button$/) do
find_and_wait_click('button.btn-danger').click
end
When(/^I click on the clear SSM button$/) do
find_and_wait_click(:xpath, '//*[@id=\'clear-ssm\']').click
end
When(/^I click on the filter button$/) do
find_and_wait_click('button.spacewalk-button-filter').click
has_text?('is filtered', wait: 10)
end
Then(/^I click on the filter button until page does not contain "([^"]*)" text$/) do |text|
repeat_until_timeout(message: "'#{text}' still found") do
break unless check_text_and_catch_request_timeout_popup?(text)
find('button.spacewalk-button-filter').click
has_text?('is filtered', wait: 10)
end
end
Then(/^I click on the filter button until page does contain "([^"]*)" text$/) do |text|
repeat_until_timeout(message: "'#{text}' was not found") do
break if check_text_and_catch_request_timeout_popup?(text)
find('button.spacewalk-button-filter').click
has_text?('is filtered', wait: 10)
end
end
When(/^I enter the hostname of "([^"]*)" as the filtered system name$/) do |host|
system_name = get_system_name(host)
find('input[placeholder=\'Filter by System Name: \']').set(system_name)
end
When(/^I enter "([^"]*)" as the filtered package name$/) do |input|
raise 'Package name is not set' if input.empty?
find('input[placeholder=\'Filter by Package Name: \']').set(input)
end
When(/^I enter "([^"]*)" as the filtered synopsis$/) do |input|
find('input[placeholder=\'Filter by Synopsis: \']').set(input)
end
When(/^I enter "([^"]*)" as the filtered channel name$/) do |input|
find('input[placeholder=\'Filter by Channel Name: \']').set(input)
end
When(/^I enter "([^"]*)" as the filtered product description$/) do |input|
find('input[name=\'product-description-filter\']').set(input)
end
When(/^I enter "([^"]*)" as the filtered XCCDF result type$/) do |input|
find('input[placeholder=\'Filter by Result: \']').set(input)
end
When(/^I enter "([^"]*)" as the filtered snippet name$/) do |input|
find('input[placeholder=\'Filter by Snippet Name: \']').set(input)
end
When(/^I enter "([^"]*)" as the filtered formula name$/) do |input|
find('input[placeholder=\'Filter by formula name\']').set(input)
end
When(/^I enter the package for "([^"]*)" as the filtered package name$/) do |host|
step %(I enter "#{PACKAGE_BY_CLIENT[host]}" as the filtered package name)
end
When(/^I check the package for "([^"]*)" in the list$/) do |host|
step %(I check "#{PACKAGE_BY_CLIENT[host]}" in the list)
end
When(/^I check row with "([^"]*)" and arch of "([^"]*)"$/) do |text, client|
arch = PKGARCH_BY_CLIENT[client]
step %(I check row with "#{text}" and "#{arch}" in the list)
end
When(/^I uncheck row with "([^"]*)" and arch of "([^"]*)"$/) do |text, client|
arch = PKGARCH_BY_CLIENT[client]
step %(I uncheck row with "#{text}" and "#{arch}" in the list)
end
When(/^I check row with "([^"]*)" and "([^"]*)" in the list$/) do |text1, text2|
top_level_xpath_query = "//div[@class=\"table-responsive\"]/table/tbody/tr[.//td[contains(.,'#{text1}')] and .//td[contains(.,'#{text2}')]]//input[@type='checkbox']"
row = find(:xpath, top_level_xpath_query)
raise ScriptError, "xpath: #{top_level_xpath_query} not found" if row.nil?
row.set(true)
end
When(/^I uncheck row with "([^"]*)" and "([^"]*)" in the list$/) do |text1, text2|
top_level_xpath_query = "//div[@class=\"table-responsive\"]/table/tbody/tr[.//td[contains(.,'#{text1}')] and .//td[contains(.,'#{text2}')]]//input[@type='checkbox']"
row = find(:xpath, top_level_xpath_query, match: :first)
raise ScriptError, "xpath: #{top_level_xpath_query} not found" if row.nil?
row.set(false)
end
When(/^I check the second row in the list$/) do
within(:xpath, '//section') do
row = find(:xpath, '//div[@class=\'table-responsive\']/table/tbody/tr[2]/td', match: :first)
row.find(:xpath, './/input[@type=\'checkbox\']', match: :first).set(true)
end
end
When(/^I check the first row in the list$/) do
within(:xpath, '//section') do
row = find(:xpath, '//div[@class=\'table-responsive\']/table/tbody/tr[.//td]', match: :first)
row.find(:xpath, './/input[@type=\'checkbox\']', match: :first).set(true)
end
end
When(/^I (check|uncheck) "([^"]*)" in the list$/) do |check_option, text|
top_level_xpath_query = "//div[@class=\"table-responsive\"]/table/tbody/tr[.//td[contains(.,'#{text}')]]//input[@type='checkbox']"
row = find(:xpath, top_level_xpath_query, match: :first)
raise "xpath: #{top_level_xpath_query} not found" if row.nil?
row.set(check_option == 'check')
end
#
# Test if an option is selected
#
Then(/^option "([^"]*)" is selected as "([^"]*)"$/) do |option, field|
next if has_select?(field, selected: option)
# Custom React selector
next if has_xpath?("//*[contains(@class, 'data-testid-#{field}-child__value-container')]/*[contains(text(),'#{option}')]")
raise ScriptError, "#{option} is not selected as #{field}"
end
#
# Wait for an option to appear in a list
#
When(/^I wait until option "([^"]*)" appears in list "([^"]*)"$/) do |option, field|
repeat_until_timeout(message: "#{option} has not been listed in #{field}") do
break if has_select?(field, with_options: [option])
# Custom React selector
break if has_xpath?("//*[contains(@class, 'data-testid-#{field}-child__value-container')]/*[contains(text(),'#{option}')]")
end
end
#
# Test if a radio button is checked
#
Then(/^radio button "([^"]*)" should be checked$/) do |arg1|
raise ScriptError, "#{arg1} is unchecked" unless has_checked_field?(arg1)
end
#
# Test if a checkbox is checked
#
Then(/^I should see "([^"]*)" as checked$/) do |arg1|
raise ScriptError, "#{arg1} is unchecked" unless has_checked_field?(arg1)
end
#
# Test if a checkbox is unchecked
#
Then(/^I should see "([^"]*)" as unchecked$/) do |arg1|
raise ScriptError, "#{arg1} is checked" unless has_unchecked_field?(arg1)
end
#
# Test if a checkbox is disabled
#
Then(/^the "([^"]*)" checkbox should be disabled$/) do |arg1|
has_css?("##{arg1}[disabled]")
end
Then(/^the "([^"]*)" field should be disabled$/) do |arg1|
has_css?("##{arg1}[disabled]")
end
# identifier must be the value of name, ID or other element attribute, not the shown text
Then(/^I should see "([^"]*)" in field identified by "([^"]*)"$/) do |text, field|
raise ScriptError, "'#{text}' not found in #{field}" unless find_field(field, with: /#{text}/).visible?
end
Then(/^I should see a "([^"]*)" field in "([^"]*)" form$/) do |field, form|
within(:xpath, "//form[@id=\"#{form}\"] | //form[@name=\"#{form}\"]") do
raise ScriptError, "Field #{field} not found" unless find_field(field, match: :first).visible?
end
end
Then(/^I should see a "([^"]*)" editor in "([^"]*)" form$/) do |editor, form|
within(:xpath, "//form[@id=\"#{form}\"] | //form[@name=\"#{form}\"]") do