page-object 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +16 -0
- data/features/headings.feature +42 -6
- data/features/html/nested_elements.html +11 -5
- data/features/html/static_elements.html +1 -1
- data/features/nested_elements.feature +19 -3
- data/features/paragraph.feature +33 -0
- data/features/step_definitions/nested_elements_steps.rb +12 -16
- data/features/step_definitions/paragraph_steps.rb +16 -0
- data/features/support/page.rb +32 -0
- data/lib/page-object/accessors.rb +116 -0
- data/lib/page-object/element_locators.rb +60 -0
- data/lib/page-object/elements/button.rb +3 -1
- data/lib/page-object/elements/check_box.rb +4 -2
- data/lib/page-object/elements/element.rb +23 -3
- data/lib/page-object/elements/form.rb +4 -2
- data/lib/page-object/elements/image.rb +4 -2
- data/lib/page-object/elements/link.rb +3 -1
- data/lib/page-object/elements/ordered_list.rb +4 -2
- data/lib/page-object/elements/paragraph.rb +7 -0
- data/lib/page-object/elements/radio_button.rb +4 -2
- data/lib/page-object/elements/select_list.rb +4 -2
- data/lib/page-object/elements/table.rb +4 -2
- data/lib/page-object/elements/table_row.rb +4 -2
- data/lib/page-object/elements/text_area.rb +4 -2
- data/lib/page-object/elements/text_field.rb +4 -2
- data/lib/page-object/elements/unordered_list.rb +4 -2
- data/lib/page-object/elements.rb +1 -0
- data/lib/page-object/nested_elements.rb +16 -0
- data/lib/page-object/platforms/selenium_webdriver/page_object.rb +120 -0
- data/lib/page-object/platforms/watir_webdriver/page_object.rb +100 -0
- data/lib/page-object/version.rb +1 -1
- data/lib/page-object.rb +22 -0
- data/page-object.gemspec +3 -2
- data/spec/page-object/accessors_spec.rb +212 -31
- data/spec/page-object/element_locators_spec.rb +24 -0
- data/spec/page-object/elements/element_spec.rb +9 -250
- data/spec/page-object/elements/nested_element_spec.rb +125 -86
- data/spec/page-object/elements/selenium_element_spec.rb +128 -0
- data/spec/page-object/elements/watir_element_spec.rb +116 -0
- data/spec/page-object/page-object_spec.rb +32 -0
- metadata +30 -10
@@ -24,6 +24,10 @@ class AccessorsTestPageObject
|
|
24
24
|
h1(:heading1, :id => 'main_heading')
|
25
25
|
h2(:heading2, :id => 'main_heading')
|
26
26
|
h3(:heading3, :id => 'main_heading')
|
27
|
+
h4(:heading4, :id => 'main_heading')
|
28
|
+
h5(:heading5, :id => 'main_heading')
|
29
|
+
h6(:heading6, :id => 'main_heading')
|
30
|
+
paragraph(:first_para, :id => 'first')
|
27
31
|
end
|
28
32
|
|
29
33
|
class BlockPageObject
|
@@ -91,6 +95,18 @@ class BlockPageObject
|
|
91
95
|
h3 :heading3 do |element|
|
92
96
|
"h3"
|
93
97
|
end
|
98
|
+
h4 :heading4 do |element|
|
99
|
+
"h4"
|
100
|
+
end
|
101
|
+
h5 :heading5 do |element|
|
102
|
+
"h5"
|
103
|
+
end
|
104
|
+
h6 :heading6 do |element|
|
105
|
+
"h6"
|
106
|
+
end
|
107
|
+
paragraph :first_para do |element|
|
108
|
+
"p"
|
109
|
+
end
|
94
110
|
end
|
95
111
|
|
96
112
|
describe PageObject::Accessors do
|
@@ -953,45 +969,210 @@ describe PageObject::Accessors do
|
|
953
969
|
element.should be_instance_of PageObject::Elements::Heading
|
954
970
|
end
|
955
971
|
end
|
972
|
+
end
|
973
|
+
|
974
|
+
describe "h3 accessors" do
|
975
|
+
context "when called on a page object" do
|
976
|
+
it "should generate accessor methods" do
|
977
|
+
watir_page_object.should respond_to(:heading3)
|
978
|
+
watir_page_object.should respond_to(:heading3_element)
|
979
|
+
end
|
980
|
+
|
981
|
+
it "should call a block on the element method when present" do
|
982
|
+
block_page_object.heading3_element.should == "h3"
|
983
|
+
end
|
984
|
+
end
|
985
|
+
|
986
|
+
context "watir implementation" do
|
987
|
+
it "should retrieve the text from the h3" do
|
988
|
+
watir_browser.should_receive(:h3).and_return(watir_browser)
|
989
|
+
watir_browser.should_receive(:text).and_return("value")
|
990
|
+
watir_page_object.heading3.should == "value"
|
991
|
+
end
|
992
|
+
|
993
|
+
it "should retrieve the element from the page" do
|
994
|
+
watir_browser.should_receive(:h3).and_return(watir_browser)
|
995
|
+
element = watir_page_object.heading3_element
|
996
|
+
element.should be_instance_of PageObject::Elements::Heading
|
997
|
+
end
|
998
|
+
end
|
999
|
+
|
1000
|
+
context "selenium implementation" do
|
1001
|
+
it "should retrieve the text from the h3" do
|
1002
|
+
selenium_browser.should_receive(:find_element).and_return(selenium_browser)
|
1003
|
+
selenium_browser.should_receive(:text).and_return("value")
|
1004
|
+
selenium_page_object.heading3.should == "value"
|
1005
|
+
end
|
1006
|
+
|
1007
|
+
it "should retrieve the element from the page" do
|
1008
|
+
selenium_browser.should_receive(:find_element).and_return(selenium_browser)
|
1009
|
+
element = selenium_page_object.heading3_element
|
1010
|
+
element.should be_instance_of PageObject::Elements::Heading
|
1011
|
+
end
|
1012
|
+
end
|
1013
|
+
end
|
1014
|
+
|
1015
|
+
describe "h4 accessors" do
|
1016
|
+
context "when called on a page object" do
|
1017
|
+
it "should generate accessor methods" do
|
1018
|
+
watir_page_object.should respond_to(:heading4)
|
1019
|
+
watir_page_object.should respond_to(:heading4_element)
|
1020
|
+
end
|
1021
|
+
|
1022
|
+
it "should call a block on the element method when present" do
|
1023
|
+
block_page_object.heading4_element.should == "h4"
|
1024
|
+
end
|
1025
|
+
end
|
1026
|
+
|
1027
|
+
context "watir implementation" do
|
1028
|
+
it "should retrieve the text from the h4" do
|
1029
|
+
watir_browser.should_receive(:h4).and_return(watir_browser)
|
1030
|
+
watir_browser.should_receive(:text).and_return("value")
|
1031
|
+
watir_page_object.heading4.should == "value"
|
1032
|
+
end
|
1033
|
+
|
1034
|
+
it "should retrieve the element from the page" do
|
1035
|
+
watir_browser.should_receive(:h4).and_return(watir_browser)
|
1036
|
+
element = watir_page_object.heading4_element
|
1037
|
+
element.should be_instance_of PageObject::Elements::Heading
|
1038
|
+
end
|
1039
|
+
end
|
1040
|
+
|
1041
|
+
context "selenium implementation" do
|
1042
|
+
it "should retrieve the text from the h4" do
|
1043
|
+
selenium_browser.should_receive(:find_element).and_return(selenium_browser)
|
1044
|
+
selenium_browser.should_receive(:text).and_return("value")
|
1045
|
+
selenium_page_object.heading4.should == "value"
|
1046
|
+
end
|
1047
|
+
|
1048
|
+
it "should retrieve the element from the page" do
|
1049
|
+
selenium_browser.should_receive(:find_element).and_return(selenium_browser)
|
1050
|
+
element = selenium_page_object.heading4_element
|
1051
|
+
element.should be_instance_of PageObject::Elements::Heading
|
1052
|
+
end
|
1053
|
+
end
|
1054
|
+
end
|
1055
|
+
|
1056
|
+
describe "h5 accessors" do
|
1057
|
+
context "when called on a page object" do
|
1058
|
+
it "should generate accessor methods" do
|
1059
|
+
watir_page_object.should respond_to(:heading5)
|
1060
|
+
watir_page_object.should respond_to(:heading5_element)
|
1061
|
+
end
|
1062
|
+
|
1063
|
+
it "should call a block on the element method when present" do
|
1064
|
+
block_page_object.heading5_element.should == "h5"
|
1065
|
+
end
|
1066
|
+
end
|
1067
|
+
|
1068
|
+
context "watir implementation" do
|
1069
|
+
it "should retrieve the text from the h5" do
|
1070
|
+
watir_browser.should_receive(:h5).and_return(watir_browser)
|
1071
|
+
watir_browser.should_receive(:text).and_return("value")
|
1072
|
+
watir_page_object.heading5.should == "value"
|
1073
|
+
end
|
1074
|
+
|
1075
|
+
it "should retrieve the element from the page" do
|
1076
|
+
watir_browser.should_receive(:h5).and_return(watir_browser)
|
1077
|
+
element = watir_page_object.heading5_element
|
1078
|
+
element.should be_instance_of PageObject::Elements::Heading
|
1079
|
+
end
|
1080
|
+
end
|
956
1081
|
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
1082
|
+
context "selenium implementation" do
|
1083
|
+
it "should retrieve the text from the h5" do
|
1084
|
+
selenium_browser.should_receive(:find_element).and_return(selenium_browser)
|
1085
|
+
selenium_browser.should_receive(:text).and_return("value")
|
1086
|
+
selenium_page_object.heading5.should == "value"
|
1087
|
+
end
|
963
1088
|
|
964
|
-
|
965
|
-
|
966
|
-
|
1089
|
+
it "should retrieve the element from the page" do
|
1090
|
+
selenium_browser.should_receive(:find_element).and_return(selenium_browser)
|
1091
|
+
element = selenium_page_object.heading5_element
|
1092
|
+
element.should be_instance_of PageObject::Elements::Heading
|
967
1093
|
end
|
1094
|
+
end
|
1095
|
+
end
|
968
1096
|
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
1097
|
+
describe "h6 accessors" do
|
1098
|
+
context "when called on a page object" do
|
1099
|
+
it "should generate accessor methods" do
|
1100
|
+
watir_page_object.should respond_to(:heading6)
|
1101
|
+
watir_page_object.should respond_to(:heading6_element)
|
1102
|
+
end
|
975
1103
|
|
976
|
-
|
977
|
-
|
978
|
-
element = watir_page_object.heading3_element
|
979
|
-
element.should be_instance_of PageObject::Elements::Heading
|
980
|
-
end
|
1104
|
+
it "should call a block on the element method when present" do
|
1105
|
+
block_page_object.heading6_element.should == "h6"
|
981
1106
|
end
|
1107
|
+
end
|
982
1108
|
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
1109
|
+
context "watir implementation" do
|
1110
|
+
it "should retrieve the text from the h6" do
|
1111
|
+
watir_browser.should_receive(:h6).and_return(watir_browser)
|
1112
|
+
watir_browser.should_receive(:text).and_return("value")
|
1113
|
+
watir_page_object.heading6.should == "value"
|
1114
|
+
end
|
1115
|
+
|
1116
|
+
it "should retrieve the element from the page" do
|
1117
|
+
watir_browser.should_receive(:h6).and_return(watir_browser)
|
1118
|
+
element = watir_page_object.heading6_element
|
1119
|
+
element.should be_instance_of PageObject::Elements::Heading
|
1120
|
+
end
|
1121
|
+
end
|
989
1122
|
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
1123
|
+
context "selenium implementation" do
|
1124
|
+
it "should retrieve the text from the h6" do
|
1125
|
+
selenium_browser.should_receive(:find_element).and_return(selenium_browser)
|
1126
|
+
selenium_browser.should_receive(:text).and_return("value")
|
1127
|
+
selenium_page_object.heading6.should == "value"
|
1128
|
+
end
|
1129
|
+
|
1130
|
+
it "should retrieve the element from the page" do
|
1131
|
+
selenium_browser.should_receive(:find_element).and_return(selenium_browser)
|
1132
|
+
element = selenium_page_object.heading6_element
|
1133
|
+
element.should be_instance_of PageObject::Elements::Heading
|
1134
|
+
end
|
1135
|
+
end
|
1136
|
+
end
|
1137
|
+
|
1138
|
+
|
1139
|
+
describe "p accessors" do
|
1140
|
+
context "when called on a page object" do
|
1141
|
+
it "should generate accessor methods" do
|
1142
|
+
watir_page_object.should respond_to(:first_para)
|
1143
|
+
watir_page_object.should respond_to(:first_para_element)
|
1144
|
+
end
|
1145
|
+
|
1146
|
+
it "should call a block on the element method when present" do
|
1147
|
+
block_page_object.first_para_element.should == "p"
|
1148
|
+
end
|
1149
|
+
end
|
1150
|
+
|
1151
|
+
context "watir implementation" do
|
1152
|
+
it "should retrieve the text from the p" do
|
1153
|
+
watir_browser.should_receive(:p).and_return(watir_browser)
|
1154
|
+
watir_browser.should_receive(:text).and_return("value")
|
1155
|
+
watir_page_object.first_para.should == "value"
|
1156
|
+
end
|
1157
|
+
|
1158
|
+
it "should retrieve the element from the page" do
|
1159
|
+
watir_browser.should_receive(:p).and_return(watir_browser)
|
1160
|
+
element = watir_page_object.first_para_element
|
1161
|
+
element.should be_instance_of PageObject::Elements::Paragraph
|
1162
|
+
end
|
1163
|
+
end
|
1164
|
+
|
1165
|
+
context "selenium implementation" do
|
1166
|
+
it "should retrieve the text from the p" do
|
1167
|
+
selenium_browser.should_receive(:find_element).and_return(selenium_browser)
|
1168
|
+
selenium_browser.should_receive(:text).and_return("value")
|
1169
|
+
selenium_page_object.first_para.should == "value"
|
1170
|
+
end
|
1171
|
+
|
1172
|
+
it "should retrieve the element from the page" do
|
1173
|
+
selenium_browser.should_receive(:find_element).and_return(selenium_browser)
|
1174
|
+
element = selenium_page_object.first_para_element
|
1175
|
+
element.should be_instance_of PageObject::Elements::Paragraph
|
995
1176
|
end
|
996
1177
|
end
|
997
1178
|
end
|
@@ -128,4 +128,28 @@ describe PageObject::ElementLocators do
|
|
128
128
|
element = watir_page_object.h3_element(:id => 'blah')
|
129
129
|
element.should be_instance_of PageObject::Elements::Heading
|
130
130
|
end
|
131
|
+
|
132
|
+
it "should find a h4 element" do
|
133
|
+
watir_browser.should_receive(:h4).with(:id => 'blah').and_return(watir_browser)
|
134
|
+
element = watir_page_object.h4_element(:id => 'blah')
|
135
|
+
element.should be_instance_of PageObject::Elements::Heading
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should find a h5 element" do
|
139
|
+
watir_browser.should_receive(:h5).with(:id => 'blah').and_return(watir_browser)
|
140
|
+
element = watir_page_object.h5_element(:id => 'blah')
|
141
|
+
element.should be_instance_of PageObject::Elements::Heading
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should find a h6 element" do
|
145
|
+
watir_browser.should_receive(:h6).with(:id => 'blah').and_return(watir_browser)
|
146
|
+
element = watir_page_object.h6_element(:id => 'blah')
|
147
|
+
element.should be_instance_of PageObject::Elements::Heading
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should find a paragraph element" do
|
151
|
+
watir_browser.should_receive(:p).with(:id => 'blah').and_return(watir_browser)
|
152
|
+
element = watir_page_object.paragraph_element(:id => 'blah')
|
153
|
+
element.should be_instance_of PageObject::Elements::Paragraph
|
154
|
+
end
|
131
155
|
end
|
@@ -2,8 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require 'page-object/elements'
|
3
3
|
|
4
4
|
|
5
|
-
describe
|
6
|
-
let(:element) { PageObject::Elements::Element }
|
5
|
+
describe "Element class methods" do
|
7
6
|
|
8
7
|
context "when handling unknown requests" do
|
9
8
|
it "should delegate to the driver element" do
|
@@ -18,7 +17,7 @@ describe PageObject::Elements::Element do
|
|
18
17
|
it "should build xpath when finding elements by name where not supported" do
|
19
18
|
['table', 'span', 'div', 'td', 'li', 'ol', 'ul'].each do |tag|
|
20
19
|
how = {:tag_name => tag, :name => 'blah'}
|
21
|
-
result =
|
20
|
+
result = PageObject::Elements::Element.watir_identifier_for how
|
22
21
|
result[:xpath].should == ".//#{tag}[@name='blah']"
|
23
22
|
end
|
24
23
|
end
|
@@ -36,7 +35,7 @@ describe PageObject::Elements::Element do
|
|
36
35
|
it "should build xpath when index is provided for basic elements" do
|
37
36
|
all_basic_elements.each do |tag|
|
38
37
|
identifier = {:tag_name => tag, :index => 1}
|
39
|
-
how, what =
|
38
|
+
how, what = PageObject::Elements::Element.selenium_identifier_for identifier
|
40
39
|
how.should == :xpath
|
41
40
|
what.should == ".//#{tag}[2]"
|
42
41
|
end
|
@@ -45,7 +44,7 @@ describe PageObject::Elements::Element do
|
|
45
44
|
it "should should build xpath when index is provided for input elements" do
|
46
45
|
all_input_elements.each do |tag|
|
47
46
|
identifier = {:tag_name => 'input', :type => tag, :index => 1}
|
48
|
-
how, what =
|
47
|
+
how, what = PageObject::Elements::Element.selenium_identifier_for identifier
|
49
48
|
how.should == :xpath
|
50
49
|
what.should == ".//input[@type='#{tag}'][2]"
|
51
50
|
end
|
@@ -54,7 +53,7 @@ describe PageObject::Elements::Element do
|
|
54
53
|
it "should build xpath when locating basic elements by name and index" do
|
55
54
|
all_basic_elements.each do |tag|
|
56
55
|
identifier = {:tag_name => tag, :name => 'blah', :index => 0}
|
57
|
-
how, what =
|
56
|
+
how, what = PageObject::Elements::Element.selenium_identifier_for identifier
|
58
57
|
how.should == :xpath
|
59
58
|
what.should == ".//#{tag}[@name='blah'][1]"
|
60
59
|
end
|
@@ -63,7 +62,7 @@ describe PageObject::Elements::Element do
|
|
63
62
|
it "should build xpath when locating input elements by name and index" do
|
64
63
|
all_input_elements.each do |type|
|
65
64
|
identifier = {:tag_name => 'input', :type => "#{type}", :name => 'blah', :index => 0}
|
66
|
-
how, what =
|
65
|
+
how, what = PageObject::Elements::Element.selenium_identifier_for identifier
|
67
66
|
how.should == :xpath
|
68
67
|
what.should == ".//input[@type='#{type}' and @name='blah'][1]"
|
69
68
|
end
|
@@ -72,7 +71,7 @@ describe PageObject::Elements::Element do
|
|
72
71
|
it "should build xpath when locating basic elements by name and class" do
|
73
72
|
all_basic_elements.each do |tag|
|
74
73
|
identifier = {:tag_name => tag, :name => 'foo', :class => 'bar'}
|
75
|
-
how, what =
|
74
|
+
how, what = PageObject::Elements::Element.selenium_identifier_for identifier
|
76
75
|
how.should == :xpath
|
77
76
|
what.should == ".//#{tag}[@name='foo' and @class='bar']"
|
78
77
|
end
|
@@ -81,249 +80,9 @@ describe PageObject::Elements::Element do
|
|
81
80
|
it "should build xpath when locating input elements by name and class" do
|
82
81
|
all_input_elements.each do |type|
|
83
82
|
identifier = {:tag_name => 'input', :type => "#{type}", :name => 'foo', :class => 'bar'}
|
84
|
-
how, what =
|
83
|
+
how, what = PageObject::Elements::Element.selenium_identifier_for identifier
|
85
84
|
what.should == ".//input[@type='#{type}' and @name='foo' and @class='bar']"
|
86
85
|
end
|
87
86
|
end
|
88
|
-
end
|
89
|
-
|
90
|
-
context "when using Watir" do
|
91
|
-
let(:watir_driver) { double('watir_element_driver') }
|
92
|
-
let(:watir_element) { PageObject::Elements::Element.new(watir_driver, :platform => :watir_webdriver) }
|
93
|
-
|
94
|
-
it "should know when it is visible" do
|
95
|
-
watir_driver.should_receive(:present?).and_return(true)
|
96
|
-
watir_element.visible?.should == true
|
97
|
-
end
|
98
|
-
|
99
|
-
it "should know when it is not visible" do
|
100
|
-
watir_driver.should_receive(:present?).and_return(false)
|
101
|
-
watir_element.visible?.should == false
|
102
|
-
end
|
103
|
-
|
104
|
-
it "should know when it exists" do
|
105
|
-
watir_driver.should_receive(:exists?).and_return(true)
|
106
|
-
watir_element.exists?.should == true
|
107
|
-
end
|
108
|
-
|
109
|
-
it "should know when it does not exist" do
|
110
|
-
watir_driver.should_receive(:exists?).and_return(false)
|
111
|
-
watir_element.exists?.should == false
|
112
|
-
end
|
113
|
-
|
114
|
-
it "should be able to return the text contained in the element" do
|
115
|
-
watir_driver.should_receive(:text).and_return("my text")
|
116
|
-
watir_element.text.should == "my text"
|
117
|
-
end
|
118
|
-
|
119
|
-
it "should know when it is equal to another" do
|
120
|
-
watir_driver.should_receive(:==).and_return(true)
|
121
|
-
watir_element.should == watir_element
|
122
|
-
end
|
123
|
-
|
124
|
-
it "should return its tag name" do
|
125
|
-
watir_driver.should_receive(:tag_name).and_return("h1")
|
126
|
-
watir_element.tag_name.should == "h1"
|
127
|
-
end
|
128
|
-
|
129
|
-
it "should know its value" do
|
130
|
-
watir_driver.should_receive(:value).and_return("value")
|
131
|
-
watir_element.value.should == "value"
|
132
|
-
end
|
133
|
-
|
134
|
-
it "should know how to retrieve the value of an attribute" do
|
135
|
-
watir_driver.should_receive(:attribute_value).and_return(true)
|
136
|
-
watir_element.attribute("readonly").should be_true
|
137
|
-
end
|
138
|
-
|
139
|
-
it "should be clickable" do
|
140
|
-
watir_driver.should_receive(:click)
|
141
|
-
watir_element.click
|
142
|
-
end
|
143
|
-
|
144
|
-
it "should be double clickable" do
|
145
|
-
watir_driver.should_receive(:double_click)
|
146
|
-
watir_element.double_click
|
147
|
-
end
|
148
|
-
|
149
|
-
it "should be right clickable" do
|
150
|
-
watir_driver.should_receive(:right_click)
|
151
|
-
watir_element.right_click
|
152
|
-
end
|
153
|
-
|
154
|
-
it "should be able to block until it is present" do
|
155
|
-
watir_driver.should_receive(:wait_until_present).with(10)
|
156
|
-
watir_element.when_present(10)
|
157
|
-
end
|
158
|
-
|
159
|
-
it "should return the element when it is present" do
|
160
|
-
watir_driver.should_receive(:wait_until_present).with(10)
|
161
|
-
element = watir_element.when_present(10)
|
162
|
-
element.should === watir_element
|
163
|
-
end
|
164
|
-
|
165
|
-
it "should be able to block until it is visible" do
|
166
|
-
Watir::Wait.should_receive(:until).with(10, "Element was not visible in 10 seconds")
|
167
|
-
watir_element.when_visible(10)
|
168
|
-
end
|
169
|
-
|
170
|
-
it "should return the element when it is visible" do
|
171
|
-
Watir::Wait.should_receive(:until).with(10, "Element was not visible in 10 seconds")
|
172
|
-
element = watir_element.when_visible(10)
|
173
|
-
element.should === watir_element
|
174
|
-
end
|
175
|
-
|
176
|
-
it "should be able to block until it is not visible" do
|
177
|
-
Watir::Wait.should_receive(:while).with(10, "Element still visible after 10 seconds")
|
178
|
-
watir_element.when_not_visible(10)
|
179
|
-
end
|
180
|
-
|
181
|
-
it "should return the element when it is not visible" do
|
182
|
-
Watir::Wait.should_receive(:while).with(10, "Element still visible after 10 seconds")
|
183
|
-
element = watir_element.when_not_visible(10)
|
184
|
-
element.should === watir_element
|
185
|
-
end
|
186
|
-
|
187
|
-
it "should be able to block until a user define event fires true" do
|
188
|
-
Watir::Wait.should_receive(:until).with(10, "Element blah")
|
189
|
-
watir_element.wait_until(10, "Element blah") {}
|
190
|
-
end
|
191
|
-
|
192
|
-
it "should send keys to the element" do
|
193
|
-
watir_driver.should_receive(:send_keys).with([:control, 'a'])
|
194
|
-
watir_element.send_keys([:control, 'a'])
|
195
|
-
end
|
196
|
-
|
197
|
-
it "should clear its' contents" do
|
198
|
-
watir_driver.should_receive(:clear)
|
199
|
-
watir_element.clear
|
200
|
-
end
|
201
|
-
|
202
|
-
end
|
203
|
-
|
204
|
-
context "when using Selenium" do
|
205
|
-
let(:selenium_driver) { double('selenium') }
|
206
|
-
let(:selenium_element) { PageObject::Elements::Element.new(selenium_driver, :platform => :selenium_webdriver) }
|
207
|
-
|
208
|
-
it "should know when it is visible" do
|
209
|
-
selenium_driver.should_receive(:displayed?).and_return(true)
|
210
|
-
selenium_element.visible?.should == true
|
211
|
-
end
|
212
|
-
|
213
|
-
it "should know when it is not visible" do
|
214
|
-
selenium_driver.should_receive(:displayed?).and_return(false)
|
215
|
-
selenium_element.visible?.should == false
|
216
|
-
end
|
217
|
-
|
218
|
-
it "should know when it exists" do
|
219
|
-
selenium_element.exists?.should == true
|
220
|
-
end
|
221
|
-
|
222
|
-
it "should know when it does not exist" do
|
223
|
-
selenium_element = PageObject::Elements::Element.new(nil, :platform => :selenium_webdriver)
|
224
|
-
selenium_element.exists?.should == false
|
225
|
-
end
|
226
|
-
|
227
|
-
it "should be able to return the text contained in the element" do
|
228
|
-
selenium_driver.should_receive(:text).and_return("my text")
|
229
|
-
selenium_element.text.should == "my text"
|
230
|
-
end
|
231
|
-
|
232
|
-
it "should know when it is equal to another" do
|
233
|
-
selenium_driver.should_receive(:==).and_return(true)
|
234
|
-
selenium_element.should == selenium_element
|
235
|
-
end
|
236
|
-
|
237
|
-
it "should return its tag name" do
|
238
|
-
selenium_driver.should_receive(:tag_name).and_return("h1")
|
239
|
-
selenium_element.tag_name.should == "h1"
|
240
|
-
end
|
241
|
-
|
242
|
-
it "should know its value" do
|
243
|
-
selenium_driver.should_receive(:attribute).with('value').and_return("value")
|
244
|
-
selenium_element.value.should == "value"
|
245
|
-
end
|
246
|
-
|
247
|
-
it "should know how to retrieve the value of an attribute" do
|
248
|
-
selenium_driver.should_receive(:attribute).and_return(true)
|
249
|
-
selenium_element.attribute('readonly').should be_true
|
250
|
-
end
|
251
|
-
|
252
|
-
it "should be clickable" do
|
253
|
-
selenium_driver.should_receive(:click)
|
254
|
-
selenium_element.click
|
255
|
-
end
|
256
|
-
|
257
|
-
it "should be double clickable" do
|
258
|
-
selenium_driver.should_receive(:double_click)
|
259
|
-
selenium_element.double_click
|
260
|
-
end
|
261
|
-
|
262
|
-
it "should be right clickable" do
|
263
|
-
selenium_driver.should_receive(:context_click)
|
264
|
-
selenium_element.right_click
|
265
|
-
end
|
266
|
-
|
267
|
-
it "should be able to block until it is present" do
|
268
|
-
wait = double('wait')
|
269
|
-
Object::Selenium::WebDriver::Wait.should_receive(:new).and_return(wait)
|
270
|
-
wait.should_receive(:until)
|
271
|
-
selenium_element.when_present(10)
|
272
|
-
end
|
273
|
-
|
274
|
-
it "should return the element when it is present" do
|
275
|
-
wait = double('wait')
|
276
|
-
Object::Selenium::WebDriver::Wait.should_receive(:new).and_return(wait)
|
277
|
-
wait.should_receive(:until)
|
278
|
-
element = selenium_element.when_present(10)
|
279
|
-
element.should === selenium_element
|
280
|
-
end
|
281
|
-
|
282
|
-
it "should be able to block until it is visible" do
|
283
|
-
wait = double('wait')
|
284
|
-
Object::Selenium::WebDriver::Wait.should_receive(:new).and_return(wait)
|
285
|
-
wait.should_receive(:until)
|
286
|
-
selenium_element.when_visible(10)
|
287
|
-
end
|
288
|
-
|
289
|
-
it "should return the element when it is visible" do
|
290
|
-
wait = double('wait')
|
291
|
-
Object::Selenium::WebDriver::Wait.should_receive(:new).and_return(wait)
|
292
|
-
wait.should_receive(:until)
|
293
|
-
element = selenium_element.when_visible(10)
|
294
|
-
element.should === selenium_element
|
295
|
-
end
|
296
|
-
|
297
|
-
it "should be able to block until it is not visible" do
|
298
|
-
wait = double('wait')
|
299
|
-
Object::Selenium::WebDriver::Wait.should_receive(:new).and_return(wait)
|
300
|
-
wait.should_receive(:until)
|
301
|
-
selenium_element.when_not_visible(10)
|
302
|
-
end
|
303
|
-
|
304
|
-
it "should return the element when it is not visible" do
|
305
|
-
wait = double('wait')
|
306
|
-
Object::Selenium::WebDriver::Wait.should_receive(:new).and_return(wait)
|
307
|
-
wait.should_receive(:until)
|
308
|
-
element = selenium_element.when_not_visible(10)
|
309
|
-
element.should === selenium_element
|
310
|
-
end
|
311
|
-
|
312
|
-
it "should be able to block until a user define event fires true" do
|
313
|
-
wait = double('wait')
|
314
|
-
Object::Selenium::WebDriver::Wait.should_receive(:new).and_return(wait)
|
315
|
-
wait.should_receive(:until)
|
316
|
-
selenium_element.wait_until(10, "Element blah") {}
|
317
|
-
end
|
318
|
-
|
319
|
-
it "should send keys to the element" do
|
320
|
-
selenium_driver.should_receive(:send_keys).with([:control, 'a'])
|
321
|
-
selenium_element.send_keys([:control, 'a'])
|
322
|
-
end
|
323
|
-
|
324
|
-
it "should clear its' contents" do
|
325
|
-
selenium_driver.should_receive(:clear)
|
326
|
-
selenium_element.clear
|
327
|
-
end
|
328
|
-
end
|
87
|
+
end
|
329
88
|
end
|