-
Notifications
You must be signed in to change notification settings - Fork 220
/
accessors.rb
1466 lines (1406 loc) · 58 KB
/
accessors.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
require 'erb'
require 'page-object/locator_generator'
module PageObject
#
# Contains the class level methods that are inserted into your page objects
# when you include the PageObject module. These methods will generate another
# set of methods that provide access to the elements on the web pages.
#
# @see PageObject::WatirPageObject for the watir implementation of the platform delegate
# @see PageObject::SeleniumPageObject for the selenium implementation of the platform delegate
#
module Accessors
#
# Set some values that can be used within the class. This is
# typically used to provide values that help build dynamic urls in
# the page_url method
#
# @param [Hash] the value to set the params
#
def params=(the_params)
@params = the_params
end
#
# Return the params that exist on this page class
#
def params
@params ||= {}
end
#
# Specify the url for the page. A call to this method will generate a
# 'goto' method to take you to the page.
#
# @param [String] the url for the page.
# @param [Symbol] a method name to call to get the url
#
def page_url(url)
define_method("goto") do
platform.navigate_to self.page_url_value
end
define_method('page_url_value') do
lookup = url.kind_of?(Symbol) ? self.send(url) : url
erb = ERB.new(%Q{#{lookup}})
merged_params = self.class.instance_variable_get("@merged_params")
params = merged_params ? merged_params : self.class.params
erb.result(binding)
end
end
alias_method :direct_url, :page_url
#
# Creates a method that waits the expected_title of a page to match the actual.
# @param [String] expected_title the literal expected title for the page
# @param [Regexp] expected_title the expected title pattern for the page
# @param [optional, Integer] timeout default value is nil - do not wait
# @return [boolean]
# @raise An exception if expected_title does not match actual title
#
# @example Specify 'Google' as the expected title of a page
# expected_title "Google"
# page.has_expected_title?
#
def wait_for_expected_title(expected_title, timeout=::PageObject.default_element_wait)
define_method("wait_for_expected_title?") do
error_message = lambda { "Expected title '#{expected_title}' instead of '#{title}'" }
has_expected_title = (expected_title === title)
wait_until(timeout, error_message.call) do
has_expected_title = (expected_title === title)
end unless has_expected_title
raise error_message.call unless has_expected_title
has_expected_title
end
end
#
# Creates a method that compares the expected_title of a page against the actual.
# @param [String] expected_title the literal expected title for the page
# @param [Regexp] expected_title the expected title pattern for the page
# @return [boolean]
# @raise An exception if expected_title does not match actual title
#
# @example Specify 'Google' as the expected title of a page
# expected_title "Google"
# page.has_expected_title?
#
def expected_title(expected_title)
define_method("has_expected_title?") do
page_title = title
has_expected_title = (expected_title === page_title)
raise "Expected title '#{expected_title}' instead of '#{page_title}'" unless has_expected_title
has_expected_title
end
end
#
# Creates a method that provides a way to initialize a page based upon an expected element.
# This is useful for pages that load dynamic content.
# @param [Symbol] the name given to the element in the declaration
# @param [optional, Integer] timeout default value is 5 seconds
# @return [boolean]
#
# @example Specify a text box named :address expected on the page within 10 seconds
# expected_element(:address, 10)
# page.has_expected_element?
#
def expected_element(element_name, timeout=::PageObject.default_element_wait)
define_method("has_expected_element?") do
self.respond_to? "#{element_name}_element" and self.send("#{element_name}_element").when_present timeout
end
end
#
# Creates a method that provides a way to initialize a page based upon an expected element to become visible.
# This is useful for pages that load dynamic content and might have hidden elements that are not shown.
# @param [Symbol] the name given to the element in the declaration
# @param [optional, Integer] timeout default value is 5 seconds
# @param [optional, boolean] also check that element to be visible if set to true
# @return [boolean]
#
# @example Specify a text box named :address expected on the page within 10 seconds
# expected_element_visible(:address, 10)
# page.has_expected_element_visible?
#
def expected_element_visible(element_name, timeout=::PageObject.default_element_wait, check_visible=false)
define_method("has_expected_element_visible?") do
self.respond_to? "#{element_name}_element" and self.send("#{element_name}_element").when_present timeout
self.respond_to? "#{element_name}_element" and self.send("#{element_name}_element").when_visible timeout
end
end
#
# Identify an element as existing within a frame . A frame parameter
# is passed to the block and must be passed to the other calls to PageObject.
# You can nest calls to in_frame by passing the frame to the next level.
#
# @example
# in_frame(:id => 'frame_id') do |frame|
# text_field(:first_name, :id => 'fname', :frame => frame)
# end
#
# @param [Hash] identifier how we find the frame. The valid keys are:
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :regexp => Watir only
# @param frame passed from a previous call to in_frame. Used to nest calls
# @param block that contains the calls to elements that exist inside the frame.
#
def in_frame(identifier, frame=nil, &block)
frame = [] if frame.nil?
frame << {frame: identifier}
block.call(frame)
end
#
# Identify an element as existing within an iframe. A frame parameter
# is passed to the block and must be passed to the other calls to PageObject.
# You can nest calls to in_frame by passing the frame to the next level.
#
# @example
# in_iframe(:id => 'frame_id') do |frame|
# text_field(:first_name, :id => 'fname', :frame => frame)
# end
#
# @param [Hash] identifier how we find the frame. The valid keys are:
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :regexp => Watir only
# @param frame passed from a previous call to in_iframe. Used to nest calls
# @param block that contains the calls to elements that exist inside the iframe.
#
def in_iframe(identifier, frame=nil, &block)
frame = [] if frame.nil?
frame << {iframe: identifier}
block.call(frame)
end
#
# adds four methods to the page object - one to set text in a text field,
# another to retrieve text from a text field, another to return the text
# field element, another to check the text field's existence.
#
# @example
# text_field(:first_name, :id => "first_name")
# # will generate 'first_name', 'first_name=', 'first_name_element',
# # 'first_name?' methods
#
# @param [String] the name used for the generated methods
# @param [Hash] identifier how we find a text field. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
# * :css => Selenium only
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :label => Watir and Selenium
# * :name => Watir and Selenium
# * :text => Watir and Selenium
# * :title => Watir and Selenium
# * :value => Watir only
# * :xpath => Watir and Selenium
# @param optional block to be invoked when element method is called
#
def text_field(name, identifier={:index => 0}, &block)
standard_methods(name, identifier, 'text_field_for', &block)
define_method(name) do
return platform.text_field_value_for identifier.clone unless block_given?
self.send("#{name}_element").value
end
define_method("#{name}=") do |value|
return platform.text_field_value_set(identifier.clone, value) unless block_given?
self.send("#{name}_element").value = value
end
end
#
# adds three methods to the page object - one to get the text from a hidden field,
# another to retrieve the hidden field element, and another to check the hidden
# field's existence.
#
# @example
# hidden_field(:user_id, :id => "user_identity")
# # will generate 'user_id', 'user_id_element' and 'user_id?' methods
#
# @param [String] the name used for the generated methods
# @param [Hash] identifier how we find a hidden field. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
# * :css => Selenium only
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :text => Watir and Selenium
# * :value => Watir and Selenium
# * :xpath => Watir and Selenium
# @param optional block to be invoked when element method is called
#
def hidden_field(name, identifier={:index => 0}, &block)
standard_methods(name, identifier, 'hidden_field_for', &block)
define_method(name) do
return platform.hidden_field_value_for identifier.clone unless block_given?
self.send("#{name}_element").value
end
end
alias_method :hidden, :hidden_field
#
# adds four methods to the page object - one to set text in a text area,
# another to retrieve text from a text area, another to return the text
# area element, and another to check the text area's existence.
#
# @example
# text_area(:address, :id => "address")
# # will generate 'address', 'address=', 'address_element',
# # 'address?' methods
#
# @param [String] the name used for the generated methods
# @param [Hash] identifier how we find a text area. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
# * :css => Selenium only
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :xpath => Watir and Selenium
# * :label => Watir and Selenium
# @param optional block to be invoked when element method is called
#
def text_area(name, identifier={:index => 0}, &block)
standard_methods(name, identifier, 'text_area_for', &block)
define_method(name) do
return platform.text_area_value_for identifier.clone unless block_given?
self.send("#{name}_element").value
end
define_method("#{name}=") do |value|
return platform.text_area_value_set(identifier.clone, value) unless block_given?
self.send("#{name}_element").value = value
end
end
alias_method :textarea, :text_area
#
# adds five methods - one to select an item in a drop-down,
# another to fetch the currently selected item text, another
# to retrieve the select list element, another to check the
# drop down's existence and another to get all the available options
# to select from.
#
# @example
# select_list(:state, :id => "state")
# # will generate 'state', 'state=', 'state_element', 'state?', "state_options" methods
#
# @param [Symbol] the name used for the generated methods
# @param [Hash] identifier how we find a select list. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
# * :css => Selenium only
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :text => Watir only
# * :value => Watir only
# * :xpath => Watir and Selenium
# * :label => Watir and Selenium
# @param optional block to be invoked when element method is called
#
def select_list(name, identifier={:index => 0}, &block)
standard_methods(name, identifier, 'select_list_for', &block)
define_method(name) do
return platform.select_list_value_for identifier.clone unless block_given?
self.send("#{name}_element").value
end
define_method("#{name}=") do |value|
return platform.select_list_value_set(identifier.clone, value) unless block_given?
self.send("#{name}_element").select(value)
end
define_method("#{name}_options") do
element = self.send("#{name}_element")
(element && element.options) ? element.options.collect(&:text) : []
end
end
alias_method :select, :select_list
#
# adds three methods - one to select a link, another
# to return a PageObject::Elements::Link object representing
# the link, and another that checks the link's existence.
#
# @example
# link(:add_to_cart, :text => "Add to Cart")
# # will generate 'add_to_cart', 'add_to_cart_element', and 'add_to_cart?' methods
#
# @param [Symbol] the name used for the generated methods
# @param [Hash] identifier how we find a link. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
# * :css => Watir and Selenium
# * :href => Watir and Selenium
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :link => Watir and Selenium
# * :link_text => Watir and Selenium
# * :name => Watir and Selenium
# * :text => Watir and Selenium
# * :title => Watir and Selenium
# * :xpath => Watir and Selenium
# @param optional block to be invoked when element method is called
#
def link(name, identifier={:index => 0}, &block)
standard_methods(name, identifier, 'link_for', &block)
define_method(name) do
return platform.click_link_for identifier.clone unless block_given?
self.send("#{name}_element").click
end
end
alias_method :a, :link
#
# adds five methods - one to check, another to uncheck, another
# to return the state of a checkbox, another to return
# a PageObject::Elements::CheckBox object representing the checkbox, and
# a final method to check the checkbox's existence.
#
# @example
# checkbox(:active, :name => "is_active")
# # will generate 'check_active', 'uncheck_active', 'active_checked?',
# # 'active_element', and 'active?' methods
#
# @param [Symbol] the name used for the generated methods
# @param [Hash] identifier how we find a checkbox. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
# * :css => Selenium only
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :value => Watir and Selenium
# * :xpath => Watir and Selenium
# * :label => Watir and Selenium
# @param optional block to be invoked when element method is called
#
def checkbox(name, identifier={:index => 0}, &block)
standard_methods(name, identifier, 'checkbox_for', &block)
define_method("check_#{name}") do
return platform.check_checkbox(identifier.clone) unless block_given?
self.send("#{name}_element").check
end
define_method("uncheck_#{name}") do
return platform.uncheck_checkbox(identifier.clone) unless block_given?
self.send("#{name}_element").uncheck
end
define_method("#{name}_checked?") do
return platform.checkbox_checked?(identifier.clone) unless block_given?
self.send("#{name}_element").checked?
end
end
#
# adds four methods - one to select, another to return if a radio button
# is selected, another method to return a PageObject::Elements::RadioButton
# object representing the radio button element, and another to check
# the radio button's existence.
#
# @example
# radio_button(:north, :id => "north")
# # will generate 'select_north', 'north_selected?',
# # 'north_element', and 'north?' methods
#
# @param [Symbol] the name used for the generated methods
# @param [Hash] identifier how we find a radio button. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
# * :css => Selenium only
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :value => Watir and Selenium
# * :xpath => Watir and Selenium
# * :label => Watir and Selenium
# @param optional block to be invoked when element method is called
#
def radio_button(name, identifier={:index => 0}, &block)
standard_methods(name, identifier, 'radio_button_for', &block)
define_method("select_#{name}") do
return platform.select_radio(identifier.clone) unless block_given?
self.send("#{name}_element").select
end
define_method("#{name}_selected?") do
return platform.radio_selected?(identifier.clone) unless block_given?
self.send("#{name}_element").selected?
end
end
alias_method :radio, :radio_button
#
# adds five methods to help interact with a radio button group -
# a method to select a radio button in the group by given value/text,
# a method to return the values of all radio buttons in the group, a method
# to return if a radio button in the group is selected (will return
# the text of the selected radio button, if true), a method to return
# an array of PageObject::Elements::RadioButton objects representing
# the radio button group, and finally a method to check the existence
# of the radio button group.
#
# @example
# radio_button_group(:color, :name => "preferred_color")
# will generate 'select_color', 'color_values', 'color_selected?',
# 'color_elements', and 'color?' methods
#
# @param [Symbol] the name used for the generated methods
# @param [Hash] shared identifier for the radio button group. Typically, a 'name' attribute.
# The valid keys are:
# * :name => Watir and Selenium
#
def radio_button_group(name, identifier)
define_method("select_#{name}") do |value|
platform.radio_buttons_for(identifier.clone).each do |radio_elem|
if radio_elem.value == value
return radio_elem.select
end
end
end
define_method("#{name}_values") do
result = []
platform.radio_buttons_for(identifier.clone).each do |radio_elem|
result << radio_elem.value
end
return result
end
define_method("#{name}_selected?") do
platform.radio_buttons_for(identifier.clone).each do |radio_elem|
return radio_elem.value if radio_elem.selected?
end
return false
end
define_method("#{name}_elements") do
return platform.radio_buttons_for(identifier.clone)
end
define_method("#{name}?") do
return platform.radio_buttons_for(identifier.clone).any?
end
end
alias_method :radio_group, :radio_button_group
#
# adds three methods - one to click a button, another to
# return the button element, and another to check the button's existence.
#
# @example
# button(:purchase, :id => 'purchase')
# # will generate 'purchase', 'purchase_element', and 'purchase?' methods
#
# @param [Symbol] the name used for the generated methods
# @param [Hash] identifier how we find a button. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
# * :css => Watir and Selenium
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :text => Watir only
# * :value => Watir and Selenium
# * :xpath => Watir and Selenium
# * :src => Watir and Selenium (input type=image only)
# * :alt => Watir and Selenium (input type=image only)
# @param optional block to be invoked when element method is called
#
def button(name, identifier={:index => 0}, &block)
standard_methods(name, identifier, 'button_for', &block)
define_method(name) do
return platform.click_button_for identifier.clone unless block_given?
self.send("#{name}_element").click
end
end
#
# adds three methods - one to retrieve the text from a div,
# another to return the div element, and another to check the div's existence.
#
# @example
# div(:message, :id => 'message')
# # will generate 'message', 'message_element', and 'message?' methods
#
# @param [Symbol] the name used for the generated methods
# @param [Hash] identifier how we find a div. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
# * :css => Watir and Selenium
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :text => Watir and Selenium
# * :title => Watir and Selenium
# * :xpath => Watir and Selenium
# @param optional block to be invoked when element method is called
#
def div(name, identifier={:index => 0}, &block)
standard_methods(name, identifier, 'div_for', &block)
define_method(name) do
return platform.div_text_for identifier.clone unless block_given?
self.send("#{name}_element").text
end
end
#
# adds three methods - one to retrieve the text from a span,
# another to return the span element, and another to check the span's existence.
#
# @example
# span(:alert, :id => 'alert')
# # will generate 'alert', 'alert_element', and 'alert?' methods
#
# @param [Symbol] the name used for the generated methods
# @param [Hash] identifier how we find a span. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
# * :css => Watir and Selenium
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :text => Watir and Selenium
# * :title => Watir and Selenium
# * :xpath => Watir and Selenium
# @param optional block to be invoked when element method is called
#
def span(name, identifier={:index => 0}, &block)
standard_methods(name, identifier, 'span_for', &block)
define_method(name) do
return platform.span_text_for identifier.clone unless block_given?
self.send("#{name}_element").text
end
end
#
# adds three methods - one to return the text for the table, one
# to retrieve the table element, and another to
# check the table's existence. The existence method does not work
# on Selenium so it should not be called.
#
# @example
# table(:cart, :id => 'shopping_cart')
# # will generate a 'cart', 'cart_element' and 'cart?' method
#
# @param [Symbol] the name used for the generated methods
# @param [Hash] identifier how we find a table. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
# * :css => Selenium only
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :xpath => Watir and Selenium
# @param optional block to be invoked when element method is called
#
def table(name, identifier={:index => 0}, &block)
standard_methods(name, identifier, 'table_for', &block)
define_method(name) do
return platform.table_text_for identifier.clone unless block_given?
self.send("#{name}_element").text
end
end
#
# adds three methods - one to retrieve the text from a table cell,
# another to return the table cell element, and another to check the cell's
# existence.
#
# @example
# cell(:total, :id => 'total_cell')
# # will generate 'total', 'total_element', and 'total?' methods
#
# @param [Symbol] the name used for the generated methods
# @param [Hash] identifier how we find a cell. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
# * :css => Watir and Selenium
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :text => Watir and Selenium
# * :xpath => Watir and Selenium
# * :css => Selenium only
# @param optional block to be invoked when element method is called
#
def cell(name, identifier={:index => 0}, &block)
standard_methods(name, identifier, 'cell_for', &block)
define_method("#{name}") do
return platform.cell_text_for identifier.clone unless block_given?
self.send("#{name}_element").text
end
end
alias_method :td, :cell
#
# adds three methods - one to retrieve the text from a table row,
# another to return the table row element, and another to check the row's
# existence.
#
# @example
# row(:sums, :id => 'sum_row')
# # will generate 'sums', 'sums_element', and 'sums?' methods
#
# @param [Symbol] the name used for the generated methods
# @param [Hash] identifier how we find a cell. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
# * :css => Watir and Selenium
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :text => Watir only
# * :xpath => Watir and Selenium
# * :css => Watir and Selenium
# @param optional block to be invoked when element method is called
#
def row(name, identifier={:index => 0}, &block)
standard_methods(name, identifier, 'row_for', &block)
define_method("#{name}") do
return platform.row_text_for identifier.clone unless block_given?
self.send("#{name}_element").text
end
end
#
# adds two methods - one to retrieve the image element, and another to
# check the image's existence.
#
# @example
# image(:logo, :id => 'logo')
# # will generate 'logo_element' and 'logo?' methods
#
# @param [Symbol] the name used for the generated methods
# @param [Hash] identifier how we find an image. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :alt => Watir and Selenium
# * :class => Watir and Selenium
# * :css => Selenium only
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :src => Watir and Selenium
# * :xpath => Watir and Selenium
# @param optional block to be invoked when element method is called
#
def image(name, identifier={:index => 0}, &block)
standard_methods(name, identifier, 'image_for', &block)
end
alias_method :img, :image
#
# adds two methods - one to retrieve the form element, and another to
# check the form's existence.
#
# @example
# form(:login, :id => 'login')
# # will generate 'login_element' and 'login?' methods
#
# @param [Symbol] the name used for the generated methods
# @param [Hash] identifier how we find a form. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :action => Watir and Selenium
# * :class => Watir and Selenium
# * :css => Selenium only
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :xpath => Watir and Selenium
# @param optional block to be invoked when element method is called
#
def form(name, identifier={:index => 0}, &block)
standard_methods(name, identifier, 'form_for', &block)
end
#
# adds three methods - one to retrieve the text from a list item,
# another to return the list item element, and another to check the list item's
# existence.
#
# @example
# list_item(:item_one, :id => 'one')
# # will generate 'item_one', 'item_one_element', and 'item_one?' methods
#
# @param [Symbol] the name used for the generated methods
# @param [Hash] identifier how we find a list item. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
# * :css => Watir and Selenium
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :text => Watir and Selenium
# * :xpath => Watir and Selenium
# @param optional block to be invoked when element method is called
#
def list_item(name, identifier={:index => 0}, &block)
standard_methods(name, identifier, 'list_item_for', &block)
define_method(name) do
return platform.list_item_text_for identifier.clone unless block_given?
self.send("#{name}_element").text
end
end
alias_method :li, :list_item
#
# adds three methods - one to return the text within the unordered
# list, one to retrieve the unordered list element, and another to
# check it's existence.
#
# @example
# unordered_list(:menu, :id => 'main_menu')
# # will generate 'menu', 'menu_element' and 'menu?' methods
#
# @param [Symbol] the name used for the generated methods
# @param [Hash] identifier how we find an unordered list. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
# * :css => Selenium only
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :xpath => Watir and Selenium
# @param optional block to be invoked when element method is called
#
def unordered_list(name, identifier={:index => 0}, &block)
standard_methods(name, identifier, 'unordered_list_for', &block)
define_method(name) do
return platform.unordered_list_text_for identifier.clone unless block_given?
self.send("#{name}_element").text
end
end
alias_method :ul, :unordered_list
#
# adds three methods - one to return the text within the ordered
# list, one to retrieve the ordered list element, and another to
# test it's existence.
#
# @example
# ordered_list(:top_five, :id => 'top')
# # will generate 'top_five', 'top_five_element' and 'top_five?' methods
#
# @param [Symbol] the name used for the generated methods
# @param [Hash] identifier how we find an ordered list. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
# * :css => Selenium only
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :xpath => Watir and Selenium
# @param optional block to be invoked when element method is called
#
def ordered_list(name, identifier={:index => 0}, &block)
standard_methods(name, identifier, 'ordered_list_for', &block)
define_method(name) do
return platform.ordered_list_text_for identifier.clone unless block_given?
self.send("#{name}_element").text
end
end
alias_method :ol, :ordered_list
#
# adds three methods - one to retrieve the text of a h1 element, another to
# retrieve a h1 element, and another to check for it's existence.
#
# @example
# h1(:title, :id => 'title')
# # will generate 'title', 'title_element', and 'title?' methods
#
# @param [Symbol] the name used for the generated methods
# @param [Hash] identifier how we find a H1. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
# * :css => Watir and Selenium
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :xpath => Watir and Selenium
# @param optional block to be invoked when element method is called
#
def h1(name, identifier={:index => 0}, &block)
standard_methods(name, identifier,'h1_for', &block)
define_method(name) do
return platform.h1_text_for identifier.clone unless block_given?
self.send("#{name}_element").text
end
end
#
# adds three methods - one to retrieve the text of a h2 element, another
# to retrieve a h2 element, and another to check for it's existence.
#
# @example
# h2(:title, :id => 'title')
# # will generate 'title', 'title_element', and 'title?' methods
#
# @param [Symbol] the name used for the generated methods
# @param [Hash] identifier how we find a H2. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
# * :css => Watir and Selenium
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :xpath => Watir and Selenium
# @param optional block to be invoked when element method is called
#
def h2(name, identifier={:index => 0}, &block)
standard_methods(name, identifier, 'h2_for', &block)
define_method(name) do
return platform.h2_text_for identifier.clone unless block_given?
self.send("#{name}_element").text
end
end
#
# adds three methods - one to retrieve the text of a h3 element,
# another to return a h3 element, and another to check for it's existence.
#
# @example
# h3(:title, :id => 'title')
# # will generate 'title', 'title_element', and 'title?' methods
#
# @param [Symbol] the name used for the generated methods
# @param [Hash] identifier how we find a H3. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
# * :css => Watir and Selenium
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :xpath => Watir and Selenium
# @param optional block to be invoked when element method is called
#
def h3(name, identifier={:index => 0}, &block)
standard_methods(name, identifier, 'h3_for', &block)
define_method(name) do
return platform.h3_text_for identifier.clone unless block_given?
self.send("#{name}_element").text
end
end
#
# adds three methods - one to retrieve the text of a h4 element,
# another to return a h4 element, and another to check for it's existence.
#
# @example
# h4(:title, :id => 'title')
# # will generate 'title', 'title_element', and 'title?' methods
#
# @param [Symbol] the name used for the generated methods
# @param [Hash] identifier how we find a H4. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
# * :css => Watir and Selenium
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :xpath => Watir and Selenium
# @param optional block to be invoked when element method is called
#
def h4(name, identifier={:index => 0}, &block)
standard_methods(name, identifier, 'h4_for', &block)
define_method(name) do
return platform.h4_text_for identifier.clone unless block_given?
self.send("#{name}_element").text
end
end
#
# adds three methods - one to retrieve the text of a h5 element,
# another to return a h5 element, and another to check for it's existence.
#
# @example
# h5(:title, :id => 'title')
# # will generate 'title', 'title_element', and 'title?' methods
#
# @param [Symbol] the name used for the generated methods
# @param [Hash] identifier how we find a H5. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
# * :css => Watir and Selenium
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :xpath => Watir and Selenium
# @param optional block to be invoked when element method is called
#
def h5(name, identifier={:index => 0}, &block)
standard_methods(name, identifier, 'h5_for', &block)
define_method(name) do
return platform.h5_text_for identifier.clone unless block_given?
self.send("#{name}_element").text
end
end
#
# adds three methods - one to retrieve the text of a h6 element,
# another to return a h6 element, and another to check for it's existence.
#
# @example
# h6(:title, :id => 'title')
# # will generate 'title', 'title_element', and 'title?' methods
#
# @param [Symbol] the name used for the generated methods
# @param [Hash] identifier how we find a H6. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
# * :css => Watir and Selenium
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :xpath => Watir and Selenium
# @param optional block to be invoked when element method is called
#
def h6(name, identifier={:index => 0}, &block)
standard_methods(name, identifier, 'h6_for', &block)
define_method(name) do
return platform.h6_text_for identifier.clone unless block_given?
self.send("#{name}_element").text
end
end
#
# adds three methods - one to retrieve the text of a paragraph, another
# to retrieve a paragraph element, and another to check the paragraph's existence.
#
# @example
# paragraph(:title, :id => 'title')
# # will generate 'title', 'title_element', and 'title?' methods
#
# @param [Symbol] the name used for the generated methods
# @param [Hash] identifier how we find a paragraph. You can use a multiple parameters
# by combining of any of the following except xpath. The valid keys are:
# * :class => Watir and Selenium
# * :css => Watir and Selenium
# * :id => Watir and Selenium
# * :index => Watir and Selenium
# * :name => Watir and Selenium
# * :xpath => Watir and Selenium
# @param optional block to be invoked when element method is called
#
def paragraph(name, identifier={:index => 0}, &block)
standard_methods(name, identifier, 'paragraph_for', &block)
define_method(name) do
return platform.paragraph_text_for identifier.clone unless block_given?
self.send("#{name}_element").text
end
end
alias_method :p, :paragraph
#
# adds three methods - one to set the file for a file field, another to retrieve
# the file field element, and another to check it's existence.
#