page-object 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.
- data/.gitignore +6 -0
- data/Gemfile +3 -0
- data/LICENSE +20 -0
- data/README.md +87 -0
- data/Rakefile +51 -0
- data/cucumber.yml +5 -0
- data/features/check_box.feature +39 -0
- data/features/html/static_elements.html +34 -0
- data/features/link.feature +42 -0
- data/features/page_level_actions.feature +19 -0
- data/features/radio_button.feature +40 -0
- data/features/select_list.feature +40 -0
- data/features/step_definitions/accessor_steps.rb +88 -0
- data/features/step_definitions/element_steps.rb +28 -0
- data/features/step_definitions/page_level_actions_steps.rb +12 -0
- data/features/step_definitions/page_traversal_steps.rb +5 -0
- data/features/support/env.rb +18 -0
- data/features/support/page.rb +45 -0
- data/features/support/url_helper.rb +16 -0
- data/features/text_field.feature +39 -0
- data/lib/page-object.rb +52 -0
- data/lib/page-object/accessors.rb +171 -0
- data/lib/page-object/elements.rb +8 -0
- data/lib/page-object/elements/button.rb +15 -0
- data/lib/page-object/elements/check_box.rb +15 -0
- data/lib/page-object/elements/element.rb +52 -0
- data/lib/page-object/elements/link.rb +34 -0
- data/lib/page-object/elements/radio_button.rb +15 -0
- data/lib/page-object/elements/select_list.rb +21 -0
- data/lib/page-object/elements/text_field.rb +33 -0
- data/lib/page-object/selenium_element.rb +12 -0
- data/lib/page-object/selenium_page_object.rb +190 -0
- data/lib/page-object/version.rb +3 -0
- data/lib/page-object/watir_element.rb +12 -0
- data/lib/page-object/watir_page_object.rb +190 -0
- data/page-object.gemspec +29 -0
- data/spec/page-object/accessors_spec.rb +297 -0
- data/spec/page-object/elements/button_spec.rb +23 -0
- data/spec/page-object/elements/check_box_spec.rb +21 -0
- data/spec/page-object/elements/element_spec.rb +54 -0
- data/spec/page-object/elements/link_spec.rb +34 -0
- data/spec/page-object/elements/radio_button_spec.rb +21 -0
- data/spec/page-object/elements/select_list_spec.rb +22 -0
- data/spec/page-object/elements/text_field_spec.rb +32 -0
- data/spec/page-object/page-object_spec.rb +78 -0
- data/spec/spec_helper.rb +31 -0
- metadata +179 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
module PageObject
|
2
|
+
module Elements
|
3
|
+
class Link < Element
|
4
|
+
|
5
|
+
def self.watir_identifier_for identifier
|
6
|
+
identifier_for identifier, watir_finders, watir_mapping
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.selenium_identifier_for identifier
|
10
|
+
identifier = identifier_for identifier, selenium_finders, selenium_mapping
|
11
|
+
return identifier.keys.first, identifier.values.first
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
def self.watir_finders
|
17
|
+
super + [:href, :text]
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.watir_mapping
|
21
|
+
super.merge({ :link => :text, :link_text => :text })
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.selenium_finders
|
25
|
+
super + [:link, :link_text]
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.selenium_mapping
|
29
|
+
super.merge(:text => :link_text)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module PageObject
|
2
|
+
module Elements
|
3
|
+
class RadioButton < Element
|
4
|
+
|
5
|
+
def self.watir_identifier_for identifier
|
6
|
+
identifier_for identifier, watir_finders, watir_mapping
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.selenium_identifier_for identifier
|
10
|
+
identifier = identifier_for identifier, selenium_finders, selenium_mapping
|
11
|
+
return identifier.keys.first, identifier.values.first
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module PageObject
|
2
|
+
module Elements
|
3
|
+
class SelectList < Element
|
4
|
+
|
5
|
+
def self.watir_identifier_for identifier
|
6
|
+
identifier_for identifier, watir_finders, watir_mapping
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.selenium_identifier_for identifier
|
10
|
+
identifier = identifier_for identifier, selenium_finders, selenium_mapping
|
11
|
+
return identifier.keys.first, identifier.values.first
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
def self.watir_finders
|
17
|
+
super + [:text, :value]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module PageObject
|
2
|
+
module Elements
|
3
|
+
class TextField < Element
|
4
|
+
|
5
|
+
def self.watir_identifier_for identifier
|
6
|
+
identifier_for identifier, watir_finders, watir_mapping
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.selenium_identifier_for identifier
|
10
|
+
identifier = identifier_for identifier, selenium_finders, selenium_mapping
|
11
|
+
return identifier.keys.first, identifier.values.first
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
def self.watir_finders
|
17
|
+
super + [:tag_name, :text, :value]
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.watir_mapping
|
21
|
+
super.merge({:css => :tag_name})
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.selenium_finders
|
25
|
+
super + [:css]
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.selenium_mapping
|
29
|
+
super.merge({:tag_name => :css})
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
require 'page-object/elements'
|
2
|
+
|
3
|
+
module PageObject
|
4
|
+
class SeleniumPageObject
|
5
|
+
def initialize(browser)
|
6
|
+
@browser = browser
|
7
|
+
end
|
8
|
+
|
9
|
+
#
|
10
|
+
# platform method to navigate to a provided url
|
11
|
+
# See PageObject#navigate_to
|
12
|
+
#
|
13
|
+
def navigate_to(url)
|
14
|
+
@browser.navigate.to url
|
15
|
+
end
|
16
|
+
|
17
|
+
#
|
18
|
+
# platform method to retrieve the text from the current page
|
19
|
+
# See PageObject#text
|
20
|
+
#
|
21
|
+
def text
|
22
|
+
@browser.find_element(:tag_name, 'body').text
|
23
|
+
end
|
24
|
+
|
25
|
+
#
|
26
|
+
# platform method to retrieve the html for the current page
|
27
|
+
# See PageObject#html
|
28
|
+
#
|
29
|
+
def html
|
30
|
+
@browser.page_source
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# platform method to retrieve the title for the current page
|
35
|
+
# See PageObject#title
|
36
|
+
#
|
37
|
+
def title
|
38
|
+
@browser.title
|
39
|
+
end
|
40
|
+
|
41
|
+
#
|
42
|
+
# platform method to get the value stored in a text field
|
43
|
+
# See PageObject::Accessors#text_field
|
44
|
+
#
|
45
|
+
def text_field_value_for(identifier)
|
46
|
+
how, what = Elements::TextField.selenium_identifier_for identifier
|
47
|
+
@browser.find_element(how, what).value
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
# platform method to set the value for a text field
|
52
|
+
# See PageObject::Accessors#text_field
|
53
|
+
#
|
54
|
+
def text_field_value_set(identifier, value)
|
55
|
+
how, what = Elements::TextField.selenium_identifier_for identifier
|
56
|
+
@browser.find_element(how, what).send_keys(value)
|
57
|
+
end
|
58
|
+
|
59
|
+
#
|
60
|
+
# platform method to retrieve a text field element
|
61
|
+
# See PageObject::Accessors#text_field
|
62
|
+
#
|
63
|
+
def text_field_for(identifier)
|
64
|
+
how, what = Elements::TextField.selenium_identifier_for identifier
|
65
|
+
element = @browser.find_element(how, what)
|
66
|
+
PageObject::Elements::TextField.new(element, :platform => :selenium)
|
67
|
+
end
|
68
|
+
|
69
|
+
#
|
70
|
+
# platform method to get the currently selected value from a select list
|
71
|
+
# See PageObject::Accessors#select_list
|
72
|
+
#
|
73
|
+
def select_list_value_for(identifier)
|
74
|
+
how, what = Elements::SelectList.selenium_identifier_for identifier
|
75
|
+
@browser.find_element(how, what).attribute('value')
|
76
|
+
end
|
77
|
+
|
78
|
+
#
|
79
|
+
# platform method to select a value from a select list
|
80
|
+
# See PageObject::Accessors#select_list
|
81
|
+
#
|
82
|
+
def select_list_value_set(identifier, value)
|
83
|
+
how, what = Elements::SelectList.selenium_identifier_for identifier
|
84
|
+
@browser.find_element(how, what).send_keys(value)
|
85
|
+
end
|
86
|
+
|
87
|
+
#
|
88
|
+
# platform method to return the select list element
|
89
|
+
# See PageObject::Accessors#select_list
|
90
|
+
#
|
91
|
+
def select_list_for(identifier)
|
92
|
+
how, what = Elements::SelectList.selenium_identifier_for identifier
|
93
|
+
element = @browser.find_element(how, what)
|
94
|
+
Elements::SelectList.new(element, :platform => :selenium)
|
95
|
+
end
|
96
|
+
|
97
|
+
#
|
98
|
+
# platform method to click a link
|
99
|
+
# See PageObject::Accessors#link
|
100
|
+
#
|
101
|
+
def click_link_for(identifier)
|
102
|
+
how, what = Elements::Link.selenium_identifier_for identifier
|
103
|
+
@browser.find_element(how, what).click
|
104
|
+
end
|
105
|
+
|
106
|
+
#
|
107
|
+
# platform method to return a PageObject::Elements::Link object
|
108
|
+
# see PageObject::Accessors#link
|
109
|
+
#
|
110
|
+
def link_for(identifier)
|
111
|
+
how, what = Elements::Link.selenium_identifier_for identifier
|
112
|
+
element = @browser.find_element(how, what)
|
113
|
+
Elements::Link.new(element, :platform => :selenium)
|
114
|
+
end
|
115
|
+
|
116
|
+
#
|
117
|
+
# platform method to check a checkbox
|
118
|
+
# See PageObject::Accessors#checkbox
|
119
|
+
#
|
120
|
+
def check_checkbox(identifier)
|
121
|
+
how, what = Elements::CheckBox.selenium_identifier_for identifier
|
122
|
+
@browser.find_element(how, what).toggle unless checkbox_checked?(identifier)
|
123
|
+
end
|
124
|
+
|
125
|
+
#
|
126
|
+
# platform method to uncheck a checkbox
|
127
|
+
# See PageObject::Accessors#checkbox
|
128
|
+
#
|
129
|
+
def uncheck_checkbox(identifier)
|
130
|
+
how, what = Elements::CheckBox.selenium_identifier_for identifier
|
131
|
+
@browser.find_element(how, what).toggle if checkbox_checked?(identifier)
|
132
|
+
end
|
133
|
+
|
134
|
+
#
|
135
|
+
# platform method to determine if a checkbox is checked
|
136
|
+
# See PageObject::Accessors#checkbox
|
137
|
+
#
|
138
|
+
def checkbox_checked?(identifier)
|
139
|
+
how, what = Elements::CheckBox.selenium_identifier_for identifier
|
140
|
+
@browser.find_element(how, what).selected?
|
141
|
+
end
|
142
|
+
|
143
|
+
#
|
144
|
+
# platform method to return a PageObject::Elements::CheckBox element
|
145
|
+
# See PageObject::Accessors#checkbox
|
146
|
+
#
|
147
|
+
def checkbox_for(identifier)
|
148
|
+
how, what = Elements::CheckBox.selenium_identifier_for identifier
|
149
|
+
element = @browser.find_element(how, what)
|
150
|
+
Elements::CheckBox.new(element, :platform => :selenium)
|
151
|
+
end
|
152
|
+
|
153
|
+
#
|
154
|
+
# platform method to select a radio button
|
155
|
+
# See PageObject::Accessors#radio_button
|
156
|
+
#
|
157
|
+
def select_radio(identifier)
|
158
|
+
how, what = Elements::RadioButton.selenium_identifier_for identifier
|
159
|
+
@browser.find_element(how, what).click unless @browser.find_element(how, what).selected?
|
160
|
+
end
|
161
|
+
|
162
|
+
#
|
163
|
+
# platform method to clear a radio button
|
164
|
+
# See PageObject::Accessors#radio_button
|
165
|
+
#
|
166
|
+
def clear_radio(identifier)
|
167
|
+
how, what = Elements::RadioButton.selenium_identifier_for identifier
|
168
|
+
@browser.find_element(how, what).click if @browser.find_element(how, what).selected?
|
169
|
+
end
|
170
|
+
|
171
|
+
#
|
172
|
+
# platform method to determine if a radio button is selected
|
173
|
+
# See PageObject::Accessors#radio_button
|
174
|
+
#
|
175
|
+
def radio_selected?(identifier)
|
176
|
+
how, what = Elements::RadioButton.selenium_identifier_for identifier
|
177
|
+
@browser.find_element(how, what).selected?
|
178
|
+
end
|
179
|
+
|
180
|
+
#
|
181
|
+
# platform method to return a PageObject::Eements::RadioButton element
|
182
|
+
# See PageObject::Accessors#radio_button
|
183
|
+
#
|
184
|
+
def radio_button_for(identifier)
|
185
|
+
how, what = Elements::RadioButton.selenium_identifier_for identifier
|
186
|
+
element = @browser.find_element(how, what)
|
187
|
+
PageObject::Elements::RadioButton.new(element, :platform => :selenium)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
require 'page-object/elements'
|
2
|
+
|
3
|
+
module PageObject
|
4
|
+
class WatirPageObject
|
5
|
+
def initialize(browser)
|
6
|
+
@browser = browser
|
7
|
+
end
|
8
|
+
|
9
|
+
#
|
10
|
+
# platform method to navigate to a provided url
|
11
|
+
# See PageObject#navigate_to
|
12
|
+
#
|
13
|
+
def navigate_to(url)
|
14
|
+
@browser.goto url
|
15
|
+
end
|
16
|
+
|
17
|
+
#
|
18
|
+
# platform method to retrieve the text from the current page
|
19
|
+
# See PageObject#text
|
20
|
+
#
|
21
|
+
def text
|
22
|
+
@browser.text
|
23
|
+
end
|
24
|
+
|
25
|
+
#
|
26
|
+
# platform method to retrieve the html for the current page
|
27
|
+
# See PageObject#html
|
28
|
+
#
|
29
|
+
def html
|
30
|
+
@browser.html
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# platform method to retrieve the title for the current page
|
35
|
+
# See PageObject#title
|
36
|
+
#
|
37
|
+
def title
|
38
|
+
@browser.title
|
39
|
+
end
|
40
|
+
|
41
|
+
#
|
42
|
+
# platform method to get the value stored in a text field
|
43
|
+
# See PageObject::Accessors#text_field
|
44
|
+
#
|
45
|
+
def text_field_value_for(identifier)
|
46
|
+
identifier = Elements::TextField.watir_identifier_for identifier
|
47
|
+
@browser.text_field(identifier).value
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
# platform method to set the value for a text field
|
52
|
+
# See PageObject::Accessors#text_field
|
53
|
+
#
|
54
|
+
def text_field_value_set(identifier, value)
|
55
|
+
identifier = Elements::TextField.watir_identifier_for identifier
|
56
|
+
@browser.text_field(identifier).set(value)
|
57
|
+
end
|
58
|
+
|
59
|
+
#
|
60
|
+
# platform method to retrieve a text field element
|
61
|
+
# See PageObject::Accessors#text_field
|
62
|
+
#
|
63
|
+
def text_field_for(identifier)
|
64
|
+
identifier = Elements::TextField.watir_identifier_for identifier
|
65
|
+
element = @browser.text_field(identifier)
|
66
|
+
Elements::TextField.new(element, :platform => :watir)
|
67
|
+
end
|
68
|
+
|
69
|
+
#
|
70
|
+
# platform method to get the currently selected value from a select list
|
71
|
+
# See PageObject::Accessors#select_list
|
72
|
+
#
|
73
|
+
def select_list_value_for(identifier)
|
74
|
+
identifier = Elements::SelectList.watir_identifier_for identifier
|
75
|
+
@browser.select_list(identifier).value
|
76
|
+
end
|
77
|
+
|
78
|
+
#
|
79
|
+
# platform method to select a value from a select list
|
80
|
+
# See PageObject::Accessors#select_list
|
81
|
+
#
|
82
|
+
def select_list_value_set(identifier, value)
|
83
|
+
identifier = Elements::SelectList.watir_identifier_for identifier
|
84
|
+
@browser.select_list(identifier).select(value)
|
85
|
+
end
|
86
|
+
|
87
|
+
#
|
88
|
+
# platform method to return the select list element
|
89
|
+
# See PageObject::Accessors#select_list
|
90
|
+
#
|
91
|
+
def select_list_for(identifier)
|
92
|
+
identifier = Elements::SelectList.watir_identifier_for identifier
|
93
|
+
element = @browser.select_list(identifier)
|
94
|
+
Elements::SelectList.new(element, :platform => :watir)
|
95
|
+
end
|
96
|
+
|
97
|
+
#
|
98
|
+
# platform method to click a link
|
99
|
+
# See PageObject::Accessors#link
|
100
|
+
#
|
101
|
+
def click_link_for(identifier)
|
102
|
+
identifier = Elements::Link.watir_identifier_for identifier
|
103
|
+
@browser.link(identifier).click if identifier
|
104
|
+
end
|
105
|
+
|
106
|
+
#
|
107
|
+
# platform method to return a PageObject::Elements::Link object
|
108
|
+
# see PageObject::Accessors#link
|
109
|
+
#
|
110
|
+
def link_for(identifier)
|
111
|
+
identifier = Elements::Link.watir_identifier_for identifier
|
112
|
+
element = @browser.link(identifier)
|
113
|
+
Elements::Link.new(element, :platform => :watir)
|
114
|
+
end
|
115
|
+
|
116
|
+
#
|
117
|
+
# platform method to check a checkbox
|
118
|
+
# See PageObject::Accessors#checkbox
|
119
|
+
#
|
120
|
+
def check_checkbox(identifier)
|
121
|
+
identifier = Elements::CheckBox.watir_identifier_for identifier
|
122
|
+
@browser.checkbox(identifier).set
|
123
|
+
end
|
124
|
+
|
125
|
+
#
|
126
|
+
# platform method to uncheck a checkbox
|
127
|
+
# See PageObject::Accessors#checkbox
|
128
|
+
#
|
129
|
+
def uncheck_checkbox(identifier)
|
130
|
+
identifier = Elements::CheckBox.watir_identifier_for identifier
|
131
|
+
@browser.checkbox(identifier).clear
|
132
|
+
end
|
133
|
+
|
134
|
+
#
|
135
|
+
# platform method to determine if a checkbox is checked
|
136
|
+
# See PageObject::Accessors#checkbox
|
137
|
+
#
|
138
|
+
def checkbox_checked?(identifier)
|
139
|
+
identifier = Elements::CheckBox.watir_identifier_for identifier
|
140
|
+
@browser.checkbox(identifier).set?
|
141
|
+
end
|
142
|
+
|
143
|
+
#
|
144
|
+
# platform method to return a PageObject::Elements::CheckBox element
|
145
|
+
# See PageObject::Accessors#checkbox
|
146
|
+
#
|
147
|
+
def checkbox_for(identifier)
|
148
|
+
identifier = Elements::CheckBox.watir_identifier_for identifier
|
149
|
+
element = @browser.checkbox(identifier)
|
150
|
+
Elements::CheckBox.new(element, :platform => :watir)
|
151
|
+
end
|
152
|
+
|
153
|
+
#
|
154
|
+
# platform method to select a radio button
|
155
|
+
# See PageObject::Accessors#radio_button
|
156
|
+
#
|
157
|
+
def select_radio(identifier)
|
158
|
+
identifier = Elements::RadioButton.watir_identifier_for identifier
|
159
|
+
@browser.radio(identifier).set
|
160
|
+
end
|
161
|
+
|
162
|
+
#
|
163
|
+
# platform method to clear a radio button
|
164
|
+
# See PageObject::Accessors#radio_button
|
165
|
+
#
|
166
|
+
def clear_radio(identifier)
|
167
|
+
identifier = Elements::RadioButton.watir_identifier_for identifier
|
168
|
+
@browser.radio(identifier).clear
|
169
|
+
end
|
170
|
+
|
171
|
+
#
|
172
|
+
# platform method to determine if a radio button is selected
|
173
|
+
# See PageObject::Accessors#radio_button
|
174
|
+
#
|
175
|
+
def radio_selected?(identifier)
|
176
|
+
identifier = Elements::RadioButton.watir_identifier_for identifier
|
177
|
+
@browser.radio(identifier).set?
|
178
|
+
end
|
179
|
+
|
180
|
+
#
|
181
|
+
# platform method to return a PageObject::Eements::RadioButton element
|
182
|
+
# See PageObject::Accessors#radio_button
|
183
|
+
#
|
184
|
+
def radio_button_for(identifier)
|
185
|
+
identifier = Elements::RadioButton.watir_identifier_for identifier
|
186
|
+
element = @browser.radio(identifier)
|
187
|
+
PageObject::Elements::RadioButton.new(element, :platform => :watir)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|