page-object 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +10 -0
- data/features/html/static_elements.html +1 -2
- data/features/step_definitions/accessor_steps.rb +16 -16
- data/features/step_definitions/element_steps.rb +15 -16
- data/features/support/page.rb +1 -0
- data/features/table_cell.feature +1 -0
- data/lib/page-object.rb +15 -3
- data/lib/page-object/accessors.rb +87 -52
- data/lib/page-object/elements/element.rb +11 -0
- data/lib/page-object/elements/table_cell.rb +10 -0
- data/lib/page-object/platforms/selenium/page_object.rb +44 -108
- data/lib/page-object/platforms/watir/page_object.rb +43 -83
- data/lib/page-object/version.rb +1 -1
- data/page-object.gemspec +1 -1
- data/spec/page-object/accessors_spec.rb +91 -68
- data/spec/page-object/elements/element_spec.rb +7 -0
- data/spec/page-object/page-object_spec.rb +26 -0
- metadata +3 -3
data/ChangeLog
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
=== Version 0.2.3 / 2011-08-01
|
2
|
+
* Enhancements
|
3
|
+
* Can now find a TableCell by its' text
|
4
|
+
* If we receive an error calling #attach_to_window, wait one second and try again
|
5
|
+
* Will call callback method #initialize_page method if it exists on a page object
|
6
|
+
* Renamed all *_<element_type> methods to *_element. Created alias for backward compatability
|
7
|
+
* Delegating unknown method calls on Element to the driver element object
|
8
|
+
* Improved block handling when passed to element creation method
|
9
|
+
* Updated to use selenium-webdriver 2.3.2
|
10
|
+
|
1
11
|
=== Version 0.2.2 / 2011-07-31
|
2
12
|
* Enhancements
|
3
13
|
* Can find frame by name
|
@@ -181,11 +181,11 @@ When /^I retrieve a table cell element by "([^"]*)" and "([^"]*)"$/ do |param1,
|
|
181
181
|
end
|
182
182
|
|
183
183
|
When /^I retrieve a table element by "([^\"]*)"$/ do |how|
|
184
|
-
@element = @page.send "table_#{how}
|
184
|
+
@element = @page.send "table_#{how}_element"
|
185
185
|
end
|
186
186
|
|
187
187
|
When /^I retrieve a table element by "([^"]*)" and "([^"]*)"$/ do |param1, param2|
|
188
|
-
@element = @page.send "table_#{param1}_#{param2}
|
188
|
+
@element = @page.send "table_#{param1}_#{param2}_element"
|
189
189
|
end
|
190
190
|
|
191
191
|
When /^I get the image element$/ do
|
@@ -201,15 +201,15 @@ Then /^the image should be "([^\"]*)" pixels tall$/ do |height|
|
|
201
201
|
end
|
202
202
|
|
203
203
|
When /^I get the image element by "([^\"]*)"$/ do |how|
|
204
|
-
@element = @page.send "image_#{how}
|
204
|
+
@element = @page.send "image_#{how}_element"
|
205
205
|
end
|
206
206
|
|
207
207
|
When /^I get the image element by "([^"]*)" and "([^"]*)"$/ do |param1, param2|
|
208
|
-
@element = @page.send "image_#{param1}_#{param2}
|
208
|
+
@element = @page.send "image_#{param1}_#{param2}_element"
|
209
209
|
end
|
210
210
|
|
211
211
|
When /^I retrieve the hidden field element$/ do
|
212
|
-
@element = @page.
|
212
|
+
@element = @page.hidden_field_id_element
|
213
213
|
end
|
214
214
|
|
215
215
|
Then /^I should see the hidden field contains "([^\"]*)"$/ do |text|
|
@@ -217,7 +217,7 @@ Then /^I should see the hidden field contains "([^\"]*)"$/ do |text|
|
|
217
217
|
end
|
218
218
|
|
219
219
|
When /^I search for the hidden field by "([^\"]*)"$/ do |how|
|
220
|
-
@element = @page.send "hidden_field_#{how}
|
220
|
+
@element = @page.send "hidden_field_#{how}_element"
|
221
221
|
end
|
222
222
|
|
223
223
|
Then /^hidden field element should contains "([^\"]*)"$/ do |text|
|
@@ -225,7 +225,7 @@ Then /^hidden field element should contains "([^\"]*)"$/ do |text|
|
|
225
225
|
end
|
226
226
|
|
227
227
|
When /^I search for the hidden field by "([^"]*)" and "([^"]*)"$/ do |param1, param2|
|
228
|
-
@element = @page.send "hidden_field_#{param1}_#{param2}
|
228
|
+
@element = @page.send "hidden_field_#{param1}_#{param2}_element"
|
229
229
|
end
|
230
230
|
|
231
231
|
Then /^I should be able to submit the form$/ do
|
@@ -233,11 +233,11 @@ Then /^I should be able to submit the form$/ do
|
|
233
233
|
end
|
234
234
|
|
235
235
|
When /^I locate the form by "([^\"]*)"$/ do |how|
|
236
|
-
@element = @page.send "form_#{how}
|
236
|
+
@element = @page.send "form_#{how}_element"
|
237
237
|
end
|
238
238
|
|
239
239
|
When /^I locate the form using "([^"]*)" and "([^"]*)"$/ do |param1, param2|
|
240
|
-
@element = @page.send "form_#{param1}_#{param2}
|
240
|
+
@element = @page.send "form_#{param1}_#{param2}_element"
|
241
241
|
end
|
242
242
|
|
243
243
|
When /^I get the text from the list item$/ do
|
@@ -253,7 +253,7 @@ When /^I search for the list item by "([^"]*)" and "([^"]*)"$/ do |param1, param
|
|
253
253
|
end
|
254
254
|
|
255
255
|
When /^I get the first item from the unordered list$/ do
|
256
|
-
@element = @page.
|
256
|
+
@element = @page.ul_id_element[0]
|
257
257
|
end
|
258
258
|
|
259
259
|
Then /^the list items text should be "([^\"]*)"$/ do |expected_text|
|
@@ -261,11 +261,11 @@ Then /^the list items text should be "([^\"]*)"$/ do |expected_text|
|
|
261
261
|
end
|
262
262
|
|
263
263
|
When /^I search for the unordered list by "([^\"]*)"$/ do |how|
|
264
|
-
@list = @page.send "ul_#{how}
|
264
|
+
@list = @page.send "ul_#{how}_element"
|
265
265
|
end
|
266
266
|
|
267
267
|
When /^I search for the unordered list by "([^"]*)" and "([^"]*)"$/ do |param1, param2|
|
268
|
-
@list = @page.send "ul_#{param1}_#{param2}
|
268
|
+
@list = @page.send "ul_#{param1}_#{param2}_element"
|
269
269
|
end
|
270
270
|
|
271
271
|
|
@@ -274,15 +274,15 @@ When /^I get the first item from the list$/ do
|
|
274
274
|
end
|
275
275
|
|
276
276
|
When /^I get the first item from the ordered list$/ do
|
277
|
-
@element = @page.
|
277
|
+
@element = @page.ol_id_element[0]
|
278
278
|
end
|
279
279
|
|
280
280
|
When /^I search for the ordered list by "([^\"]*)"$/ do |how|
|
281
|
-
@list = @page.send "ol_#{how}
|
281
|
+
@list = @page.send "ol_#{how}_element"
|
282
282
|
end
|
283
283
|
|
284
284
|
When /^I search for the ordered list by "([^"]*)" and "([^"]*)"$/ do |param1, param2|
|
285
|
-
@list = @page.send "ol_#{param1}_#{param2}
|
285
|
+
@list = @page.send "ol_#{param1}_#{param2}_element"
|
286
286
|
end
|
287
287
|
|
288
288
|
Then /^the table should have "([^\"]*)" rows$/ do |rows|
|
@@ -315,7 +315,7 @@ Then /^each item should contain "([^\"]*)"$/ do |text|
|
|
315
315
|
end
|
316
316
|
|
317
317
|
Then /^option "([^\"]*)" should contain "([^\"]*)"$/ do |opt_num, text|
|
318
|
-
@element = @page.send "sel_list_#{@how}
|
318
|
+
@element = @page.send "sel_list_#{@how}_element".to_sym
|
319
319
|
@element[opt_num.to_i - 1].text.should == text
|
320
320
|
end
|
321
321
|
|
@@ -3,50 +3,49 @@ When /^I select a link labeled "([^"]*)" and index "([^"]*)"$/ do |label, index|
|
|
3
3
|
end
|
4
4
|
|
5
5
|
When /^I retrieve a check box element$/ do
|
6
|
-
@element = @page.
|
6
|
+
@element = @page.cb_id_element
|
7
7
|
end
|
8
8
|
|
9
9
|
When /^I retrieve a link element$/ do
|
10
|
-
@element = @page.
|
10
|
+
@element = @page.google_search_id_element
|
11
11
|
end
|
12
12
|
|
13
13
|
When /^I retrieve a radio button$/ do
|
14
|
-
@element = @page.
|
14
|
+
@element = @page.milk_id_element
|
15
15
|
end
|
16
16
|
|
17
17
|
When /^I retrieve a select list$/ do
|
18
|
-
@element = @page.
|
18
|
+
@element = @page.sel_list_id_element
|
19
19
|
end
|
20
20
|
|
21
21
|
When /^I retrieve a text field$/ do
|
22
|
-
@element = @page.
|
22
|
+
@element = @page.text_field_id_element
|
23
23
|
end
|
24
24
|
|
25
25
|
When /^I retrieve the text area$/ do
|
26
|
-
@element = @page.
|
26
|
+
@element = @page.text_area_id_element
|
27
27
|
end
|
28
28
|
|
29
29
|
When /^I retrieve the div element$/ do
|
30
|
-
@element = @page.
|
30
|
+
@element = @page.div_id_element
|
31
31
|
end
|
32
32
|
|
33
33
|
When /^I retrieve a table element$/ do
|
34
|
-
@element = @page.
|
34
|
+
@element = @page.table_id_element
|
35
35
|
end
|
36
36
|
|
37
37
|
When /^I retrieve a button element$/ do
|
38
|
-
@element = @page.
|
38
|
+
@element = @page.button_id_element
|
39
39
|
end
|
40
40
|
|
41
41
|
When /^I retrieve table cell$/ do
|
42
|
-
@element = @page.
|
42
|
+
@element = @page.cell_id_element
|
43
43
|
end
|
44
44
|
|
45
45
|
When /^I locate the form$/ do
|
46
|
-
@element = @page.
|
46
|
+
@element = @page.form_id_element
|
47
47
|
end
|
48
48
|
|
49
|
-
|
50
49
|
Then /^I should know it exists$/ do
|
51
50
|
@element.should exist
|
52
51
|
end
|
@@ -94,17 +93,17 @@ Then /^I should be able to click it$/ do
|
|
94
93
|
end
|
95
94
|
|
96
95
|
When /^I retrieve a list item element$/ do
|
97
|
-
@element = @page.
|
96
|
+
@element = @page.li_id_element
|
98
97
|
end
|
99
98
|
|
100
99
|
When /^I retrieve an unordered list element$/ do
|
101
|
-
@element = @page.
|
100
|
+
@element = @page.ul_id_element
|
102
101
|
end
|
103
102
|
|
104
103
|
When /^I retrieve an ordered list element$/ do
|
105
|
-
@element = @page.
|
104
|
+
@element = @page.ol_id_element
|
106
105
|
end
|
107
106
|
|
108
107
|
When /^I clear the text field$/ do
|
109
|
-
@page.
|
108
|
+
@page.text_field_id_element.clear
|
110
109
|
end
|
data/features/support/page.rb
CHANGED
@@ -108,6 +108,7 @@ class Page
|
|
108
108
|
cell(:cell_name, :name => 'cell_name')
|
109
109
|
cell(:cell_class, :class => 'cell_class')
|
110
110
|
cell(:cell_index, :index => 3)
|
111
|
+
cell(:cell_text, :text => 'Data4')
|
111
112
|
cell(:cell_xpath, :xpath => '//table//tr[2]//td[2]')
|
112
113
|
cell(:cell_class_index, :class => "cell_class", :index => 0)
|
113
114
|
cell(:cell_name_index, :name => "cell_name", :index => 0)
|
data/features/table_cell.feature
CHANGED
data/lib/page-object.rb
CHANGED
@@ -38,7 +38,8 @@ module PageObject
|
|
38
38
|
attr_reader :platform
|
39
39
|
|
40
40
|
#
|
41
|
-
# Construct a new page object.
|
41
|
+
# Construct a new page object. Upon initialization of the page it will call a method named
|
42
|
+
# initialize_page if it exists.
|
42
43
|
#
|
43
44
|
# @param [Watir::Browser or Selenium::WebDriver::Driver] the platform browser to use
|
44
45
|
# @param [bool] open the page if page_url is set
|
@@ -46,6 +47,7 @@ module PageObject
|
|
46
47
|
def initialize(browser, visit=false)
|
47
48
|
@browser = browser
|
48
49
|
include_platform_driver(browser)
|
50
|
+
initialize_page if respond_to?(:initialize_page)
|
49
51
|
goto if visit && respond_to?(:goto)
|
50
52
|
end
|
51
53
|
|
@@ -150,7 +152,8 @@ module PageObject
|
|
150
152
|
|
151
153
|
#
|
152
154
|
# Attach to a running window. You can locate the window using either
|
153
|
-
# the window's title or url.
|
155
|
+
# the window's title or url. If it failes to connect to a window it will
|
156
|
+
# pause for 1 second and try again.
|
154
157
|
#
|
155
158
|
# @example
|
156
159
|
# page.attach_to_window(:title => "other window's title")
|
@@ -159,7 +162,12 @@ module PageObject
|
|
159
162
|
# be the entire url - it can just be the page name like index.html
|
160
163
|
#
|
161
164
|
def attach_to_window(identifier)
|
162
|
-
|
165
|
+
begin
|
166
|
+
platform.attach_to_window(identifier)
|
167
|
+
rescue
|
168
|
+
sleep 1
|
169
|
+
platform.attach_to_window(identifier)
|
170
|
+
end
|
163
171
|
end
|
164
172
|
|
165
173
|
#
|
@@ -174,4 +182,8 @@ module PageObject
|
|
174
182
|
def include_platform_driver(browser)
|
175
183
|
@platform = load_platform(browser, PageObject::Platforms.get)
|
176
184
|
end
|
185
|
+
|
186
|
+
def call_block(&block)
|
187
|
+
block.arity == 1 ? block.call(self) : self.instance_eval(&block)
|
188
|
+
end
|
177
189
|
end
|
@@ -51,7 +51,7 @@ module PageObject
|
|
51
51
|
#
|
52
52
|
# @example
|
53
53
|
# text_field(:first_name, :id => "first_name")
|
54
|
-
# # will generate 'first_name', 'first_name=' and '
|
54
|
+
# # will generate 'first_name', 'first_name=' and 'first_name_element' methods
|
55
55
|
#
|
56
56
|
# @param [String] the name used for the generated methods
|
57
57
|
# @param [Hash] identifier how we find a text field. You can use a multiple paramaters
|
@@ -74,18 +74,20 @@ module PageObject
|
|
74
74
|
define_method("#{name}=") do |value|
|
75
75
|
platform.text_field_value_set(identifier.clone, value)
|
76
76
|
end
|
77
|
-
define_method("#{name}
|
78
|
-
|
77
|
+
define_method("#{name}_element") do
|
78
|
+
return call_block(&block) if block
|
79
|
+
platform.text_field_for(identifier.clone)
|
79
80
|
end
|
81
|
+
alias_method "#{name}_text_field".to_sym, "#{name}_element".to_sym
|
80
82
|
end
|
81
|
-
|
83
|
+
|
82
84
|
#
|
83
85
|
# adds two methods to the page object - one to get the text from a hidden field
|
84
86
|
# and another to retrieve the hidden field element.
|
85
87
|
#
|
86
88
|
# @example
|
87
89
|
# hidden_field(:user_id, :id => "user_identity")
|
88
|
-
# # will generate 'user_id' and '
|
90
|
+
# # will generate 'user_id' and 'user_id_element' methods
|
89
91
|
#
|
90
92
|
# @param [String] the name used for the generated methods
|
91
93
|
# @param [Hash] identifier how we find a hidden field. You can use a multiple paramaters
|
@@ -104,9 +106,11 @@ module PageObject
|
|
104
106
|
define_method(name) do
|
105
107
|
platform.hidden_field_value_for identifier.clone
|
106
108
|
end
|
107
|
-
define_method("#{name}
|
108
|
-
|
109
|
+
define_method("#{name}_element") do
|
110
|
+
return call_block(&block) if block
|
111
|
+
platform.hidden_field_for(identifier.clone)
|
109
112
|
end
|
113
|
+
alias_method "#{name}_hidden_field".to_sym, "#{name}_element".to_sym
|
110
114
|
end
|
111
115
|
|
112
116
|
#
|
@@ -116,7 +120,7 @@ module PageObject
|
|
116
120
|
#
|
117
121
|
# @example
|
118
122
|
# text_area(:address, :id => "address")
|
119
|
-
# # will generate 'address', 'address=' and '
|
123
|
+
# # will generate 'address', 'address=' and 'address_element methods
|
120
124
|
#
|
121
125
|
# @param [String] the name used for the generated methods
|
122
126
|
# @param [Hash] identifier how we find a text area. You can use a multiple paramaters
|
@@ -137,9 +141,11 @@ module PageObject
|
|
137
141
|
define_method("#{name}=") do |value|
|
138
142
|
platform.text_area_value_set(identifier.clone, value)
|
139
143
|
end
|
140
|
-
define_method("#{name}
|
141
|
-
|
144
|
+
define_method("#{name}_element") do
|
145
|
+
return call_block(&block) if block
|
146
|
+
platform.text_area_for(identifier.clone)
|
142
147
|
end
|
148
|
+
alias_method "#{name}_text_area".to_sym, "#{name}_element".to_sym
|
143
149
|
end
|
144
150
|
|
145
151
|
#
|
@@ -149,7 +155,7 @@ module PageObject
|
|
149
155
|
#
|
150
156
|
# @example
|
151
157
|
# select_list(:state, :id => "state")
|
152
|
-
# # will generate 'state', 'state=' and '
|
158
|
+
# # will generate 'state', 'state=' and 'state_element' methods
|
153
159
|
#
|
154
160
|
# @param [String] the name used for the generated methods
|
155
161
|
# @param [Hash] identifier how we find a select list. You can use a multiple paramaters
|
@@ -170,9 +176,11 @@ module PageObject
|
|
170
176
|
define_method("#{name}=") do |value|
|
171
177
|
platform.select_list_value_set(identifier.clone, value)
|
172
178
|
end
|
173
|
-
define_method("#{name}
|
174
|
-
|
179
|
+
define_method("#{name}_element") do
|
180
|
+
return call_block(&block) if block
|
181
|
+
platform.select_list_for(identifier.clone)
|
175
182
|
end
|
183
|
+
alias_method "#{name}_select_list".to_sym, "#{name}_element".to_sym
|
176
184
|
end
|
177
185
|
|
178
186
|
#
|
@@ -182,7 +190,7 @@ module PageObject
|
|
182
190
|
#
|
183
191
|
# @example
|
184
192
|
# link(:add_to_cart, :text => "Add to Cart")
|
185
|
-
# # will generate 'add_to_cart' and '
|
193
|
+
# # will generate 'add_to_cart' and 'add_to_cart_element' methods
|
186
194
|
#
|
187
195
|
# @param [String] the name used for the generated methods
|
188
196
|
# @param [Hash] identifier how we find a link. You can use a multiple paramaters
|
@@ -202,9 +210,11 @@ module PageObject
|
|
202
210
|
define_method(name) do
|
203
211
|
platform.click_link_for identifier.clone
|
204
212
|
end
|
205
|
-
define_method("#{name}
|
206
|
-
|
213
|
+
define_method("#{name}_element") do
|
214
|
+
return call_block(&block) if block
|
215
|
+
platform.link_for(identifier.clone)
|
207
216
|
end
|
217
|
+
alias_method "#{name}_link".to_sym, "#{name}_element".to_sym
|
208
218
|
end
|
209
219
|
|
210
220
|
#
|
@@ -214,7 +224,7 @@ module PageObject
|
|
214
224
|
#
|
215
225
|
# @example
|
216
226
|
# checkbox(:active, :name => "is_active")
|
217
|
-
# # will generate 'check_active', 'uncheck_active', 'active_checked?' and '
|
227
|
+
# # will generate 'check_active', 'uncheck_active', 'active_checked?' and 'active_element' methods
|
218
228
|
#
|
219
229
|
# @param [String] the name used for the generated methods
|
220
230
|
# @param [Hash] identifier how we find a checkbox. You can use a multiple paramaters
|
@@ -236,9 +246,11 @@ module PageObject
|
|
236
246
|
define_method("#{name}_checked?") do
|
237
247
|
platform.checkbox_checked?(identifier.clone)
|
238
248
|
end
|
239
|
-
define_method("#{name}
|
240
|
-
|
249
|
+
define_method("#{name}_element") do
|
250
|
+
return call_block(&block) if block
|
251
|
+
platform.checkbox_for(identifier.clone)
|
241
252
|
end
|
253
|
+
alias_method "#{name}_checkbox".to_sym, "#{name}_element".to_sym
|
242
254
|
end
|
243
255
|
|
244
256
|
#
|
@@ -249,7 +261,7 @@ module PageObject
|
|
249
261
|
#
|
250
262
|
# @example
|
251
263
|
# radio_button(:north, :id => "north")
|
252
|
-
# # will generate 'select_north', 'clear_north', 'north_selected?' and '
|
264
|
+
# # will generate 'select_north', 'clear_north', 'north_selected?' and 'north_element' methods
|
253
265
|
#
|
254
266
|
# @param [String] the name used for the generated methods
|
255
267
|
# @param [Hash] identifier how we find a radio button. You can use a multiple paramaters
|
@@ -271,9 +283,11 @@ module PageObject
|
|
271
283
|
define_method("#{name}_selected?") do
|
272
284
|
platform.radio_selected?(identifier.clone)
|
273
285
|
end
|
274
|
-
define_method("#{name}
|
275
|
-
|
286
|
+
define_method("#{name}_element") do
|
287
|
+
return call_block(&block) if block
|
288
|
+
platform.radio_button_for(identifier.clone)
|
276
289
|
end
|
290
|
+
alias_method "#{name}_radio_button".to_sym, "#{name}_element".to_sym
|
277
291
|
end
|
278
292
|
|
279
293
|
#
|
@@ -282,7 +296,7 @@ module PageObject
|
|
282
296
|
#
|
283
297
|
# @example
|
284
298
|
# button(:purchase, :id => 'purchase')
|
285
|
-
# # will generate 'purchase' and '
|
299
|
+
# # will generate 'purchase' and 'purchase_element' methods
|
286
300
|
#
|
287
301
|
# @param [String] the name used for the generated methods
|
288
302
|
# @param [Hash] identifier how we find a button. You can use a multiple paramaters
|
@@ -299,9 +313,11 @@ module PageObject
|
|
299
313
|
define_method(name) do
|
300
314
|
platform.click_button_for identifier.clone
|
301
315
|
end
|
302
|
-
define_method("#{name}
|
303
|
-
|
316
|
+
define_method("#{name}_element") do
|
317
|
+
return call_block(&block) if block
|
318
|
+
platform.button_for(identifier.clone)
|
304
319
|
end
|
320
|
+
alias_method "#{name}_button".to_sym, "#{name}_element".to_sym
|
305
321
|
end
|
306
322
|
|
307
323
|
#
|
@@ -310,7 +326,7 @@ module PageObject
|
|
310
326
|
#
|
311
327
|
# @example
|
312
328
|
# div(:message, :id => 'message')
|
313
|
-
# # will generate 'message' and '
|
329
|
+
# # will generate 'message' and 'message_element' methods
|
314
330
|
#
|
315
331
|
# @param [String] the name used for the generated methods
|
316
332
|
# @param [Hash] identifier how we find a div. You can use a multiple paramaters
|
@@ -327,9 +343,11 @@ module PageObject
|
|
327
343
|
define_method(name) do
|
328
344
|
platform.div_text_for identifier.clone
|
329
345
|
end
|
330
|
-
define_method("#{name}
|
331
|
-
|
346
|
+
define_method("#{name}_element") do
|
347
|
+
return call_block(&block) if block
|
348
|
+
platform.div_for(identifier.clone)
|
332
349
|
end
|
350
|
+
alias_method "#{name}_div".to_sym, "#{name}_element".to_sym
|
333
351
|
end
|
334
352
|
|
335
353
|
#
|
@@ -338,7 +356,7 @@ module PageObject
|
|
338
356
|
#
|
339
357
|
# @example
|
340
358
|
# span(:alert, :id => 'alert')
|
341
|
-
# # will generate 'alert' and '
|
359
|
+
# # will generate 'alert' and 'alert_element' methods
|
342
360
|
#
|
343
361
|
# @param [String] the name used for the generated methods
|
344
362
|
# @param [Hash] identifier how we find a span. You can use a multiple paramaters
|
@@ -354,9 +372,11 @@ module PageObject
|
|
354
372
|
define_method(name) do
|
355
373
|
platform.span_text_for identifier.clone
|
356
374
|
end
|
357
|
-
define_method("#{name}
|
358
|
-
|
375
|
+
define_method("#{name}_element") do
|
376
|
+
return call_block(&block) if block
|
377
|
+
platform.span_for(identifier.clone)
|
359
378
|
end
|
379
|
+
alias_method "#{name}_span".to_sym, "#{name}_element".to_sym
|
360
380
|
end
|
361
381
|
|
362
382
|
#
|
@@ -364,7 +384,7 @@ module PageObject
|
|
364
384
|
#
|
365
385
|
# @example
|
366
386
|
# table(:cart, :id => 'shopping_cart')
|
367
|
-
# # will generate a '
|
387
|
+
# # will generate a 'cart_element' method
|
368
388
|
#
|
369
389
|
# @param [String] the name used for the generated methods
|
370
390
|
# @param [Hash] identifier how we find a table. You can use a multiple paramaters
|
@@ -377,9 +397,11 @@ module PageObject
|
|
377
397
|
# @param optional block to be invoked when element method is called
|
378
398
|
#
|
379
399
|
def table(name, identifier=nil, &block)
|
380
|
-
define_method("#{name}
|
381
|
-
|
400
|
+
define_method("#{name}_element") do
|
401
|
+
return call_block(&block) if block
|
402
|
+
platform.table_for(identifier.clone)
|
382
403
|
end
|
404
|
+
alias_method "#{name}_table".to_sym, "#{name}_element".to_sym
|
383
405
|
end
|
384
406
|
|
385
407
|
#
|
@@ -388,7 +410,7 @@ module PageObject
|
|
388
410
|
#
|
389
411
|
# @example
|
390
412
|
# cell(:total, :id => 'total_cell')
|
391
|
-
# # will generate 'total' and '
|
413
|
+
# # will generate 'total' and 'total_element' methods
|
392
414
|
#
|
393
415
|
# @param [String] the name used for the generated methods
|
394
416
|
# @param [Hash] identifier how we find a cell. You can use a multiple paramaters
|
@@ -397,6 +419,7 @@ module PageObject
|
|
397
419
|
# * :id => Watir and Selenium
|
398
420
|
# * :index => Watir only
|
399
421
|
# * :name => Watir and Selenium
|
422
|
+
# * :text => Watir and Selenium
|
400
423
|
# * :xpath => Watir and Selenium
|
401
424
|
# @param optional block to be invoked when element method is called
|
402
425
|
#
|
@@ -404,9 +427,11 @@ module PageObject
|
|
404
427
|
define_method("#{name}") do
|
405
428
|
platform.cell_text_for identifier.clone
|
406
429
|
end
|
407
|
-
define_method("#{name}
|
408
|
-
|
430
|
+
define_method("#{name}_element") do
|
431
|
+
return call_block(&block) if block
|
432
|
+
platform.cell_for(identifier.clone)
|
409
433
|
end
|
434
|
+
alias_method "#{name}_cell".to_sym, "#{name}_element".to_sym
|
410
435
|
end
|
411
436
|
|
412
437
|
#
|
@@ -414,7 +439,7 @@ module PageObject
|
|
414
439
|
#
|
415
440
|
# @example
|
416
441
|
# image(:logo, :id => 'logo')
|
417
|
-
# # will generate a '
|
442
|
+
# # will generate a 'logo_element' method
|
418
443
|
#
|
419
444
|
# @param [String] the name used for the generated methods
|
420
445
|
# @param [Hash] identifier how we find an image. You can use a multiple paramaters
|
@@ -427,9 +452,11 @@ module PageObject
|
|
427
452
|
# @param optional block to be invoked when element method is called
|
428
453
|
#
|
429
454
|
def image(name, identifier=nil, &block)
|
430
|
-
define_method("#{name}
|
431
|
-
|
455
|
+
define_method("#{name}_element") do
|
456
|
+
return call_block(&block) if block
|
457
|
+
platform.image_for(identifier.clone)
|
432
458
|
end
|
459
|
+
alias_method "#{name}_image".to_sym, "#{name}_element".to_sym
|
433
460
|
end
|
434
461
|
|
435
462
|
#
|
@@ -437,7 +464,7 @@ module PageObject
|
|
437
464
|
#
|
438
465
|
# @example
|
439
466
|
# form(:login, :id => 'login')
|
440
|
-
# # will generate a '
|
467
|
+
# # will generate a 'login_element' method
|
441
468
|
#
|
442
469
|
# @param [String] the name used for the generated methods
|
443
470
|
# @param [Hash] identifier how we find a form. You can use a multiple paramaters
|
@@ -449,9 +476,11 @@ module PageObject
|
|
449
476
|
# @param optional block to be invoked when element method is called
|
450
477
|
#
|
451
478
|
def form(name, identifier=nil, &block)
|
452
|
-
define_method("#{name}
|
453
|
-
|
479
|
+
define_method("#{name}_element") do
|
480
|
+
return call_block(&block) if block
|
481
|
+
platform.form_for(identifier.clone)
|
454
482
|
end
|
483
|
+
alias_method "#{name}_form".to_sym, "#{name}_element".to_sym
|
455
484
|
end
|
456
485
|
|
457
486
|
#
|
@@ -460,7 +489,7 @@ module PageObject
|
|
460
489
|
#
|
461
490
|
# @example
|
462
491
|
# list_item(:item_one, :id => 'one')
|
463
|
-
# # will generate 'item_one' and '
|
492
|
+
# # will generate 'item_one' and 'item_one_element' methods
|
464
493
|
#
|
465
494
|
# @param [String] the name used for the generated methods
|
466
495
|
# @param [Hash] identifier how we find a list item. You can use a multiple paramaters
|
@@ -476,9 +505,11 @@ module PageObject
|
|
476
505
|
define_method(name) do
|
477
506
|
platform.list_item_text_for identifier.clone
|
478
507
|
end
|
479
|
-
define_method("#{name}
|
480
|
-
|
508
|
+
define_method("#{name}_element") do
|
509
|
+
return call_block(&block) if block
|
510
|
+
platform.list_item_for(identifier.clone)
|
481
511
|
end
|
512
|
+
alias_method "#{name}_list_item".to_sym, "#{name}_element".to_sym
|
482
513
|
end
|
483
514
|
|
484
515
|
#
|
@@ -486,7 +517,7 @@ module PageObject
|
|
486
517
|
#
|
487
518
|
# @example
|
488
519
|
# unordered_list(:menu, :id => 'main_menu')
|
489
|
-
# # will generate a '
|
520
|
+
# # will generate a 'menu_element' method
|
490
521
|
#
|
491
522
|
# @param [String] the name used for the generated methods
|
492
523
|
# @param [Hash] identifier how we find an unordered list. You can use a multiple paramaters
|
@@ -499,9 +530,11 @@ module PageObject
|
|
499
530
|
# @param optional block to be invoked when element method is called
|
500
531
|
#
|
501
532
|
def unordered_list(name, identifier=nil, &block)
|
502
|
-
define_method("#{name}
|
503
|
-
|
533
|
+
define_method("#{name}_element") do
|
534
|
+
return call_block(&block) if block
|
535
|
+
platform.unordered_list_for(identifier.clone)
|
504
536
|
end
|
537
|
+
alias_method "#{name}_unordered_list".to_sym, "#{name}_element".to_sym
|
505
538
|
end
|
506
539
|
|
507
540
|
#
|
@@ -509,7 +542,7 @@ module PageObject
|
|
509
542
|
#
|
510
543
|
# @example
|
511
544
|
# ordered_list(:top_five, :id => 'top')
|
512
|
-
# # will generate a '
|
545
|
+
# # will generate a 'top_five_element' method
|
513
546
|
#
|
514
547
|
# @param [String] the name used for the generated methods
|
515
548
|
# @param [Hash] identifier how we find an ordered list. You can use a multiple paramaters
|
@@ -522,9 +555,11 @@ module PageObject
|
|
522
555
|
# @param optional block to be invoked when element method is called
|
523
556
|
#
|
524
557
|
def ordered_list(name, identifier=nil, &block)
|
525
|
-
define_method("#{name}
|
526
|
-
|
558
|
+
define_method("#{name}_element") do
|
559
|
+
return call_block(&block) if block
|
560
|
+
platform.ordered_list_for(identifier.clone)
|
527
561
|
end
|
562
|
+
alias_method "#{name}_ordered_list".to_sym, "#{name}_element".to_sym
|
528
563
|
end
|
529
564
|
end
|
530
565
|
end
|