druid-ts 1.1.6 → 1.1.7
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.
- checksums.yaml +4 -4
- data/ChangeLog +68 -1
- data/Gemfile +1 -0
- data/cucumber.yml +1 -1
- data/features/audio.feature +33 -33
- 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/html/static_elements.html +2 -0
- data/features/multi_elements.feature +189 -0
- data/features/sample-app/sample_app.rb +5 -1
- data/features/step_definations/element_steps.rb +8 -0
- data/features/step_definations/form_steps.rb +2 -2
- data/features/step_definations/javasript_steps.rb +8 -2
- data/features/step_definations/multi_elements_steps.rb +118 -0
- data/features/support/persistent_browser.rb +44 -2
- data/features/support/targets/firefox14_osx.rb +5 -0
- data/features/support/targets/firefox14_windows7.rb +5 -0
- data/features/support/url_helper.rb +3 -1
- data/features/video.feature +51 -51
- data/lib/druid/accessors.rb +160 -287
- data/lib/druid/assist.rb +2 -2
- data/lib/druid/element_locators.rb +9 -1032
- data/lib/druid/elements/element.rb +7 -0
- data/lib/druid/locator_generator.rb +73 -0
- data/lib/druid/nested_elements.rb +50 -233
- data/lib/druid/page_factory.rb +7 -4
- data/lib/druid/version.rb +1 -1
- data/spec/druid/accessors_spec.rb +13 -2
- data/spec/druid/element_locators_spec.rb +5 -5
- data/spec/druid/elements/element_spec.rb +6 -0
- data/spec/druid/page_factory_spec.rb +10 -1
- metadata +10 -5
@@ -1,5 +1,35 @@
|
|
1
1
|
class MultiElementsPage
|
2
2
|
include Druid
|
3
|
+
|
4
|
+
divs(:the_divs, :class => 'div')
|
5
|
+
buttons(:the_buttons, :class => 'button')
|
6
|
+
text_fields(:the_text_fields, :class => 'textfield')
|
7
|
+
hidden_fields(:the_hidden_fields, :class => 'hiddenfield')
|
8
|
+
text_areas(:the_text_areas, :class => 'textarea')
|
9
|
+
select_lists(:the_select_lists, :class => 'selectlist')
|
10
|
+
links(:the_links, :class => 'link')
|
11
|
+
checkboxes(:the_checkboxes, :class => 'checkbox')
|
12
|
+
radio_buttons(:the_radio_buttons, :class => 'radio')
|
13
|
+
spans(:the_spans, :class => 'span')
|
14
|
+
tables(:the_tables, :class => 'table')
|
15
|
+
cells(:the_cells, :class => 'td')
|
16
|
+
images(:the_images, :class => 'image')
|
17
|
+
forms(:the_forms, :class => 'form')
|
18
|
+
list_items(:the_list_items, :class => 'li')
|
19
|
+
unordered_lists(:the_unordered_lists, :class => 'ul')
|
20
|
+
ordered_lists(:the_ordered_lists, :class => 'ol')
|
21
|
+
h1s(:the_h1s, :class => 'h1')
|
22
|
+
h2s(:the_h2s, :class => 'h2')
|
23
|
+
h3s(:the_h3s, :class => 'h3')
|
24
|
+
h4s(:the_h4s, :class => 'h4')
|
25
|
+
h5s(:the_h5s, :class => 'h5')
|
26
|
+
h6s(:the_h6s, :class => 'h6')
|
27
|
+
paragraphs(:the_paragraphs, :class => 'p')
|
28
|
+
labels(:the_labels, :class => 'label')
|
29
|
+
file_fields(:the_file_fields, :class => 'file_field_class')
|
30
|
+
divs(:block_divs) do |page|
|
31
|
+
page.div_elements(:class => 'div')
|
32
|
+
end
|
3
33
|
end
|
4
34
|
|
5
35
|
Given(/^I am on the multi elements page$/) do
|
@@ -402,3 +432,91 @@ end
|
|
402
432
|
When(/^I select all file fields using no identifier$/) do
|
403
433
|
@elements = @page.file_field_elements
|
404
434
|
end
|
435
|
+
|
436
|
+
When(/^I select the divs using the generated method$/) do
|
437
|
+
@elements = @page.the_divs_elements
|
438
|
+
end
|
439
|
+
|
440
|
+
When(/^I select the buttons using the generated method$/) do
|
441
|
+
@elements = @page.the_buttons_elements
|
442
|
+
end
|
443
|
+
|
444
|
+
When(/^I select the text field using the generated method$/) do
|
445
|
+
@elements = @page.the_text_fields_elements
|
446
|
+
end
|
447
|
+
|
448
|
+
When(/^I select the hidden fields using the generated method$/) do
|
449
|
+
@elements = @page.the_hidden_fields_elements
|
450
|
+
end
|
451
|
+
|
452
|
+
When(/^I select the text areas using the generated method$/) do
|
453
|
+
@elements = @page.the_text_areas_elements
|
454
|
+
end
|
455
|
+
|
456
|
+
When(/^I select the select lists using the generated method$/) do
|
457
|
+
@elements = @page.the_select_lists_elements
|
458
|
+
end
|
459
|
+
|
460
|
+
When(/^I select the links using the generated method$/) do
|
461
|
+
@elements = @page.the_links_elements
|
462
|
+
end
|
463
|
+
|
464
|
+
When(/^I select the check boxes using the generated method$/) do
|
465
|
+
@elements = @page.the_checkboxes_elements
|
466
|
+
end
|
467
|
+
|
468
|
+
When(/^I select the radio buttons using the generated method$/) do
|
469
|
+
@elements = @page.the_radio_buttons_elements
|
470
|
+
end
|
471
|
+
|
472
|
+
When(/^I select the spans using the generated method$/) do
|
473
|
+
@elements = @page.the_spans_elements
|
474
|
+
end
|
475
|
+
|
476
|
+
When(/^I select the tables using the generated method$/) do
|
477
|
+
@elements = @page.the_tables_elements
|
478
|
+
end
|
479
|
+
|
480
|
+
When(/^I select the cells using the generated method$/) do
|
481
|
+
@elements = @page.the_cells_elements
|
482
|
+
end
|
483
|
+
|
484
|
+
When(/^I select the images using the generated method$/) do
|
485
|
+
@elements = @page.the_images_elements
|
486
|
+
end
|
487
|
+
|
488
|
+
When(/^I select the forms using the generated method$/) do
|
489
|
+
@elements = @page.the_forms_elements
|
490
|
+
end
|
491
|
+
|
492
|
+
When(/^I select the list items using the generated method$/) do
|
493
|
+
@elements = @page.the_list_items_elements
|
494
|
+
end
|
495
|
+
|
496
|
+
When(/^I select the unordered lists using the generated method$/) do
|
497
|
+
@elements = @page.the_unordered_lists_elements
|
498
|
+
end
|
499
|
+
|
500
|
+
When(/^I select the ordered lists using the generated method$/) do
|
501
|
+
@elements = @page.the_ordered_lists_elements
|
502
|
+
end
|
503
|
+
|
504
|
+
When(/^I select the h(\d+)s using the generated method$/) do |num|
|
505
|
+
@elements = @page.send("the_h#{num.to_i}s_elements")
|
506
|
+
end
|
507
|
+
|
508
|
+
When(/^I select the paragraphs using the generated method$/) do
|
509
|
+
@elements = @page.the_paragraphs_elements
|
510
|
+
end
|
511
|
+
|
512
|
+
When(/^I select the labels using the generated method$/) do
|
513
|
+
@elements = @page.the_labels_elements
|
514
|
+
end
|
515
|
+
|
516
|
+
When(/^I select the file fields using the generated method$/) do
|
517
|
+
@elements = @page.the_file_fields_elements
|
518
|
+
end
|
519
|
+
|
520
|
+
When(/^I select the divs using a block$/) do
|
521
|
+
@elements = @page.block_divs_elements
|
522
|
+
end
|
@@ -1,10 +1,19 @@
|
|
1
|
+
require 'selenium/webdriver/remote/http/persistent'
|
2
|
+
|
1
3
|
module Druid
|
2
4
|
module PersistantBrowser
|
3
5
|
@@driver = false
|
4
6
|
def self.get_browser
|
5
7
|
if !@@driver
|
6
|
-
|
7
|
-
|
8
|
+
target = ENV['BROWSER']
|
9
|
+
target = 'firefox_local' unless target
|
10
|
+
|
11
|
+
if is_remote?(target)
|
12
|
+
require File.dirname(__FILE__) + "/targets/#{target}"
|
13
|
+
extend Target
|
14
|
+
end
|
15
|
+
|
16
|
+
@@driver = watir_browser(target) if ENV['DRIVER'] == 'WATIR'
|
8
17
|
end
|
9
18
|
@@driver
|
10
19
|
end
|
@@ -12,5 +21,38 @@ module Druid
|
|
12
21
|
def self.quit
|
13
22
|
@@driver.quit
|
14
23
|
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def self.is_remote?(target)
|
28
|
+
not target.include? 'local'
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.watir_browser(target)
|
32
|
+
if is_remote?(target)
|
33
|
+
Watir::Browser.new(:remote,
|
34
|
+
:http_client => client,
|
35
|
+
:url => url,
|
36
|
+
:desired_capabilities => desired_capabilities )
|
37
|
+
else
|
38
|
+
Watir::Browser.new :firefox
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.client
|
43
|
+
Selenium::WebDriver::Remote::Http::Persistent.new
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.capabilities(browser, version, platform, name)
|
47
|
+
caps = Selenium::WebDriver::Remote::Capabilities.send browser
|
48
|
+
caps.version = version
|
49
|
+
caps.platform = platform
|
50
|
+
caps[:name] = name
|
51
|
+
caps
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.url
|
55
|
+
"http://pageobject:18002ee8-963b-472e-9425-2baf0a2b6d95@ondemand.saucelabs.com:80/wd/hub"
|
56
|
+
end
|
15
57
|
end
|
16
58
|
end
|
data/features/video.feature
CHANGED
@@ -1,54 +1,54 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
1
|
+
Feature: Support for video element
|
2
|
+
|
3
|
+
Background:
|
4
|
+
Given I am on the static elements page
|
5
|
+
|
6
|
+
Scenario: Finding an video element
|
7
|
+
When I retrieve the video element
|
8
|
+
Then I should know it exists
|
9
|
+
And I should know it is visible
|
10
|
+
|
11
|
+
Scenario Outline: Locating a video element on the page
|
12
|
+
When I search for the video element by "<search_by>"
|
13
|
+
Then I should know it is visible
|
14
|
+
|
15
|
+
Examples:
|
16
|
+
| search_by |
|
17
|
+
| id |
|
18
|
+
| class |
|
19
|
+
| name |
|
20
|
+
| xpath |
|
21
|
+
| index |
|
22
|
+
|
23
|
+
Scenario Outline: Locating videos using multiple parameters
|
24
|
+
When I search for the video element by "<param1>" and "<param2>"
|
25
|
+
Then I should know it is visible
|
26
|
+
|
27
|
+
Examples:
|
28
|
+
| param1 | param2 |
|
29
|
+
| class | index |
|
30
|
+
| name | index |
|
31
|
+
|
32
|
+
Scenario Outline: Locating videos using multiple parameters
|
33
|
+
When I search for the video element by "<param1>" and "<param2>"
|
34
|
+
Then I should know it is visible
|
35
|
+
|
36
|
+
Examples:
|
37
|
+
| param1 | param2 |
|
38
|
+
| class | index |
|
39
|
+
| name | index |
|
40
|
+
|
41
|
+
Scenario: Should know if it is autoplay
|
42
|
+
When I retrieve the video element
|
43
|
+
Then I should know the video is not autoplay
|
44
|
+
|
45
|
+
Scenario: Should know if the controls are displayed
|
46
|
+
When I retrieve the video element
|
47
|
+
Then I should know that the controls are displayed
|
48
|
+
|
49
|
+
Scenario: Should know if it is paused
|
50
|
+
When I retrieve the video element
|
51
|
+
Then I should know that the video is paused
|
52
52
|
|
53
53
|
#Scenario: Should know its duration
|
54
54
|
# When I retrieve the video element
|
data/lib/druid/accessors.rb
CHANGED
@@ -58,8 +58,9 @@ module Druid
|
|
58
58
|
#
|
59
59
|
def expected_title(expected_title)
|
60
60
|
define_method("has_expected_title?") do
|
61
|
-
|
62
|
-
|
61
|
+
page_title = title
|
62
|
+
has_expected_title = (expected_title === page_title)
|
63
|
+
raise "Expected title '#{expected_title}' instead of '#{page_title}'" unless has_expected_title
|
63
64
|
has_expected_title
|
64
65
|
end
|
65
66
|
end
|
@@ -75,7 +76,7 @@ module Druid
|
|
75
76
|
# expected_element(:address, 10)
|
76
77
|
# page.has_expected_element?
|
77
78
|
#
|
78
|
-
def expected_element(element_name, timeout=
|
79
|
+
def expected_element(element_name, timeout=Druid.default_element_wait)
|
79
80
|
define_method("has_expected_element?") do
|
80
81
|
self.respond_to? "#{element_name}_element" and self.send("#{element_name}_element").when_present timeout
|
81
82
|
end
|
@@ -156,16 +157,7 @@ module Druid
|
|
156
157
|
return click_link_for identifier.clone unless block_given?
|
157
158
|
self.send("#{name}_element").click
|
158
159
|
end
|
159
|
-
|
160
|
-
return call_block(&block) if block_given?
|
161
|
-
link_for(identifier.clone)
|
162
|
-
# block ? call_block(&block) : link_for(identifier.clone)
|
163
|
-
end
|
164
|
-
define_method("#{name}?") do
|
165
|
-
return call_block(&block).exist? if block_given?
|
166
|
-
link_for(identifier.clone).exist?
|
167
|
-
end
|
168
|
-
alias_method "#{name}_link".to_sym, "#{name}_element".to_sym
|
160
|
+
standard_methods(name, identifier, 'link_for', &block)
|
169
161
|
end
|
170
162
|
|
171
163
|
alias_method :a, :link
|
@@ -203,16 +195,7 @@ module Druid
|
|
203
195
|
return text_field_value_set(identifier.clone, value) unless block_given?
|
204
196
|
self.send("#{name}_element").value = value
|
205
197
|
end
|
206
|
-
|
207
|
-
return call_block(&block) if block_given?
|
208
|
-
text_field_for(identifier.clone)
|
209
|
-
# block ? call_block(&block) : text_field_for(identifier.clone)
|
210
|
-
end
|
211
|
-
define_method("#{name}?") do
|
212
|
-
return call_block(&block).exist? if block_given?
|
213
|
-
text_field_for(identifier.clone).exist?
|
214
|
-
end
|
215
|
-
alias_method "#{name}_text_field".to_sym, "#{name}_element".to_sym
|
198
|
+
standard_methods(name, identifier, 'text_field_for', &block)
|
216
199
|
end
|
217
200
|
|
218
201
|
#
|
@@ -250,27 +233,19 @@ module Druid
|
|
250
233
|
return checkbox_checked? identifier.clone unless block_given?
|
251
234
|
self.send("#{name}_element").checked?
|
252
235
|
end
|
253
|
-
|
254
|
-
return call_block(&block) if block_given?
|
255
|
-
checkbox_for(identifier.clone)
|
256
|
-
# block ? call_block(&block) : checkbox_for(identifier.clone)
|
257
|
-
end
|
258
|
-
define_method("#{name}?") do
|
259
|
-
return call_block(&block).exist? if block_given?
|
260
|
-
checkbox_for(identifier.clone).exist?
|
261
|
-
end
|
262
|
-
alias_method "#{name}_checkbox".to_sym, "#{name}_element".to_sym
|
236
|
+
standard_methods(name, identifier, 'checkbox_for', &block)
|
263
237
|
end
|
264
238
|
|
265
239
|
#
|
266
|
-
# adds
|
240
|
+
# adds five methods - one to select an item in a drop-down,
|
267
241
|
# another to fetch the currently selected item text, another
|
268
242
|
# to retrieve the select list element, and another to check the
|
269
|
-
# drop down's existence
|
243
|
+
# drop down's existence and another to get all the available options
|
244
|
+
# to select from
|
270
245
|
#
|
271
246
|
# @example
|
272
247
|
# select_list(:state, :id => "state")
|
273
|
-
# # will generate 'state', 'state=', 'state_element', 'state?' methods
|
248
|
+
# # will generate 'state', 'state=', 'state_element', 'state?', 'state_options' methods
|
274
249
|
#
|
275
250
|
# @param [Symbol] the name used for the generated methods
|
276
251
|
# @param [Hash] identifier how we find a select_list. You can use a multiple parameters
|
@@ -291,16 +266,11 @@ module Druid
|
|
291
266
|
return select_list_value_set(identifier.clone, value) unless block_given?
|
292
267
|
self.send("#{name}_element").select(value)
|
293
268
|
end
|
294
|
-
define_method("#{name}
|
295
|
-
|
296
|
-
|
297
|
-
# block ? call_block(&block) : select_list_for(identifier.clone)
|
298
|
-
end
|
299
|
-
define_method("#{name}?") do
|
300
|
-
return call_block(&block).exist? if block_given?
|
301
|
-
select_list_for(identifier.clone).exist?
|
269
|
+
define_method("#{name}_options") do
|
270
|
+
element = self.send("#{name}_element")
|
271
|
+
(element && element.options) ? element.options.collect(&:text) : []
|
302
272
|
end
|
303
|
-
|
273
|
+
standard_methods(name, identifier, 'select_list_for', &block)
|
304
274
|
end
|
305
275
|
alias_method :select, :select_list
|
306
276
|
|
@@ -340,16 +310,7 @@ module Druid
|
|
340
310
|
return radio_selected? identifier.clone unless block_given?
|
341
311
|
self.send("#{name}_element").selected?
|
342
312
|
end
|
343
|
-
|
344
|
-
return call_block(&block) if block_given?
|
345
|
-
radio_button_for(identifier.clone)
|
346
|
-
# block ? call_block(&block) : radio_button_for(identifier.clone)
|
347
|
-
end
|
348
|
-
define_method("#{name}?") do
|
349
|
-
return call_block(&block).exist? if block_given?
|
350
|
-
radio_button_for(identifier.clone).exist?
|
351
|
-
end
|
352
|
-
alias_method "#{name}_radio_button".to_sym, "#{name}_element".to_sym
|
313
|
+
standard_methods(name, identifier, 'radio_button_for', &block)
|
353
314
|
end
|
354
315
|
alias_method :radio, :radio_button
|
355
316
|
|
@@ -380,16 +341,7 @@ module Druid
|
|
380
341
|
return click_button_for identifier.clone unless block_given?
|
381
342
|
self.send("#{name}_element").click
|
382
343
|
end
|
383
|
-
|
384
|
-
return call_block(&block) if block_given?
|
385
|
-
button_for(identifier.clone)
|
386
|
-
# block ? call_block(&block) : button_for(identifier.clone)
|
387
|
-
end
|
388
|
-
define_method("#{name}?") do
|
389
|
-
return call_block(&block).exist? if block_given?
|
390
|
-
button_for(identifier.clone).exist?
|
391
|
-
end
|
392
|
-
alias_method "#{name}_button".to_sym, "#{name}_element".to_sym
|
344
|
+
standard_methods(name, identifier, 'button_for', &block)
|
393
345
|
end
|
394
346
|
|
395
347
|
#
|
@@ -418,16 +370,7 @@ module Druid
|
|
418
370
|
return div_text_for identifier.clone unless block_given?
|
419
371
|
self.send("#{name}_element").text
|
420
372
|
end
|
421
|
-
|
422
|
-
return call_block(&block) if block_given?
|
423
|
-
div_for(identifier.clone)
|
424
|
-
# block ? call_block(&block) : div_for(identifier.clone)
|
425
|
-
end
|
426
|
-
define_method("#{name}?") do
|
427
|
-
return call_block(&block).exist? if block_given?
|
428
|
-
div_for(identifier.clone).exist?
|
429
|
-
end
|
430
|
-
alias_method "#{name}_div".to_sym, "#{name}_element".to_sym
|
373
|
+
standard_methods(name, identifier, 'div_for', &block)
|
431
374
|
end
|
432
375
|
|
433
376
|
#
|
@@ -454,16 +397,7 @@ module Druid
|
|
454
397
|
return table_text_for identifier.clone unless block_given?
|
455
398
|
self.send("#{name}_element").text
|
456
399
|
end
|
457
|
-
|
458
|
-
return call_block(&block) if block_given?
|
459
|
-
table_for(identifier.clone)
|
460
|
-
# block ? call_block(&block) : table_for(identifier.clone)
|
461
|
-
end
|
462
|
-
define_method("#{name}?") do
|
463
|
-
return call_block(&block).exist? if block_given?
|
464
|
-
table_for(identifier.clone).exist?
|
465
|
-
end
|
466
|
-
alias_method "#{name}_table".to_sym, "#{name}_element".to_sym
|
400
|
+
standard_methods(name, identifier, 'table_for', &block)
|
467
401
|
end
|
468
402
|
|
469
403
|
#
|
@@ -491,16 +425,7 @@ module Druid
|
|
491
425
|
return cell_text_for identifier.clone unless block_given?
|
492
426
|
self.send("#{name}_element").text
|
493
427
|
end
|
494
|
-
|
495
|
-
return call_block(&block) if block_given?
|
496
|
-
cell_for(identifier.clone)
|
497
|
-
# block ? call_block(&block) : cell_for(identifier.clone)
|
498
|
-
end
|
499
|
-
define_method("#{name}?") do
|
500
|
-
return call_block(&block).exist? if block_given?
|
501
|
-
cell_for(identifier.clone).exist?
|
502
|
-
end
|
503
|
-
alias_method "#{name}_cell".to_sym, "#{name}_element".to_sym
|
428
|
+
standard_methods(name, identifier, 'cell_for', &block)
|
504
429
|
end
|
505
430
|
alias_method :td, :cell
|
506
431
|
|
@@ -529,16 +454,7 @@ module Druid
|
|
529
454
|
return span_text_for identifier.clone unless block_given?
|
530
455
|
self.send("#{name}_element").text
|
531
456
|
end
|
532
|
-
|
533
|
-
return call_block(&block) if block_given?
|
534
|
-
span_for(identifier.clone)
|
535
|
-
# block ? call_block(&block) : span_for(identifier.clone)
|
536
|
-
end
|
537
|
-
define_method("#{name}?") do
|
538
|
-
return call_block(&block).exist? if block_given?
|
539
|
-
span_for(identifier.clone).exist?
|
540
|
-
end
|
541
|
-
alias_method "#{name}_span".to_sym, "#{name}_element".to_sym
|
457
|
+
standard_methods(name, identifier, 'span_for', &block)
|
542
458
|
end
|
543
459
|
|
544
460
|
#
|
@@ -562,16 +478,7 @@ module Druid
|
|
562
478
|
# @param optional block to be invoked when element method is called
|
563
479
|
#
|
564
480
|
def image(name, identifier={:index => 0}, &block)
|
565
|
-
|
566
|
-
return call_block(&block) if block_given?
|
567
|
-
image_for(identifier.clone)
|
568
|
-
# block ? call_block(&block) : image_for(identifier.clone)
|
569
|
-
end
|
570
|
-
define_method("#{name}?") do
|
571
|
-
return call_block(&block).exist? if block_given?
|
572
|
-
image_for(identifier.clone).exist?
|
573
|
-
end
|
574
|
-
alias_method "#{name}_image".to_sym, "#{name}_element".to_sym
|
481
|
+
standard_methods(name, identifier, 'image_for', &block)
|
575
482
|
end
|
576
483
|
alias_method :img, :image
|
577
484
|
|
@@ -595,16 +502,7 @@ module Druid
|
|
595
502
|
# @param optional block to be invoked when element method is called
|
596
503
|
#
|
597
504
|
def form(name, identifier={:index => 0}, &block)
|
598
|
-
|
599
|
-
return call_block(&block) if block_given?
|
600
|
-
form_for(identifier.clone)
|
601
|
-
# block ? call_block(&block) : form_for(identifier.clone)
|
602
|
-
end
|
603
|
-
define_method("#{name}?") do
|
604
|
-
return call_block(&block).exist? if block_given?
|
605
|
-
form_for(identifier.clone).exist?
|
606
|
-
end
|
607
|
-
alias_method "#{name}_form".to_sym, "#{name}_element".to_sym
|
505
|
+
standard_methods(name, identifier, 'form_for', &block)
|
608
506
|
end
|
609
507
|
|
610
508
|
#
|
@@ -629,20 +527,11 @@ module Druid
|
|
629
527
|
# @param optional block to be invoked when element method is called
|
630
528
|
#
|
631
529
|
def hidden_field(name, identifier={:index => 0}, &block)
|
632
|
-
define_method("#{name}_element") do
|
633
|
-
return call_block(&block) if block_given?
|
634
|
-
hidden_field_for(identifier.clone)
|
635
|
-
# block ? call_block(&block) : hidden_field_for(identifier.clone)
|
636
|
-
end
|
637
530
|
define_method(name) do
|
638
531
|
return hidden_field_value_for identifier.clone unless block_given?
|
639
532
|
self.send("#{name}_element").value
|
640
533
|
end
|
641
|
-
|
642
|
-
return call_block(&block).exist? if block_given?
|
643
|
-
hidden_field_for(identifier.clone).exist?
|
644
|
-
end
|
645
|
-
alias_method "#{name}_hidden_field".to_sym, "#{name}_element".to_sym
|
534
|
+
standard_methods(name, identifier, 'hidden_field_for', &block)
|
646
535
|
end
|
647
536
|
alias_method :hidden, :hidden_field
|
648
537
|
|
@@ -671,16 +560,7 @@ module Druid
|
|
671
560
|
return list_item_text_for identifier.clone unless block_given?
|
672
561
|
self.send("#{name}_element").text
|
673
562
|
end
|
674
|
-
|
675
|
-
return call_block(&block) if block_given?
|
676
|
-
list_item_for(identifier.clone)
|
677
|
-
# block ? call_block(&block) : list_item_for(identifier.clone)
|
678
|
-
end
|
679
|
-
define_method("#{name}?") do
|
680
|
-
return call_block(&block).exist? if block_given?
|
681
|
-
list_item_for(identifier.clone).exist?
|
682
|
-
end
|
683
|
-
alias_method "#{name}_list_item".to_sym, "#{name}_element".to_sym
|
563
|
+
standard_methods(name, identifier, 'list_item_for', &block)
|
684
564
|
end
|
685
565
|
alias_method :li, :list_item
|
686
566
|
|
@@ -708,16 +588,7 @@ module Druid
|
|
708
588
|
return ordered_list_text_for identifier.clone unless block_given?
|
709
589
|
self.send("#{name}_element").text
|
710
590
|
end
|
711
|
-
|
712
|
-
return call_block(&block) if block_given?
|
713
|
-
ordered_list_for(identifier.clone)
|
714
|
-
# block ? call_block(&block) : ordered_list_for(identifier.clone)
|
715
|
-
end
|
716
|
-
define_method("#{name}?") do
|
717
|
-
return call_block(&block).exist? if block_given?
|
718
|
-
ordered_list_for(identifier.clone).exist?
|
719
|
-
end
|
720
|
-
alias_method "#{name}_ordered_list".to_sym, "#{name}_element".to_sym
|
591
|
+
standard_methods(name, identifier, 'ordered_list_for', &block)
|
721
592
|
end
|
722
593
|
alias_method :ol, :ordered_list
|
723
594
|
|
@@ -750,16 +621,7 @@ module Druid
|
|
750
621
|
return text_area_value_for identifier.clone unless block_given?
|
751
622
|
self.send("#{name}_element").value
|
752
623
|
end
|
753
|
-
|
754
|
-
return call_block(&block) if block_given?
|
755
|
-
text_area_for(identifier.clone)
|
756
|
-
# block ? call_block(&block) : text_area_for(identifier.clone)
|
757
|
-
end
|
758
|
-
define_method("#{name}?") do
|
759
|
-
return call_block(&block).exist? if block_given?
|
760
|
-
text_area_for(identifier.clone).exist?
|
761
|
-
end
|
762
|
-
alias_method "#{name}_text_area".to_sym, "#{name}_element".to_sym
|
624
|
+
standard_methods(name, identifier, 'text_area_for', &block)
|
763
625
|
end
|
764
626
|
alias_method :textarea, :text_area
|
765
627
|
|
@@ -785,16 +647,7 @@ module Druid
|
|
785
647
|
return unordered_list_text_for identifier.clone unless block_given?
|
786
648
|
self.send("#{name}_element").text
|
787
649
|
end
|
788
|
-
|
789
|
-
return call_block(&block) if block_given?
|
790
|
-
unordered_list_for(identifier.clone)
|
791
|
-
# block ? call_block(&block) : unordered_list_for(identifier.clone)
|
792
|
-
end
|
793
|
-
define_method("#{name}?") do
|
794
|
-
return call_block(&block).exist? if block_given?
|
795
|
-
unordered_list_for(identifier.clone).exist?
|
796
|
-
end
|
797
|
-
alias_method "#{name}_unordered_list".to_sym, "#{name}_element".to_sym
|
650
|
+
standard_methods(name, identifier, 'unordered_list_for', &block)
|
798
651
|
end
|
799
652
|
alias_method :ul, :unordered_list
|
800
653
|
|
@@ -821,15 +674,7 @@ module Druid
|
|
821
674
|
return h1_text_for identifier.clone unless block_given?
|
822
675
|
self.send("#{name}_element").text
|
823
676
|
end
|
824
|
-
|
825
|
-
return call_block(&block) if block_given?
|
826
|
-
h1_for(identifier.clone)
|
827
|
-
end
|
828
|
-
define_method("#{name}?") do
|
829
|
-
return call_block(&block).exist? if block_given?
|
830
|
-
h1_for(identifier.clone).exist?
|
831
|
-
end
|
832
|
-
alias_method "#{name}_h1".to_sym, "#{name}_element".to_sym
|
677
|
+
standard_methods(name, identifier, 'h1_for', &block)
|
833
678
|
end
|
834
679
|
|
835
680
|
#
|
@@ -855,15 +700,7 @@ module Druid
|
|
855
700
|
return h2_text_for identifier.clone unless block_given?
|
856
701
|
self.send("#{name}_element").text
|
857
702
|
end
|
858
|
-
|
859
|
-
return call_block(&block) if block_given?
|
860
|
-
h2_for(identifier.clone)
|
861
|
-
end
|
862
|
-
define_method("#{name}?") do
|
863
|
-
return call_block(&block).exist? if block_given?
|
864
|
-
h2_for(identifier.clone).exist?
|
865
|
-
end
|
866
|
-
alias_method "#{name}_h2".to_sym, "#{name}_element".to_sym
|
703
|
+
standard_methods(name, identifier, 'h2_for', &block)
|
867
704
|
end
|
868
705
|
|
869
706
|
#
|
@@ -889,15 +726,7 @@ module Druid
|
|
889
726
|
return h3_text_for identifier.clone unless block_given?
|
890
727
|
self.send("#{name}_element").text
|
891
728
|
end
|
892
|
-
|
893
|
-
return call_block(&block) if block_given?
|
894
|
-
h3_for(identifier.clone)
|
895
|
-
end
|
896
|
-
define_method("#{name}?") do
|
897
|
-
return call_block(&block).exist? if block_given?
|
898
|
-
h3_for(identifier.clone).exist?
|
899
|
-
end
|
900
|
-
alias_method "#{name}_h3".to_sym, "#{name}_element".to_sym
|
729
|
+
standard_methods(name, identifier, 'h3_for', &block)
|
901
730
|
end
|
902
731
|
|
903
732
|
#
|
@@ -923,15 +752,7 @@ module Druid
|
|
923
752
|
return h4_text_for identifier.clone unless block_given?
|
924
753
|
self.send("#{name}_element").text
|
925
754
|
end
|
926
|
-
|
927
|
-
return call_block(&block) if block_given?
|
928
|
-
h4_for(identifier.clone)
|
929
|
-
end
|
930
|
-
define_method("#{name}?") do
|
931
|
-
return call_block(&block).exist? if block_given?
|
932
|
-
h4_for(identifier.clone).exist?
|
933
|
-
end
|
934
|
-
alias_method "#{name}_h4".to_sym, "#{name}_element".to_sym
|
755
|
+
standard_methods(name, identifier, 'h4_for', &block)
|
935
756
|
end
|
936
757
|
|
937
758
|
#
|
@@ -957,15 +778,7 @@ module Druid
|
|
957
778
|
return h5_text_for identifier.clone unless block_given?
|
958
779
|
self.send("#{name}_element").text
|
959
780
|
end
|
960
|
-
|
961
|
-
return call_block(&block) if block_given?
|
962
|
-
h5_for(identifier.clone)
|
963
|
-
end
|
964
|
-
define_method("#{name}?") do
|
965
|
-
return call_block(&block).exist? if block_given?
|
966
|
-
h5_for(identifier.clone).exist?
|
967
|
-
end
|
968
|
-
alias_method "#{name}_h5".to_sym, "#{name}_element".to_sym
|
781
|
+
standard_methods(name, identifier, 'h5_for', &block)
|
969
782
|
end
|
970
783
|
|
971
784
|
#
|
@@ -991,15 +804,7 @@ module Druid
|
|
991
804
|
return h6_text_for identifier.clone unless block_given?
|
992
805
|
self.send("#{name}_element").text
|
993
806
|
end
|
994
|
-
|
995
|
-
return call_block(&block) if block_given?
|
996
|
-
h6_for(identifier.clone)
|
997
|
-
end
|
998
|
-
define_method("#{name}?") do
|
999
|
-
return call_block(&block).exist? if block_given?
|
1000
|
-
h6_for(identifier.clone).exist?
|
1001
|
-
end
|
1002
|
-
alias_method "#{name}_h6".to_sym, "#{name}_element".to_sym
|
807
|
+
standard_methods(name, identifier, 'h6_for', &block)
|
1003
808
|
end
|
1004
809
|
|
1005
810
|
#
|
@@ -1025,15 +830,7 @@ module Druid
|
|
1025
830
|
return paragraph_text_for identifier.clone unless block_given?
|
1026
831
|
self.send("#{name}_element").text
|
1027
832
|
end
|
1028
|
-
|
1029
|
-
return call_block(&block) if block_given?
|
1030
|
-
paragraph_for(identifier.clone)
|
1031
|
-
end
|
1032
|
-
define_method("#{name}?") do
|
1033
|
-
return call_block(&block).exist? if block_given?
|
1034
|
-
paragraph_for(identifier.clone).exist?
|
1035
|
-
end
|
1036
|
-
alias_method "#{name}_paragraph".to_sym, "#{name}_element".to_sym
|
833
|
+
standard_methods(name, identifier, 'paragraph_for', &block)
|
1037
834
|
end
|
1038
835
|
alias_method :p, :paragraph
|
1039
836
|
|
@@ -1061,14 +858,7 @@ module Druid
|
|
1061
858
|
return file_field_value_set(identifier.clone, value) unless block_given?
|
1062
859
|
self.send("#{name}_element").value = value
|
1063
860
|
end
|
1064
|
-
|
1065
|
-
return call_block(&block) if block_given?
|
1066
|
-
file_field_for(identifier.clone)
|
1067
|
-
end
|
1068
|
-
define_method("#{name}?") do
|
1069
|
-
return call_block(&block).exist? if block_given?
|
1070
|
-
file_field_for(identifier.clone).exist?
|
1071
|
-
end
|
861
|
+
standard_methods(name, identifier, 'file_field_for', &block)
|
1072
862
|
end
|
1073
863
|
|
1074
864
|
#
|
@@ -1095,15 +885,7 @@ module Druid
|
|
1095
885
|
return label_text_for identifier.clone unless block_given?
|
1096
886
|
self.send("#{name}_element").text
|
1097
887
|
end
|
1098
|
-
|
1099
|
-
return call_block(&block) if block_given?
|
1100
|
-
label_for(identifier.clone)
|
1101
|
-
end
|
1102
|
-
define_method("#{name}?") do
|
1103
|
-
return call_block(&block).exist? if block_given?
|
1104
|
-
label_for(identifier.clone).exist?
|
1105
|
-
end
|
1106
|
-
alias_method "#{name}_label".to_sym, "#{name}_element".to_sym
|
888
|
+
standard_methods(name, identifier, 'label_for', &block)
|
1107
889
|
end
|
1108
890
|
|
1109
891
|
#
|
@@ -1130,14 +912,7 @@ module Druid
|
|
1130
912
|
return click_area_for identifier.clone unless block_given?
|
1131
913
|
self.send("#{name}_element").click
|
1132
914
|
end
|
1133
|
-
|
1134
|
-
return call_block(&block) if block_given?
|
1135
|
-
area_for(identifier.clone)
|
1136
|
-
end
|
1137
|
-
define_method("#{name}?") do
|
1138
|
-
return call_block(&block).exist? if block_given?
|
1139
|
-
area_for(identifier.clone).exist?
|
1140
|
-
end
|
915
|
+
standard_methods(name, identifier, 'area_for', &block)
|
1141
916
|
end
|
1142
917
|
|
1143
918
|
#
|
@@ -1159,14 +934,7 @@ module Druid
|
|
1159
934
|
# @param optional block to be invoked when element method is called
|
1160
935
|
#
|
1161
936
|
def canvas(name, identifier={:index => 0}, &block)
|
1162
|
-
|
1163
|
-
return call_block(&block) if block_given?
|
1164
|
-
canvas_for(identifier.clone)
|
1165
|
-
end
|
1166
|
-
define_method("#{name}?") do
|
1167
|
-
return call_block(&block).exist? if block_given?
|
1168
|
-
canvas_for(identifier.clone).exist?
|
1169
|
-
end
|
937
|
+
standard_methods(name, identifier, 'canvas_for', &block)
|
1170
938
|
end
|
1171
939
|
|
1172
940
|
#
|
@@ -1188,14 +956,7 @@ module Druid
|
|
1188
956
|
# @param optional block to be invoked when element method is called
|
1189
957
|
#
|
1190
958
|
def audio(name, identifier={:index => 0}, &block)
|
1191
|
-
|
1192
|
-
return call_block(&block) if block_given?
|
1193
|
-
audio_for(identifier.clone)
|
1194
|
-
end
|
1195
|
-
define_method("#{name}?") do
|
1196
|
-
return call_block(&block).exist? if block_given?
|
1197
|
-
audio_for(identifier.clone).exist?
|
1198
|
-
end
|
959
|
+
standard_methods(name, identifier, 'audio_for', &block)
|
1199
960
|
end
|
1200
961
|
|
1201
962
|
#
|
@@ -1217,14 +978,7 @@ module Druid
|
|
1217
978
|
# @param optional block to be invoked when element method is called
|
1218
979
|
#
|
1219
980
|
def video(name, identifier={:index => 0}, &block)
|
1220
|
-
|
1221
|
-
return call_block(&block) if block_given?
|
1222
|
-
video_for(identifier.clone)
|
1223
|
-
end
|
1224
|
-
define_method("#{name}?") do
|
1225
|
-
return call_block(&block).exist? if block_given?
|
1226
|
-
video_for(identifier.clone).exist?
|
1227
|
-
end
|
981
|
+
standard_methods(name, identifier, 'video_for', &block)
|
1228
982
|
end
|
1229
983
|
|
1230
984
|
#
|
@@ -1257,5 +1011,124 @@ module Druid
|
|
1257
1011
|
self.send("#{name}_element").exist?
|
1258
1012
|
end
|
1259
1013
|
end
|
1014
|
+
|
1015
|
+
#
|
1016
|
+
# methods to generate accessors for types that follow the same
|
1017
|
+
# pattern as element
|
1018
|
+
#
|
1019
|
+
# @example
|
1020
|
+
# address(:home_address, :id => "home_address")
|
1021
|
+
# will generate 'home_address', 'home_address_element' and 'home_address?'
|
1022
|
+
#
|
1023
|
+
# @param [Symbol] the name used for the generated methods
|
1024
|
+
# @param [Symbol] the name of the tag for the element
|
1025
|
+
# @param [Hash] identifier how we find an element. You can use a multiple paramaters
|
1026
|
+
# by combining of any of the following except xpath. The valid keys are:
|
1027
|
+
# * :class
|
1028
|
+
# * :css
|
1029
|
+
# * :id
|
1030
|
+
# * :index
|
1031
|
+
# * :name
|
1032
|
+
# * :xpath
|
1033
|
+
# @param optional block to be invoked when element method is called
|
1034
|
+
#
|
1035
|
+
[:abbr,
|
1036
|
+
:address,
|
1037
|
+
:article,
|
1038
|
+
:aside,
|
1039
|
+
:bdi,
|
1040
|
+
:bdo,
|
1041
|
+
:cite,
|
1042
|
+
:code,
|
1043
|
+
:dd,
|
1044
|
+
:dfn,
|
1045
|
+
:dt,
|
1046
|
+
:em,
|
1047
|
+
:figcaption,
|
1048
|
+
:figure,
|
1049
|
+
:footer,
|
1050
|
+
:header,
|
1051
|
+
:hgroup,
|
1052
|
+
:kbd,
|
1053
|
+
:mark,
|
1054
|
+
:nav,
|
1055
|
+
:noscript,
|
1056
|
+
:rp,
|
1057
|
+
:rt,
|
1058
|
+
:ruby,
|
1059
|
+
:samp,
|
1060
|
+
:section,
|
1061
|
+
:sub,
|
1062
|
+
:summary,
|
1063
|
+
:sup,
|
1064
|
+
:var,
|
1065
|
+
:wbr].each do |type|
|
1066
|
+
define_method(type) do |name, *identifier, &block|
|
1067
|
+
identifier = identifier[0] ? identifier[0] : {:index => 0}
|
1068
|
+
element(name, type, identifier, &block)
|
1069
|
+
end
|
1070
|
+
end
|
1071
|
+
|
1072
|
+
def standard_methods(name, identifier, method, &block)
|
1073
|
+
define_method("#{name}_element") do
|
1074
|
+
return call_block(&block) if block_given?
|
1075
|
+
self.send(method, identifier.clone)
|
1076
|
+
end
|
1077
|
+
define_method("#{name}?") do
|
1078
|
+
return call_block(&block).exist? if block_given?
|
1079
|
+
self.send(method, identifier.clone).exist?
|
1080
|
+
end
|
1081
|
+
end
|
1082
|
+
|
1083
|
+
#
|
1084
|
+
# methods to fetch multiple elements of the same type
|
1085
|
+
#
|
1086
|
+
# adds a method to the page objec to retrun all of the matching elements
|
1087
|
+
#
|
1088
|
+
# @example
|
1089
|
+
# text_fields(:first_name, :id => "first_name")
|
1090
|
+
# # will generate 'first_name_elements'
|
1091
|
+
#
|
1092
|
+
# @param [String] the name used for the generated methods
|
1093
|
+
# @param [Hash] identifier how we find a text field. You can use a multiple paramaters
|
1094
|
+
# by combining of any of the following except xpath. The valid
|
1095
|
+
# keys are the same ones supported by the standard methods.
|
1096
|
+
# @param optional block to be invoked when element method is called
|
1097
|
+
#
|
1098
|
+
[:text_fields,
|
1099
|
+
:hidden_fields,
|
1100
|
+
:text_areas,
|
1101
|
+
:select_lists,
|
1102
|
+
:links,
|
1103
|
+
:checkboxes,
|
1104
|
+
:radio_buttons,
|
1105
|
+
:buttons,
|
1106
|
+
:divs,
|
1107
|
+
:spans,
|
1108
|
+
:tables,
|
1109
|
+
:cells,
|
1110
|
+
:images,
|
1111
|
+
:forms,
|
1112
|
+
:list_items,
|
1113
|
+
:unordered_lists,
|
1114
|
+
:ordered_lists,
|
1115
|
+
:h1s,
|
1116
|
+
:h2s,
|
1117
|
+
:h3s,
|
1118
|
+
:h4s,
|
1119
|
+
:h5s,
|
1120
|
+
:h6s,
|
1121
|
+
:paragraphs,
|
1122
|
+
:labels,
|
1123
|
+
:file_fields].each do |method_name|
|
1124
|
+
define_method(method_name) do |name, *identifier, &block|
|
1125
|
+
define_method("#{name}_elements") do
|
1126
|
+
return call_block(&block) unless block.nil?
|
1127
|
+
platform_method = (method_name == :checkboxes) ? 'checkboxs_for' : "#{method_name.to_s}_for"
|
1128
|
+
self.send platform_method, identifier.first.clone
|
1129
|
+
end
|
1130
|
+
end
|
1131
|
+
end
|
1132
|
+
|
1260
1133
|
end
|
1261
1134
|
end
|