page-object 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +39 -0
- data/Gemfile +1 -0
- data/Rakefile +2 -2
- data/cucumber.yml +4 -4
- data/features/element.feature +5 -0
- data/features/{sample-app/public → html}/04-Death_Becomes_Fur.mp4 +0 -0
- data/features/{sample-app/public → html}/04-Death_Becomes_Fur.oga +0 -0
- data/features/{sample-app/public → html}/movie.mp4 +0 -0
- data/features/{sample-app/public → html}/movie.ogg +0 -0
- data/features/html/static_elements.html +7 -7
- data/features/sample-app/sample_app.rb +1 -1
- data/features/step_definitions/element_steps.rb +7 -0
- data/features/step_definitions/image_steps.rb +1 -1
- data/features/step_definitions/javascript_steps.rb +8 -2
- data/features/support/persistent_browser.rb +56 -3
- data/features/support/targets/firefox14_osx.rb +6 -0
- data/features/support/targets/firefox14_windows7.rb +6 -0
- data/features/support/url_helper.rb +3 -1
- data/lib/page-object/accessors.rb +131 -1003
- data/lib/page-object/element_locators.rb +9 -1008
- data/lib/page-object/locator_generator.rb +77 -0
- data/lib/page-object/nested_elements.rb +7 -230
- data/lib/page-object/page_factory.rb +10 -6
- data/lib/page-object/platforms/selenium_webdriver/element.rb +7 -0
- data/lib/page-object/platforms/selenium_webdriver/page_object.rb +2 -2
- data/lib/page-object/platforms/watir_webdriver/element.rb +7 -0
- data/lib/page-object/platforms/watir_webdriver/page_object.rb +2 -2
- data/lib/page-object/version.rb +1 -1
- data/spec/page-object/elements/selenium_element_spec.rb +5 -0
- data/spec/page-object/elements/watir_element_spec.rb +6 -0
- data/spec/page-object/page_factory_spec.rb +9 -0
- data/spec/page-object/platforms/watir_webdriver/watir_page_object_spec.rb +29 -0
- data/spec/page-object/platforms/watir_webdriver_spec.rb +0 -24
- data/spec/page-object/selenium_accessors_spec.rb +14 -0
- data/spec/page-object/watir_accessors_spec.rb +16 -17
- metadata +19 -12
@@ -0,0 +1,77 @@
|
|
1
|
+
module PageObject
|
2
|
+
module LocatorGenerator
|
3
|
+
|
4
|
+
def self.generate_locators(target)
|
5
|
+
[:text_field,
|
6
|
+
:hidden_field,
|
7
|
+
:text_area,
|
8
|
+
:select_list,
|
9
|
+
:link,
|
10
|
+
:checkbox,
|
11
|
+
:radio_button,
|
12
|
+
:button,
|
13
|
+
:div,
|
14
|
+
:span,
|
15
|
+
:table,
|
16
|
+
:cell,
|
17
|
+
:image,
|
18
|
+
:form,
|
19
|
+
:list_item,
|
20
|
+
:ordered_list,
|
21
|
+
:unordered_list,
|
22
|
+
:h1,
|
23
|
+
:h2,
|
24
|
+
:h3,
|
25
|
+
:h4,
|
26
|
+
:h5,
|
27
|
+
:h6,
|
28
|
+
:paragraph,
|
29
|
+
:label,
|
30
|
+
:file_field,
|
31
|
+
:area,
|
32
|
+
:canvas,
|
33
|
+
:audio,
|
34
|
+
:video,
|
35
|
+
:abbr,
|
36
|
+
:address,
|
37
|
+
:article,
|
38
|
+
:aside,
|
39
|
+
:bdi,
|
40
|
+
:bdo,
|
41
|
+
:cite,
|
42
|
+
:code,
|
43
|
+
:dd,
|
44
|
+
:dfn,
|
45
|
+
:dt,
|
46
|
+
:em,
|
47
|
+
:figcaption,
|
48
|
+
:figure,
|
49
|
+
:footer,
|
50
|
+
:header,
|
51
|
+
:hgroup,
|
52
|
+
:kbd,
|
53
|
+
:mark,
|
54
|
+
:nav,
|
55
|
+
:noscript,
|
56
|
+
:rp,
|
57
|
+
:rt,
|
58
|
+
:ruby,
|
59
|
+
:samp,
|
60
|
+
:section,
|
61
|
+
:sub,
|
62
|
+
:summary,
|
63
|
+
:sup,
|
64
|
+
:var,
|
65
|
+
:wbr].each do |tag|
|
66
|
+
target.send(:define_method, "#{tag.to_s}_element") do |*identifier|
|
67
|
+
@platform.send "#{tag.to_s}_for", locator(identifier)
|
68
|
+
end
|
69
|
+
|
70
|
+
target.send(:define_method, "#{tag.to_s}_elements") do |*identifier|
|
71
|
+
@platform.send("#{tag.to_s}s_for", identifier[0] ? identifier[0] : {})
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
@@ -1,240 +1,17 @@
|
|
1
|
+
require 'page-object/locator_generator'
|
2
|
+
|
1
3
|
module PageObject
|
2
4
|
module NestedElements
|
3
5
|
|
4
|
-
def
|
5
|
-
|
6
|
-
end
|
7
|
-
|
8
|
-
def link_elements(identifier={:index => 0})
|
9
|
-
@platform.links_for(identifier)
|
10
|
-
end
|
11
|
-
|
12
|
-
def button_element(identifier={:index => 0})
|
13
|
-
@platform.button_for(identifier)
|
14
|
-
end
|
15
|
-
|
16
|
-
def button_elements(identifier={:index => 0})
|
17
|
-
@platform.buttons_for(identifier)
|
6
|
+
def self.included(cls)
|
7
|
+
::PageObject::LocatorGenerator.generate_locators(cls)
|
18
8
|
end
|
19
9
|
|
20
|
-
|
21
|
-
@platform.text_field_for(identifier)
|
22
|
-
end
|
10
|
+
private
|
23
11
|
|
24
|
-
def
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
def hidden_field_element(identifier={:index => 0})
|
29
|
-
@platform.hidden_field_for(identifier)
|
30
|
-
end
|
31
|
-
|
32
|
-
def hidden_field_elements(identifier={:index => 0})
|
33
|
-
@platform.hidden_fields_for(identifier)
|
34
|
-
end
|
35
|
-
|
36
|
-
def text_area_element(identifier={:index => 0})
|
37
|
-
@platform.text_area_for(identifier)
|
38
|
-
end
|
39
|
-
|
40
|
-
def text_area_elements(identifier={:index => 0})
|
41
|
-
@platform.text_areas_for(identifier)
|
42
|
-
end
|
43
|
-
|
44
|
-
def select_list_element(identifier={:index => 0})
|
45
|
-
@platform.select_list_for(identifier)
|
46
|
-
end
|
47
|
-
|
48
|
-
def select_list_elements(identifier={:index => 0})
|
49
|
-
@platform.select_lists_for(identifier)
|
50
|
-
end
|
51
|
-
|
52
|
-
def checkbox_element(identifier={:index => 0})
|
53
|
-
@platform.checkbox_for(identifier)
|
54
|
-
end
|
55
|
-
|
56
|
-
def checkbox_elements(identifier={:index => 0})
|
57
|
-
@platform.checkboxes_for(identifier)
|
58
|
-
end
|
59
|
-
|
60
|
-
def radio_button_element(identifier={:index => 0})
|
61
|
-
@platform.radio_button_for(identifier)
|
62
|
-
end
|
63
|
-
|
64
|
-
def radio_button_elements(identifier={:index => 0})
|
65
|
-
@platform.radio_buttons_for(identifier)
|
66
|
-
end
|
67
|
-
|
68
|
-
def div_element(identifier={:index => 0})
|
69
|
-
@platform.div_for(identifier)
|
70
|
-
end
|
71
|
-
|
72
|
-
def div_elements(identifier={:index => 0})
|
73
|
-
@platform.divs_for(identifier)
|
74
|
-
end
|
75
|
-
|
76
|
-
def span_element(identifier={:index => 0})
|
77
|
-
@platform.span_for(identifier)
|
78
|
-
end
|
79
|
-
|
80
|
-
def span_elements(identifier={:index => 0})
|
81
|
-
@platform.spans_for(identifier)
|
82
|
-
end
|
83
|
-
|
84
|
-
def table_element(identifier={:index => 0})
|
85
|
-
@platform.table_for(identifier)
|
86
|
-
end
|
87
|
-
|
88
|
-
def table_elements(identifier={:index => 0})
|
89
|
-
@platform.tables_for(identifier)
|
90
|
-
end
|
91
|
-
|
92
|
-
def cell_element(identifier={:index => 0})
|
93
|
-
@platform.cell_for(identifier)
|
94
|
-
end
|
95
|
-
|
96
|
-
def cell_elements(identifier={:index => 0})
|
97
|
-
@platform.cells_for(identifier)
|
98
|
-
end
|
99
|
-
|
100
|
-
def image_element(identifier={:index => 0})
|
101
|
-
@platform.image_for(identifier)
|
102
|
-
end
|
103
|
-
|
104
|
-
def image_elements(identifier={:index => 0})
|
105
|
-
@platform.images_for(identifier)
|
106
|
-
end
|
107
|
-
|
108
|
-
def form_element(identifier={:index => 0})
|
109
|
-
@platform.form_for(identifier)
|
12
|
+
def locator(identifier)
|
13
|
+
identifier[0] ? identifier[0] : {:index => 0}
|
110
14
|
end
|
111
15
|
|
112
|
-
def form_elements(identifier={:index => 0})
|
113
|
-
@platform.forms_for(identifier)
|
114
|
-
end
|
115
|
-
|
116
|
-
def ordered_list_element(identifier={:index => 0})
|
117
|
-
@platform.ordered_list_for(identifier)
|
118
|
-
end
|
119
|
-
|
120
|
-
def ordered_list_elements(identifier={:index => 0})
|
121
|
-
@platform.ordered_lists_for(identifier)
|
122
|
-
end
|
123
|
-
|
124
|
-
def unordered_list_element(identifier={:index => 0})
|
125
|
-
@platform.unordered_list_for(identifier)
|
126
|
-
end
|
127
|
-
|
128
|
-
def unordered_list_elements(identifier={:index => 0})
|
129
|
-
@platform.unordered_lists_for(identifier)
|
130
|
-
end
|
131
|
-
|
132
|
-
def list_item_element(identifier={:index => 0})
|
133
|
-
@platform.list_item_for(identifier)
|
134
|
-
end
|
135
|
-
|
136
|
-
def list_item_elements(identifier={:index => 0})
|
137
|
-
@platform.list_items_for(identifier)
|
138
|
-
end
|
139
|
-
|
140
|
-
def h1_element(identifier={:index => 0})
|
141
|
-
@platform.h1_for(identifier)
|
142
|
-
end
|
143
|
-
|
144
|
-
def h1_elements(identifier={:index => 0})
|
145
|
-
@platform.h1s_for(identifier)
|
146
|
-
end
|
147
|
-
|
148
|
-
def h2_element(identifier={:index => 0})
|
149
|
-
@platform.h2_for(identifier)
|
150
|
-
end
|
151
|
-
|
152
|
-
def h2_elements(identifier={:index => 0})
|
153
|
-
@platform.h2s_for(identifier)
|
154
|
-
end
|
155
|
-
|
156
|
-
def h3_element(identifier={:index => 0})
|
157
|
-
@platform.h3_for(identifier)
|
158
|
-
end
|
159
|
-
|
160
|
-
def h3_elements(identifier={:index => 0})
|
161
|
-
@platform.h3s_for(identifier)
|
162
|
-
end
|
163
|
-
|
164
|
-
def h4_element(identifier={:index => 0})
|
165
|
-
@platform.h4_for(identifier)
|
166
|
-
end
|
167
|
-
|
168
|
-
def h4_elements(identifier={:index => 0})
|
169
|
-
@platform.h4s_for(identifier)
|
170
|
-
end
|
171
|
-
|
172
|
-
def h5_element(identifier={:index => 0})
|
173
|
-
@platform.h5_for(identifier)
|
174
|
-
end
|
175
|
-
|
176
|
-
def h5_elements(identifier={:index => 0})
|
177
|
-
@platform.h5s_for(identifier)
|
178
|
-
end
|
179
|
-
|
180
|
-
def h6_element(identifier={:index => 0})
|
181
|
-
@platform.h6_for(identifier)
|
182
|
-
end
|
183
|
-
|
184
|
-
def h6_elements(identifier={:index => 0})
|
185
|
-
@platform.h6s_for(identifier)
|
186
|
-
end
|
187
|
-
|
188
|
-
def paragraph_element(identifier={:index => 0})
|
189
|
-
@platform.paragraph_for(identifier)
|
190
|
-
end
|
191
|
-
|
192
|
-
def paragraph_elements(identifier={:index => 0})
|
193
|
-
@platform.paragraphs_for(identifier)
|
194
|
-
end
|
195
|
-
|
196
|
-
def label_element(identifier={:index => 0})
|
197
|
-
@platform.label_for(identifier)
|
198
|
-
end
|
199
|
-
|
200
|
-
def label_elements(identifier={:index => 0})
|
201
|
-
@platform.labels_for(identifier)
|
202
|
-
end
|
203
|
-
|
204
|
-
def file_field_element(identifier={:index => 0})
|
205
|
-
@platform.file_field_for(identifier)
|
206
|
-
end
|
207
|
-
|
208
|
-
def area_element(identifier={:index => 0})
|
209
|
-
@platform.area_for(identifier)
|
210
|
-
end
|
211
|
-
|
212
|
-
def area_elements(identifier={:index => 0})
|
213
|
-
@platform.areas_for(identifier)
|
214
|
-
end
|
215
|
-
|
216
|
-
def canvas_element(identifier={:index => 0})
|
217
|
-
@platform.canvas_for(identifier)
|
218
|
-
end
|
219
|
-
|
220
|
-
def canvas_elements(identifier={:index => 0})
|
221
|
-
@platform.canvases_for(identifier)
|
222
|
-
end
|
223
|
-
|
224
|
-
def audio_element(identifier={:index => 0})
|
225
|
-
@platform.audio_for(identifier)
|
226
|
-
end
|
227
|
-
|
228
|
-
def audio_elements(identifier={:index => 0})
|
229
|
-
@platform.audios_for(identifier)
|
230
|
-
end
|
231
|
-
|
232
|
-
def video_element(identifier={:index => 0})
|
233
|
-
@platform.video_for(identifier)
|
234
|
-
end
|
235
|
-
|
236
|
-
def video_elements(identifier={:index => 0})
|
237
|
-
@platform.video_for(identifier)
|
238
|
-
end
|
239
16
|
end
|
240
17
|
end
|
@@ -26,9 +26,12 @@ module PageObject
|
|
26
26
|
# @example Example routes defined in env.rb
|
27
27
|
# PageObject::PageFactory.routes = {
|
28
28
|
# :default => [[PageOne,:method1], [PageTwoA,:method2], [PageThree,:method3]],
|
29
|
-
# :another_route => [[PageOne,:method1], [PageTwoB,:method2b], [PageThree,:method3]]
|
29
|
+
# :another_route => [[PageOne,:method1, "arg1"], [PageTwoB,:method2b], [PageThree,:method3]]
|
30
30
|
# }
|
31
|
-
#
|
31
|
+
#
|
32
|
+
# Notice the first entry of :anouther_route is passing an argument
|
33
|
+
# to the method.
|
34
|
+
#
|
32
35
|
module PageFactory
|
33
36
|
|
34
37
|
#
|
@@ -147,15 +150,16 @@ module PageObject
|
|
147
150
|
end
|
148
151
|
|
149
152
|
def navigate_through_pages(pages)
|
150
|
-
pages.each do |cls, method|
|
153
|
+
pages.each do |cls, method, *args|
|
151
154
|
page = on_page(cls)
|
152
|
-
fail("Navigation method not specified on #{cls}.
|
153
|
-
page.send method
|
155
|
+
fail("Navigation method not specified on #{cls}.") unless page.respond_to? method
|
156
|
+
page.send method unless args
|
157
|
+
page.send method, *args if args
|
154
158
|
end
|
155
159
|
end
|
156
160
|
|
157
161
|
def find_index_for(path, item)
|
158
|
-
path.
|
162
|
+
path.find_index { |each| each[0] == item}
|
159
163
|
end
|
160
164
|
|
161
165
|
class << self
|
@@ -401,7 +401,7 @@ module PageObject
|
|
401
401
|
#
|
402
402
|
# platform method to retrieve all checkbox elements
|
403
403
|
#
|
404
|
-
def
|
404
|
+
def checkboxs_for(identifier)
|
405
405
|
find_selenium_elements(identifier, Elements::CheckBox, 'input', :type => 'checkbox')
|
406
406
|
end
|
407
407
|
|
@@ -940,7 +940,7 @@ module PageObject
|
|
940
940
|
#
|
941
941
|
# platform method to return an array of canvas elements
|
942
942
|
#
|
943
|
-
def
|
943
|
+
def canvass_for(identifier)
|
944
944
|
find_selenium_elements(identifier, Elements::Canvas, 'canvas')
|
945
945
|
end
|
946
946
|
|
@@ -366,7 +366,7 @@ module PageObject
|
|
366
366
|
#
|
367
367
|
# platform method to retrieve an array of checkbox elements
|
368
368
|
#
|
369
|
-
def
|
369
|
+
def checkboxs_for(identifier)
|
370
370
|
find_watir_elements("checkboxes(identifier)", Elements::CheckBox, identifier)
|
371
371
|
end
|
372
372
|
|
@@ -867,7 +867,7 @@ module PageObject
|
|
867
867
|
#
|
868
868
|
# platform method to retrieve an array of canvas elements
|
869
869
|
#
|
870
|
-
def
|
870
|
+
def canvass_for(identifier)
|
871
871
|
find_watir_elements("canvases(identifier)", Elements::Canvas, identifier, 'canvas')
|
872
872
|
end
|
873
873
|
|
data/lib/page-object/version.rb
CHANGED
@@ -164,4 +164,9 @@ describe "Element for Selenium" do
|
|
164
164
|
@selenium_driver.should_receive(:executeScript)
|
165
165
|
@selenium_element.focus
|
166
166
|
end
|
167
|
+
|
168
|
+
it "should scroll into view" do
|
169
|
+
@selenium_driver.should_receive(:location_once_scrolled_into_view)
|
170
|
+
@selenium_element.scroll_into_view
|
171
|
+
end
|
167
172
|
end
|
@@ -133,4 +133,10 @@ describe "Element for Watir" do
|
|
133
133
|
watir_driver.should_receive(:clear)
|
134
134
|
watir_element.clear
|
135
135
|
end
|
136
|
+
|
137
|
+
it "should scroll into view" do
|
138
|
+
watir_driver.stub(:wd).and_return(watir_driver)
|
139
|
+
watir_driver.should_receive(:location_once_scrolled_into_view)
|
140
|
+
watir_element.scroll_into_view
|
141
|
+
end
|
136
142
|
end
|