page-object-lds 0.0.1
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 +7 -0
- data/.gitignore +8 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +10 -0
- data/ChangeLog +799 -0
- data/Gemfile +13 -0
- data/Guardfile +20 -0
- data/LICENSE +20 -0
- data/README.md +111 -0
- data/Rakefile +35 -0
- data/cucumber.yml +10 -0
- data/features/area.feature +35 -0
- data/features/async.feature +30 -0
- data/features/audio.feature +68 -0
- data/features/bold.feature +21 -0
- data/features/button.feature +88 -0
- data/features/canvas.feature +37 -0
- data/features/check_box.feature +55 -0
- data/features/div.feature +45 -0
- data/features/element.feature +322 -0
- data/features/file_field.feature +40 -0
- data/features/form.feature +43 -0
- data/features/frames.feature +75 -0
- data/features/generic_elements.feature +29 -0
- data/features/gxt_table_extension.feature +24 -0
- data/features/headings.feature +97 -0
- data/features/hidden_field.feature +45 -0
- data/features/html/04-Death_Becomes_Fur.mp4 +0 -0
- data/features/html/04-Death_Becomes_Fur.oga +0 -0
- data/features/html/async.html +36 -0
- data/features/html/double_click.html +13 -0
- data/features/html/failure.html +8 -0
- data/features/html/frame_1.html +18 -0
- data/features/html/frame_2.html +16 -0
- data/features/html/frame_3.html +14 -0
- data/features/html/frames.html +12 -0
- data/features/html/hover.html +12 -0
- data/features/html/iframes.html +12 -0
- data/features/html/images/circle.png +0 -0
- data/features/html/images/img_pulpit.jpg +0 -0
- data/features/html/images/submit.gif +0 -0
- data/features/html/indexed_property.html +52 -0
- data/features/html/modal.html +17 -0
- data/features/html/modal_1.html +38 -0
- data/features/html/modal_2.html +27 -0
- data/features/html/movie.mp4 +0 -0
- data/features/html/movie.ogg +0 -0
- data/features/html/multi_elements.html +144 -0
- data/features/html/nested_elements.html +77 -0
- data/features/html/nested_frame_1.html +1 -0
- data/features/html/nested_frame_2.html +11 -0
- data/features/html/nested_frame_3.html +14 -0
- data/features/html/nested_frames.html +10 -0
- data/features/html/planets.gif +0 -0
- data/features/html/static_elements.html +205 -0
- data/features/html/success.html +8 -0
- data/features/html/sun.gif +0 -0
- data/features/html/sun.html +7 -0
- data/features/image.feature +50 -0
- data/features/indexed_property.feature +98 -0
- data/features/javascript.feature +28 -0
- data/features/label.feature +46 -0
- data/features/link.feature +52 -0
- data/features/list_item.feature +36 -0
- data/features/modal_dialog.feature +15 -0
- data/features/multi_elements.feature +492 -0
- data/features/nested_elements.feature +117 -0
- data/features/ordered_list.feature +56 -0
- data/features/page_level_actions.feature +90 -0
- data/features/paragraph.feature +35 -0
- data/features/radio_button.feature +58 -0
- data/features/radio_button_group.feature +29 -0
- data/features/sample-app/public/jquery-1.3.2.js +4376 -0
- data/features/sample-app/public/jquery.html +30 -0
- data/features/sample-app/public/prototype-1.6.0.3.js +4320 -0
- data/features/sample-app/public/prototype.html +35 -0
- data/features/sample-app/sample_app.rb +35 -0
- data/features/select_list.feature +86 -0
- data/features/span.feature +37 -0
- data/features/step_definitions/accessor_steps.rb +60 -0
- data/features/step_definitions/area_steps.rb +19 -0
- data/features/step_definitions/async_steps.rb +83 -0
- data/features/step_definitions/audio_steps.rb +27 -0
- data/features/step_definitions/bold_steps.rb +12 -0
- data/features/step_definitions/button_steps.rb +43 -0
- data/features/step_definitions/canvas_steps.rb +15 -0
- data/features/step_definitions/check_box_steps.rb +35 -0
- data/features/step_definitions/div_steps.rb +19 -0
- data/features/step_definitions/element_steps.rb +266 -0
- data/features/step_definitions/file_field_steps.rb +19 -0
- data/features/step_definitions/form_steps.rb +19 -0
- data/features/step_definitions/frames_steps.rb +159 -0
- data/features/step_definitions/generic_element_steps.rb +31 -0
- data/features/step_definitions/gxt_table_steps.rb +58 -0
- data/features/step_definitions/headings_steps.rb +12 -0
- data/features/step_definitions/hidden_field_steps.rb +27 -0
- data/features/step_definitions/image_steps.rb +27 -0
- data/features/step_definitions/indexed_property_steps.rb +129 -0
- data/features/step_definitions/javascript_steps.rb +53 -0
- data/features/step_definitions/label_steps.rb +19 -0
- data/features/step_definitions/link_steps.rb +40 -0
- data/features/step_definitions/list_item_steps.rb +19 -0
- data/features/step_definitions/modal_dialog_steps.rb +62 -0
- data/features/step_definitions/multi_elements_steps.rb +541 -0
- data/features/step_definitions/nested_elements_steps.rb +212 -0
- data/features/step_definitions/ordered_list_steps.rb +23 -0
- data/features/step_definitions/page_level_actions_steps.rb +135 -0
- data/features/step_definitions/page_traversal_steps.rb +4 -0
- data/features/step_definitions/paragraph_steps.rb +28 -0
- data/features/step_definitions/radio_button_group_steps.rb +36 -0
- data/features/step_definitions/radio_button_steps.rb +27 -0
- data/features/step_definitions/select_list_steps.rb +65 -0
- data/features/step_definitions/span_steps.rb +19 -0
- data/features/step_definitions/table_cell_steps.rb +15 -0
- data/features/step_definitions/table_steps.rb +70 -0
- data/features/step_definitions/text_area_steps.rb +35 -0
- data/features/step_definitions/text_field_steps.rb +35 -0
- data/features/step_definitions/unordered_list_steps.rb +23 -0
- data/features/step_definitions/video_steps.rb +45 -0
- data/features/support/ajax_text_environment.rb +26 -0
- data/features/support/env.rb +8 -0
- data/features/support/hooks.rb +8 -0
- data/features/support/page.rb +373 -0
- data/features/support/persistent_browser.rb +70 -0
- data/features/support/targets/firefox14_osx.rb +6 -0
- data/features/support/targets/firefox14_windows7.rb +6 -0
- data/features/support/url_helper.rb +57 -0
- data/features/table.feature +122 -0
- data/features/table_cell.feature +45 -0
- data/features/text_area.feature +51 -0
- data/features/text_field.feature +70 -0
- data/features/unordered_list.feature +56 -0
- data/features/video.feature +73 -0
- data/lib/page-object-lds.rb +421 -0
- data/lib/page-object/accessors.rb +1334 -0
- data/lib/page-object/core_ext/string.rb +5 -0
- data/lib/page-object/element_locators.rb +21 -0
- data/lib/page-object/elements/area.rb +31 -0
- data/lib/page-object/elements/audio.rb +9 -0
- data/lib/page-object/elements/bold.rb +11 -0
- data/lib/page-object/elements/button.rb +35 -0
- data/lib/page-object/elements/canvas.rb +23 -0
- data/lib/page-object/elements/check_box.rb +40 -0
- data/lib/page-object/elements/div.rb +19 -0
- data/lib/page-object/elements/element.rb +225 -0
- data/lib/page-object/elements/file_field.rb +41 -0
- data/lib/page-object/elements/form.rb +39 -0
- data/lib/page-object/elements/heading.rb +15 -0
- data/lib/page-object/elements/hidden_field.rb +22 -0
- data/lib/page-object/elements/image.rb +39 -0
- data/lib/page-object/elements/label.rb +19 -0
- data/lib/page-object/elements/link.rb +49 -0
- data/lib/page-object/elements/list_item.rb +19 -0
- data/lib/page-object/elements/media.rb +45 -0
- data/lib/page-object/elements/option.rb +10 -0
- data/lib/page-object/elements/ordered_list.rb +53 -0
- data/lib/page-object/elements/paragraph.rb +9 -0
- data/lib/page-object/elements/radio_button.rb +40 -0
- data/lib/page-object/elements/select_list.rb +45 -0
- data/lib/page-object/elements/span.rb +19 -0
- data/lib/page-object/elements/table.rb +82 -0
- data/lib/page-object/elements/table_cell.rb +28 -0
- data/lib/page-object/elements/table_row.rb +53 -0
- data/lib/page-object/elements/text_area.rb +41 -0
- data/lib/page-object/elements/text_field.rb +45 -0
- data/lib/page-object/elements/unordered_list.rb +54 -0
- data/lib/page-object/elements/video.rb +18 -0
- data/lib/page-object/indexed_properties.rb +36 -0
- data/lib/page-object/javascript/angularjs.rb +14 -0
- data/lib/page-object/javascript/jquery.rb +14 -0
- data/lib/page-object/javascript/prototype.rb +14 -0
- data/lib/page-object/javascript/yui.rb +19 -0
- data/lib/page-object/javascript_framework_facade.rb +80 -0
- data/lib/page-object/loads_platform.rb +26 -0
- data/lib/page-object/locator_generator.rb +130 -0
- data/lib/page-object/nested_elements.rb +17 -0
- data/lib/page-object/page_factory.rb +108 -0
- data/lib/page-object/page_populator.rb +83 -0
- data/lib/page-object/platforms.rb +19 -0
- data/lib/page-object/platforms/lds_watir_webdriver.rb +17 -0
- data/lib/page-object/platforms/lds_watir_webdriver/check_box.rb +29 -0
- data/lib/page-object/platforms/lds_watir_webdriver/element.rb +249 -0
- data/lib/page-object/platforms/lds_watir_webdriver/file_field.rb +16 -0
- data/lib/page-object/platforms/lds_watir_webdriver/form.rb +16 -0
- data/lib/page-object/platforms/lds_watir_webdriver/image.rb +22 -0
- data/lib/page-object/platforms/lds_watir_webdriver/link.rb +15 -0
- data/lib/page-object/platforms/lds_watir_webdriver/ordered_list.rb +35 -0
- data/lib/page-object/platforms/lds_watir_webdriver/page_object.rb +1044 -0
- data/lib/page-object/platforms/lds_watir_webdriver/radio_button.rb +22 -0
- data/lib/page-object/platforms/lds_watir_webdriver/select_list.rb +74 -0
- data/lib/page-object/platforms/lds_watir_webdriver/table.rb +38 -0
- data/lib/page-object/platforms/lds_watir_webdriver/table_row.rb +37 -0
- data/lib/page-object/platforms/lds_watir_webdriver/text_area.rb +23 -0
- data/lib/page-object/platforms/lds_watir_webdriver/text_field.rb +16 -0
- data/lib/page-object/platforms/lds_watir_webdriver/unordered_list.rb +36 -0
- data/lib/page-object/platforms/selenium_webdriver.rb +17 -0
- data/lib/page-object/platforms/selenium_webdriver/button.rb +15 -0
- data/lib/page-object/platforms/selenium_webdriver/check_box.rb +29 -0
- data/lib/page-object/platforms/selenium_webdriver/element.rb +291 -0
- data/lib/page-object/platforms/selenium_webdriver/file_field.rb +16 -0
- data/lib/page-object/platforms/selenium_webdriver/form.rb +16 -0
- data/lib/page-object/platforms/selenium_webdriver/image.rb +28 -0
- data/lib/page-object/platforms/selenium_webdriver/link.rb +23 -0
- data/lib/page-object/platforms/selenium_webdriver/ordered_list.rb +39 -0
- data/lib/page-object/platforms/selenium_webdriver/page_object.rb +1162 -0
- data/lib/page-object/platforms/selenium_webdriver/radio_button.rb +22 -0
- data/lib/page-object/platforms/selenium_webdriver/select_list.rb +93 -0
- data/lib/page-object/platforms/selenium_webdriver/surrogate_selenium_element.rb +42 -0
- data/lib/page-object/platforms/selenium_webdriver/table.rb +42 -0
- data/lib/page-object/platforms/selenium_webdriver/table_row.rb +43 -0
- data/lib/page-object/platforms/selenium_webdriver/text_area.rb +17 -0
- data/lib/page-object/platforms/selenium_webdriver/text_field.rb +17 -0
- data/lib/page-object/platforms/selenium_webdriver/unordered_list.rb +39 -0
- data/lib/page-object/platforms/watir_webdriver.rb +17 -0
- data/lib/page-object/platforms/watir_webdriver/check_box.rb +29 -0
- data/lib/page-object/platforms/watir_webdriver/element.rb +249 -0
- data/lib/page-object/platforms/watir_webdriver/file_field.rb +16 -0
- data/lib/page-object/platforms/watir_webdriver/form.rb +16 -0
- data/lib/page-object/platforms/watir_webdriver/image.rb +22 -0
- data/lib/page-object/platforms/watir_webdriver/link.rb +15 -0
- data/lib/page-object/platforms/watir_webdriver/ordered_list.rb +35 -0
- data/lib/page-object/platforms/watir_webdriver/page_object.rb +1044 -0
- data/lib/page-object/platforms/watir_webdriver/radio_button.rb +22 -0
- data/lib/page-object/platforms/watir_webdriver/select_list.rb +74 -0
- data/lib/page-object/platforms/watir_webdriver/table.rb +38 -0
- data/lib/page-object/platforms/watir_webdriver/table_row.rb +37 -0
- data/lib/page-object/platforms/watir_webdriver/text_area.rb +23 -0
- data/lib/page-object/platforms/watir_webdriver/text_field.rb +16 -0
- data/lib/page-object/platforms/watir_webdriver/unordered_list.rb +36 -0
- data/lib/page-object/version.rb +4 -0
- data/lib/page-object/widgets.rb +134 -0
- data/page-object-lds.gemspec +33 -0
- data/pageobject.gems +1 -0
- data/spec/page-object/accessors_spec.rb +40 -0
- data/spec/page-object/element_locators_spec.rb +1100 -0
- data/spec/page-object/elements/area_spec.rb +45 -0
- data/spec/page-object/elements/bold_spec.rb +29 -0
- data/spec/page-object/elements/button_spec.rb +50 -0
- data/spec/page-object/elements/canvas_spec.rb +40 -0
- data/spec/page-object/elements/check_box_spec.rb +49 -0
- data/spec/page-object/elements/div_spec.rb +28 -0
- data/spec/page-object/elements/element_spec.rb +114 -0
- data/spec/page-object/elements/file_field_spec.rb +39 -0
- data/spec/page-object/elements/form_spec.rb +28 -0
- data/spec/page-object/elements/heading_spec.rb +48 -0
- data/spec/page-object/elements/hidden_field_spec.rb +28 -0
- data/spec/page-object/elements/image_spec.rb +66 -0
- data/spec/page-object/elements/label_spec.rb +29 -0
- data/spec/page-object/elements/link_spec.rb +49 -0
- data/spec/page-object/elements/list_item_spec.rb +29 -0
- data/spec/page-object/elements/nested_element_spec.rb +254 -0
- data/spec/page-object/elements/option_spec.rb +11 -0
- data/spec/page-object/elements/ordered_list_spec.rb +94 -0
- data/spec/page-object/elements/paragraph_spec.rb +27 -0
- data/spec/page-object/elements/select_list_spec.rb +142 -0
- data/spec/page-object/elements/selenium/radio_button_spec.rb +44 -0
- data/spec/page-object/elements/selenium/text_field_spec.rb +49 -0
- data/spec/page-object/elements/selenium_element_spec.rb +172 -0
- data/spec/page-object/elements/span_spec.rb +26 -0
- data/spec/page-object/elements/table_cell_spec.rb +21 -0
- data/spec/page-object/elements/table_row_spec.rb +70 -0
- data/spec/page-object/elements/table_spec.rb +98 -0
- data/spec/page-object/elements/text_area_spec.rb +39 -0
- data/spec/page-object/elements/unordered_list_spec.rb +94 -0
- data/spec/page-object/elements/watir_element_spec.rb +141 -0
- data/spec/page-object/javascript_framework_facade_spec.rb +61 -0
- data/spec/page-object/loads_platform_spec.rb +53 -0
- data/spec/page-object/page-object_spec.rb +413 -0
- data/spec/page-object/page_factory_spec.rb +238 -0
- data/spec/page-object/page_populator_spec.rb +122 -0
- data/spec/page-object/platforms/selenium_webdriver/selenium_page_object_spec.rb +68 -0
- data/spec/page-object/platforms/selenium_webdriver_spec.rb +29 -0
- data/spec/page-object/platforms/watir_webdriver/watir_page_object_spec.rb +29 -0
- data/spec/page-object/platforms/watir_webdriver_spec.rb +9 -0
- data/spec/page-object/selenium_accessors_spec.rb +609 -0
- data/spec/page-object/watir_accessors_spec.rb +1134 -0
- data/spec/page-object/widget_spec.rb +226 -0
- data/spec/spec_helper.rb +44 -0
- metadata +430 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module PageObject
|
|
2
|
+
#
|
|
3
|
+
# module which provides a function for determining
|
|
4
|
+
# which platform to provide to the page object
|
|
5
|
+
#
|
|
6
|
+
module LoadsPlatform
|
|
7
|
+
#
|
|
8
|
+
# Determines which platform the Page Object should use based upon browser
|
|
9
|
+
#
|
|
10
|
+
# @example
|
|
11
|
+
# platform = load_platform(watir_webdriver_browser, PageObject.Adapters.list).send(:new, watir_webdriver_browser)
|
|
12
|
+
#
|
|
13
|
+
# @param [Object] A browser driver that has a supported adapter
|
|
14
|
+
# @param [adapters] a list of adapters that are currently supported
|
|
15
|
+
# @returns [PageObject]
|
|
16
|
+
#
|
|
17
|
+
def load_platform(browser, adapters)
|
|
18
|
+
adapters.each_value { |adapter|
|
|
19
|
+
return adapter.create_page_object(browser) if adapter.is_for?(browser)
|
|
20
|
+
}
|
|
21
|
+
message = 'Unable to pick a platform for the provided browser.'
|
|
22
|
+
message += "\nnil was passed to the PageObject constructor instead of a valid browser object." if browser.nil?
|
|
23
|
+
raise message
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
module PageObject
|
|
2
|
+
module LocatorGenerator
|
|
3
|
+
|
|
4
|
+
BASIC_ELEMENTS = [:abbr,
|
|
5
|
+
:address,
|
|
6
|
+
:article,
|
|
7
|
+
:as,
|
|
8
|
+
:aside,
|
|
9
|
+
:bdi,
|
|
10
|
+
:bdo,
|
|
11
|
+
:blockquote,
|
|
12
|
+
:body,
|
|
13
|
+
:br,
|
|
14
|
+
:caption,
|
|
15
|
+
:cite,
|
|
16
|
+
:code,
|
|
17
|
+
:col,
|
|
18
|
+
:colgroup,
|
|
19
|
+
:command,
|
|
20
|
+
:data,
|
|
21
|
+
:datalist,
|
|
22
|
+
:dd,
|
|
23
|
+
:del,
|
|
24
|
+
:details,
|
|
25
|
+
:dfn,
|
|
26
|
+
:dialog,
|
|
27
|
+
:dl,
|
|
28
|
+
:dt,
|
|
29
|
+
:em,
|
|
30
|
+
:embed,
|
|
31
|
+
:fieldset,
|
|
32
|
+
:figcaption,
|
|
33
|
+
:figure,
|
|
34
|
+
:footer,
|
|
35
|
+
:head,
|
|
36
|
+
:header,
|
|
37
|
+
:hgroup,
|
|
38
|
+
:hr,
|
|
39
|
+
:ins,
|
|
40
|
+
:kbd,
|
|
41
|
+
:keygen,
|
|
42
|
+
:legend,
|
|
43
|
+
:map,
|
|
44
|
+
:mark,
|
|
45
|
+
:menu,
|
|
46
|
+
:meta,
|
|
47
|
+
:meter,
|
|
48
|
+
:nav,
|
|
49
|
+
:noscript,
|
|
50
|
+
:object,
|
|
51
|
+
:optgroup,
|
|
52
|
+
:output,
|
|
53
|
+
:param,
|
|
54
|
+
:pre,
|
|
55
|
+
:progress,
|
|
56
|
+
:rp,
|
|
57
|
+
:rt,
|
|
58
|
+
:ruby,
|
|
59
|
+
:samp,
|
|
60
|
+
:section,
|
|
61
|
+
:small,
|
|
62
|
+
:strong,
|
|
63
|
+
:style,
|
|
64
|
+
:sub,
|
|
65
|
+
:summary,
|
|
66
|
+
:sup,
|
|
67
|
+
:time,
|
|
68
|
+
:title,
|
|
69
|
+
:track,
|
|
70
|
+
:var,
|
|
71
|
+
:wbr]
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
ADVANCED_ELEMENTS = [:text_field,
|
|
75
|
+
:hidden_field,
|
|
76
|
+
:text_area,
|
|
77
|
+
:select_list,
|
|
78
|
+
:link,
|
|
79
|
+
:checkbox,
|
|
80
|
+
:radio_button,
|
|
81
|
+
:button,
|
|
82
|
+
:div,
|
|
83
|
+
:span,
|
|
84
|
+
:table,
|
|
85
|
+
:cell,
|
|
86
|
+
:image,
|
|
87
|
+
:form,
|
|
88
|
+
:list_item,
|
|
89
|
+
:ordered_list,
|
|
90
|
+
:unordered_list,
|
|
91
|
+
:h1,
|
|
92
|
+
:h2,
|
|
93
|
+
:h3,
|
|
94
|
+
:h4,
|
|
95
|
+
:h5,
|
|
96
|
+
:h6,
|
|
97
|
+
:paragraph,
|
|
98
|
+
:label,
|
|
99
|
+
:file_field,
|
|
100
|
+
:area,
|
|
101
|
+
:canvas,
|
|
102
|
+
:audio,
|
|
103
|
+
:video,
|
|
104
|
+
:b,
|
|
105
|
+
:svg]
|
|
106
|
+
|
|
107
|
+
def self.generate_locators(target)
|
|
108
|
+
ADVANCED_ELEMENTS.each do |tag|
|
|
109
|
+
target.send(:define_method, "#{tag.to_s}_element") do |*identifier|
|
|
110
|
+
@platform.send "#{tag.to_s}_for", locator(identifier)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
target.send(:define_method, "#{tag.to_s}_elements") do |*identifier|
|
|
114
|
+
@platform.send("#{tag.to_s}s_for", identifier[0] ? identifier[0] : {})
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
BASIC_ELEMENTS.each do |tag|
|
|
119
|
+
target.send(:define_method, "#{tag.to_s}_element") do |*identifier|
|
|
120
|
+
@platform.send :element_for, tag, locator(identifier)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
target.send(:define_method, "#{tag.to_s}_elements") do |*identifier|
|
|
124
|
+
@platform.send(:elements_for, tag, identifier[0] ? identifier[0] : {})
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
end
|
|
130
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'page-object/locator_generator'
|
|
2
|
+
|
|
3
|
+
module PageObject
|
|
4
|
+
module NestedElements
|
|
5
|
+
|
|
6
|
+
def self.included(cls)
|
|
7
|
+
::PageObject::LocatorGenerator.generate_locators(cls)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
private
|
|
11
|
+
|
|
12
|
+
def locator(identifier)
|
|
13
|
+
identifier[0] ? identifier[0] : {:index => 0}
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
require 'page_navigation'
|
|
2
|
+
|
|
3
|
+
module PageObject
|
|
4
|
+
#
|
|
5
|
+
# Module to facilitate to creating of page objects in step definitions. You
|
|
6
|
+
# can make the methods below available to all of your step definitions by adding
|
|
7
|
+
# this module to World. This idea was first discussed in Alister Scott's blog
|
|
8
|
+
# entry http://watirmelon.com/2011/06/07/removing-local-page-references-from-cucumber-steps/.
|
|
9
|
+
#
|
|
10
|
+
# @example Making the PageFactory available to your step definitions
|
|
11
|
+
# World PageObject::PageFactory
|
|
12
|
+
#
|
|
13
|
+
# @example Visiting a page for the first time in a Scenario
|
|
14
|
+
# visit_page MyPageObject do |page|
|
|
15
|
+
# page.name = 'Cheezy'
|
|
16
|
+
# end
|
|
17
|
+
#
|
|
18
|
+
# @example using a page that has already been visited in a Scenario
|
|
19
|
+
# on_page MyPageObject do |page|
|
|
20
|
+
# page.name.should == 'Cheezy'
|
|
21
|
+
# end
|
|
22
|
+
#
|
|
23
|
+
# If you plan to use the navigate_to method you will need to ensure
|
|
24
|
+
# you setup the possible routes ahead of time. You must always have
|
|
25
|
+
# a default route in order for this to work. Here is an example of
|
|
26
|
+
# how you define routes:
|
|
27
|
+
#
|
|
28
|
+
# @example Example routes defined in env.rb
|
|
29
|
+
# PageObject::PageFactory.routes = {
|
|
30
|
+
# :default => [[PageOne,:method1], [PageTwoA,:method2], [PageThree,:method3]],
|
|
31
|
+
# :another_route => [[PageOne,:method1, "arg1"], [PageTwoB,:method2b], [PageThree,:method3]]
|
|
32
|
+
# }
|
|
33
|
+
#
|
|
34
|
+
# Notice the first entry of :another_route is passing an argument
|
|
35
|
+
# to the method.
|
|
36
|
+
#
|
|
37
|
+
module PageFactory
|
|
38
|
+
include PageNavigation
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
#
|
|
42
|
+
# Create and navigate to a page object. The navigation will only work if the
|
|
43
|
+
# 'page_url' method was call on the page object.
|
|
44
|
+
#
|
|
45
|
+
# @param [PageObject, String] a class that has included the
|
|
46
|
+
# PageObject module or a string containing the name of the class
|
|
47
|
+
# @param Hash values that is pass through to page class a
|
|
48
|
+
# available in the @params instance variable.
|
|
49
|
+
# @param an optional block to be called
|
|
50
|
+
# @return [PageObject] the newly created page object
|
|
51
|
+
#
|
|
52
|
+
def visit_page(page_class, params={:using_params => {}}, &block)
|
|
53
|
+
on_page page_class, params, true, &block
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Support 'visit' for readability of usage
|
|
57
|
+
alias_method :visit, :visit_page
|
|
58
|
+
|
|
59
|
+
#
|
|
60
|
+
# Create a page object.
|
|
61
|
+
#
|
|
62
|
+
# @param [PageObject, String] a class that has included the PageObject module or a string containing the name of the class
|
|
63
|
+
# @param Hash values that is pass through to page class a
|
|
64
|
+
# available in the @params instance variable.
|
|
65
|
+
# @param [Boolean] a boolean indicating if the page should be visited? default is false.
|
|
66
|
+
# @param [block] an optional block to be called
|
|
67
|
+
# @return [PageObject] the newly created page object
|
|
68
|
+
#
|
|
69
|
+
def on_page(page_class, params={:using_params => {}}, visit=false, &block)
|
|
70
|
+
page_class = class_from_string(page_class) if page_class.is_a? String
|
|
71
|
+
return super(page_class, params, visit, &block) unless page_class.ancestors.include? PageObject
|
|
72
|
+
merged = page_class.params.merge(params[:using_params])
|
|
73
|
+
page_class.instance_variable_set("@merged_params", merged) unless merged.empty?
|
|
74
|
+
@current_page = page_class.new(@browser, visit)
|
|
75
|
+
block.call @current_page if block
|
|
76
|
+
@current_page
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Support 'on' for readability of usage
|
|
80
|
+
alias_method :on, :on_page
|
|
81
|
+
|
|
82
|
+
#
|
|
83
|
+
# Create a page object if and only if the current page is the same page to be created
|
|
84
|
+
#
|
|
85
|
+
# @param [PageObject, String] a class that has included the PageObject module or a string containing the name of the class
|
|
86
|
+
# @param Hash values that is pass through to page class a
|
|
87
|
+
# available in the @params instance variable.
|
|
88
|
+
# @param [block] an optional block to be called
|
|
89
|
+
# @return [PageObject] the newly created page object
|
|
90
|
+
#
|
|
91
|
+
def if_page(page_class, params={:using_params => {}},&block)
|
|
92
|
+
page_class = class_from_string(page_class) if page_class.is_a? String
|
|
93
|
+
return @current_page unless @current_page.class == page_class
|
|
94
|
+
on_page(page_class, params, false, &block)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Support 'if' for readability of usage
|
|
98
|
+
alias_method :if, :if_page
|
|
99
|
+
|
|
100
|
+
private
|
|
101
|
+
|
|
102
|
+
def class_from_string(str)
|
|
103
|
+
str.split('::').inject(Object) do |mod, class_name|
|
|
104
|
+
mod.const_get(class_name)
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
module PageObject
|
|
2
|
+
module PagePopulator
|
|
3
|
+
|
|
4
|
+
#
|
|
5
|
+
# This method will populate all matched page TextFields,
|
|
6
|
+
# TextAreas, SelectLists, FileFields, Checkboxes, and Radio Buttons from the
|
|
7
|
+
# Hash passed as an argument. The way it find an element is by
|
|
8
|
+
# matching the Hash key to the name you provided when declaring
|
|
9
|
+
# the element on your page.
|
|
10
|
+
#
|
|
11
|
+
# Checkboxe and Radio Button values must be true or false.
|
|
12
|
+
#
|
|
13
|
+
# @example
|
|
14
|
+
# class ExamplePage
|
|
15
|
+
# include PageObject
|
|
16
|
+
#
|
|
17
|
+
# text_field(:username, :id => 'username_id')
|
|
18
|
+
# checkbox(:active, :id => 'active_id')
|
|
19
|
+
# end
|
|
20
|
+
#
|
|
21
|
+
# ...
|
|
22
|
+
#
|
|
23
|
+
# @browser = Watir::Browser.new :firefox
|
|
24
|
+
# example_page = ExamplePage.new(@browser)
|
|
25
|
+
# example_page.populate_page_with :username => 'a name', :active => true
|
|
26
|
+
#
|
|
27
|
+
# @param [Hash] the data to use to populate this page. The key
|
|
28
|
+
# can be either a string or a symbol. The value must be a string
|
|
29
|
+
# for TextField, TextArea, SelectList, and FileField and must be true or
|
|
30
|
+
# false for a Checkbox or RadioButton.
|
|
31
|
+
#
|
|
32
|
+
def populate_page_with(data)
|
|
33
|
+
data.each do |key, value|
|
|
34
|
+
populate_checkbox(key, value) if is_checkbox?(key) and is_enabled?(key)
|
|
35
|
+
populate_radiobuttongroup(key, value) if is_radiobuttongroup?(key)
|
|
36
|
+
populate_radiobutton(key, value) if is_radiobutton?(key) and is_enabled?(key)
|
|
37
|
+
populate_text(key, value) if is_text?(key) and is_enabled?(key)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
def populate_text(key, value)
|
|
44
|
+
self.send "#{key}=", value
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def populate_checkbox(key, value)
|
|
48
|
+
return self.send "check_#{key}" if value
|
|
49
|
+
return self.send "uncheck_#{key}"
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def populate_radiobutton(key, value)
|
|
53
|
+
return self.send "select_#{key}" if value
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def populate_radiobuttongroup(key, value)
|
|
57
|
+
return self.send("select_#{key}", value)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def is_text?(key)
|
|
61
|
+
respond_to?("#{key}=".to_sym)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def is_checkbox?(key)
|
|
65
|
+
respond_to?("check_#{key}".to_sym)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def is_radiobutton?(key)
|
|
69
|
+
respond_to?("select_#{key}".to_sym)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def is_radiobuttongroup?(key)
|
|
73
|
+
respond_to?("select_#{key}".to_sym) and respond_to?("#{key}_values")
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def is_enabled?(key)
|
|
77
|
+
return false if is_radiobuttongroup?(key)
|
|
78
|
+
return true if (self.send "#{key}_element").tag_name == "textarea"
|
|
79
|
+
element = self.send("#{key}_element")
|
|
80
|
+
element.enabled? and element.visible?
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'page-object/loads_platform'
|
|
2
|
+
|
|
3
|
+
module PageObject
|
|
4
|
+
module Platforms
|
|
5
|
+
@@adapters = {}
|
|
6
|
+
|
|
7
|
+
def self.get
|
|
8
|
+
@@adapters
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.register(key, adapter)
|
|
12
|
+
@@adapters[key] = adapter
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
require 'page-object/platforms/watir_webdriver'
|
|
17
|
+
require 'page-object/platforms/lds_watir_webdriver'
|
|
18
|
+
require 'page-object/platforms/selenium_webdriver'
|
|
19
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module PageObject
|
|
2
|
+
module Platforms
|
|
3
|
+
module LdsWatirWebDriver
|
|
4
|
+
|
|
5
|
+
def self.create_page_object(browser)
|
|
6
|
+
return LdsWatirWebDriver::PageObject.new(browser)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def self.is_for?(browser)
|
|
10
|
+
require 'watir-webdriver'
|
|
11
|
+
browser.is_a?(::Watir::Browser)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
PageObject::Platforms.register(:lds_watir_webdriver, PageObject::Platforms::LdsWatirWebDriver)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module PageObject
|
|
2
|
+
module Platforms
|
|
3
|
+
module LdsWatirWebDriver
|
|
4
|
+
module CheckBox
|
|
5
|
+
|
|
6
|
+
#
|
|
7
|
+
# check the checkbox
|
|
8
|
+
#
|
|
9
|
+
def check
|
|
10
|
+
element.set
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
#
|
|
14
|
+
# uncheck the checkbox
|
|
15
|
+
#
|
|
16
|
+
def uncheck
|
|
17
|
+
element.clear
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
#
|
|
21
|
+
# return true if checkbox is checked
|
|
22
|
+
#
|
|
23
|
+
def checked?
|
|
24
|
+
element.set?
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
require 'watir-webdriver/extensions/select_text'
|
|
2
|
+
|
|
3
|
+
module PageObject
|
|
4
|
+
module Platforms
|
|
5
|
+
#
|
|
6
|
+
# Watir implementation of the common functionality found across all elements
|
|
7
|
+
#
|
|
8
|
+
module LdsWatirWebDriver
|
|
9
|
+
module Element
|
|
10
|
+
|
|
11
|
+
#
|
|
12
|
+
# return true if an element is visible
|
|
13
|
+
#
|
|
14
|
+
def visible?
|
|
15
|
+
element.present?
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
#
|
|
19
|
+
# return true if an element exists
|
|
20
|
+
#
|
|
21
|
+
def exists?
|
|
22
|
+
element.exists?
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
#
|
|
26
|
+
# flash the element by temporarily changing the background color
|
|
27
|
+
#
|
|
28
|
+
def flash
|
|
29
|
+
element.flash
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
#
|
|
33
|
+
# Get the text for the element
|
|
34
|
+
#
|
|
35
|
+
# @return [String]
|
|
36
|
+
#
|
|
37
|
+
def text
|
|
38
|
+
element.text
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
#
|
|
42
|
+
# Get the html for the element
|
|
43
|
+
#
|
|
44
|
+
# @return [String]
|
|
45
|
+
#
|
|
46
|
+
def html
|
|
47
|
+
element.html
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
#
|
|
51
|
+
# Get the value of this element
|
|
52
|
+
#
|
|
53
|
+
# @return [String]
|
|
54
|
+
#
|
|
55
|
+
def value
|
|
56
|
+
element.value
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
#
|
|
60
|
+
# compare this element to another to determine if they are equal
|
|
61
|
+
#
|
|
62
|
+
def ==(other)
|
|
63
|
+
element == other.element
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
#
|
|
67
|
+
# Get the tag name of this element
|
|
68
|
+
#
|
|
69
|
+
# @return [String]
|
|
70
|
+
#
|
|
71
|
+
def tag_name
|
|
72
|
+
element.tag_name
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
#
|
|
76
|
+
# Get the value of a the given attribute of the element. Will
|
|
77
|
+
# return the current value, even if this has been modified
|
|
78
|
+
# after the page has been loaded. More exactly, this method
|
|
79
|
+
# will return the value of the given attribute, unless that
|
|
80
|
+
# attribute is not present, in which case the value of the
|
|
81
|
+
# property with the same name is returned. If neither value is
|
|
82
|
+
# set, nil is returned. The "style" attribute is converted as
|
|
83
|
+
# best can be to a text representation with a trailing
|
|
84
|
+
# semi-colon. The following are deemed to be "boolean"
|
|
85
|
+
# attributes, and will return either "true" or "false":
|
|
86
|
+
#
|
|
87
|
+
# async, autofocus, autoplay, checked, compact, complete,
|
|
88
|
+
# controls, declare, defaultchecked, defaultselected, defer,
|
|
89
|
+
# disabled, draggable, ended, formnovalidate, hidden, indeterminate,
|
|
90
|
+
# iscontenteditable, ismap, itemscope, loop, multiple, muted,
|
|
91
|
+
# nohref, noresize, noshade, novalidate, nowrap, open, paused,
|
|
92
|
+
# pubdate, readonly, required, reversed, scoped, seamless, seeking,
|
|
93
|
+
# selected, spellcheck, truespeed, willvalidate
|
|
94
|
+
#
|
|
95
|
+
# Finally, the following commonly mis-capitalized
|
|
96
|
+
# attribute/property names are evaluated as expected:
|
|
97
|
+
#
|
|
98
|
+
# class, readonly
|
|
99
|
+
#
|
|
100
|
+
# @param [String]
|
|
101
|
+
# attribute name
|
|
102
|
+
# @return [String,nil]
|
|
103
|
+
# attribute value
|
|
104
|
+
#
|
|
105
|
+
def attribute(attribute_name)
|
|
106
|
+
element.attribute_value attribute_name
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
#
|
|
110
|
+
# Fire the provided event on the current element
|
|
111
|
+
#
|
|
112
|
+
def fire_event(event_name)
|
|
113
|
+
element.fire_event(event_name)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
#
|
|
117
|
+
# hover over the element
|
|
118
|
+
#
|
|
119
|
+
def hover
|
|
120
|
+
element.hover
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
#
|
|
124
|
+
# double click the element
|
|
125
|
+
#
|
|
126
|
+
def double_click
|
|
127
|
+
element.double_click
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
#
|
|
131
|
+
# find the parent element
|
|
132
|
+
#
|
|
133
|
+
def parent
|
|
134
|
+
parent = element.parent
|
|
135
|
+
type = element.type if parent.tag_name.to_sym == :input
|
|
136
|
+
cls = ::PageObject::Elements.element_class_for(parent.tag_name, type)
|
|
137
|
+
cls.new(parent, :platform => :lds_watir_webdriver)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
#
|
|
141
|
+
# Set the focus to the current element
|
|
142
|
+
#
|
|
143
|
+
def focus
|
|
144
|
+
element.focus
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
#
|
|
148
|
+
# Select the provided text
|
|
149
|
+
#
|
|
150
|
+
def select_text(text)
|
|
151
|
+
element.select_text text
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
#
|
|
155
|
+
# Waits until the element is present
|
|
156
|
+
#
|
|
157
|
+
# @param [Integer] (defaults to: 5) seconds to wait before timing out
|
|
158
|
+
#
|
|
159
|
+
def when_present(timeout=::PageObject.default_element_wait)
|
|
160
|
+
element.wait_until_present(timeout)
|
|
161
|
+
self
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
#
|
|
165
|
+
# Waits until the element is not present
|
|
166
|
+
#
|
|
167
|
+
# @param [Integer] (defaults to: 5) seconds to wait before
|
|
168
|
+
# timing out
|
|
169
|
+
#
|
|
170
|
+
def when_not_present(timeout=::PageObject.default_element_wait)
|
|
171
|
+
element.wait_while_present(timeout)
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
#
|
|
175
|
+
# Waits until the element is visible
|
|
176
|
+
#
|
|
177
|
+
# @param [Integer] (defaults to: 5) seconds to wait before timing out
|
|
178
|
+
#
|
|
179
|
+
def when_visible(timeout=::PageObject.default_element_wait)
|
|
180
|
+
Object::Watir::Wait.until(timeout, "Element was not visible in #{timeout} seconds") do
|
|
181
|
+
visible?
|
|
182
|
+
end
|
|
183
|
+
self
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
#
|
|
187
|
+
# Waits until the element is not visible
|
|
188
|
+
#
|
|
189
|
+
# @param [Integer] (defaults to: 5) seconds to wait before timing out
|
|
190
|
+
#
|
|
191
|
+
def when_not_visible(timeout=::PageObject.default_element_wait)
|
|
192
|
+
Object::Watir::Wait.while(timeout, "Element still visible after #{timeout} seconds") do
|
|
193
|
+
visible?
|
|
194
|
+
end
|
|
195
|
+
self
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
#
|
|
199
|
+
# Waits until the block returns true
|
|
200
|
+
#
|
|
201
|
+
# @param [Integer] (defaults to: 5) seconds to wait before timing out
|
|
202
|
+
# @param [String] the message to display if the event timeouts
|
|
203
|
+
# @param the block to execute when the event occurs
|
|
204
|
+
#
|
|
205
|
+
def wait_until(timeout=::PageObject.default_element_wait, message=nil, &block)
|
|
206
|
+
Object::Watir::Wait.until(timeout, message, &block)
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
#
|
|
210
|
+
# Send keystrokes to this element
|
|
211
|
+
#
|
|
212
|
+
# @param [String, Symbol, Array]
|
|
213
|
+
#
|
|
214
|
+
# Examples:
|
|
215
|
+
#
|
|
216
|
+
# element.send_keys "foo" #=> value: 'foo'
|
|
217
|
+
# element.send_keys "tet", :arrow_left, "s" #=> value: 'test'
|
|
218
|
+
# element.send_keys [:control, 'a'], :space #=> value: ' '
|
|
219
|
+
#
|
|
220
|
+
# @see Selenium::WebDriver::Keys::KEYS
|
|
221
|
+
#
|
|
222
|
+
def send_keys(*args)
|
|
223
|
+
element.send_keys(*args)
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
#
|
|
227
|
+
# clear the contents of the element
|
|
228
|
+
#
|
|
229
|
+
def clear
|
|
230
|
+
element.clear
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
#
|
|
234
|
+
# get the id of the element
|
|
235
|
+
#
|
|
236
|
+
def id
|
|
237
|
+
element.id
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
#
|
|
241
|
+
# Scroll until the element is viewable
|
|
242
|
+
#
|
|
243
|
+
def scroll_into_view
|
|
244
|
+
element.wd.location_once_scrolled_into_view
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
end
|