forked from zammad/zammad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowser_test_helper.rb
4967 lines (4151 loc) · 126 KB
/
browser_test_helper.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) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
ENV['RAILS_ENV'] = 'test'
# rubocop:disable Lint/NonLocalExitFromIterator, Style/GuardClause, Lint/MissingCopEnableDirective
require File.expand_path('../config/environment', __dir__)
require 'selenium-webdriver'
require 'json'
require 'net/http'
require 'uri'
# This is a workaround for running the browser test suite
# in an alphabetical order
# because `test/browser/aaa_*` tests are required to run first
require 'minitest'
module Minitest
def self.__run(reporter, options)
Runnable.runnables
.reject { |s| s.runnable_methods.empty? }
.map { |suite| suite.run reporter, options }
end
end
class TestCase < ActiveSupport::TestCase
DEBUG = true
setup do
# print current test case to STDOUT
# for status reasoning and debugging purposes
source_location = self.class.instance_method(method_name).source_location
test_file_path = source_location[0].remove("#{Rails.root}/") # rubocop:disable Rails/FilePath
test_method_line = source_location[1]
puts <<~HTML
Performing test #{self.class.name}##{method_name} (#{test_file_path}:#{test_method_line}):
HTML
end
def browser
ENV['BROWSER'] || 'firefox'
end
def browser_support_cookies
if browser.match?(%r{(internet_explorer|ie)}i)
return false
end
true
end
def browser_url
return ENV['BROWSER_URL'] if ENV['BROWSER_URL'].present?
"http://#{host}:3000"
end
def host
return 'localhost' if ENV['CI'].blank?
Socket.ip_address_list.detect(&:ipv4_private?).ip_address
end
def browser_options
case browser
when 'firefox'
profile = Selenium::WebDriver::Firefox::Profile.new
profile['intl.locale.matchOS'] = false
profile['intl.accept_languages'] = 'en-US'
profile['general.useragent.locale'] = 'en-US'
profile['permissions.default.desktop-notification'] = 1 # ALLOW notifications
options = Selenium::WebDriver::Firefox::Options.new(
profile: profile
)
if ENV['BROWSER_HEADLESS'].present?
options.add_argument '-headless'
end
when 'chrome'
options = Selenium::WebDriver::Chrome::Options.new(
logging_prefs: {
browser: 'ALL'
},
prefs: {
'intl.accept_languages' => 'en-US',
'profile.default_content_setting_values.notifications' => 1, # ALLOW notifications
},
# Disable shared memory usage as it does not really provide a performance gain but cause resource limit issues in CI.
args: %w[--enable-logging --v=1 --disable-dev-shm-usage],
# Disable the "Chrome is being controlled by automated test software." info bar.
exclude_switches: ['enable-automation'],
)
if ENV['BROWSER_HEADLESS'].present?
options.add_argument '--headless=new' # native headless for v109+
end
end
options
end
def browser_instance
@browsers ||= {}
if ENV['REMOTE_URL'].blank?
local_browser = Selenium::WebDriver.for(browser.to_sym, options: browser_options)
@browsers[local_browser.hash] = local_browser
browser_instance_preferences(local_browser)
return local_browser
end
# avoid "Cannot read property 'get_Current' of undefined" issues
(1..5).each do |count|
local_browser = browser_instance_remote
break
rescue => e
wait_until_ready = rand(5..13) # rubocop:disable Zammad/ForbidRand
log('browser_instance', { rescure: true, count: count, sleep: wait_until_ready, exception: e })
sleep wait_until_ready
end
local_browser
end
def browser_instance_remote
http_client = Selenium::WebDriver::Remote::Http::Default.new(
open_timeout: 120,
read_timeout: 120
)
local_browser = Selenium::WebDriver.for(
:remote,
url: ENV['REMOTE_URL'],
http_client: http_client,
options: browser_options,
)
@browsers[local_browser.hash] = local_browser
browser_instance_preferences(local_browser)
# upload files from remote dir
local_browser.file_detector = lambda do |args|
str = args.first.to_s
str if File.file?(str)
end
local_browser
end
def browser_instance_close(local_browser)
return if !@browsers[local_browser.hash]
@browsers.delete(local_browser.hash)
local_browser.quit
end
def browser_instance_preferences(local_browser)
browser_width = ENV['BROWSER_WIDTH'] || 1024
browser_height = ENV['BROWSER_HEIGHT'] || 800
local_browser.manage.window.resize_to(browser_width, browser_height)
if !ENV['REMOTE_URL']&.match?(%r{saucelabs|(grid|ci)\.(zammad\.org|znuny\.com)}i)
if @browsers.count == 1
local_browser.manage.window.move_to(0, 0)
else
local_browser.manage.window.move_to(browser_width, 0)
end
end
local_browser.manage.timeouts.implicit_wait = 3 # seconds
end
def teardown
return if !@browsers
@browsers.each_value do |local_browser|
screenshot(browser: local_browser, comment: 'teardown')
browser_instance_close(local_browser)
end
end
def screenshot(params = {})
instance = params[:browser] || @browser
comment = params[:comment] || ''
filename = "tmp/#{Time.zone.now.strftime('screenshot_%Y_%m_%d__%H_%M_%S_%L')}_#{comment}#{instance.hash}.png"
log('screenshot', { filename: filename })
instance.save_screenshot(filename)
end
=begin
username = login(
browser: browser1,
username: 'someuser',
password: 'somepassword',
url: 'some url', # optional, in case of aleady opened brower a reload is done because url is called again
remember_me: true, # optional
auto_wizard: false, # optional, in case of auto wizard, skip login
success: false, #optional
)
=end
def login(params)
switch_window_focus(params)
log('login', params)
instance = params[:browser] || @browser
if params[:url]
instance.get(params[:url])
end
element = instance.find_elements(css: '#login input[name="username"]')[0]
if !element
if params[:auto_wizard]
watch_for(
browser: instance,
css: 'body',
value: 'auto wizard is enabled',
timeout: 10,
)
location(url: "#{browser_url}/#getting_started/auto_wizard")
sleep 10
login = instance.find_elements(css: '.user-menu .user a')[0].attribute('title')
if login != params[:username]
screenshot(browser: instance, comment: 'auto wizard login failed')
raise 'auto wizard login failed'
end
assert(true, 'auto wizard login ok')
clues_close(
browser: instance,
optional: true,
)
return
end
screenshot(browser: instance, comment: 'login_failed')
raise 'No login box found'
end
element.clear
element.send_keys(params[:username])
element = instance.find_elements(css: '#login input[name="password"]')[0]
element.clear
element.send_keys(params[:password])
if params[:remember_me]
instance.find_elements(css: '#login .checkbox-replacement')[0].click
end
instance.find_elements(css: '#login button')[0].click
sleep 4
login_failed = false
if instance.find_elements(css: '.user-menu .user a')[0]
login = instance.find_elements(css: '.user-menu .user a')[0].attribute('title')
if login != params[:username]
login_failed = true
end
else
login_failed = true
end
if login_failed
if params[:success] == false
assert(true, 'login not successfull, like wanted')
return true
end
screenshot(browser: instance, comment: 'login_failed')
raise 'login failed'
end
if params[:success] == false
raise 'login successfull but should not'
end
clues_close(
browser: instance,
optional: true,
)
assert(true, 'login ok')
login
end
=begin
logout(
browser: browser1
)
=end
def logout(params = {})
switch_window_focus(params)
log('logout', params)
instance = params[:browser] || @browser
click(
browser: instance,
css: 'a[href="#current_user"]',
mute_log: true,
)
click(
browser: instance,
css: 'a[href="#logout"]',
mute_log: true,
)
5.times do
sleep 1
login = instance.find_elements(css: '#login')[0]
next if !login
assert(true, 'logout ok')
return
end
screenshot(browser: instance, comment: 'logout_failed')
raise 'no login box found, seems logout was not successfully!'
end
=begin
clues_close(
browser: browser1,
optional: false,
)
=end
def clues_close(params = {})
switch_window_focus(params)
log('clues_close', params)
instance = params[:browser] || @browser
clues = instance.find_elements(css: '.js-modal--clue .js-close')[0]
if !params[:optional] && !clues
screenshot(browser: instance, comment: 'no_clues')
raise 'Unable to closes clues, no clues found!'
end
return if !clues
checks = 25
previous = clues.location
(checks + 1).times do |check|
raise "Element still moving after #{checks} checks" if check == checks
current = clues.location
sleep 0.2 if ENV['CI']
break if previous == current
previous = current
end
clues.click
watch_for_disappear(
browser: instance,
css: 'modal-backdrop js-backdrop',
)
assert(true, 'clues closed')
end
=begin
notify_close(
browser: browser1,
optional: false,
)
=end
def notify_close(params = {})
switch_window_focus(params)
log('notify_close', params)
instance = params[:browser] || @browser
notify = instance.find_elements(css: '.noty_inline_layout_container.i-am-new')[0]
if !params[:optional] && !notify
screenshot(browser: instance, comment: 'no_notify')
raise 'Unable to closes notify, no notify found!'
end
return if !notify
notify.click
assert(true, 'notify closed')
sleep 1
end
=begin
location(
browser: browser1,
url: 'http://someurl',
)
=end
def location(params)
switch_window_focus(params)
log('location', params)
instance = params[:browser] || @browser
instance.get(params[:url])
# check if reload was successfull
if !instance.find_elements(css: 'body')[0] || instance.find_elements(css: 'body')[0].text =~ %r{unavailable or too busy}i
instance.navigate.refresh
end
end
=begin
location_check(
browser: browser1,
url: 'http://someurl',
)
=end
def location_check(params)
switch_window_focus(params)
log('location_check', params)
instance = params[:browser] || @browser
sleep 0.7
current_url = instance.current_url
if !current_url.match?(%r{#{Regexp.quote(params[:url])}})
screenshot(browser: instance, comment: 'location_check_failed')
raise "url #{current_url} is not matching #{params[:url]}"
end
assert(true, "url #{current_url} is matching #{params[:url]}")
end
=begin
reload(
browser: browser1,
)
=end
def reload(params = {})
switch_window_focus(params)
log('reload', params)
instance = params[:browser] || @browser
instance.navigate.refresh
# check if reload was successfull
if !instance.find_elements(css: 'body')[0] || instance.find_elements(css: 'body')[0].text =~ %r{unavailable or too busy}i
instance.navigate.refresh
end
screenshot(browser: instance, comment: 'reload_after')
end
=begin
click(
browser: browser1,
css: '.some_class',
fast: false, # do not wait
wait: 1, # wait 1 sec.
)
click(
browser: browser1,
xpath: '//a[contains(@class,".text-1")]',
fast: false, # do not wait
wait: 1, # wait 1 sec.
)
click(
browser: browser1,
text: '.partial_link_text',
fast: false, # do not wait
wait: 1, # wait 1 sec.
)
=end
def click(params)
switch_window_focus(params)
log('click', params)
instance = params[:browser] || @browser
if params.include?(:css)
param_key = :css
find_element_key = :css
elsif params.include?(:xpath)
param_key = :xpath
find_element_key = :xpath
else
param_key = :text
find_element_key = :partial_link_text
sleep 0.5
end
begin
elements = instance.find_elements(find_element_key => params[param_key])
.tap { |e| e.slice!(1..-1) if !params[:all] }
if elements.empty?
return if params[:only_if_exists] == true
raise "No such element '#{params[param_key]}'"
end
# a clumsy substitute for elements.each(&:click)
# (we need to refresh element references after each element.click
# because if clicks alter page content,
# subsequent element.clicks will raise a StaleElementReferenceError)
elements.length.times do |i|
instance.find_elements(find_element_key => params[param_key])[i].try(:click)
end
rescue => e
raise e if (fail_count ||= 0).positive?
fail_count += 1
log('click', { rescure: true })
sleep 0.5
retry
end
sleep 0.2 if !params[:fast]
sleep params[:wait] if params[:wait]
if params[:expect_alert]
check_alert(params)
else
await_empty_ajax_queue(params)
end
end
=begin
perform_macro('Close & Tag as Spam')
# or
perform_macro(
name: 'Close & Tag as Spam',
browser: browser1,
)
=end
def perform_macro(params)
switch_window_focus(params)
log('perform_macro', params)
instance = params[:browser] || @browser
click(
browser: instance,
css: '.active.content .js-submitDropdown .js-openDropdownMacro'
)
click(
browser: instance,
xpath: "//div[contains(@class, 'content') and contains(@class, 'active')]//li[contains(@class, 'js-dropdownActionMacro') and contains(text(), '#{params[:name]}')]"
)
end
=begin
scroll_to(
browser: browser1,
position: 'top', # botton
css: '.some_class',
)
=end
def scroll_to(params)
switch_window_focus(params)
log('scroll_to', params)
instance = params[:browser] || @browser
position = 'true'
if params[:position] == 'botton'
position = 'false'
end
execute(
browser: instance,
js: "$('#{params[:css]}').get(0).scrollIntoView(#{position})",
mute_log: params[:mute_log]
)
sleep 0.3
screenshot(browser: instance, comment: 'scroll_to_after')
end
=begin
modal_close(
browser: browser1,
)
=end
def modal_close(params = {})
switch_window_focus(params)
log('modal_close', params)
instance = params[:browser] || @browser
element = instance.find_elements(css: '.modal .js-close')[0]
raise "No such modal to close #{params.inspect}" if !element
element.click
end
=begin
modal_ready(
browser: browser1,
)
=end
def modal_ready(params = {})
switch_window_focus(params)
log('modal_ready', params)
instance = params[:browser] || @browser
watch_for(
browser: instance,
css: '.modal.in.modal--ready',
timeout: params[:timeout] || 4,
)
end
=begin
modal_disappear(
browser: browser1,
timeout: 12, # default 8
)
=end
def modal_disappear(params = {})
switch_window_focus(params)
log('modal_disappear', params)
instance = params[:browser] || @browser
watch_for_disappear(
browser: instance,
css: '.modal',
timeout: params[:timeout] || 8,
)
end
=begin
execute(
browser: browser1,
js: '.some_class',
)
=end
def execute(params)
switch_window_focus(params)
log('js', params)
instance = params[:browser] || @browser
if params[:js]
return instance.execute_script(params[:js])
end
raise "Invalid execute params #{params.inspect}"
end
=begin
exists(
browser: browser1,
css: '.some_class',
)
exists(
displayed: false, # true|false
browser: browser1,
css: '.some_class',
displayed: true, # true|false
)
=end
def exists(params)
retries ||= 0
switch_window_focus(params)
log('exists', params)
instance = params[:browser] || @browser
if !instance.find_elements(css: params[:css])[0]
screenshot(browser: instance, comment: 'exists_failed')
raise "#{params[:css]} dosn't exist, but should"
end
if params.key?(:displayed)
if params[:displayed] == true && !instance.find_elements(css: params[:css])[0].displayed?
raise "#{params[:css]} is not displayed, but should"
end
if params[:displayed] == false && instance.find_elements(css: params[:css])[0].displayed?
raise "#{params[:css]} is displayed, but should not"
end
end
true
rescue
sleep retries
retries += 1
retry if retries < 3
end
=begin
exists_not(
browser: browser1,
css: '.some_class',
)
=end
def exists_not(params)
switch_window_focus(params)
log('exists_not', params)
instance = params[:browser] || @browser
if instance.find_elements(css: params[:css])[0]
screenshot(browser: instance, comment: 'exists_not_failed')
raise "#{params[:css]} exists but should not"
end
true
end
=begin
set(
browser: browser1,
css: '.some_class',
value: true,
slow: false,
blur: true, # default false
clear: true, # todo | default: true
no_click: true,
)
=end
def set(params)
switch_window_focus(params)
log('set', params)
instance = params[:browser] || @browser
begin
retries ||= 0
element = instance.find_elements(css: params[:css])[0]
if !params[:no_click]
element.click
end
element.clear
rescue Selenium::WebDriver::Error::StaleElementReferenceError
sleep retries
retries += 1
retry if retries < 3
end
begin
if params[:slow]
element.send_keys('')
keys = params[:value].to_s.chars
keys.each do |key|
instance.action.send_keys(key).perform
end
else
element.send_keys(params[:value])
end
rescue
sleep 0.5
# just try again
log('set', { rescure: true })
element = instance.find_elements(css: params[:css])[0]
raise "No such element '#{params[:css]}'" if !element
if params[:slow]
element.send_keys('')
keys = params[:value].to_s.chars
keys.each do |key|
instance.action.send_keys(key).perform
end
else
element.send_keys(params[:value])
end
end
# it's not working stable with ff via selenium, use js
if browser =~ %r{firefox}i && params[:css].include?('[data-name=')
log('set_ff_trigger_workaround', params)
instance.execute_script("$('#{params[:css]}').trigger('focusout')")
end
if params[:blur]
instance.execute_script("$('#{params[:css]}').blur()")
end
sleep 0.2
await_empty_ajax_queue(params)
end
=begin
select(
browser: browser1,
css: '.some_class',
value: 'Some Value',
deselect_all: false, # default false
)
=end
def select(params)
switch_window_focus(params)
log('select', params)
instance = params[:browser] || @browser
# searchable select
element = instance.find_elements(css: "#{params[:css]}.js-shadow")[0]
if element
element = instance.find_elements(css: "#{params[:css]}.js-shadow + .js-input")[0]
element.click
element.clear
sleep 0.2
element.send_keys(params[:value])
sleep 0.2
element.send_keys(:enter)
sleep 0.2
return
end
# native select
begin
element = instance.find_elements(css: params[:css])[0]
dropdown = Selenium::WebDriver::Support::Select.new(element)
if params[:deselect_all]
dropdown.deselect_all
end
dropdown.select_by(:text, params[:value])
# puts "select - #{params.inspect}"
rescue
sleep 0.4
# just try again
log('select', { rescure: true })
element = instance.find_elements(css: params[:css])[0]
dropdown = Selenium::WebDriver::Support::Select.new(element)
if params[:deselect_all]
dropdown.deselect_all
end
dropdown.select_by(:text, params[:value])
# puts "select2 - #{params.inspect}"
end
await_empty_ajax_queue(params)
end
=begin
switch(
browser: browser1,
css: '.some_class',
type: 'on', # 'off'
no_check: true, # do not check is switch has changed, in case if js alert
)
=end
def switch(params)
switch_window_focus(params)
log('switch', params)
instance = params[:browser] || @browser
element = instance.find_elements(css: "#{params[:css]} input[type=checkbox]")[0]
checked = element.attribute('checked')
if !checked
if params[:type] == 'on'
instance.find_elements(css: "#{params[:css]} label")[0].click
sleep 2
if params[:no_check] != true
element = instance.find_elements(css: "#{params[:css]} input[type=checkbox]")[0]
checked = element.attribute('checked')
raise 'Switch not on!' if !checked
end
end
elsif params[:type] == 'off'
instance.find_elements(css: "#{params[:css]} label")[0].click
sleep 2
if params[:no_check] != true
element = instance.find_elements(css: "#{params[:css]} input[type=checkbox]")[0]
checked = element.attribute('checked')
raise 'Switch not off!' if checked
end
end
end
=begin
check(
browser: browser1,
css: '.some_class',
)
=end
def check(params)
switch_window_focus(params)
log('check', params)
instance = params[:browser] || @browser
instance.execute_script("$('#{params[:css]}:not(:checked)').trigger('click')")
# element = instance.find_elements(css: params[:css])[0]
# checked = element.attribute('checked')
# element.click if !checked
end
=begin
uncheck(
browser: browser1,
css: '.some_class',
)
=end
def uncheck(params)
switch_window_focus(params)
log('uncheck', params)
instance = params[:browser] || @browser
instance.execute_script("$('#{params[:css]}:checked').trigger('click')")
# element = instance.find_elements(css: params[:css])[0]
# checked = element.attribute('checked')
# element.click if checked
end
=begin
sendkey(
browser: browser1,
value: :enter,
slow: false, # default false
)
=end
def sendkey(params)
switch_window_focus(params)
log('sendkey', params)
instance = params[:browser] || @browser
element = nil
if params[:css]
element = instance.find_elements(css: params[:css])[0]
end
if params[:value].instance_of?(Array)
params[:value].each do |key|
if element
element.send_keys(key)
else
instance.action.send_keys(key).perform
end
end
return
end
if element
element.send_keys(params[:value])
else
instance.action.send_keys(params[:value]).perform
end
if params[:slow]
sleep 1.5