page-object 0.2.4 → 0.2.5

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.
Files changed (47) hide show
  1. data/ChangeLog +26 -2
  2. data/features/button.feature +5 -0
  3. data/features/check_box.feature +4 -2
  4. data/features/div.feature +4 -0
  5. data/features/form.feature +3 -0
  6. data/features/hidden_field.feature +4 -0
  7. data/features/image.feature +5 -0
  8. data/features/link.feature +4 -0
  9. data/features/list_item.feature +4 -0
  10. data/features/ordered_list.feature +5 -0
  11. data/features/radio_button.feature +4 -0
  12. data/features/select_list.feature +5 -1
  13. data/features/span.feature +4 -0
  14. data/features/step_definitions/accessor_steps.rb +0 -266
  15. data/features/step_definitions/button_steps.rb +23 -0
  16. data/features/step_definitions/check_box_steps.rb +31 -0
  17. data/features/step_definitions/div_steps.rb +15 -0
  18. data/features/step_definitions/element_steps.rb +0 -4
  19. data/features/step_definitions/form_steps.rb +15 -0
  20. data/features/step_definitions/hidden_field_steps.rb +23 -0
  21. data/features/step_definitions/image_steps.rb +23 -0
  22. data/features/step_definitions/link_steps.rb +20 -0
  23. data/features/step_definitions/list_item_steps.rb +15 -0
  24. data/features/step_definitions/ordered_list_steps.rb +15 -0
  25. data/features/step_definitions/radio_button_steps.rb +23 -0
  26. data/features/step_definitions/select_list_steps.rb +28 -0
  27. data/features/step_definitions/span_steps.rb +15 -0
  28. data/features/step_definitions/table_cell_steps.rb +11 -0
  29. data/features/step_definitions/table_steps.rb +12 -0
  30. data/features/step_definitions/text_area_steps.rb +27 -0
  31. data/features/step_definitions/text_field_steps.rb +27 -0
  32. data/features/step_definitions/unordered_list_steps.rb +16 -0
  33. data/features/table.feature +4 -0
  34. data/features/table_cell.feature +3 -0
  35. data/features/text_area.feature +4 -0
  36. data/features/text_field.feature +4 -0
  37. data/features/unordered_list.feature +5 -0
  38. data/lib/page-object.rb +8 -3
  39. data/lib/page-object/element_locators.rb +277 -0
  40. data/lib/page-object/platforms/selenium/page_object.rb +6 -5
  41. data/lib/page-object/platforms/watir/page_object.rb +2 -2
  42. data/lib/page-object/platforms/watir/text_area.rb +1 -1
  43. data/lib/page-object/version.rb +1 -1
  44. data/page-object.gemspec +2 -2
  45. data/spec/page-object/element_locators_spec.rb +113 -0
  46. data/spec/page-object/page-object_spec.rb +4 -4
  47. metadata +40 -5
@@ -0,0 +1,277 @@
1
+ module PageObject
2
+ module ElementLocators
3
+
4
+ #
5
+ # Finds a button
6
+ #
7
+ # @param [Hash] identifier how we find a button. You can use a multiple paramaters
8
+ # by combining of any of the following except xpath. The valid keys are:
9
+ # * :class => Watir and Selenium
10
+ # * :id => Watir and Selenium
11
+ # * :index => Watir and Selenium
12
+ # * :name => Watir and Selenium
13
+ # * :text => Watir only
14
+ # * :value => Watir and Selenium
15
+ # * :xpath => Watir and Selenium
16
+ #
17
+ def button_element(identifier)
18
+ platform.button_for(identifier.clone)
19
+ end
20
+
21
+ #
22
+ # Finds a text field
23
+ #
24
+ # @param [Hash] identifier how we find a text field. You can use a multiple paramaters
25
+ # by combining of any of the following except xpath. The valid keys are:
26
+ # * :class => Watir and Selenium
27
+ # * :css => Watir and Selenium
28
+ # * :id => Watir and Selenium
29
+ # * :index => Watir and Selenium
30
+ # * :name => Watir and Selenium
31
+ # * :tag_name => Watir and Selenium
32
+ # * :text => Watir only
33
+ # * :value => Watir only
34
+ # * :xpath => Watir and Selenium
35
+ #
36
+ def text_field_element(identifier)
37
+ platform.text_field_for(identifier.clone)
38
+ end
39
+
40
+ #
41
+ # Finds a hidden field
42
+ #
43
+ # @param [Hash] identifier how we find a hidden field. You can use a multiple paramaters
44
+ # by combining of any of the following except xpath. The valid keys are:
45
+ # * :class => Watir and Selenium
46
+ # * :css => Watir and Selenium
47
+ # * :id => Watir and Selenium
48
+ # * :index => Watir and Selenium
49
+ # * :name => Watir and Selenium
50
+ # * :tag_name => Watir and Selenium
51
+ # * :text => Watir and Selenium
52
+ # * :xpath => Watir and Selenium
53
+ #
54
+ def hidden_field_element(identifier)
55
+ platform.hidden_field_for(identifier.clone)
56
+ end
57
+
58
+ #
59
+ # Finds a text area
60
+ #
61
+ # @param [Hash] identifier how we find a text area. You can use a multiple paramaters
62
+ # by combining of any of the following except xpath. The valid keys are:
63
+ # * :class => Watir and Selenium
64
+ # * :css => Watir and Selenium
65
+ # * :id => Watir and Selenium
66
+ # * :index => Watir and Selenium
67
+ # * :name => Watir and Selenium
68
+ # * :tag_name => Watir and Selenium
69
+ # * :xpath => Watir and Selenium
70
+ #
71
+ def text_area_element(identifier)
72
+ platform.text_area_for(identifier.clone)
73
+ end
74
+
75
+ #
76
+ # Finds a select list
77
+ #
78
+ # @param [Hash] identifier how we find a select list. You can use a multiple paramaters
79
+ # by combining of any of the following except xpath. The valid keys are:
80
+ # * :class => Watir and Selenium
81
+ # * :id => Watir and Selenium
82
+ # * :index => Watir and Selenium
83
+ # * :name => Watir and Selenium
84
+ # * :text => Watir only
85
+ # * :value => Watir only
86
+ # * :xpath => Watir and Selenium
87
+ #
88
+ def select_list_element(identifier)
89
+ platform.select_list_for(identifier.clone)
90
+ end
91
+
92
+ #
93
+ # Finds a link
94
+ #
95
+ # @param [Hash] identifier how we find a link. You can use a multiple paramaters
96
+ # by combining of any of the following except xpath. The valid keys are:
97
+ # * :class => Watir and Selenium
98
+ # * :href => Watir and Selenium
99
+ # * :id => Watir and Selenium
100
+ # * :index => Watir and Selenium
101
+ # * :link => Watir and Selenium
102
+ # * :link_text => Watir and Selenium
103
+ # * :name => Watir and Selenium
104
+ # * :text => Watir and Selenium
105
+ # * :xpath => Watir and Selenium
106
+ #
107
+ def link_element(identifier)
108
+ platform.link_for(identifier.clone)
109
+ end
110
+
111
+ #
112
+ # Finds a checkbox
113
+ #
114
+ # @param [Hash] identifier how we find a checkbox. You can use a multiple paramaters
115
+ # by combining of any of the following except xpath. The valid keys are:
116
+ # * :class => Watir and Selenium
117
+ # * :id => Watir and Selenium
118
+ # * :index => Watir and Selenium
119
+ # * :name => Watir and Selenium
120
+ # * :xpath => Watir and Selenium
121
+ #
122
+ def checkbox_element(identifier)
123
+ platform.checkbox_for(identifier.clone)
124
+ end
125
+
126
+ #
127
+ # Finds a radio button
128
+ #
129
+ # @param [Hash] identifier how we find a radio button. You can use a multiple paramaters
130
+ # by combining of any of the following except xpath. The valid keys are:
131
+ # * :class => Watir and Selenium
132
+ # * :id => Watir and Selenium
133
+ # * :index => Watir and Selenium
134
+ # * :name => Watir and Selenium
135
+ # * :xpath => Watir and Selenium
136
+ #
137
+ def radio_button_element(identifier)
138
+ platform.radio_button_for(identifier.clone)
139
+ end
140
+
141
+ #
142
+ # Finds a div
143
+ #
144
+ # @param [Hash] identifier how we find a div. You can use a multiple paramaters
145
+ # by combining of any of the following except xpath. The valid keys are:
146
+ # * :class => Watir and Selenium
147
+ # * :id => Watir and Selenium
148
+ # * :index => Watir and Selenium
149
+ # * :name => Watir and Selenium
150
+ # * :text => Watir and Selenium
151
+ # * :xpath => Watir and Selenium
152
+ #
153
+ def div_element(identifier)
154
+ platform.div_for(identifier.clone)
155
+ end
156
+
157
+ #
158
+ # Finds a span
159
+ #
160
+ # @param [Hash] identifier how we find a span. You can use a multiple paramaters
161
+ # by combining of any of the following except xpath. The valid keys are:
162
+ # * :class => Watir and Selenium
163
+ # * :id => Watir and Selenium
164
+ # * :index => Watir and Selenium
165
+ # * :name => Watir and Selenium
166
+ # * :xpath => Watir and Selenium
167
+ #
168
+ def span_element(identifier)
169
+ platform.span_for(identifier.clone)
170
+ end
171
+
172
+ #
173
+ # Finds a table
174
+ #
175
+ # @param [Hash] identifier how we find a table. You can use a multiple paramaters
176
+ # by combining of any of the following except xpath. The valid keys are:
177
+ # * :class => Watir and Selenium
178
+ # * :id => Watir and Selenium
179
+ # * :index => Watir and Selenium
180
+ # * :name => Watir and Selenium
181
+ # * :xpath => Watir and Selenium
182
+ #
183
+ def table_element(identifier)
184
+ platform.table_for(identifier.clone)
185
+ end
186
+
187
+ #
188
+ # Finds a table cell
189
+ #
190
+ # @param [Hash] identifier how we find a cell. You can use a multiple paramaters
191
+ # by combining of any of the following except xpath. The valid keys are:
192
+ # * :class => Watir and Selenium
193
+ # * :id => Watir and Selenium
194
+ # * :index => Watir only
195
+ # * :name => Watir and Selenium
196
+ # * :text => Watir and Selenium
197
+ # * :xpath => Watir and Selenium
198
+ #
199
+ def cell_element(identifier)
200
+ platform.cell_for(identifier.clone)
201
+ end
202
+
203
+ #
204
+ # Finds an image
205
+ #
206
+ # @param [Hash] identifier how we find an image. You can use a multiple paramaters
207
+ # by combining of any of the following except xpath. The valid keys are:
208
+ # * :class => Watir and Selenium
209
+ # * :id => Watir and Selenium
210
+ # * :index => Watir and Selenium
211
+ # * :name => Watir and Selenium
212
+ # * :xpath => Watir and Selenium
213
+ #
214
+ def image_element(identifier)
215
+ platform.image_for(identifier.clone)
216
+ end
217
+
218
+ #
219
+ # Finds a form
220
+ #
221
+ # @param [Hash] identifier how we find a form. You can use a multiple paramaters
222
+ # by combining of any of the following except xpath. The valid keys are:
223
+ # * :class => Watir and Selenium
224
+ # * :id => Watir and Selenium
225
+ # * :index => Watir and Selenium
226
+ # * :xpath => Watir and Selenium
227
+ #
228
+ def form_element(identifier)
229
+ platform.form_for(identifier.clone)
230
+ end
231
+
232
+ #
233
+ # Finds a list item
234
+ #
235
+ # @param [Hash] identifier how we find a list item. You can use a multiple paramaters
236
+ # by combining of any of the following except xpath. The valid keys are:
237
+ # * :class => Watir and Selenium
238
+ # * :id => Watir and Selenium
239
+ # * :index => Watir and Selenium
240
+ # * :name => Watir and Selenium
241
+ # * :xpath => Watir and Selenium
242
+ #
243
+ def list_item_element(identifier)
244
+ platform.list_item_for(identifier.clone)
245
+ end
246
+
247
+ #
248
+ # Finds an unordered list
249
+ #
250
+ # @param [Hash] identifier how we find an unordered list. You can use a multiple paramaters
251
+ # by combining of any of the following except xpath. The valid keys are:
252
+ # * :class => Watir and Selenium
253
+ # * :id => Watir and Selenium
254
+ # * :index => Watir and Selenium
255
+ # * :name => Watir and Selenium
256
+ # * :xpath => Watir and Selenium
257
+ #
258
+ def unordered_list_element(identifier)
259
+ platform.unordered_list_for(identifier.clone)
260
+ end
261
+
262
+ #
263
+ # Finds an ordered list
264
+ #
265
+ # @param [Hash] identifier how we find an ordered list. You can use a multiple paramaters
266
+ # by combining of any of the following except xpath. The valid keys are:
267
+ # * :class => Watir and Selenium
268
+ # * :id => Watir and Selenium
269
+ # * :index => Watir and Selenium
270
+ # * :name => Watir and Selenium
271
+ # * :xpath => Watir and Selenium
272
+ #
273
+ def ordered_list_element(identifier)
274
+ platform.ordered_list_for(identifier.clone)
275
+ end
276
+ end
277
+ end
@@ -93,14 +93,15 @@ module PageObject
93
93
  # platform method to handle attaching to a running window
94
94
  # See PageObject#attach_to_window
95
95
  #
96
- def attach_to_window(identifier)
96
+ def attach_to_window(identifier, &block)
97
+ match = identifier.values.first
97
98
  handles = @browser.window_handles
98
99
  handles.each do |handle|
99
100
  @browser.switch_to.window handle
100
- if identifier.keys.first == :title
101
- return if @browser.title == identifier.values.first
102
- elsif identifier.keys.first == :url
103
- return if @browser.current_url == identifier.values.first
101
+ if identifier.keys.first == :title and @browser.title == match
102
+ return @browser.switch_to.window handle, &block
103
+ elsif identifier.keys.first == :url and @browser.current_url == match
104
+ return @browser.switch_to.window handle, &block
104
105
  end
105
106
  end
106
107
  end
@@ -83,9 +83,9 @@ module PageObject
83
83
  # platform method to handle attaching to a running window
84
84
  # See PageObject#attach_to_window
85
85
  #
86
- def attach_to_window(identifier)
86
+ def attach_to_window(identifier, &block)
87
87
  win_id = {identifier.keys.first => /#{Regexp.escape(identifier.values.first)}/}
88
- @browser.window(win_id).use
88
+ @browser.window(win_id).use &block
89
89
  end
90
90
 
91
91
  #
@@ -8,7 +8,7 @@ module PageObject
8
8
  # Set the value of the TextArea
9
9
  #
10
10
  def value=(new_value)
11
- element.set(new_value)
11
+ element.send_keys(new_value)
12
12
  end
13
13
  end
14
14
  end
@@ -1,4 +1,4 @@
1
1
  module PageObject
2
2
  # @private
3
- VERSION = "0.2.4"
3
+ VERSION = "0.2.5"
4
4
  end
@@ -19,8 +19,8 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_dependency 'watir-webdriver', '>= 0.3.0'
23
- s.add_dependency 'selenium-webdriver', '>= 2.3.2'
22
+ s.add_dependency 'watir-webdriver', '>= 0.3.2'
23
+ s.add_dependency 'selenium-webdriver', '>= 2.4.0'
24
24
 
25
25
  s.add_development_dependency 'rspec', '>= 2.6.0'
26
26
  s.add_development_dependency 'cucumber', '>= 1.0.0'
@@ -0,0 +1,113 @@
1
+ require 'spec_helper'
2
+
3
+ class ElementLocatorsTestPageObject
4
+ include PageObject
5
+ end
6
+
7
+
8
+ describe PageObject::ElementLocators do
9
+ let(:watir_browser) { mock_watir_browser }
10
+ let(:watir_page_object) { ElementLocatorsTestPageObject.new(watir_browser) }
11
+
12
+ it "should find a button element" do
13
+ watir_browser.should_receive(:button).with(:id => 'blah').and_return(watir_browser)
14
+ element = watir_page_object.button_element(:id => 'blah')
15
+ element.should be_instance_of PageObject::Elements::Button
16
+ end
17
+
18
+ it "should find a text field element" do
19
+ watir_browser.should_receive(:text_field).with(:id => 'blah').and_return(watir_browser)
20
+ element = watir_page_object.text_field_element(:id => 'blah')
21
+ element.should be_instance_of PageObject::Elements::TextField
22
+ end
23
+
24
+ it "should find a hidden field element" do
25
+ watir_browser.should_receive(:hidden).with(:id => 'blah').and_return(watir_browser)
26
+ element = watir_page_object.hidden_field_element(:id => 'blah')
27
+ element.should be_instance_of PageObject::Elements::HiddenField
28
+ end
29
+
30
+ it "should find a text area element" do
31
+ watir_browser.should_receive(:textarea).with(:id => 'blah').and_return(watir_browser)
32
+ element = watir_page_object.text_area_element(:id => 'blah')
33
+ element.should be_instance_of PageObject::Elements::TextArea
34
+ end
35
+
36
+ it "should find a select list element" do
37
+ watir_browser.should_receive(:select_list).with(:id => 'blah').and_return(watir_browser)
38
+ element = watir_page_object.select_list_element(:id => 'blah')
39
+ element.should be_instance_of PageObject::Elements::SelectList
40
+ end
41
+
42
+ it "should find a link element" do
43
+ watir_browser.should_receive(:link).with(:id => 'blah').and_return(watir_browser)
44
+ element = watir_page_object.link_element(:id => 'blah')
45
+ element.should be_instance_of PageObject::Elements::Link
46
+ end
47
+
48
+ it "should find a check box" do
49
+ watir_browser.should_receive(:checkbox).with(:id => 'blah').and_return(watir_browser)
50
+ element = watir_page_object.checkbox_element(:id => 'blah')
51
+ element.should be_instance_of PageObject::Elements::CheckBox
52
+ end
53
+
54
+ it "should find a radio button" do
55
+ watir_browser.should_receive(:radio).with(:id => 'blah').and_return(watir_browser)
56
+ element = watir_page_object.radio_button_element(:id => 'blah')
57
+ element.should be_instance_of PageObject::Elements::RadioButton
58
+ end
59
+
60
+ it "should find a div" do
61
+ watir_browser.should_receive(:div).with(:id => 'blah').and_return(watir_browser)
62
+ element = watir_page_object.div_element(:id => 'blah')
63
+ element.should be_instance_of PageObject::Elements::Div
64
+ end
65
+
66
+ it "should find a span" do
67
+ watir_browser.should_receive(:span).with(:id => 'blah').and_return(watir_browser)
68
+ element = watir_page_object.span_element(:id => 'blah')
69
+ element.should be_instance_of PageObject::Elements::Span
70
+ end
71
+
72
+ it "should find a table" do
73
+ watir_browser.should_receive(:table).with(:id => 'blah').and_return(watir_browser)
74
+ element = watir_page_object.table_element(:id => 'blah')
75
+ element.should be_instance_of PageObject::Elements::Table
76
+ end
77
+
78
+ it "should find a table cell" do
79
+ watir_browser.should_receive(:td).with(:id => 'blah').and_return(watir_browser)
80
+ element = watir_page_object.cell_element(:id => 'blah')
81
+ element.should be_instance_of PageObject::Elements::TableCell
82
+ end
83
+
84
+ it "should find an image" do
85
+ watir_browser.should_receive(:image).with(:id => 'blah').and_return(watir_browser)
86
+ element = watir_page_object.image_element(:id => 'blah')
87
+ element.should be_instance_of PageObject::Elements::Image
88
+ end
89
+
90
+ it "should find a form" do
91
+ watir_browser.should_receive(:form).with(:id => 'blah').and_return(watir_browser)
92
+ element = watir_page_object.form_element(:id => 'blah')
93
+ element.should be_instance_of PageObject::Elements::Form
94
+ end
95
+
96
+ it "should find a list item" do
97
+ watir_browser.should_receive(:li).with(:id => 'blah').and_return(watir_browser)
98
+ element = watir_page_object.list_item_element(:id => 'blah')
99
+ element.should be_instance_of PageObject::Elements::ListItem
100
+ end
101
+
102
+ it "should find an unordered list" do
103
+ watir_browser.should_receive(:ul).with(:id => 'blah').and_return(watir_browser)
104
+ element = watir_page_object.unordered_list_element(:id => 'blah')
105
+ element.should be_instance_of PageObject::Elements::UnorderedList
106
+ end
107
+
108
+ it "should find an ordered list" do
109
+ watir_browser.should_receive(:ol).with(:id => 'blah').and_return(watir_browser)
110
+ element = watir_page_object.ordered_list_element(:id => 'blah')
111
+ element.should be_instance_of PageObject::Elements::OrderedList
112
+ end
113
+ end