page_object_wrapper 1.4.2 → 1.4.3

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.
@@ -13,554 +13,556 @@ require 'Pagination'
13
13
  require 'Element'
14
14
  require 'known_elements'
15
15
 
16
- class PageObject < DslElementWithLocator
17
- attr_reader :esets, :elements, :actions, :aliases, :validators, :tables, :paginations, :uniq_element_type, :uniq_element_hash
18
- @@browser = nil
19
- @@pages = []
20
- @@current_page = nil
21
-
22
- REQUIRED_ELEMENT_WAIT_PERIOD = 10
23
- FEED_ALL = Regexp.new(/^feed_all$/)
24
- FEED = Regexp.new(/^feed_([\w_]+)$/)
25
- FIRE_ACTION = Regexp.new(/^fire_([\w_]+)$/)
26
- SELECT_FROM = Regexp.new(/^select_from_([\w_]+)$/)
27
- PAGINATION_EACH = Regexp.new(/^([\w_]+)_each$/)
28
- PAGINATION_OPEN = Regexp.new(/^([\w_]+)_open$/)
29
- VALIDATE = Regexp.new(/^validate_([\w_\?]+)$/)
30
- PRESS = Regexp.new(/^press_([\w_\?]+)$/)
31
-
32
- def initialize(label)
33
- super label
34
- @esets = []
35
- @elements = []
36
- @actions = []
37
- @aliases = []
38
- @validators = []
39
- @tables = []
40
- @paginations = []
41
- end
42
-
43
- KNOWN_ELEMENTS.each{|m|
44
- PageObject.send :define_method, m do |l, &b|
45
- e = Element.new(l, m.to_sym)
46
- e.instance_eval(&b)
47
- @elements << e
16
+ module PageObjectWrapper
17
+ class PageObject < DslElementWithLocator
18
+ attr_reader :esets, :elements, :actions, :aliases, :validators, :tables, :paginations, :uniq_element_type, :uniq_element_hash
19
+ @@browser = nil
20
+ @@pages = []
21
+ @@current_page = nil
22
+
23
+ REQUIRED_ELEMENT_WAIT_PERIOD = 10
24
+ FEED_ALL = Regexp.new(/^feed_all$/)
25
+ FEED = Regexp.new(/^feed_([\w_]+)$/)
26
+ FIRE_ACTION = Regexp.new(/^fire_([\w_]+)$/)
27
+ SELECT_FROM = Regexp.new(/^select_from_([\w_]+)$/)
28
+ PAGINATION_EACH = Regexp.new(/^([\w_]+)_each$/)
29
+ PAGINATION_OPEN = Regexp.new(/^([\w_]+)_open$/)
30
+ VALIDATE = Regexp.new(/^validate_([\w_\?]+)$/)
31
+ PRESS = Regexp.new(/^press_([\w_\?]+)$/)
32
+
33
+ def initialize(label)
34
+ super label
35
+ @esets = []
36
+ @elements = []
37
+ @actions = []
38
+ @aliases = []
39
+ @validators = []
40
+ @tables = []
41
+ @paginations = []
48
42
  end
49
- }
50
-
51
- # lazy evaluated calls of real watir elements are handled by :method_missing
52
- def method_missing(method_name, *args, &block)
53
- case
54
- when KNOWN_ELEMENTS.include?(method_name.to_s.gsub(/^uniq_/,''))
55
- # page_object.uniq_xxx(hash)
56
- meth = method_name.to_s.gsub(/^uniq_/,'')
57
- e = Element.new(method_name.to_sym, meth)
58
- e.instance_eval { locator(args[0]); required(true) }
43
+
44
+ KNOWN_ELEMENTS.each{|m|
45
+ PageObject.send :define_method, m do |l, &b|
46
+ e = Element.new(l, m.to_sym)
47
+ e.instance_eval(&b)
59
48
  @elements << e
60
- when has_eset?(method_name)
61
- # page_object.some_elements_set
62
- eset = eset_for(method_name)
63
- PageObject.return_array_of_watir_elements(eset)
64
- when has_element?(method_name)
65
- # page_object.some_element
66
- element = element_for(method_name)
67
- PageObject.return_watir_element element
68
- when FEED_ALL.match(method_name)
69
- # page_object.feed_all(:fresh_food)
70
- feed_elements(@elements, *args)
71
- when (FEED.match(method_name) and has_eset?($1))
72
- # page_object.feed_some_elements_set(:fresh_food)
73
- eset = eset_for($1)
74
- feed_elements(eset.elements, *args)
75
- when (FEED.match(method_name) and has_element?($1))
76
- # page_object.feed_some_element(:fresh_food)
77
- e = element_for($1)
78
- if [true, false].include? args[0] or args[0].is_a? String
79
- feed_field(e, args[0])
80
- else
81
- feed_elements([e], *args)
82
- end
83
- when (FIRE_ACTION.match(method_name) and has_action?($1))
84
- # page_object.fire_some_action
85
- a = action_for($1)
86
- fire_action(a, *args)
87
- when (FIRE_ACTION.match(method_name) and has_alias?($1))
88
- # page_object.fire_some_action
89
- a = alias_for($1)
90
- fire_action(a, *args)
91
- when (VALIDATE.match(method_name) and has_validator?($1))
92
- # page_object.validate_something
93
- v = validator_for($1)
94
- run_validator(v, *args)
95
- when (SELECT_FROM.match(method_name) and has_table?($1))
96
- # page_object.select_from_some_table(:header_column, {:column => 'value'})
97
- table = table_for($1)
98
- select_from(table, *args)
99
- when (PAGINATION_EACH.match(method_name) and has_pagination?($1))
100
- # page_object.each_pagination
101
- pagination = pagination_for($1)
102
- run_each_subpage(pagination, *args, &block)
103
- when (PAGINATION_OPEN.match(method_name) and has_pagination?($1))
104
- # page_object.open_padination(1)
105
- pagination = pagination_for($1)
106
- open_subpage(pagination, *args)
107
- when (PRESS.match(method_name) and has_element?($1))
108
- # page_object.press_element
109
- element = element_for($1)
110
- press(element)
111
- else
112
- super
113
- end
114
- end
49
+ end
50
+ }
115
51
 
116
- # corresponding respond_to?
117
- def respond_to?(method_sym, include_private = false)
118
- method_name = method_sym.to_s
119
- case
120
- when KNOWN_ELEMENTS.include?(method_name.gsub(/^uniq_/,''))
121
- # page_object.uniq_xxx(hash)
122
- true
123
- when has_eset?(method_name)
124
- # page_object.some_elements_set
125
- true
126
- when has_element?(method_name)
127
- # page_object.some_element
128
- true
129
- when FEED_ALL.match(method_name)
130
- # page_object.feed_all(:fresh_food)
131
- true
132
- when (FEED.match(method_name) and has_eset?($1))
133
- # page_object.feed_some_elements_set(:fresh_food)
134
- true
135
- when (FEED.match(method_name) and has_element?($1))
136
- # page_object.feed_some_element(:fresh_food)
137
- true
138
- when (FIRE_ACTION.match(method_name) and has_action?($1))
139
- # page_object.fire_some_action
140
- true
141
- when (FIRE_ACTION.match(method_name) and has_alias?($1))
142
- # page_object.fire_some_action
143
- true
144
- when (VALIDATE.match(method_name) and has_action?($1))
145
- # page_object.validate_xxx
146
- true
147
- when (SELECT_FROM.match(method_name) and has_table?($1))
148
- # page_object.select_from_some_table(:header_column, {:column => 'value'})
149
- true
150
- when (PAGINATION_EACH.match(method_name) and has_pagination?($1))
151
- # page_object.each_pagination
152
- true
153
- when (PAGINATION_OPEN.match(method_name) and has_pagination?($1))
154
- # page_object.open_padination(1)
155
- true
156
- when (PRESS.match(method_name) and has_element?($1))
157
- # page_object.press_element
158
- true
159
- else
160
- super
52
+ # lazy evaluated calls of real watir elements are handled by :method_missing
53
+ def method_missing(method_name, *args, &block)
54
+ case
55
+ when KNOWN_ELEMENTS.include?(method_name.to_s.gsub(/^uniq_/,''))
56
+ # page_object.uniq_xxx(hash)
57
+ meth = method_name.to_s.gsub(/^uniq_/,'')
58
+ e = Element.new(method_name.to_sym, meth)
59
+ e.instance_eval { locator(args[0]); required(true) }
60
+ @elements << e
61
+ when has_eset?(method_name)
62
+ # page_object.some_elements_set
63
+ eset = eset_for(method_name)
64
+ PageObject.return_array_of_watir_elements(eset)
65
+ when has_element?(method_name)
66
+ # page_object.some_element
67
+ element = element_for(method_name)
68
+ PageObject.return_watir_element element
69
+ when FEED_ALL.match(method_name)
70
+ # page_object.feed_all(:fresh_food)
71
+ feed_elements(@elements, *args)
72
+ when (FEED.match(method_name) and has_eset?($1))
73
+ # page_object.feed_some_elements_set(:fresh_food)
74
+ eset = eset_for($1)
75
+ feed_elements(eset.elements, *args)
76
+ when (FEED.match(method_name) and has_element?($1))
77
+ # page_object.feed_some_element(:fresh_food)
78
+ e = element_for($1)
79
+ if [true, false].include? args[0] or args[0].is_a? String
80
+ feed_field(e, args[0])
81
+ else
82
+ feed_elements([e], *args)
83
+ end
84
+ when (FIRE_ACTION.match(method_name) and has_action?($1))
85
+ # page_object.fire_some_action
86
+ a = action_for($1)
87
+ fire_action(a, *args)
88
+ when (FIRE_ACTION.match(method_name) and has_alias?($1))
89
+ # page_object.fire_some_action
90
+ a = alias_for($1)
91
+ fire_action(a, *args)
92
+ when (VALIDATE.match(method_name) and has_validator?($1))
93
+ # page_object.validate_something
94
+ v = validator_for($1)
95
+ run_validator(v, *args)
96
+ when (SELECT_FROM.match(method_name) and has_table?($1))
97
+ # page_object.select_from_some_table(:header_column, {:column => 'value'})
98
+ table = table_for($1)
99
+ select_from(table, *args)
100
+ when (PAGINATION_EACH.match(method_name) and has_pagination?($1))
101
+ # page_object.each_pagination
102
+ pagination = pagination_for($1)
103
+ run_each_subpage(pagination, *args, &block)
104
+ when (PAGINATION_OPEN.match(method_name) and has_pagination?($1))
105
+ # page_object.open_padination(1)
106
+ pagination = pagination_for($1)
107
+ open_subpage(pagination, *args)
108
+ when (PRESS.match(method_name) and has_element?($1))
109
+ # page_object.press_element
110
+ element = element_for($1)
111
+ press(element)
112
+ else
113
+ super
114
+ end
161
115
  end
162
- end
163
116
 
164
- def self.open_page label, optional_hash=nil
165
- raise PageObjectWrapper::BrowserNotFound if @@browser.nil?
166
- raise PageObjectWrapper::UnknownPageObject, label.inspect if not @@pages.collect(&:label_value).include?(label)
167
- page_object = PageObject.find_page_object(label)
168
- url = ''
169
- url += @@domain if page_object.locator_value[0]=='/'
170
- url += page_object.locator_value
171
- if not (optional_hash.nil? or optional_hash.empty?)
172
- optional_hash.each{|k,v|
173
- raise ArgumentError, "#{k.inspect} not Symbol" if not k.is_a? Symbol
174
- raise ArgumentError, "#{v.inspect} not meaningful String" if not v.is_a? String or v.empty?
175
- raise PageObjectWrapper::DynamicUrl, "#{k.inspect} not known parameter" if not url.match(':'+k.to_s)
176
- url.gsub!(/:#{k.to_s}/, v)
177
- }
117
+ # corresponding respond_to?
118
+ def respond_to?(method_sym, include_private = false)
119
+ method_name = method_sym.to_s
120
+ case
121
+ when KNOWN_ELEMENTS.include?(method_name.gsub(/^uniq_/,''))
122
+ # page_object.uniq_xxx(hash)
123
+ true
124
+ when has_eset?(method_name)
125
+ # page_object.some_elements_set
126
+ true
127
+ when has_element?(method_name)
128
+ # page_object.some_element
129
+ true
130
+ when FEED_ALL.match(method_name)
131
+ # page_object.feed_all(:fresh_food)
132
+ true
133
+ when (FEED.match(method_name) and has_eset?($1))
134
+ # page_object.feed_some_elements_set(:fresh_food)
135
+ true
136
+ when (FEED.match(method_name) and has_element?($1))
137
+ # page_object.feed_some_element(:fresh_food)
138
+ true
139
+ when (FIRE_ACTION.match(method_name) and has_action?($1))
140
+ # page_object.fire_some_action
141
+ true
142
+ when (FIRE_ACTION.match(method_name) and has_alias?($1))
143
+ # page_object.fire_some_action
144
+ true
145
+ when (VALIDATE.match(method_name) and has_action?($1))
146
+ # page_object.validate_xxx
147
+ true
148
+ when (SELECT_FROM.match(method_name) and has_table?($1))
149
+ # page_object.select_from_some_table(:header_column, {:column => 'value'})
150
+ true
151
+ when (PAGINATION_EACH.match(method_name) and has_pagination?($1))
152
+ # page_object.each_pagination
153
+ true
154
+ when (PAGINATION_OPEN.match(method_name) and has_pagination?($1))
155
+ # page_object.open_padination(1)
156
+ true
157
+ when (PRESS.match(method_name) and has_element?($1))
158
+ # page_object.press_element
159
+ true
160
+ else
161
+ super
162
+ end
178
163
  end
179
- @@browser.goto url
180
- end
181
164
 
182
- def self.map_current_page label
183
- raise PageObjectWrapper::BrowserNotFound if @@browser.nil?
184
- raise PageObjectWrapper::UnknownPageObject, label.inspect if not @@pages.collect(&:label_value).include?(label)
185
- page_object = PageObject.find_page_object(label)
186
- page_object.elements.select{ |e| e.required_value == true }.each{ |required_element|
187
- begin
188
- watir_element = return_watir_element required_element
189
- watir_element.wait_until_present REQUIRED_ELEMENT_WAIT_PERIOD
190
- rescue Watir::Wait::TimeoutError => e
191
- raise PageObjectWrapper::UnmappedPageObject, "#{label} <=> #{@@browser.url} (#{e.message})" if not watir_element.present?
165
+ def self.open_page label, optional_hash=nil
166
+ raise PageObjectWrapper::BrowserNotFound if @@browser.nil?
167
+ raise PageObjectWrapper::UnknownPageObject, label.inspect if not @@pages.collect(&:label_value).include?(label)
168
+ page_object = PageObject.find_page_object(label)
169
+ url = ''
170
+ url += @@domain if page_object.locator_value[0]=='/'
171
+ url += page_object.locator_value
172
+ if not (optional_hash.nil? or optional_hash.empty?)
173
+ optional_hash.each{|k,v|
174
+ raise ArgumentError, "#{k.inspect} not Symbol" if not k.is_a? Symbol
175
+ raise ArgumentError, "#{v.inspect} not meaningful String" if not v.is_a? String or v.empty?
176
+ raise PageObjectWrapper::DynamicUrl, "#{k.inspect} not known parameter" if not url.match(':'+k.to_s)
177
+ url.gsub!(/:#{k.to_s}/, v)
178
+ }
192
179
  end
193
- }
194
- @@current_page = page_object
195
- end
196
-
197
- def self.current_page? label
198
- self.map_current_page label
199
- true
200
- end
180
+ @@browser.goto url
181
+ end
201
182
 
202
- def self.current_page
203
- @@current_page
204
- end
183
+ def self.map_current_page label
184
+ raise PageObjectWrapper::BrowserNotFound if @@browser.nil?
185
+ raise PageObjectWrapper::UnknownPageObject, label.inspect if not @@pages.collect(&:label_value).include?(label)
186
+ page_object = PageObject.find_page_object(label)
187
+ page_object.elements.select{ |e| e.required_value == true }.each{ |required_element|
188
+ begin
189
+ watir_element = return_watir_element required_element
190
+ watir_element.wait_until_present REQUIRED_ELEMENT_WAIT_PERIOD
191
+ rescue Watir::Wait::TimeoutError => e
192
+ raise PageObjectWrapper::UnmappedPageObject, "#{label} <=> #{@@browser.url} (#{e.message})" if not watir_element.present?
193
+ end
194
+ }
195
+ @@current_page = page_object
196
+ end
205
197
 
206
- def self.pages
207
- @@pages
208
- end
198
+ def self.current_page? label
199
+ self.map_current_page label
200
+ true
201
+ end
209
202
 
210
- def self.browser=(val)
211
- @@browser = val
212
- end
203
+ def self.current_page
204
+ @@current_page
205
+ end
213
206
 
214
- def self.browser
215
- @@browser
216
- end
207
+ def self.pages
208
+ @@pages
209
+ end
217
210
 
218
- def elements_set(label, &block)
219
- eset = ElementsSet.new(label)
220
- eset.instance_eval(&block)
221
- @esets << eset
222
- eset.elements.each{|e|
223
- PageObject.send :define_method, (e.label_value.to_s+'_menu').to_sym do |food_type|
224
- e.menu_value[food_type].to_s
225
- end
226
- }
227
- @elements += eset.elements
228
- eset
229
- end
211
+ def self.browser=(val)
212
+ @@browser = val
213
+ end
230
214
 
231
- def action(label, next_page=nil, &block)
232
- a = Action.new(label, next_page, &block)
233
- @actions << a
234
- a
235
- end
215
+ def self.browser
216
+ @@browser
217
+ end
236
218
 
237
- def action_alias(label, next_page=nil, &block)
238
- a = Alias.new(label, next_page)
239
- a.instance_eval(&block)
240
- @aliases << a
241
- a
242
- end
219
+ def elements_set(label, &block)
220
+ eset = ElementsSet.new(label)
221
+ eset.instance_eval(&block)
222
+ @esets << eset
223
+ eset.elements.each{|e|
224
+ PageObject.send :define_method, (e.label_value.to_s+'_menu').to_sym do |food_type|
225
+ e.menu_value[food_type].to_s
226
+ end
227
+ }
228
+ @elements += eset.elements
229
+ eset
230
+ end
243
231
 
244
- def validator(label, &block)
245
- v = Validator.new(label, &block)
246
- @validators << v
247
- v
248
- end
232
+ def action(label, next_page=nil, &block)
233
+ a = Action.new(label, next_page, &block)
234
+ @actions << a
235
+ a
236
+ end
249
237
 
250
- def table(label, &block)
251
- t = Table.new(label)
252
- t.instance_eval(&block)
253
- @tables << t
254
- @elements << t
255
- t
256
- end
238
+ def action_alias(label, next_page=nil, &block)
239
+ a = Alias.new(label, next_page)
240
+ a.instance_eval(&block)
241
+ @aliases << a
242
+ a
243
+ end
257
244
 
245
+ def validator(label, &block)
246
+ v = Validator.new(label, &block)
247
+ @validators << v
248
+ v
249
+ end
258
250
 
259
- def pagination(label, &block)
260
- p = Pagination.new(label)
261
- p.instance_eval(&block)
262
- @paginations << p
263
- p
264
- end
251
+ def table(label, &block)
252
+ t = Table.new(label)
253
+ t.instance_eval(&block)
254
+ @tables << t
255
+ @elements << t
256
+ t
257
+ end
265
258
 
266
- def validate
267
- output = []
268
- # commented out; already defined pages will e redifined with new definitions
269
- raise PageObjectWrapper::Load, "\tpage_object #{label_value.inspect} already defined\n" if labeled(@@pages).count(label_value) > 1
270
- output << "\tlabel #{label_value.inspect} not a Symbol\n" if not label_value.is_a?(Symbol)
271
- output << "\tlocator #{locator_value.inspect} not a meaningful String\n" if not locator_value.is_a?(String) or locator_value.empty?
272
- @esets.each{|eset|
273
- eset_output = []
274
- eset_output << "\telements_set #{eset.label_value.inspect} already defined\n" if labeled(@esets).count(eset.label_value) > 1
275
- eset_output << "\tlabel #{eset.label_value.inspect} not a Symbol\n" if not eset.label_value.is_a?(Symbol)
276
- eset_output.unshift "elements_set(#{eset.label_value.inspect}):\n" if not eset_output.empty?
277
- output += eset_output
278
- }
279
- @elements.each{|e|
280
- element_output = []
281
- element_output << "\telement #{e.label_value.inspect} already defined\n" if labeled(@elements).count(e.label_value) > 1
282
- element_output << "\tlabel #{e.label_value.inspect} not a Symbol\n" if not e.label_value.is_a?(Symbol)
283
- element_output << "\tlocator #{e.locator_value.inspect} not a meaningful Hash or String\n" if (not e.locator_value.is_a?(Hash) and not e.locator_value.is_a?(String)) \
284
- or e.locator_value.empty?
285
- element_output << "\tmenu #{e.menu_value.inspect} not properly defined (must be { :food_type => 'a string' | true | false })\n" if (not e.menu_value.empty?) and \
286
- ((e.menu_value.keys.collect(&:class).uniq != [Symbol]) \
287
- or not (e.menu_value.values.collect(&:class).uniq - [String, TrueClass, FalseClass]).empty?)
288
- element_output << "\trequired flag #{e.required_value.inspect} not a true | false\n" if not [true, false].include? e.required_value
289
- element_output.unshift "element(#{e.label_value.inspect}):\n" if not element_output.empty?
290
- output += element_output
291
- }
292
- @actions.each{|a|
293
- action_output = []
294
- action_output << "\taction #{a.label_value.inspect} already defined\n" if labeled(@actions).count(a.label_value) > 1
295
- action_output << "\tlabel #{a.label_value.inspect} not a Symbol\n" if not a.label_value.is_a?(Symbol)
296
- if not a.next_page_value.nil?
297
- action_output << "\tnext_page #{a.next_page_value.inspect} not a Symbol\n" if not a.next_page_value.is_a? Symbol
298
- action_output << "\tnext_page #{a.next_page_value.inspect} unknown page_object\n" if not labeled(@@pages).include?(a.next_page_value)
299
- end
300
- action_output << "\tfire event is not a Proc\n" if not a.fire_block_value.is_a?(Proc)
301
- action_output.unshift "action(#{a.label_value.inspect}):\n" if not action_output.empty?
302
- output += action_output
303
- }
304
- @aliases.each{|a|
305
- alias_output = []
306
- alias_output << "\talias #{a.label_value.inspect} already defined\n" if labeled(@aliases).count(a.label_value) > 1
307
- alias_output << "\tlabel #{a.label_value.inspect} not a Symbol\n" if not a.label_value.is_a?(Symbol)
308
- if not a.next_page_value.nil?
309
- alias_output << "\tnext_page #{a.next_page_value.inspect} not a Symbol\n" if not a.next_page_value.is_a? Symbol
310
- alias_output << "\tnext_page #{a.next_page_value.inspect} unknown page_object\n" if not labeled(@@pages).include?(a.next_page_value)
311
- end
312
- alias_output << "\taction #{a.action_value.inspect} not known Action\n" if not labeled(@actions).include? a.action_value
313
- alias_output.unshift "alias(#{a.label_value.inspect}):\n" if not alias_output.empty?
314
- output += alias_output
315
- }
316
- @validators.each{|v|
317
- validator_output = []
318
- validator_output << "\tvalidator #{v.label_value.inspect} already defined\n" if labeled(@validators).count(v.label_value) > 1
319
- validator_output << "\tlabel #{v.label_value.inspect} not a Symbol\n" if not v.label_value.is_a?(Symbol)
320
- validator_output << "\tvalidation block is not a Proc\n" if not v.validate_block_value.is_a?(Proc)
321
- validator_output.unshift "validator(#{v.label_value.inspect}):\n" if not validator_output.empty?
322
- output += validator_output
323
- }
324
- @tables.each{|t|
325
- table_output = []
326
- table_output << "\theader #{t.header_value.inspect} not a meaningful Array\n" if not t.header_value.is_a?(Array) or t.header_value.empty?
327
- table_output.unshift "table(#{t.label_value.inspect}):\n" if not table_output.empty?
328
- output += table_output
329
- }
330
- @paginations.each{|p|
331
- pagination_output = []
332
- pagination_output << "\tpagination #{p.label_value.inspect} already defined\n" if labeled(@paginations).count(p.label_value) > 1
333
- pagination_output << "\tlabel #{p.label_value.inspect} not a Symbol\n" if not p.label_value.is_a?(Symbol)
334
- pagination_output << "\tlocator #{p.locator_value.inspect} not a meaningful String\n" if not p.locator_value.is_a?(String) or p.locator_value.empty?
335
- pagination_output << "\t\"#{p.finds_value}\" not found in #{p.locator_value}\n" if not p.locator_value =~ /#{p.finds_value.to_s}/
336
- pagination_output.unshift "pagination(#{p.label_value.inspect}):\n" if not pagination_output.empty?
337
- output += pagination_output
338
- }
339
- output.unshift "page_object(#{label_value.inspect}):\n" if not output.empty?
340
- output
341
- end
342
259
 
343
- private
260
+ def pagination(label, &block)
261
+ p = Pagination.new(label)
262
+ p.instance_eval(&block)
263
+ @paginations << p
264
+ p
265
+ end
344
266
 
345
- def self.find_page_object(l)
346
- p = @@pages.select{|p| p.label_value == l}.first
347
- raise ArgumentError, "#{l.inspect} not known Page" if p.nil?
348
- p
349
- end
350
-
351
- def self.return_watir_element(e)
352
- el = nil
353
- if e.locator_value.is_a? Hash
354
- el = @@browser.send e.type, e.locator_value
355
- elsif e.locator_value.is_a? String
356
- el = @@browser.instance_eval e.locator_value
267
+ def validate
268
+ output = []
269
+ # commented out; already defined pages will e redifined with new definitions
270
+ raise PageObjectWrapper::Load, "\tpage_object #{label_value.inspect} already defined\n" if labeled(@@pages).count(label_value) > 1
271
+ output << "\tlabel #{label_value.inspect} not a Symbol\n" if not label_value.is_a?(Symbol)
272
+ output << "\tlocator #{locator_value.inspect} not a meaningful String\n" if not locator_value.is_a?(String) or locator_value.empty?
273
+ @esets.each{|eset|
274
+ eset_output = []
275
+ eset_output << "\telements_set #{eset.label_value.inspect} already defined\n" if labeled(@esets).count(eset.label_value) > 1
276
+ eset_output << "\tlabel #{eset.label_value.inspect} not a Symbol\n" if not eset.label_value.is_a?(Symbol)
277
+ eset_output.unshift "elements_set(#{eset.label_value.inspect}):\n" if not eset_output.empty?
278
+ output += eset_output
279
+ }
280
+ @elements.each{|e|
281
+ element_output = []
282
+ element_output << "\telement #{e.label_value.inspect} already defined\n" if labeled(@elements).count(e.label_value) > 1
283
+ element_output << "\tlabel #{e.label_value.inspect} not a Symbol\n" if not e.label_value.is_a?(Symbol)
284
+ element_output << "\tlocator #{e.locator_value.inspect} not a meaningful Hash or String\n" if (not e.locator_value.is_a?(Hash) and not e.locator_value.is_a?(String)) \
285
+ or e.locator_value.empty?
286
+ element_output << "\tmenu #{e.menu_value.inspect} not properly defined (must be { :food_type => 'a string' | true | false })\n" if (not e.menu_value.empty?) and \
287
+ ((e.menu_value.keys.collect(&:class).uniq != [Symbol]) \
288
+ or not (e.menu_value.values.collect(&:class).uniq - [String, TrueClass, FalseClass]).empty?)
289
+ element_output << "\trequired flag #{e.required_value.inspect} not a true | false\n" if not [true, false].include? e.required_value
290
+ element_output.unshift "element(#{e.label_value.inspect}):\n" if not element_output.empty?
291
+ output += element_output
292
+ }
293
+ @actions.each{|a|
294
+ action_output = []
295
+ action_output << "\taction #{a.label_value.inspect} already defined\n" if labeled(@actions).count(a.label_value) > 1
296
+ action_output << "\tlabel #{a.label_value.inspect} not a Symbol\n" if not a.label_value.is_a?(Symbol)
297
+ if not a.next_page_value.nil?
298
+ action_output << "\tnext_page #{a.next_page_value.inspect} not a Symbol\n" if not a.next_page_value.is_a? Symbol
299
+ action_output << "\tnext_page #{a.next_page_value.inspect} unknown page_object\n" if not labeled(@@pages).include?(a.next_page_value)
300
+ end
301
+ action_output << "\tfire event is not a Proc\n" if not a.fire_block_value.is_a?(Proc)
302
+ action_output.unshift "action(#{a.label_value.inspect}):\n" if not action_output.empty?
303
+ output += action_output
304
+ }
305
+ @aliases.each{|a|
306
+ alias_output = []
307
+ alias_output << "\talias #{a.label_value.inspect} already defined\n" if labeled(@aliases).count(a.label_value) > 1
308
+ alias_output << "\tlabel #{a.label_value.inspect} not a Symbol\n" if not a.label_value.is_a?(Symbol)
309
+ if not a.next_page_value.nil?
310
+ alias_output << "\tnext_page #{a.next_page_value.inspect} not a Symbol\n" if not a.next_page_value.is_a? Symbol
311
+ alias_output << "\tnext_page #{a.next_page_value.inspect} unknown page_object\n" if not labeled(@@pages).include?(a.next_page_value)
312
+ end
313
+ alias_output << "\taction #{a.action_value.inspect} not known Action\n" if not labeled(@actions).include? a.action_value
314
+ alias_output.unshift "alias(#{a.label_value.inspect}):\n" if not alias_output.empty?
315
+ output += alias_output
316
+ }
317
+ @validators.each{|v|
318
+ validator_output = []
319
+ validator_output << "\tvalidator #{v.label_value.inspect} already defined\n" if labeled(@validators).count(v.label_value) > 1
320
+ validator_output << "\tlabel #{v.label_value.inspect} not a Symbol\n" if not v.label_value.is_a?(Symbol)
321
+ validator_output << "\tvalidation block is not a Proc\n" if not v.validate_block_value.is_a?(Proc)
322
+ validator_output.unshift "validator(#{v.label_value.inspect}):\n" if not validator_output.empty?
323
+ output += validator_output
324
+ }
325
+ @tables.each{|t|
326
+ table_output = []
327
+ table_output << "\theader #{t.header_value.inspect} not a meaningful Array\n" if not t.header_value.is_a?(Array) or t.header_value.empty?
328
+ table_output.unshift "table(#{t.label_value.inspect}):\n" if not table_output.empty?
329
+ output += table_output
330
+ }
331
+ @paginations.each{|p|
332
+ pagination_output = []
333
+ pagination_output << "\tpagination #{p.label_value.inspect} already defined\n" if labeled(@paginations).count(p.label_value) > 1
334
+ pagination_output << "\tlabel #{p.label_value.inspect} not a Symbol\n" if not p.label_value.is_a?(Symbol)
335
+ pagination_output << "\tlocator #{p.locator_value.inspect} not a meaningful String\n" if not p.locator_value.is_a?(String) or p.locator_value.empty?
336
+ pagination_output << "\t\"#{p.finds_value}\" not found in #{p.locator_value}\n" if not p.locator_value =~ /#{p.finds_value.to_s}/
337
+ pagination_output.unshift "pagination(#{p.label_value.inspect}):\n" if not pagination_output.empty?
338
+ output += pagination_output
339
+ }
340
+ output.unshift "page_object(#{label_value.inspect}):\n" if not output.empty?
341
+ output
357
342
  end
358
- el
359
- end
360
343
 
361
- def self.return_array_of_watir_elements(eset)
362
- eset.elements.collect{|e| return_watir_element(e)}
363
- end
344
+ private
364
345
 
365
- def feed_elements(elements, *args)
366
- raise PageObjectWrapper::BrowserNotFound if @@browser.nil? or not @@browser.exist?
367
- menu_name, cheef_menu = nil, nil
346
+ def self.find_page_object(l)
347
+ p = @@pages.select{|p| p.label_value == l}.first
348
+ raise ArgumentError, "#{l.inspect} not known Page" if p.nil?
349
+ p
350
+ end
368
351
 
369
- if args[0].is_a? Symbol
370
- menu_name = args[0]
371
- cheef_menu = args[1]
372
- elsif args[0].is_a? Hash
373
- cheef_menu = args[0]
352
+ def self.return_watir_element(e)
353
+ el = nil
354
+ if e.locator_value.is_a? Hash
355
+ el = @@browser.send e.type, e.locator_value
356
+ elsif e.locator_value.is_a? String
357
+ el = @@browser.instance_eval e.locator_value
358
+ end
359
+ el
374
360
  end
375
- if not cheef_menu.nil?
376
- raise ArgumentError, "#{cheef_menu.inspect} not meaningful Hash" if not cheef_menu.is_a? Hash or cheef_menu.empty?
361
+
362
+ def self.return_array_of_watir_elements(eset)
363
+ eset.elements.collect{|e| return_watir_element(e)}
377
364
  end
378
- menus = []
379
- elements.each{ |e| menus += e.menu_value.keys }
380
- elements.each{|e|
381
- if not cheef_menu.nil? and cheef_menu.keys.include? e.label_value
382
- food = cheef_menu[e.label_value]
383
- else
384
- food = e.menu_value[menu_name].to_s
365
+
366
+ def feed_elements(elements, *args)
367
+ raise PageObjectWrapper::BrowserNotFound if @@browser.nil? or not @@browser.exist?
368
+ menu_name, cheef_menu = nil, nil
369
+
370
+ if args[0].is_a? Symbol
371
+ menu_name = args[0]
372
+ cheef_menu = args[1]
373
+ elsif args[0].is_a? Hash
374
+ cheef_menu = args[0]
385
375
  end
386
- watir_element = PageObject.return_watir_element e
387
- case watir_element
388
- when Watir::CheckBox
389
- watir_element.when_present.set eval(food) if ["true", "false"].include? food
390
- when Watir::Radio
391
- watir_element.when_present.set if food=="true"
392
- when Watir::Select
393
- watir_element.select food if watir_element.include? food
376
+ if not cheef_menu.nil?
377
+ raise ArgumentError, "#{cheef_menu.inspect} not meaningful Hash" if not cheef_menu.is_a? Hash or cheef_menu.empty?
378
+ end
379
+ menus = []
380
+ elements.each{ |e| menus += e.menu_value.keys }
381
+ elements.each{|e|
382
+ if not cheef_menu.nil? and cheef_menu.keys.include? e.label_value
383
+ food = cheef_menu[e.label_value]
394
384
  else
395
- if watir_element.respond_to?(:set)
396
- watir_element.when_present.set food if food!=''
385
+ food = e.menu_value[menu_name].to_s
386
+ end
387
+ watir_element = PageObject.return_watir_element e
388
+ case watir_element
389
+ when Watir::CheckBox
390
+ watir_element.when_present.set eval(food) if ["true", "false"].include? food
391
+ when Watir::Radio
392
+ watir_element.when_present.set if food=="true"
393
+ when Watir::Select
394
+ watir_element.select food if watir_element.include? food
397
395
  else
398
- # this is an element which does not support input (e.g. button) => skipping it
399
- next
400
- #raise PageObjectWrapper::UnableToFeedObject, to_tree(@@current_page, e) + ' check element type'
396
+ if watir_element.respond_to?(:set)
397
+ watir_element.when_present.set food if food!=''
398
+ else
399
+ # this is an element which does not support input (e.g. button) => skipping it
400
+ next
401
+ #raise PageObjectWrapper::UnableToFeedObject, to_tree(@@current_page, e) + ' check element type'
402
+ end
401
403
  end
402
- end
403
- }
404
- self
405
- end
404
+ }
405
+ self
406
+ end
406
407
 
407
- def feed_field(e, value)
408
- watir_element = PageObject.return_watir_element e
409
- case watir_element
410
- when Watir::CheckBox
411
- watir_element.when_present.set value if [true, false].include? value
412
- when Watir::Radio
413
- watir_element.when_present.set if value==true
414
- when Watir::Select
415
- watir_element.select value if watir_element.include? value
416
- else
417
- if watir_element.respond_to?(:set)
418
- watir_element.when_present.set value
408
+ def feed_field(e, value)
409
+ watir_element = PageObject.return_watir_element e
410
+ case watir_element
411
+ when Watir::CheckBox
412
+ watir_element.when_present.set value if [true, false].include? value
413
+ when Watir::Radio
414
+ watir_element.when_present.set if value==true
415
+ when Watir::Select
416
+ watir_element.select value if watir_element.include? value
417
+ else
418
+ if watir_element.respond_to?(:set)
419
+ watir_element.when_present.set value
420
+ end
419
421
  end
420
422
  end
421
- end
422
423
 
423
424
 
424
- def fire_action(a, *args)
425
- raise PageObjectWrapper::BrowserNotFound if @@browser.nil? or not @@browser.exist?
426
- block = (a.is_a? Action)? a.fire_block_value : action_for(a.action_value).fire_block_value
427
- block_result = @@browser.instance_exec *args, &block
428
- if not a.next_page_value.nil?
429
- self.class.map_current_page a.next_page_value
430
- return @@current_page
431
- else
432
- return block_result
433
- end
434
- end
435
-
436
- def run_validator(v, *args)
437
- raise PageObjectWrapper::BrowserNotFound if @@browser.nil? or not @@browser.exist?
438
- @@browser.instance_exec *args, &v.validate_block_value
439
- end
425
+ def fire_action(a, *args)
426
+ raise PageObjectWrapper::BrowserNotFound if @@browser.nil? or not @@browser.exist?
427
+ block = (a.is_a? Action)? a.fire_block_value : action_for(a.action_value).fire_block_value
428
+ block_result = @@browser.instance_exec *args, &block
429
+ if not a.next_page_value.nil?
430
+ self.class.map_current_page a.next_page_value
431
+ return @@current_page
432
+ else
433
+ return block_result
434
+ end
435
+ end
440
436
 
441
- def select_from(table, header, *args)
442
- where = args[0]
443
- next_page = args[1]
444
- raise PageObjectWrapper::BrowserNotFound if @@browser.nil? or not @@browser.exist?
445
- t = @@browser.table(table.locator_value)
446
- raise ArgumentError, "#{header.inspect} not a Symbol" if not header.is_a? Symbol
447
- raise ArgumentError, "#{header.inspect} not in table header" if not table.header_value.include? header
448
- search_for_index = table.header_value.index(header)
449
- found = nil
450
-
451
- if not next_page.nil?
452
- raise ArgumentError, "#{next_page.inspect} not a Symbol" if not next_page.is_a? Symbol
453
- raise ArgumentError, "#{next_page.inspect} not known Page" if not labeled(@@pages).include?(next_page)
437
+ def run_validator(v, *args)
438
+ raise PageObjectWrapper::BrowserNotFound if @@browser.nil? or not @@browser.exist?
439
+ @@browser.instance_exec *args, &v.validate_block_value
454
440
  end
455
441
 
456
- if not where.nil?
457
- raise ArgumentError, "#{where.inspect} not a meaningful Hash" if not where.is_a? Hash or where.empty?
458
- raise ArgumentError, "#{where.inspect} has more than 1 keys" if not where.keys.length == 1
459
- raise ArgumentError, "#{where.keys.first.inspect} not a Symbol" if not where.keys.first.is_a? Symbol
460
- raise ArgumentError, "#{where.keys.first.inspect} not in table header and not == :row" if not ( table.header_value.include? where.keys.first or where.keys.first == :row )
461
- raise ArgumentError, "#{where.values.first.inspect} not a String or Regexp or Integer" if not ( where.values.first.is_a? String or where.values.first.is_a? Regexp or where.values.first.is_a? Integer)
462
- search_value = where.values.first
463
- if where.keys.first == :row # finding by row number
464
- raise ArgumentError, "#{where.values.first.inspect} not Integer" if not ( where.values.first.is_a? Integer)
465
- begin
466
- found = t.rows[search_value+1].cells[search_for_index] # +1 because we want rows to start from 0 (similar to columns)
442
+ def select_from(table, header, *args)
443
+ where = args[0]
444
+ next_page = args[1]
445
+ raise PageObjectWrapper::BrowserNotFound if @@browser.nil? or not @@browser.exist?
446
+ t = @@browser.table(table.locator_value)
447
+ raise ArgumentError, "#{header.inspect} not a Symbol" if not header.is_a? Symbol
448
+ raise ArgumentError, "#{header.inspect} not in table header" if not table.header_value.include? header
449
+ search_for_index = table.header_value.index(header)
450
+ found = nil
451
+
452
+ if not next_page.nil?
453
+ raise ArgumentError, "#{next_page.inspect} not a Symbol" if not next_page.is_a? Symbol
454
+ raise ArgumentError, "#{next_page.inspect} not known Page" if not labeled(@@pages).include?(next_page)
455
+ end
456
+
457
+ if not where.nil?
458
+ raise ArgumentError, "#{where.inspect} not a meaningful Hash" if not where.is_a? Hash or where.empty?
459
+ raise ArgumentError, "#{where.inspect} has more than 1 keys" if not where.keys.length == 1
460
+ raise ArgumentError, "#{where.keys.first.inspect} not a Symbol" if not where.keys.first.is_a? Symbol
461
+ raise ArgumentError, "#{where.keys.first.inspect} not in table header and not == :row" if not ( table.header_value.include? where.keys.first or where.keys.first == :row )
462
+ raise ArgumentError, "#{where.values.first.inspect} not a String or Regexp or Integer" if not ( where.values.first.is_a? String or where.values.first.is_a? Regexp or where.values.first.is_a? Integer)
463
+ search_value = where.values.first
464
+ if where.keys.first == :row # finding by row number
465
+ raise ArgumentError, "#{where.values.first.inspect} not Integer" if not ( where.values.first.is_a? Integer)
466
+ begin
467
+ found = t.rows[search_value+1].cells[search_for_index] # +1 because we want rows to start from 0 (similar to columns)
468
+ rescue Watir::Exception::UnknownObjectException
469
+ found = nil
470
+ end
471
+ else # finding by String or Regexp
472
+ search_in_index = table.header_value.index(where.keys.first)
473
+ t.rows.each{|r|
474
+ if search_value.is_a? String
475
+ begin
476
+ found = r.cells[search_for_index] if r.cells[search_in_index].text == search_value
477
+ rescue Watir::Exception::UnknownObjectException
478
+ found = nil
479
+ end
480
+ elsif search_value.is_a? Regexp
481
+ begin
482
+ found = r.cells[search_for_index] if search_value.match(r.cells[search_in_index].text)
483
+ rescue Watir::Exception::UnknownObjectException
484
+ found = nil
485
+ end
486
+ else
487
+ raise ArgumentError, "#{search_value} not a Regexp or String"
488
+ end
489
+ }
490
+ end
491
+ else # where == nil
492
+ begin
493
+ found = t.rows[t.rows.length/2].cells[search_for_index] # returning some "middle" row cell value
467
494
  rescue Watir::Exception::UnknownObjectException
468
495
  found = nil
469
496
  end
470
- else # finding by String or Regexp
471
- search_in_index = table.header_value.index(where.keys.first)
472
- t.rows.each{|r|
473
- if search_value.is_a? String
474
- begin
475
- found = r.cells[search_for_index] if r.cells[search_in_index].text == search_value
476
- rescue Watir::Exception::UnknownObjectException
477
- found = nil
478
- end
479
- elsif search_value.is_a? Regexp
480
- begin
481
- found = r.cells[search_for_index] if search_value.match(r.cells[search_in_index].text)
482
- rescue Watir::Exception::UnknownObjectException
483
- found = nil
484
- end
485
- else
486
- raise ArgumentError, "#{search_value} not a Regexp or String"
487
- end
488
- }
489
497
  end
490
- else # where == nil
491
- begin
492
- found = t.rows[t.rows.length/2].cells[search_for_index] # returning some "middle" row cell value
493
- rescue Watir::Exception::UnknownObjectException
494
- found = nil
498
+
499
+ if not next_page.nil?
500
+ if not found.nil?
501
+ return PageObject.find_page_object(next_page)
502
+ else
503
+ return nil
504
+ end
505
+ else # next_page == nil
506
+ return found
495
507
  end
496
508
  end
497
509
 
498
- if not next_page.nil?
499
- if not found.nil?
500
- return PageObject.find_page_object(next_page)
501
- else
502
- return nil
510
+ def run_each_subpage(p, opts=nil, &block)
511
+ raise PageObjectWrapper::BrowserNotFound if @@browser.nil? or not @@browser.exist?
512
+ limit = opts[:limit] if not opts.nil?
513
+ raise PageObjectWrapper::InvalidPagination, opts.inspect if limit < 0 if not limit.nil?
514
+
515
+ current_link = @@browser.instance_eval p.locator_value
516
+ raise PageObjectWrapper::InvalidPagination, p.locator_value+'; '+p.finds_value if not current_link.present?
517
+ current_page_number = p.finds_value.to_i
518
+ counter = 0
519
+
520
+ while current_link.present?
521
+ break if limit.is_a? Integer and counter >= limit
522
+ current_link.when_present.click
523
+ self.class.map_current_page self.label_value
524
+ current_link.wait_while_present # waiting for the page to load by waiting current_link to become inactive
525
+ block.call self
526
+ current_page_number += 1
527
+ current_link_locator = p.locator_value.gsub( p.finds_value.to_s, current_page_number.to_s )
528
+ current_link = @@browser.instance_eval current_link_locator
529
+ counter += 1
503
530
  end
504
- else # next_page == nil
505
- return found
506
531
  end
507
- end
508
-
509
- def run_each_subpage(p, opts=nil, &block)
510
- raise PageObjectWrapper::BrowserNotFound if @@browser.nil? or not @@browser.exist?
511
- limit = opts[:limit] if not opts.nil?
512
- raise PageObjectWrapper::InvalidPagination, opts.inspect if limit < 0 if not limit.nil?
513
-
514
- current_link = @@browser.instance_eval p.locator_value
515
- raise PageObjectWrapper::InvalidPagination, p.locator_value+'; '+p.finds_value if not current_link.present?
516
- current_page_number = p.finds_value.to_i
517
- counter = 0
518
532
 
519
- while current_link.present?
520
- break if limit.is_a? Integer and counter >= limit
521
- current_link.when_present.click
533
+ def open_subpage p, n, *args
534
+ raise PageObjectWrapper::BrowserNotFound if @@browser.nil? or not @@browser.exist?
535
+ pagination_link = @@browser.instance_eval p.locator_value
536
+ raise PageObjectWrapper::InvalidPagination, p.locator_value+'; '+p.finds_value if not pagination_link.present?
537
+ n_th_link_locator = p.locator_value.gsub( p.finds_value.to_s, n.to_s )
538
+ n_th_link = @@browser.instance_eval n_th_link_locator
539
+ n_th_link.when_present.click
522
540
  self.class.map_current_page self.label_value
523
- current_link.wait_while_present # waiting for the page to load by waiting current_link to become inactive
524
- block.call self
525
- current_page_number += 1
526
- current_link_locator = p.locator_value.gsub( p.finds_value.to_s, current_page_number.to_s )
527
- current_link = @@browser.instance_eval current_link_locator
528
- counter += 1
541
+ self
529
542
  end
530
- end
531
543
 
532
- def open_subpage p, n, *args
533
- raise PageObjectWrapper::BrowserNotFound if @@browser.nil? or not @@browser.exist?
534
- pagination_link = @@browser.instance_eval p.locator_value
535
- raise PageObjectWrapper::InvalidPagination, p.locator_value+'; '+p.finds_value if not pagination_link.present?
536
- n_th_link_locator = p.locator_value.gsub( p.finds_value.to_s, n.to_s )
537
- n_th_link = @@browser.instance_eval n_th_link_locator
538
- n_th_link.when_present.click
539
- self.class.map_current_page self.label_value
540
- self
541
- end
544
+ def press e
545
+ raise PageObjectWrapper::BrowserNotFound if @@browser.nil? or not @@browser.exist?
546
+ watir_element = PageObject.return_watir_element e
547
+ raise PageObjectWrapper::InvalidElement, "Element #{e.locator_value} not found in #{@@current_page}"\
548
+ if not watir_element.present?
549
+ raise PageObjectWrapper::InvalidElement, "Element #{e.locator_value} does not respond to #{e.press_action_value}"\
550
+ if not watir_element.respond_to? e.press_action_value
551
+ watir_element.when_present.send e.press_action_value
552
+ watir_element
553
+ end
542
554
 
543
- def press e
544
- raise PageObjectWrapper::BrowserNotFound if @@browser.nil? or not @@browser.exist?
545
- watir_element = PageObject.return_watir_element e
546
- raise PageObjectWrapper::InvalidElement, "Element #{e.locator_value} not found in #{@@current_page}"\
547
- if not watir_element.present?
548
- raise PageObjectWrapper::InvalidElement, "Element #{e.locator_value} does not respond to #{e.press_action_value}"\
549
- if not watir_element.respond_to? e.press_action_value
550
- watir_element.when_present.send e.press_action_value
551
- watir_element
552
- end
555
+ def labeled(ary)
556
+ ary.collect(&:label_value)
557
+ end
553
558
 
554
- def labeled(ary)
555
- ary.collect(&:label_value)
559
+ [:eset, :element, :table, :pagination, :action, :alias, :validator].each{|el|
560
+ PageObject.send :define_method, 'has_'+el.to_s+'?' do |label| # has_xxx?(label)
561
+ labeled(instance_variable_get("@#{el.to_s.pluralize}")).include?(label.to_sym)
562
+ end
563
+ PageObject.send :define_method, el.to_s+'_for' do |label| # xxx_for(label)
564
+ instance_variable_get("@#{el.to_s.pluralize}")[labeled(instance_variable_get("@#{el.to_s.pluralize}")).index(label.to_sym)]
565
+ end
566
+ }
556
567
  end
557
-
558
- [:eset, :element, :table, :pagination, :action, :alias, :validator].each{|el|
559
- PageObject.send :define_method, 'has_'+el.to_s+'?' do |label| # has_xxx?(label)
560
- labeled(instance_variable_get("@#{el.to_s.pluralize}")).include?(label.to_sym)
561
- end
562
- PageObject.send :define_method, el.to_s+'_for' do |label| # xxx_for(label)
563
- instance_variable_get("@#{el.to_s.pluralize}")[labeled(instance_variable_get("@#{el.to_s.pluralize}")).index(label.to_sym)]
564
- end
565
- }
566
568
  end