page-object 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -1
- data/ChangeLog +14 -1
- data/features/button.feature +1 -0
- data/features/html/static_elements.html +1 -1
- data/features/page_level_actions.feature +9 -0
- data/features/span.feature +1 -0
- data/features/step_definitions/page_level_actions_steps.rb +7 -0
- data/features/support/page.rb +2 -0
- data/lib/page-object.rb +14 -0
- data/lib/page-object/accessors.rb +39 -19
- data/lib/page-object/elements/button.rb +5 -1
- data/lib/page-object/elements/check_box.rb +19 -0
- data/lib/page-object/elements/radio_button.rb +20 -1
- data/lib/page-object/elements/span.rb +5 -1
- data/lib/page-object/elements/text_area.rb +18 -0
- data/lib/page-object/elements/text_field.rb +18 -0
- data/lib/page-object/platforms/selenium/check_box.rb +29 -0
- data/lib/page-object/platforms/selenium/element.rb +2 -2
- data/lib/page-object/platforms/selenium/page_object.rb +18 -2
- data/lib/page-object/platforms/selenium/radio_button.rb +29 -0
- data/lib/page-object/platforms/selenium/select_list.rb +7 -0
- data/lib/page-object/platforms/selenium/text_area.rb +17 -0
- data/lib/page-object/platforms/selenium/text_field.rb +17 -0
- data/lib/page-object/platforms/watir/check_box.rb +29 -0
- data/lib/page-object/platforms/watir/element.rb +0 -7
- data/lib/page-object/platforms/watir/page_object.rb +16 -0
- data/lib/page-object/platforms/watir/radio_button.rb +29 -0
- data/lib/page-object/platforms/watir/select_list.rb +7 -0
- data/lib/page-object/platforms/watir/text_area.rb +16 -0
- data/lib/page-object/platforms/watir/text_field.rb +16 -0
- data/lib/page-object/version.rb +1 -1
- data/page-object.gemspec +1 -1
- data/spec/page-object/elements/button_spec.rb +2 -2
- data/spec/page-object/elements/check_box_spec.rb +25 -0
- data/spec/page-object/elements/element_spec.rb +20 -0
- data/spec/page-object/elements/radio_button_spec.rb +24 -0
- data/spec/page-object/elements/select_list_spec.rb +6 -1
- data/spec/page-object/elements/span_spec.rb +2 -2
- data/spec/page-object/elements/table_spec.rb +4 -6
- data/spec/page-object/elements/text_area_spec.rb +12 -0
- data/spec/page-object/elements/text_field_spec.rb +14 -1
- data/spec/page-object/page-object_spec.rb +22 -0
- metadata +11 -3
data/.rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rvm 1.9.2-
|
1
|
+
rvm 1.9.2-p290@page-object --create
|
data/ChangeLog
CHANGED
@@ -1,9 +1,22 @@
|
|
1
|
+
=== Version 0.2.4 / 2011-08-80
|
2
|
+
* Ehnancements
|
3
|
+
* Can now find span by :text
|
4
|
+
* Can now find button by :value
|
5
|
+
* Added #forward and #back methods to PageObject
|
6
|
+
* Added #right_click and #double_click methods to Element
|
7
|
+
* Added #value= to TextField and TextArea
|
8
|
+
* Added #select to SelectList
|
9
|
+
* Added #check, #uncheck, and #checked? to CheckBox
|
10
|
+
* Added #select, #clear, and #selected? to RadioButton
|
11
|
+
* Can properly pass blocks to all accessor methods
|
12
|
+
* Updated to use watir-webdriver 0.3.0
|
13
|
+
|
1
14
|
=== Version 0.2.3 / 2011-08-01
|
2
15
|
* Enhancements
|
3
16
|
* Can now find a TableCell by its' text
|
4
17
|
* If we receive an error calling #attach_to_window, wait one second and try again
|
5
18
|
* Will call callback method #initialize_page method if it exists on a page object
|
6
|
-
* Renamed all *_<element_type> methods to *_element. Created alias for backward
|
19
|
+
* Renamed all *_<element_type> methods to *_element. Created alias for backward compatibility
|
7
20
|
* Delegating unknown method calls on Element to the driver element object
|
8
21
|
* Improved block handling when passed to element creation method
|
9
22
|
* Updated to use selenium-webdriver 2.3.2
|
data/features/button.feature
CHANGED
@@ -40,3 +40,12 @@ Feature: Page level actions
|
|
40
40
|
|
41
41
|
Scenario: Refreshing the page
|
42
42
|
Then I should be able to refresh the page
|
43
|
+
|
44
|
+
Scenario: Going back and forward
|
45
|
+
When I select the link labeled "Google Search"
|
46
|
+
Then the page should contain the text "Success"
|
47
|
+
When I press the back button
|
48
|
+
Then the page should contain the text "Static Elements Page"
|
49
|
+
When I press the forward button
|
50
|
+
Then the page should contain the text "Success"
|
51
|
+
|
data/features/span.feature
CHANGED
data/features/support/page.rb
CHANGED
@@ -92,6 +92,7 @@ class Page
|
|
92
92
|
span(:span_name, :name => 'span_name')
|
93
93
|
span(:span_class, :class => 'span_class')
|
94
94
|
span(:span_index, :index => 0)
|
95
|
+
span(:span_text, :text => 'My alert')
|
95
96
|
span(:span_xpath, :xpath => '//span')
|
96
97
|
span(:span_class_index, :class => "span_class", :index => 0)
|
97
98
|
span(:span_name_index, :name => "span_name", :index => 0)
|
@@ -119,6 +120,7 @@ class Page
|
|
119
120
|
button(:button_index, :index => 0)
|
120
121
|
button(:button_xpath, :xpath=> "//input[@type='submit']")
|
121
122
|
button(:button_text, :text => 'Click Me')
|
123
|
+
button(:button_value, :value => 'Click Me')
|
122
124
|
button(:button_class_index, :class => "button_class", :index => 0)
|
123
125
|
button(:button_name_index, :name => "button_name", :index => 0)
|
124
126
|
|
data/lib/page-object.rb
CHANGED
@@ -176,6 +176,20 @@ module PageObject
|
|
176
176
|
def refresh
|
177
177
|
platform.refresh
|
178
178
|
end
|
179
|
+
|
180
|
+
#
|
181
|
+
# Go back to the previous page
|
182
|
+
#
|
183
|
+
def back
|
184
|
+
platform.back
|
185
|
+
end
|
186
|
+
|
187
|
+
#
|
188
|
+
# Go forward to the next page
|
189
|
+
#
|
190
|
+
def forward
|
191
|
+
platform.forward
|
192
|
+
end
|
179
193
|
|
180
194
|
private
|
181
195
|
|
@@ -69,10 +69,12 @@ module PageObject
|
|
69
69
|
#
|
70
70
|
def text_field(name, identifier=nil, &block)
|
71
71
|
define_method(name) do
|
72
|
-
platform.text_field_value_for identifier.clone
|
72
|
+
return platform.text_field_value_for identifier.clone unless block
|
73
|
+
self.send("#{name}_element").value
|
73
74
|
end
|
74
75
|
define_method("#{name}=") do |value|
|
75
|
-
platform.text_field_value_set(identifier.clone, value)
|
76
|
+
return platform.text_field_value_set(identifier.clone, value) unless block
|
77
|
+
self.send("#{name}_element").value = value
|
76
78
|
end
|
77
79
|
define_method("#{name}_element") do
|
78
80
|
return call_block(&block) if block
|
@@ -104,7 +106,8 @@ module PageObject
|
|
104
106
|
#
|
105
107
|
def hidden_field(name, identifier=nil, &block)
|
106
108
|
define_method(name) do
|
107
|
-
platform.hidden_field_value_for identifier.clone
|
109
|
+
return platform.hidden_field_value_for identifier.clone unless block
|
110
|
+
self.send("#{name}_element").value
|
108
111
|
end
|
109
112
|
define_method("#{name}_element") do
|
110
113
|
return call_block(&block) if block
|
@@ -136,10 +139,12 @@ module PageObject
|
|
136
139
|
#
|
137
140
|
def text_area(name, identifier=nil, &block)
|
138
141
|
define_method(name) do
|
139
|
-
platform.text_area_value_for identifier.clone
|
142
|
+
return platform.text_area_value_for identifier.clone unless block
|
143
|
+
self.send("#{name}_element").value
|
140
144
|
end
|
141
145
|
define_method("#{name}=") do |value|
|
142
|
-
platform.text_area_value_set(identifier.clone, value)
|
146
|
+
return platform.text_area_value_set(identifier.clone, value) unless block
|
147
|
+
self.send("#{name}_element").value = value
|
143
148
|
end
|
144
149
|
define_method("#{name}_element") do
|
145
150
|
return call_block(&block) if block
|
@@ -171,10 +176,12 @@ module PageObject
|
|
171
176
|
#
|
172
177
|
def select_list(name, identifier=nil, &block)
|
173
178
|
define_method(name) do
|
174
|
-
platform.select_list_value_for identifier.clone
|
179
|
+
return platform.select_list_value_for identifier.clone unless block
|
180
|
+
self.send("#{name}_element").value
|
175
181
|
end
|
176
182
|
define_method("#{name}=") do |value|
|
177
|
-
platform.select_list_value_set(identifier.clone, value)
|
183
|
+
return platform.select_list_value_set(identifier.clone, value) unless block
|
184
|
+
self.send("#{name}_element").select(value)
|
178
185
|
end
|
179
186
|
define_method("#{name}_element") do
|
180
187
|
return call_block(&block) if block
|
@@ -208,7 +215,8 @@ module PageObject
|
|
208
215
|
#
|
209
216
|
def link(name, identifier=nil, &block)
|
210
217
|
define_method(name) do
|
211
|
-
platform.click_link_for identifier.clone
|
218
|
+
return platform.click_link_for identifier.clone unless block
|
219
|
+
self.send("#{name}_element").click
|
212
220
|
end
|
213
221
|
define_method("#{name}_element") do
|
214
222
|
return call_block(&block) if block
|
@@ -238,13 +246,16 @@ module PageObject
|
|
238
246
|
#
|
239
247
|
def checkbox(name, identifier=nil, &block)
|
240
248
|
define_method("check_#{name}") do
|
241
|
-
platform.check_checkbox(identifier.clone)
|
249
|
+
return platform.check_checkbox(identifier.clone) unless block
|
250
|
+
self.send("#{name}_element").check
|
242
251
|
end
|
243
252
|
define_method("uncheck_#{name}") do
|
244
|
-
platform.uncheck_checkbox(identifier.clone)
|
253
|
+
return platform.uncheck_checkbox(identifier.clone) unless block
|
254
|
+
self.send("#{name}_element").uncheck
|
245
255
|
end
|
246
256
|
define_method("#{name}_checked?") do
|
247
|
-
platform.checkbox_checked?(identifier.clone)
|
257
|
+
return platform.checkbox_checked?(identifier.clone) unless block
|
258
|
+
self.send("#{name}_element").checked?
|
248
259
|
end
|
249
260
|
define_method("#{name}_element") do
|
250
261
|
return call_block(&block) if block
|
@@ -275,13 +286,16 @@ module PageObject
|
|
275
286
|
#
|
276
287
|
def radio_button(name, identifier=nil, &block)
|
277
288
|
define_method("select_#{name}") do
|
278
|
-
platform.select_radio(identifier.clone)
|
289
|
+
return platform.select_radio(identifier.clone) unless block
|
290
|
+
self.send("#{name}_element").select
|
279
291
|
end
|
280
292
|
define_method("clear_#{name}") do
|
281
|
-
platform.clear_radio(identifier.clone)
|
293
|
+
return platform.clear_radio(identifier.clone) unless block
|
294
|
+
self.send("#{name}_element").clear
|
282
295
|
end
|
283
296
|
define_method("#{name}_selected?") do
|
284
|
-
platform.radio_selected?(identifier.clone)
|
297
|
+
return platform.radio_selected?(identifier.clone) unless block
|
298
|
+
self.send("#{name}_element").selected?
|
285
299
|
end
|
286
300
|
define_method("#{name}_element") do
|
287
301
|
return call_block(&block) if block
|
@@ -306,12 +320,14 @@ module PageObject
|
|
306
320
|
# * :index => Watir and Selenium
|
307
321
|
# * :name => Watir and Selenium
|
308
322
|
# * :text => Watir only
|
323
|
+
# * :value => Watir and Selenium
|
309
324
|
# * :xpath => Watir and Selenium
|
310
325
|
# @param optional block to be invoked when element method is called
|
311
326
|
#
|
312
327
|
def button(name, identifier=nil, &block)
|
313
328
|
define_method(name) do
|
314
|
-
platform.click_button_for identifier.clone
|
329
|
+
return platform.click_button_for identifier.clone unless block
|
330
|
+
self.send("#{name}_element").click
|
315
331
|
end
|
316
332
|
define_method("#{name}_element") do
|
317
333
|
return call_block(&block) if block
|
@@ -341,7 +357,8 @@ module PageObject
|
|
341
357
|
#
|
342
358
|
def div(name, identifier=nil, &block)
|
343
359
|
define_method(name) do
|
344
|
-
platform.div_text_for identifier.clone
|
360
|
+
return platform.div_text_for identifier.clone unless block
|
361
|
+
self.send("#{name}_element").text
|
345
362
|
end
|
346
363
|
define_method("#{name}_element") do
|
347
364
|
return call_block(&block) if block
|
@@ -370,7 +387,8 @@ module PageObject
|
|
370
387
|
#
|
371
388
|
def span(name, identifier=nil, &block)
|
372
389
|
define_method(name) do
|
373
|
-
platform.span_text_for identifier.clone
|
390
|
+
return platform.span_text_for identifier.clone unless block
|
391
|
+
self.send("#{name}_element").text
|
374
392
|
end
|
375
393
|
define_method("#{name}_element") do
|
376
394
|
return call_block(&block) if block
|
@@ -425,7 +443,8 @@ module PageObject
|
|
425
443
|
#
|
426
444
|
def cell(name, identifier=nil, &block)
|
427
445
|
define_method("#{name}") do
|
428
|
-
platform.cell_text_for identifier.clone
|
446
|
+
return platform.cell_text_for identifier.clone unless block
|
447
|
+
self.send("#{name}_element").text
|
429
448
|
end
|
430
449
|
define_method("#{name}_element") do
|
431
450
|
return call_block(&block) if block
|
@@ -503,7 +522,8 @@ module PageObject
|
|
503
522
|
#
|
504
523
|
def list_item(name, identifier=nil, &block)
|
505
524
|
define_method(name) do
|
506
|
-
platform.list_item_text_for identifier.clone
|
525
|
+
return platform.list_item_text_for identifier.clone unless block
|
526
|
+
self.send("#{name}_element").text
|
507
527
|
end
|
508
528
|
define_method("#{name}_element") do
|
509
529
|
return call_block(&block) if block
|
@@ -2,6 +2,25 @@ module PageObject
|
|
2
2
|
module Elements
|
3
3
|
class CheckBox < Element
|
4
4
|
|
5
|
+
def initialize(element, platform)
|
6
|
+
@element = element
|
7
|
+
include_platform_for platform
|
8
|
+
end
|
9
|
+
|
10
|
+
protected
|
11
|
+
|
12
|
+
def include_platform_for platform
|
13
|
+
super
|
14
|
+
if platform[:platform] == :watir
|
15
|
+
require 'page-object/platforms/watir/check_box'
|
16
|
+
self.class.send :include, PageObject::Platforms::Watir::CheckBox
|
17
|
+
elsif platform[:platform] == :selenium
|
18
|
+
require 'page-object/platforms/selenium/check_box'
|
19
|
+
self.class.send :include, PageObject::Platforms::Selenium::CheckBox
|
20
|
+
else
|
21
|
+
raise ArgumentError, "expect platform to be :watir or :selenium"
|
22
|
+
end
|
23
|
+
end
|
5
24
|
end
|
6
25
|
end
|
7
26
|
end
|
@@ -2,6 +2,25 @@ module PageObject
|
|
2
2
|
module Elements
|
3
3
|
class RadioButton < Element
|
4
4
|
|
5
|
+
def initialize(element, platform)
|
6
|
+
@element = element
|
7
|
+
include_platform_for platform
|
8
|
+
end
|
9
|
+
|
10
|
+
protected
|
11
|
+
|
12
|
+
def include_platform_for platform
|
13
|
+
super
|
14
|
+
if platform[:platform] == :watir
|
15
|
+
require 'page-object/platforms/watir/radio_button'
|
16
|
+
self.class.send :include, PageObject::Platforms::Watir::RadioButton
|
17
|
+
elsif platform[:platform] == :selenium
|
18
|
+
require 'page-object/platforms/selenium/radio_button'
|
19
|
+
self.class.send :include, PageObject::Platforms::Selenium::RadioButton
|
20
|
+
else
|
21
|
+
raise ArgumentError, "expect platform to be :watir or :selenium"
|
22
|
+
end
|
23
|
+
end
|
5
24
|
end
|
6
25
|
end
|
7
|
-
end
|
26
|
+
end
|
@@ -2,6 +2,11 @@ module PageObject
|
|
2
2
|
module Elements
|
3
3
|
class TextArea < Element
|
4
4
|
|
5
|
+
def initialize(element, platform)
|
6
|
+
@element = element
|
7
|
+
include_platform_for platform
|
8
|
+
end
|
9
|
+
|
5
10
|
protected
|
6
11
|
|
7
12
|
def self.watir_finders
|
@@ -19,6 +24,19 @@ module PageObject
|
|
19
24
|
def self.selenium_mapping
|
20
25
|
super.merge({:tag_name => :css})
|
21
26
|
end
|
27
|
+
|
28
|
+
def include_platform_for platform
|
29
|
+
super
|
30
|
+
if platform[:platform] == :watir
|
31
|
+
require 'page-object/platforms/watir/text_area'
|
32
|
+
self.class.send :include, PageObject::Platforms::Watir::TextArea
|
33
|
+
elsif platform[:platform] == :selenium
|
34
|
+
require 'page-object/platforms/selenium/text_area'
|
35
|
+
self.class.send :include, PageObject::Platforms::Selenium::TextArea
|
36
|
+
else
|
37
|
+
raise ArgumentError, "expect platform to be :watir or :selenium"
|
38
|
+
end
|
39
|
+
end
|
22
40
|
end
|
23
41
|
end
|
24
42
|
end
|
@@ -2,6 +2,11 @@ module PageObject
|
|
2
2
|
module Elements
|
3
3
|
class TextField < Element
|
4
4
|
|
5
|
+
def initialize(element, platform)
|
6
|
+
@element = element
|
7
|
+
include_platform_for platform
|
8
|
+
end
|
9
|
+
|
5
10
|
protected
|
6
11
|
|
7
12
|
def self.watir_finders
|
@@ -19,6 +24,19 @@ module PageObject
|
|
19
24
|
def self.selenium_mapping
|
20
25
|
super.merge({:tag_name => :css})
|
21
26
|
end
|
27
|
+
|
28
|
+
def include_platform_for platform
|
29
|
+
super
|
30
|
+
if platform[:platform] == :watir
|
31
|
+
require 'page-object/platforms/watir/text_field'
|
32
|
+
self.class.send :include, PageObject::Platforms::Watir::TextField
|
33
|
+
elsif platform[:platform] == :selenium
|
34
|
+
require 'page-object/platforms/selenium/text_field'
|
35
|
+
self.class.send :include, PageObject::Platforms::Selenium::TextField
|
36
|
+
else
|
37
|
+
raise ArgumentError, "expect platform to be :watir or :selenium"
|
38
|
+
end
|
39
|
+
end
|
22
40
|
end
|
23
41
|
end
|
24
42
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module PageObject
|
2
|
+
module Platforms
|
3
|
+
module Selenium
|
4
|
+
module CheckBox
|
5
|
+
|
6
|
+
#
|
7
|
+
# check the checkbox
|
8
|
+
#
|
9
|
+
def check
|
10
|
+
element.click unless selected?
|
11
|
+
end
|
12
|
+
|
13
|
+
#
|
14
|
+
# uncheck the checkbox
|
15
|
+
#
|
16
|
+
def uncheck
|
17
|
+
element.click if selected?
|
18
|
+
end
|
19
|
+
|
20
|
+
#
|
21
|
+
# return true if it is checked
|
22
|
+
#
|
23
|
+
def checked?
|
24
|
+
element.selected?
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -113,6 +113,22 @@ module PageObject
|
|
113
113
|
@browser.navigate.refresh
|
114
114
|
end
|
115
115
|
|
116
|
+
#
|
117
|
+
# platform method to go back to the previous page
|
118
|
+
# See PageObject#back
|
119
|
+
#
|
120
|
+
def back
|
121
|
+
@browser.navigate.back
|
122
|
+
end
|
123
|
+
|
124
|
+
#
|
125
|
+
# platform method to go forward to the next page
|
126
|
+
# See PageObject#forward
|
127
|
+
#
|
128
|
+
def forward
|
129
|
+
@browser.navigate.forward
|
130
|
+
end
|
131
|
+
|
116
132
|
#
|
117
133
|
# platform method to get the value stored in a text field
|
118
134
|
# See PageObject::Accessors#text_field
|
@@ -561,8 +577,8 @@ module PageObject
|
|
561
577
|
return false if identifier[:index]
|
562
578
|
return false if identifier[:text] and tag == 'input' and additional[:type] == 'hidden'
|
563
579
|
return false if identifier[:href] and tag == 'a'
|
564
|
-
return false if identifier[:text] and
|
565
|
-
return false if identifier[:
|
580
|
+
return false if identifier[:text] and ['div', 'span', 'td'].include? tag
|
581
|
+
return false if identifier[:value] and tag == 'input' and additional[:type] == 'submit'
|
566
582
|
true
|
567
583
|
end
|
568
584
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module PageObject
|
2
|
+
module Platforms
|
3
|
+
module Selenium
|
4
|
+
module RadioButton
|
5
|
+
|
6
|
+
#
|
7
|
+
# select the radiobutton
|
8
|
+
#
|
9
|
+
def select
|
10
|
+
element.click unless selected?
|
11
|
+
end
|
12
|
+
|
13
|
+
#
|
14
|
+
# clear the radiobutton
|
15
|
+
#
|
16
|
+
def clear
|
17
|
+
element.click if selected?
|
18
|
+
end
|
19
|
+
|
20
|
+
#
|
21
|
+
# return if it is selected
|
22
|
+
#
|
23
|
+
def selected?
|
24
|
+
element.selected?
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module PageObject
|
2
|
+
module Platforms
|
3
|
+
module Watir
|
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
|
@@ -95,6 +95,22 @@ module PageObject
|
|
95
95
|
def refresh
|
96
96
|
@browser.refresh
|
97
97
|
end
|
98
|
+
|
99
|
+
#
|
100
|
+
# platform method to go back to the previous page
|
101
|
+
# See PageObject#back
|
102
|
+
#
|
103
|
+
def back
|
104
|
+
@browser.back
|
105
|
+
end
|
106
|
+
|
107
|
+
#
|
108
|
+
# platform method to go forward to the next page
|
109
|
+
# See PageObject#forward
|
110
|
+
#
|
111
|
+
def forward
|
112
|
+
@browser.forward
|
113
|
+
end
|
98
114
|
|
99
115
|
#
|
100
116
|
# platform method to get the value stored in a text field
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module PageObject
|
2
|
+
module Platforms
|
3
|
+
module Watir
|
4
|
+
module RadioButton
|
5
|
+
|
6
|
+
#
|
7
|
+
# select the radiobutton
|
8
|
+
#
|
9
|
+
def select
|
10
|
+
element.set
|
11
|
+
end
|
12
|
+
|
13
|
+
#
|
14
|
+
# clear the radiobutton
|
15
|
+
#
|
16
|
+
def clear
|
17
|
+
element.clear
|
18
|
+
end
|
19
|
+
|
20
|
+
#
|
21
|
+
# return if it is selected
|
22
|
+
#
|
23
|
+
def selected?
|
24
|
+
element.set?
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -13,6 +13,13 @@ module PageObject
|
|
13
13
|
PageObject::Elements::Option.new(options[idx], :platform => :watir)
|
14
14
|
end
|
15
15
|
|
16
|
+
#
|
17
|
+
# Select a value from the list
|
18
|
+
#
|
19
|
+
def select(value)
|
20
|
+
@element.select(value)
|
21
|
+
end
|
22
|
+
|
16
23
|
#
|
17
24
|
# Return an array of Options contained in the select lit.
|
18
25
|
#
|
data/lib/page-object/version.rb
CHANGED
data/page-object.gemspec
CHANGED
@@ -19,7 +19,7 @@ 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.
|
22
|
+
s.add_dependency 'watir-webdriver', '>= 0.3.0'
|
23
23
|
s.add_dependency 'selenium-webdriver', '>= 2.3.2'
|
24
24
|
|
25
25
|
s.add_development_dependency 'rspec', '>= 2.6.0'
|
@@ -6,14 +6,14 @@ describe PageObject::Elements::Button do
|
|
6
6
|
|
7
7
|
context "when mapping how to find an element" do
|
8
8
|
it "should map watir types to same" do
|
9
|
-
[:class, :id, :index, :name, :xpath].each do |t|
|
9
|
+
[:class, :id, :index, :name, :value, :xpath].each do |t|
|
10
10
|
identifier = button.watir_identifier_for t => 'value'
|
11
11
|
identifier.keys.first.should == t
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should map selenium types to same" do
|
16
|
-
[:class, :id, :index, :name, :xpath].each do |t|
|
16
|
+
[:class, :id, :index, :name, :value, :xpath].each do |t|
|
17
17
|
key, value = button.selenium_identifier_for t => 'value'
|
18
18
|
key.should == t
|
19
19
|
end
|
@@ -18,4 +18,29 @@ describe PageObject::Elements::CheckBox do
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
21
|
+
|
22
|
+
describe "interface" do
|
23
|
+
let(:check_box) { double('check_box') }
|
24
|
+
let(:selenium_cb) { PageObject::Elements::CheckBox.new(check_box, :platform => :selenium) }
|
25
|
+
|
26
|
+
|
27
|
+
context "for selenium" do
|
28
|
+
it "should check" do
|
29
|
+
check_box.should_receive(:click)
|
30
|
+
check_box.should_receive(:selected?).and_return(false)
|
31
|
+
selenium_cb.check
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should uncheck" do
|
35
|
+
check_box.should_receive(:click)
|
36
|
+
check_box.should_receive(:selected?).and_return(true)
|
37
|
+
selenium_cb.uncheck
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should know if it is checked" do
|
41
|
+
check_box.should_receive(:selected?).and_return(true)
|
42
|
+
selenium_cb.should be_checked
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
21
46
|
end
|
@@ -139,6 +139,16 @@ describe PageObject::Elements::Element do
|
|
139
139
|
watir_driver.should_receive(:click)
|
140
140
|
watir_element.click
|
141
141
|
end
|
142
|
+
|
143
|
+
it "should be double clickable" do
|
144
|
+
watir_driver.should_receive(:double_click)
|
145
|
+
watir_element.double_click
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should be right clickable" do
|
149
|
+
watir_driver.should_receive(:right_click)
|
150
|
+
watir_element.right_click
|
151
|
+
end
|
142
152
|
|
143
153
|
it "should be able to block until it is present" do
|
144
154
|
watir_driver.should_receive(:wait_until_present).with(10)
|
@@ -222,6 +232,16 @@ describe PageObject::Elements::Element do
|
|
222
232
|
selenium_element.click
|
223
233
|
end
|
224
234
|
|
235
|
+
it "should be double clickable" do
|
236
|
+
selenium_driver.should_receive(:double_click)
|
237
|
+
selenium_element.double_click
|
238
|
+
end
|
239
|
+
|
240
|
+
it "should be right clickable" do
|
241
|
+
selenium_driver.should_receive(:context_click)
|
242
|
+
selenium_element.right_click
|
243
|
+
end
|
244
|
+
|
225
245
|
it "should be able to block until it is present" do
|
226
246
|
wait = double('wait')
|
227
247
|
Object::Selenium::WebDriver::Wait.should_receive(:new).and_return(wait)
|
@@ -18,4 +18,28 @@ describe PageObject::Elements::RadioButton do
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
21
|
+
|
22
|
+
describe "interface" do
|
23
|
+
context "for selenium" do
|
24
|
+
let(:selenium_rb) { double('radio_button') }
|
25
|
+
let(:radio_button) { PageObject::Elements::RadioButton.new(selenium_rb, :platform => :selenium) }
|
26
|
+
|
27
|
+
it "should select" do
|
28
|
+
selenium_rb.should_receive(:click)
|
29
|
+
selenium_rb.should_receive(:selected?).and_return(false)
|
30
|
+
radio_button.select
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should clear" do
|
34
|
+
selenium_rb.should_receive(:click)
|
35
|
+
selenium_rb.should_receive(:selected?).and_return(true)
|
36
|
+
radio_button.clear
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should know if it is selected" do
|
40
|
+
selenium_rb.should_receive(:selected?).and_return(true)
|
41
|
+
radio_button.should be_selected
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
21
45
|
end
|
@@ -43,7 +43,6 @@ describe PageObject::Elements::SelectList do
|
|
43
43
|
sel_list.should_receive(:find_elements).with(:xpath, ".//child::option").and_return(opts)
|
44
44
|
watir_sel_list.options.size.should == 2
|
45
45
|
end
|
46
|
-
|
47
46
|
end
|
48
47
|
|
49
48
|
context "for selenium" do
|
@@ -58,6 +57,12 @@ describe PageObject::Elements::SelectList do
|
|
58
57
|
sel_list.should_receive(:find_elements).with(:xpath, ".//child::option").and_return(opts)
|
59
58
|
selenium_sel_list.options.size.should == 2
|
60
59
|
end
|
60
|
+
|
61
|
+
it "should select an element" do
|
62
|
+
selenium_sel_list = PageObject::Elements::SelectList.new(sel_list, :platform => :selenium)
|
63
|
+
sel_list.should_receive(:send_keys).with('something')
|
64
|
+
selenium_sel_list.select 'something'
|
65
|
+
end
|
61
66
|
end
|
62
67
|
end
|
63
68
|
end
|
@@ -6,14 +6,14 @@ describe PageObject::Elements::Span do
|
|
6
6
|
|
7
7
|
describe "when mapping how to find an element" do
|
8
8
|
it "should map watir types to same" do
|
9
|
-
[:class, :id, :index, :xpath].each do |t|
|
9
|
+
[:class, :id, :index, :text, :xpath].each do |t|
|
10
10
|
identifier = span.watir_identifier_for t => 'value'
|
11
11
|
identifier.keys.first.should == t
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should map selenium types to same" do
|
16
|
-
[:class, :id, :index, :name, :xpath].each do |t|
|
16
|
+
[:class, :id, :index, :name, :text, :xpath].each do |t|
|
17
17
|
key, value = span.selenium_identifier_for t => 'value'
|
18
18
|
key.should == t
|
19
19
|
end
|
@@ -27,14 +27,14 @@ describe PageObject::Elements::Table do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
context "for watir" do
|
30
|
+
let(:watir_table) { PageObject::Elements::Table.new(table_element, :platform => :watir) }
|
31
|
+
|
30
32
|
it "should return a table row when indexed" do
|
31
|
-
watir_table = PageObject::Elements::Table.new(table_element, :platform => :watir)
|
32
33
|
table_element.stub(:[]).with(1).and_return(table_element)
|
33
34
|
watir_table[1].should be_instance_of PageObject::Elements::TableRow
|
34
35
|
end
|
35
36
|
|
36
37
|
it "should return the number of rows" do
|
37
|
-
watir_table = PageObject::Elements::Table.new(table_element, :platform => :watir)
|
38
38
|
table_element.stub(:wd).and_return(table_element)
|
39
39
|
table_element.should_receive(:find_elements).with(:xpath, ".//child::tr").and_return(table_element)
|
40
40
|
table_element.should_receive(:size).and_return(2)
|
@@ -42,7 +42,6 @@ describe PageObject::Elements::Table do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should iterate over the table rows" do
|
45
|
-
watir_table = PageObject::Elements::Table.new(table_element, :platform => :watir)
|
46
45
|
watir_table.should_receive(:rows).and_return(2)
|
47
46
|
count = 0
|
48
47
|
watir_table.each { |e| count += 1 }
|
@@ -51,21 +50,20 @@ describe PageObject::Elements::Table do
|
|
51
50
|
end
|
52
51
|
|
53
52
|
context "for selenium" do
|
53
|
+
let(:selenium_table) { PageObject::Elements::Table.new(table_element, :platform => :selenium) }
|
54
|
+
|
54
55
|
it "should return a table row when indexed" do
|
55
|
-
selenium_table = PageObject::Elements::Table.new(table_element, :platform => :selenium)
|
56
56
|
table_element.should_receive(:find_elements).with(:xpath, ".//child::tr").and_return(table_element)
|
57
57
|
selenium_table[1].should be_instance_of PageObject::Elements::TableRow
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should return the number of rows" do
|
61
|
-
selenium_table = PageObject::Elements::Table.new(table_element, :platform => :selenium)
|
62
61
|
table_element.should_receive(:find_elements).with(:xpath, ".//child::tr").and_return(table_element)
|
63
62
|
table_element.should_receive(:size).and_return(2)
|
64
63
|
selenium_table.rows.should == 2
|
65
64
|
end
|
66
65
|
|
67
66
|
it "should iterate over the table rows" do
|
68
|
-
selenium_table = PageObject::Elements::Table.new(table_element, :platform => :selenium)
|
69
67
|
selenium_table.should_receive(:rows).and_return(2)
|
70
68
|
count = 0
|
71
69
|
selenium_table.each { |e| count += 1 }
|
@@ -29,4 +29,16 @@ describe PageObject::Elements::TextArea do
|
|
29
29
|
key.should == :css
|
30
30
|
end
|
31
31
|
end
|
32
|
+
|
33
|
+
describe "interface" do
|
34
|
+
context "for Selenium" do
|
35
|
+
it "should set its' value" do
|
36
|
+
text_area_element = double('text_area')
|
37
|
+
text_area = PageObject::Elements::TextArea.new(text_area_element, :platform => :selenium)
|
38
|
+
text_area_element.should_receive(:clear)
|
39
|
+
text_area_element.should_receive(:send_keys).with('Joseph')
|
40
|
+
text_area.value = 'Joseph'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
32
44
|
end
|
@@ -2,9 +2,10 @@ require 'spec_helper'
|
|
2
2
|
require 'page-object/elements'
|
3
3
|
|
4
4
|
describe PageObject::Elements::TextField do
|
5
|
-
let(:textfield) { PageObject::Elements::TextField }
|
6
5
|
|
7
6
|
describe "when mapping how to find an element" do
|
7
|
+
let(:textfield) { PageObject::Elements::TextField }
|
8
|
+
|
8
9
|
it "should map watir types to same" do
|
9
10
|
[:class, :id, :index, :name, :tag_name, :xpath].each do |t|
|
10
11
|
identifier = textfield.watir_identifier_for t => 'value'
|
@@ -29,4 +30,16 @@ describe PageObject::Elements::TextField do
|
|
29
30
|
key.should == :css
|
30
31
|
end
|
31
32
|
end
|
33
|
+
|
34
|
+
describe "interface" do
|
35
|
+
context "for selenium" do
|
36
|
+
it "should set its' value" do
|
37
|
+
text_field_element = double('selenium_text_field')
|
38
|
+
selenium_text_field = PageObject::Elements::TextField.new(text_field_element, :platform => :selenium)
|
39
|
+
text_field_element.should_receive(:clear)
|
40
|
+
text_field_element.should_receive(:send_keys).with('Joseph')
|
41
|
+
selenium_text_field.value = 'Joseph'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
32
45
|
end
|
@@ -125,6 +125,16 @@ describe PageObject do
|
|
125
125
|
watir_browser.should_receive(:refresh)
|
126
126
|
watir_page_object.refresh
|
127
127
|
end
|
128
|
+
|
129
|
+
it "should know how to go back" do
|
130
|
+
watir_browser.should_receive(:back)
|
131
|
+
watir_page_object.back
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should know how to go forward" do
|
135
|
+
watir_browser.should_receive(:forward)
|
136
|
+
watir_page_object.forward
|
137
|
+
end
|
128
138
|
end
|
129
139
|
|
130
140
|
context "when using SeleniumPageObject" do
|
@@ -193,6 +203,18 @@ describe PageObject do
|
|
193
203
|
selenium_browser.should_receive(:refresh)
|
194
204
|
selenium_page_object.refresh
|
195
205
|
end
|
206
|
+
|
207
|
+
it "should know how to go back" do
|
208
|
+
selenium_browser.should_receive(:navigate).and_return(selenium_browser)
|
209
|
+
selenium_browser.should_receive(:back)
|
210
|
+
selenium_page_object.back
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should know how to go forward" do
|
214
|
+
selenium_browser.should_receive(:navigate).and_return(selenium_browser)
|
215
|
+
selenium_browser.should_receive(:forward)
|
216
|
+
selenium_page_object.forward
|
217
|
+
end
|
196
218
|
end
|
197
219
|
end
|
198
220
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: page-object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.2.
|
5
|
+
version: 0.2.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jeff Morgan
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-08-
|
13
|
+
date: 2011-08-08 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: watir-webdriver
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.
|
23
|
+
version: 0.3.0
|
24
24
|
type: :runtime
|
25
25
|
version_requirements: *id001
|
26
26
|
- !ruby/object:Gem::Dependency
|
@@ -159,25 +159,33 @@ files:
|
|
159
159
|
- lib/page-object/platforms.rb
|
160
160
|
- lib/page-object/platforms/selenium.rb
|
161
161
|
- lib/page-object/platforms/selenium/button.rb
|
162
|
+
- lib/page-object/platforms/selenium/check_box.rb
|
162
163
|
- lib/page-object/platforms/selenium/element.rb
|
163
164
|
- lib/page-object/platforms/selenium/form.rb
|
164
165
|
- lib/page-object/platforms/selenium/image.rb
|
165
166
|
- lib/page-object/platforms/selenium/link.rb
|
166
167
|
- lib/page-object/platforms/selenium/ordered_list.rb
|
167
168
|
- lib/page-object/platforms/selenium/page_object.rb
|
169
|
+
- lib/page-object/platforms/selenium/radio_button.rb
|
168
170
|
- lib/page-object/platforms/selenium/select_list.rb
|
169
171
|
- lib/page-object/platforms/selenium/table.rb
|
170
172
|
- lib/page-object/platforms/selenium/table_row.rb
|
173
|
+
- lib/page-object/platforms/selenium/text_area.rb
|
174
|
+
- lib/page-object/platforms/selenium/text_field.rb
|
171
175
|
- lib/page-object/platforms/selenium/unordered_list.rb
|
172
176
|
- lib/page-object/platforms/watir.rb
|
177
|
+
- lib/page-object/platforms/watir/check_box.rb
|
173
178
|
- lib/page-object/platforms/watir/element.rb
|
174
179
|
- lib/page-object/platforms/watir/form.rb
|
175
180
|
- lib/page-object/platforms/watir/image.rb
|
176
181
|
- lib/page-object/platforms/watir/ordered_list.rb
|
177
182
|
- lib/page-object/platforms/watir/page_object.rb
|
183
|
+
- lib/page-object/platforms/watir/radio_button.rb
|
178
184
|
- lib/page-object/platforms/watir/select_list.rb
|
179
185
|
- lib/page-object/platforms/watir/table.rb
|
180
186
|
- lib/page-object/platforms/watir/table_row.rb
|
187
|
+
- lib/page-object/platforms/watir/text_area.rb
|
188
|
+
- lib/page-object/platforms/watir/text_field.rb
|
181
189
|
- lib/page-object/platforms/watir/unordered_list.rb
|
182
190
|
- lib/page-object/version.rb
|
183
191
|
- page-object.gemspec
|