page-object 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +13 -1
- data/features/element.feature +10 -0
- data/features/headings.feature +54 -0
- data/features/html/nested_elements.html +6 -2
- data/features/html/static_elements.html +11 -26
- data/features/nested_elements.feature +14 -1
- data/features/step_definitions/element_steps.rb +4 -0
- data/features/step_definitions/headings_steps.rb +12 -0
- data/features/step_definitions/nested_elements_steps.rb +27 -0
- data/features/step_definitions/text_area_steps.rb +4 -0
- data/features/support/page.rb +24 -0
- data/features/text_area.feature +6 -0
- data/lib/page-object/accessors.rb +87 -0
- data/lib/page-object/element_locators.rb +45 -0
- data/lib/page-object/elements.rb +1 -0
- data/lib/page-object/elements/element.rb +1 -1
- data/lib/page-object/elements/heading.rb +7 -0
- data/lib/page-object/nested_elements.rb +12 -0
- data/lib/page-object/platforms/selenium_webdriver/element.rb +3 -12
- data/lib/page-object/platforms/selenium_webdriver/page_object.rb +72 -0
- data/lib/page-object/platforms/watir_webdriver/element.rb +3 -0
- data/lib/page-object/platforms/watir_webdriver/page_object.rb +57 -0
- data/lib/page-object/platforms/watir_webdriver/text_area.rb +7 -0
- data/lib/page-object/version.rb +1 -1
- data/page-object.gemspec +1 -1
- data/spec/page-object/accessors_spec.rb +135 -0
- data/spec/page-object/element_locators_spec.rb +18 -0
- data/spec/page-object/elements/element_spec.rb +42 -0
- data/spec/page-object/elements/heading_spec.rb +22 -0
- data/spec/page-object/elements/nested_element_spec.rb +33 -3
- metadata +11 -6
- data/features/element_attributes.feature +0 -233
@@ -273,5 +273,50 @@ module PageObject
|
|
273
273
|
def ordered_list_element(identifier)
|
274
274
|
platform.ordered_list_for(identifier.clone)
|
275
275
|
end
|
276
|
+
|
277
|
+
#
|
278
|
+
# Finds a h1
|
279
|
+
#
|
280
|
+
# @param [Hash] identifier how we find a H1. You can use a multiple paramaters
|
281
|
+
# by combining of any of the following except xpath. The valid keys are:
|
282
|
+
# * :class => Watir and Selenium
|
283
|
+
# * :id => Watir and Selenium
|
284
|
+
# * :index => Watir and Selenium
|
285
|
+
# * :name => Watir and Selenium
|
286
|
+
# * :xpath => Watir and Selenium
|
287
|
+
#
|
288
|
+
def h1_element(identifier)
|
289
|
+
platform.h1_for(identifier.clone)
|
290
|
+
end
|
291
|
+
|
292
|
+
#
|
293
|
+
# Finds a h2
|
294
|
+
#
|
295
|
+
# @param [Hash] identifier how we find a H2. You can use a multiple paramaters
|
296
|
+
# by combining of any of the following except xpath. The valid keys are:
|
297
|
+
# * :class => Watir and Selenium
|
298
|
+
# * :id => Watir and Selenium
|
299
|
+
# * :index => Watir and Selenium
|
300
|
+
# * :name => Watir and Selenium
|
301
|
+
# * :xpath => Watir and Selenium
|
302
|
+
#
|
303
|
+
def h2_element(identifier)
|
304
|
+
platform.h2_for(identifier.clone)
|
305
|
+
end
|
306
|
+
|
307
|
+
#
|
308
|
+
# Finds a h3
|
309
|
+
#
|
310
|
+
# @param [Hash] identifier how we find a H3. You can use a multiple paramaters
|
311
|
+
# by combining of any of the following except xpath. The valid keys are:
|
312
|
+
# * :class => Watir and Selenium
|
313
|
+
# * :id => Watir and Selenium
|
314
|
+
# * :index => Watir and Selenium
|
315
|
+
# * :name => Watir and Selenium
|
316
|
+
# * :xpath => Watir and Selenium
|
317
|
+
#
|
318
|
+
def h3_element(identifier)
|
319
|
+
platform.h3_for(identifier.clone)
|
320
|
+
end
|
276
321
|
end
|
277
322
|
end
|
data/lib/page-object/elements.rb
CHANGED
@@ -58,7 +58,7 @@ module PageObject
|
|
58
58
|
protected
|
59
59
|
|
60
60
|
def self.should_build_watir_xpath identifier
|
61
|
-
['table', 'span', 'div', 'td', 'li', 'ul', 'ol'].include? identifier[:tag_name] and identifier[:name]
|
61
|
+
['table', 'span', 'div', 'td', 'li', 'ul', 'ol', 'h1', 'h2', 'h3'].include? identifier[:tag_name] and identifier[:name]
|
62
62
|
end
|
63
63
|
|
64
64
|
def self.build_xpath_for identifier
|
@@ -68,5 +68,17 @@ module PageObject
|
|
68
68
|
def list_item_element(identifier={:index => 0})
|
69
69
|
@platform.list_item_for(identifier)
|
70
70
|
end
|
71
|
+
|
72
|
+
def h1_element(identifier={:index => 0})
|
73
|
+
@platform.h1_for(identifier)
|
74
|
+
end
|
75
|
+
|
76
|
+
def h2_element(identifier={:index => 0})
|
77
|
+
@platform.h2_for(identifier)
|
78
|
+
end
|
79
|
+
|
80
|
+
def h3_element(identifier={:index => 0})
|
81
|
+
@platform.h3_for(identifier)
|
82
|
+
end
|
71
83
|
end
|
72
84
|
end
|
@@ -100,6 +100,7 @@ module PageObject
|
|
100
100
|
wait.until do
|
101
101
|
self.exists?
|
102
102
|
end
|
103
|
+
self
|
103
104
|
end
|
104
105
|
|
105
106
|
#
|
@@ -112,6 +113,7 @@ module PageObject
|
|
112
113
|
wait.until do
|
113
114
|
self.visible?
|
114
115
|
end
|
116
|
+
self
|
115
117
|
end
|
116
118
|
|
117
119
|
#
|
@@ -124,6 +126,7 @@ module PageObject
|
|
124
126
|
wait.until do
|
125
127
|
not self.visible?
|
126
128
|
end
|
129
|
+
self
|
127
130
|
end
|
128
131
|
|
129
132
|
#
|
@@ -138,18 +141,6 @@ module PageObject
|
|
138
141
|
wait.until &block
|
139
142
|
end
|
140
143
|
|
141
|
-
#
|
142
|
-
# Waits until the block returns true
|
143
|
-
#
|
144
|
-
# @param [Integer] (defaults to: 5) seconds to wait before timing out
|
145
|
-
# @param [String] the message to display if the event timeouts
|
146
|
-
# @param the block to execute when the event occurrs
|
147
|
-
#
|
148
|
-
def wait_until(timeout=5, message=nil, &block)
|
149
|
-
wait = Object::Selenium::WebDriver::Wait.new({:timeout => timeout, :message => message})
|
150
|
-
wait.until &block
|
151
|
-
end
|
152
|
-
|
153
144
|
#
|
154
145
|
# Send keystrokes to this element
|
155
146
|
#
|
@@ -553,6 +553,78 @@ module PageObject
|
|
553
553
|
@browser.switch_to.default_content unless frame_identifiers.nil?
|
554
554
|
::PageObject::Elements::OrderedList.new(element, :platform => :selenium_webdriver)
|
555
555
|
end
|
556
|
+
|
557
|
+
#
|
558
|
+
# platform method to retrieve the text from a h1
|
559
|
+
# See PageObject::Accessors#h1
|
560
|
+
#
|
561
|
+
def h1_text_for(identifier)
|
562
|
+
how, what, frame_identifiers = parse_identifiers(identifier, Elements::Heading, 'h1')
|
563
|
+
switch_to_frame(frame_identifiers)
|
564
|
+
value = @browser.find_element(how, what).text
|
565
|
+
@browser.switch_to.default_content
|
566
|
+
value
|
567
|
+
end
|
568
|
+
|
569
|
+
#
|
570
|
+
# platform method to retrieve the h1 element
|
571
|
+
# See PageObject::Accessors#h1
|
572
|
+
#
|
573
|
+
def h1_for(identifier)
|
574
|
+
how, what, frame_identifiers = parse_identifiers(identifier, Elements::Heading, 'h1')
|
575
|
+
switch_to_frame(frame_identifiers)
|
576
|
+
element = @browser.find_element(how, what)
|
577
|
+
@browser.switch_to.default_content unless frame_identifiers.nil?
|
578
|
+
::PageObject::Elements::Heading.new(element, :platform => :selenium_webdriver)
|
579
|
+
end
|
580
|
+
|
581
|
+
#
|
582
|
+
# platform method to retrieve the text from a h2
|
583
|
+
# See PageObject::Accessors#h2
|
584
|
+
#
|
585
|
+
def h2_text_for(identifier)
|
586
|
+
how, what, frame_identifiers = parse_identifiers(identifier, Elements::Heading, 'h2')
|
587
|
+
switch_to_frame(frame_identifiers)
|
588
|
+
value = @browser.find_element(how, what).text
|
589
|
+
@browser.switch_to.default_content
|
590
|
+
value
|
591
|
+
end
|
592
|
+
|
593
|
+
#
|
594
|
+
# platform method to retrieve the h2 element
|
595
|
+
# See PageObject::Accessors#h2
|
596
|
+
#
|
597
|
+
def h2_for(identifier)
|
598
|
+
how, what, frame_identifiers = parse_identifiers(identifier, Elements::Heading, 'h2')
|
599
|
+
switch_to_frame(frame_identifiers)
|
600
|
+
element = @browser.find_element(how, what)
|
601
|
+
@browser.switch_to.default_content unless frame_identifiers.nil?
|
602
|
+
::PageObject::Elements::Heading.new(element, :platform => :selenium_webdriver)
|
603
|
+
end
|
604
|
+
|
605
|
+
#
|
606
|
+
# platform method to retrieve the text from a h3
|
607
|
+
# See PageObject::Accessors#h3
|
608
|
+
#
|
609
|
+
def h3_text_for(identifier)
|
610
|
+
how, what, frame_identifiers = parse_identifiers(identifier, Elements::Heading, 'h3')
|
611
|
+
switch_to_frame(frame_identifiers)
|
612
|
+
value = @browser.find_element(how, what).text
|
613
|
+
@browser.switch_to.default_content
|
614
|
+
value
|
615
|
+
end
|
616
|
+
|
617
|
+
#
|
618
|
+
# platform method to retrieve the h3 element
|
619
|
+
# See PageObject::Accessors#h3
|
620
|
+
#
|
621
|
+
def h3_for(identifier)
|
622
|
+
how, what, frame_identifiers = parse_identifiers(identifier, Elements::Heading, 'h3')
|
623
|
+
switch_to_frame(frame_identifiers)
|
624
|
+
element = @browser.find_element(how, what)
|
625
|
+
@browser.switch_to.default_content unless frame_identifiers.nil?
|
626
|
+
::PageObject::Elements::Heading.new(element, :platform => :selenium_webdriver)
|
627
|
+
end
|
556
628
|
|
557
629
|
private
|
558
630
|
|
@@ -90,6 +90,7 @@ module PageObject
|
|
90
90
|
#
|
91
91
|
def when_present(timeout=5)
|
92
92
|
@element.wait_until_present(timeout)
|
93
|
+
self
|
93
94
|
end
|
94
95
|
|
95
96
|
#
|
@@ -101,6 +102,7 @@ module PageObject
|
|
101
102
|
Object::Watir::Wait.until(timeout, "Element was not visible in #{timeout} seconds") do
|
102
103
|
visible?
|
103
104
|
end
|
105
|
+
self
|
104
106
|
end
|
105
107
|
|
106
108
|
#
|
@@ -112,6 +114,7 @@ module PageObject
|
|
112
114
|
Object::Watir::Wait.while(timeout, "Element still visible after #{timeout} seconds") do
|
113
115
|
visible?
|
114
116
|
end
|
117
|
+
self
|
115
118
|
end
|
116
119
|
|
117
120
|
#
|
@@ -454,6 +454,63 @@ module PageObject
|
|
454
454
|
element = @browser.instance_eval "#{nested_frames(frame_identifiers)}ol(identifier)"
|
455
455
|
Object::PageObject::Elements::OrderedList.new(element, :platform => :watir_webdriver)
|
456
456
|
end
|
457
|
+
|
458
|
+
#
|
459
|
+
# platform method to retrieve the text for a h1
|
460
|
+
# See PageObject::Accessors#h1
|
461
|
+
#
|
462
|
+
def h1_text_for(identifier)
|
463
|
+
identifier, frame_identifiers = parse_identifiers(identifier, Elements::Heading, 'h1')
|
464
|
+
@browser.instance_eval "#{nested_frames(frame_identifiers)}h1(identifier).text"
|
465
|
+
end
|
466
|
+
|
467
|
+
#
|
468
|
+
# platform method to retrieve the h1 element
|
469
|
+
# See PageObject::Accessors#h1
|
470
|
+
#
|
471
|
+
def h1_for(identifier)
|
472
|
+
identifier, frame_identifiers = parse_identifiers(identifier, Elements::Heading, 'h1')
|
473
|
+
element = @browser.instance_eval "#{nested_frames(frame_identifiers)}h1(identifier)"
|
474
|
+
Object::PageObject::Elements::Heading.new(element, :platform => :watir_webdriver)
|
475
|
+
end
|
476
|
+
|
477
|
+
#
|
478
|
+
# platform method to retrieve the text for a h2
|
479
|
+
# See PageObject::Accessors#h2
|
480
|
+
#
|
481
|
+
def h2_text_for(identifier)
|
482
|
+
identifier, frame_identifiers = parse_identifiers(identifier, Elements::Heading, 'h2')
|
483
|
+
@browser.instance_eval "#{nested_frames(frame_identifiers)}h2(identifier).text"
|
484
|
+
end
|
485
|
+
|
486
|
+
#
|
487
|
+
# platform method to retrieve the h2 element
|
488
|
+
# See PageObject::Accessors#h2
|
489
|
+
#
|
490
|
+
def h2_for(identifier)
|
491
|
+
identifier, frame_identifiers = parse_identifiers(identifier, Elements::Heading, 'h2')
|
492
|
+
element = @browser.instance_eval "#{nested_frames(frame_identifiers)}h2(identifier)"
|
493
|
+
Object::PageObject::Elements::Heading.new(element, :platform => :watir_webdriver)
|
494
|
+
end
|
495
|
+
|
496
|
+
#
|
497
|
+
# platform method to retrieve the text for a h3
|
498
|
+
# See PageObject::Accessors#h3
|
499
|
+
#
|
500
|
+
def h3_text_for(identifier)
|
501
|
+
identifier, frame_identifiers = parse_identifiers(identifier, Elements::Heading, 'h3')
|
502
|
+
@browser.instance_eval "#{nested_frames(frame_identifiers)}h3(identifier).text"
|
503
|
+
end
|
504
|
+
|
505
|
+
#
|
506
|
+
# platform method to retrieve the h3 element
|
507
|
+
# See PageObject::Accessors#h3
|
508
|
+
#
|
509
|
+
def h3_for(identifier)
|
510
|
+
identifier, frame_identifiers = parse_identifiers(identifier, Elements::Heading, 'h3')
|
511
|
+
element = @browser.instance_eval "#{nested_frames(frame_identifiers)}h3(identifier)"
|
512
|
+
Object::PageObject::Elements::Heading.new(element, :platform => :watir_webdriver)
|
513
|
+
end
|
457
514
|
|
458
515
|
private
|
459
516
|
|
data/lib/page-object/version.rb
CHANGED
data/page-object.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.require_paths = ["lib"]
|
21
21
|
|
22
22
|
s.add_dependency 'watir-webdriver', '>= 0.3.3'
|
23
|
-
s.add_dependency 'selenium-webdriver', '>= 2.
|
23
|
+
s.add_dependency 'selenium-webdriver', '>= 2.6.0'
|
24
24
|
|
25
25
|
s.add_development_dependency 'rspec', '>= 2.6.0'
|
26
26
|
s.add_development_dependency 'cucumber', '>= 1.0.0'
|
@@ -21,6 +21,9 @@ class AccessorsTestPageObject
|
|
21
21
|
list_item(:item_one, :id => 'one')
|
22
22
|
unordered_list(:menu, :id => 'main_menu')
|
23
23
|
ordered_list(:top_five, :id => 'top')
|
24
|
+
h1(:heading1, :id => 'main_heading')
|
25
|
+
h2(:heading2, :id => 'main_heading')
|
26
|
+
h3(:heading3, :id => 'main_heading')
|
24
27
|
end
|
25
28
|
|
26
29
|
class BlockPageObject
|
@@ -79,6 +82,15 @@ class BlockPageObject
|
|
79
82
|
ordered_list :top_five do |element|
|
80
83
|
"ordered_list"
|
81
84
|
end
|
85
|
+
h1 :heading1 do |element|
|
86
|
+
"h1"
|
87
|
+
end
|
88
|
+
h2 :heading2 do |element|
|
89
|
+
"h2"
|
90
|
+
end
|
91
|
+
h3 :heading3 do |element|
|
92
|
+
"h3"
|
93
|
+
end
|
82
94
|
end
|
83
95
|
|
84
96
|
describe PageObject::Accessors do
|
@@ -860,4 +872,127 @@ describe PageObject::Accessors do
|
|
860
872
|
end
|
861
873
|
end
|
862
874
|
end
|
875
|
+
|
876
|
+
describe "h1 accessors" do
|
877
|
+
context "when called on a page object" do
|
878
|
+
it "should generate accessor methods" do
|
879
|
+
watir_page_object.should respond_to(:heading1)
|
880
|
+
watir_page_object.should respond_to(:heading1_element)
|
881
|
+
end
|
882
|
+
|
883
|
+
it "should call a block on the element method when present" do
|
884
|
+
block_page_object.heading1_element.should == "h1"
|
885
|
+
end
|
886
|
+
end
|
887
|
+
|
888
|
+
context "watir implementation" do
|
889
|
+
it "should retrieve the text from the h1" do
|
890
|
+
watir_browser.should_receive(:h1).and_return(watir_browser)
|
891
|
+
watir_browser.should_receive(:text).and_return("value")
|
892
|
+
watir_page_object.heading1.should == "value"
|
893
|
+
end
|
894
|
+
|
895
|
+
it "should retrieve the element from the page" do
|
896
|
+
watir_browser.should_receive(:h1).and_return(watir_browser)
|
897
|
+
element = watir_page_object.heading1_element
|
898
|
+
element.should be_instance_of PageObject::Elements::Heading
|
899
|
+
end
|
900
|
+
end
|
901
|
+
|
902
|
+
context "selenium implementation" do
|
903
|
+
it "should retrieve the text from the h1" do
|
904
|
+
selenium_browser.should_receive(:find_element).and_return(selenium_browser)
|
905
|
+
selenium_browser.should_receive(:text).and_return("value")
|
906
|
+
selenium_page_object.heading1.should == "value"
|
907
|
+
end
|
908
|
+
|
909
|
+
it "should retrieve the element from the page" do
|
910
|
+
selenium_browser.should_receive(:find_element).and_return(selenium_browser)
|
911
|
+
element = selenium_page_object.heading1_element
|
912
|
+
element.should be_instance_of PageObject::Elements::Heading
|
913
|
+
end
|
914
|
+
end
|
915
|
+
end
|
916
|
+
|
917
|
+
describe "h2 accessors" do
|
918
|
+
context "when called on a page object" do
|
919
|
+
it "should generate accessor methods" do
|
920
|
+
watir_page_object.should respond_to(:heading2)
|
921
|
+
watir_page_object.should respond_to(:heading2_element)
|
922
|
+
end
|
923
|
+
|
924
|
+
it "should call a block on the element method when present" do
|
925
|
+
block_page_object.heading2_element.should == "h2"
|
926
|
+
end
|
927
|
+
end
|
928
|
+
|
929
|
+
context "watir implementation" do
|
930
|
+
it "should retrieve the text from the h2" do
|
931
|
+
watir_browser.should_receive(:h2).and_return(watir_browser)
|
932
|
+
watir_browser.should_receive(:text).and_return("value")
|
933
|
+
watir_page_object.heading2.should == "value"
|
934
|
+
end
|
935
|
+
|
936
|
+
it "should retrieve the element from the page" do
|
937
|
+
watir_browser.should_receive(:h2).and_return(watir_browser)
|
938
|
+
element = watir_page_object.heading2_element
|
939
|
+
element.should be_instance_of PageObject::Elements::Heading
|
940
|
+
end
|
941
|
+
end
|
942
|
+
|
943
|
+
context "selenium implementation" do
|
944
|
+
it "should retrieve the text from the h2" do
|
945
|
+
selenium_browser.should_receive(:find_element).and_return(selenium_browser)
|
946
|
+
selenium_browser.should_receive(:text).and_return("value")
|
947
|
+
selenium_page_object.heading2.should == "value"
|
948
|
+
end
|
949
|
+
|
950
|
+
it "should retrieve the element from the page" do
|
951
|
+
selenium_browser.should_receive(:find_element).and_return(selenium_browser)
|
952
|
+
element = selenium_page_object.heading2_element
|
953
|
+
element.should be_instance_of PageObject::Elements::Heading
|
954
|
+
end
|
955
|
+
end
|
956
|
+
|
957
|
+
describe "h3 accessors" do
|
958
|
+
context "when called on a page object" do
|
959
|
+
it "should generate accessor methods" do
|
960
|
+
watir_page_object.should respond_to(:heading3)
|
961
|
+
watir_page_object.should respond_to(:heading3_element)
|
962
|
+
end
|
963
|
+
|
964
|
+
it "should call a block on the element method when present" do
|
965
|
+
block_page_object.heading3_element.should == "h3"
|
966
|
+
end
|
967
|
+
end
|
968
|
+
|
969
|
+
context "watir implementation" do
|
970
|
+
it "should retrieve the text from the h3" do
|
971
|
+
watir_browser.should_receive(:h3).and_return(watir_browser)
|
972
|
+
watir_browser.should_receive(:text).and_return("value")
|
973
|
+
watir_page_object.heading3.should == "value"
|
974
|
+
end
|
975
|
+
|
976
|
+
it "should retrieve the element from the page" do
|
977
|
+
watir_browser.should_receive(:h3).and_return(watir_browser)
|
978
|
+
element = watir_page_object.heading3_element
|
979
|
+
element.should be_instance_of PageObject::Elements::Heading
|
980
|
+
end
|
981
|
+
end
|
982
|
+
|
983
|
+
context "selenium implementation" do
|
984
|
+
it "should retrieve the text from the h3" do
|
985
|
+
selenium_browser.should_receive(:find_element).and_return(selenium_browser)
|
986
|
+
selenium_browser.should_receive(:text).and_return("value")
|
987
|
+
selenium_page_object.heading3.should == "value"
|
988
|
+
end
|
989
|
+
|
990
|
+
it "should retrieve the element from the page" do
|
991
|
+
selenium_browser.should_receive(:find_element).and_return(selenium_browser)
|
992
|
+
element = selenium_page_object.heading3_element
|
993
|
+
element.should be_instance_of PageObject::Elements::Heading
|
994
|
+
end
|
995
|
+
end
|
996
|
+
end
|
997
|
+
end
|
863
998
|
end
|