page-object 0.7.2 → 0.7.3
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 +1 -0
- data/ChangeLog +8 -0
- data/cucumber.yml +2 -1
- data/features/audio.feature +17 -0
- data/features/element.feature +10 -0
- data/features/html/hover.html +12 -0
- data/features/html/static_elements.html +10 -2
- data/features/page_level_actions.feature +8 -0
- data/features/sample-app/public/04-Death_Becomes_Fur.mp4 +0 -0
- data/features/sample-app/public/04-Death_Becomes_Fur.oga +0 -0
- data/features/sample-app/public/movie.mp4 +0 -0
- data/features/sample-app/public/movie.ogg +0 -0
- data/features/step_definitions/element_steps.rb +21 -0
- data/features/step_definitions/page_level_actions_steps.rb +12 -0
- data/features/step_definitions/video_steps.rb +45 -0
- data/features/support/page.rb +10 -0
- data/features/support/persistent_browser.rb +3 -2
- data/features/support/url_helper.rb +4 -0
- data/features/video.feature +72 -0
- data/lib/page-object.rb +1 -0
- data/lib/page-object/accessors.rb +29 -0
- data/lib/page-object/element_locators.rb +30 -0
- data/lib/page-object/elements.rb +2 -0
- data/lib/page-object/elements/audio.rb +1 -23
- data/lib/page-object/elements/element.rb +1 -1
- data/lib/page-object/elements/media.rb +45 -0
- data/lib/page-object/elements/video.rb +18 -0
- data/lib/page-object/nested_elements.rb +8 -0
- data/lib/page-object/platforms/selenium_webdriver/element.rb +23 -5
- data/lib/page-object/platforms/selenium_webdriver/page_object.rb +22 -4
- data/lib/page-object/platforms/watir_webdriver/element.rb +14 -0
- data/lib/page-object/platforms/watir_webdriver/page_object.rb +18 -4
- data/lib/page-object/version.rb +1 -1
- data/spec/page-object/element_locators_spec.rb +22 -0
- data/spec/page-object/page-object_spec.rb +14 -6
- data/spec/page-object/selenium_accessors_spec.rb +16 -0
- data/spec/page-object/watir_accessors_spec.rb +16 -0
- metadata +20 -4
data/.gitignore
CHANGED
data/ChangeLog
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
=== Version 0.7.3 / 2012-8-18
|
2
|
+
* Enhancements
|
3
|
+
* Improved handling of alert and confirm Javascript popups (George Shakhnazaryan)
|
4
|
+
* Added hover method to Element. Browser support is limited.
|
5
|
+
* Added method to get the id of an Element
|
6
|
+
* Added support for the following new elements
|
7
|
+
Video
|
8
|
+
|
1
9
|
=== Version 0.7.2 / 2012-8-1
|
2
10
|
* Enhancements
|
3
11
|
* Added ability to find list_item by :text
|
data/cucumber.yml
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
<%
|
2
|
-
std_opts = "--no-source --color --format Cucumber::Formatter::Fuubar"
|
2
|
+
std_opts = "BROWSER=firefox --no-source --color --format Cucumber::Formatter::Fuubar"
|
3
3
|
%>
|
4
4
|
|
5
5
|
default: DRIVER=WATIR <%= std_opts %> --tags ~@selenium_only
|
6
6
|
watir: DRIVER=WATIR <%= std_opts %> --tags ~@selenium_only
|
7
7
|
selenium: DRIVER=SELENIUM <%= std_opts %> --tags ~@watir_only
|
8
8
|
focus: DRIVER=WATIR <%= std_opts %> --tags ~@selenium_only --tags @focus
|
9
|
+
#focus: DRIVER=SELENIUM <%= std_opts %> --tags ~@watir_only --tags @focus
|
9
10
|
|
data/features/audio.feature
CHANGED
@@ -48,3 +48,20 @@ Feature: Support for the audio element
|
|
48
48
|
Scenario: Should know its volume
|
49
49
|
When I retrieve the audio element
|
50
50
|
Then I should know that its volume is 1
|
51
|
+
|
52
|
+
Scenario: Should know if it has ended
|
53
|
+
When I retrieve the audio element
|
54
|
+
Then I should know that it has not ended
|
55
|
+
|
56
|
+
Scenario: Should know if it is seeking
|
57
|
+
When I retrieve the audio element
|
58
|
+
Then I should know that it is not seeking
|
59
|
+
|
60
|
+
Scenario: Should know if it is in a loop
|
61
|
+
When I retrieve the audio element
|
62
|
+
Then I should know that it is not in a loop
|
63
|
+
|
64
|
+
Scenario: Should know if it is muted
|
65
|
+
When I retrieve the audio element
|
66
|
+
Then I should know that it is muted
|
67
|
+
|
data/features/element.feature
CHANGED
@@ -264,6 +264,11 @@ Feature: Elements
|
|
264
264
|
When I set the focus to the test text_field using the onfocus event
|
265
265
|
Then I should see the onfocus text "changed by onfocus event"
|
266
266
|
|
267
|
+
Scenario: Hovering over an element
|
268
|
+
Given I am on the hover page
|
269
|
+
When I hover over the hello link
|
270
|
+
Then the font size should be "20px"
|
271
|
+
|
267
272
|
Scenario: Setting focus on an element
|
268
273
|
When I set the focus on the test text_field
|
269
274
|
Then I should see the onfocus text "changed by onfocus event"
|
@@ -276,3 +281,8 @@ Feature: Elements
|
|
276
281
|
Scenario: Flashing an element
|
277
282
|
When I retrieve a button element
|
278
283
|
Then I should be able to flash it
|
284
|
+
|
285
|
+
@focus
|
286
|
+
Scenario: Getting an element's id
|
287
|
+
When I retrieve a button element
|
288
|
+
Then I should know its id is "button_id"
|
@@ -41,13 +41,19 @@
|
|
41
41
|
</script>
|
42
42
|
|
43
43
|
<audio controls id="audio" name="audio" class="audio">
|
44
|
-
<source src="http://
|
44
|
+
<source src="http://localhost:4567/04-Death_Becomes_Fur.mp4"
|
45
45
|
type='audio/mp4'>
|
46
|
-
<source src="http://
|
46
|
+
<source src="http://localhost:4567/04-Death_Becomes_Fur.oga"
|
47
47
|
type='audio/ogg; codecs=vorbis'>
|
48
48
|
<p>Your user agent does not support the HTML5 Audio element.</p>
|
49
49
|
</audio>
|
50
50
|
|
51
|
+
<video width="320" height="240" controls="controls" id="video" name="video" class="video">
|
52
|
+
<source src="http://localhost:4567/movie.mp4" type="video/mp4" />
|
53
|
+
<source src="http://localhost:4567/movie.ogg" type="video/ogg" />
|
54
|
+
Your browser does not support the video tag.
|
55
|
+
</video>
|
56
|
+
|
51
57
|
<a href="success.html" id="link_id" name="link_name" class="link_class" title="link_title">Google Search</a>
|
52
58
|
|
53
59
|
<input id="cb_id" name="cb_name" class="cb_class" type="checkbox" value="1"/>
|
@@ -128,7 +134,9 @@
|
|
128
134
|
<a href="success.html">Hello</a>
|
129
135
|
|
130
136
|
<input id=alert_button type=button onclick="alert('I am an alert')" value=Alert>
|
137
|
+
<input id=alert_button_that_reloads type=button onclick="alert('I am an alert'); location.reload()" value="Alert that Reloads">
|
131
138
|
<input id=confirm_button type=button onclick="this.value = confirm('set the value')" value=Confirm>
|
139
|
+
<input id=confirm_button_that_reloads type=button onclick="if(confirm('set the value')) location.reload()" value="Confirm that Reloads">
|
132
140
|
<input id=prompt_button type=button onclick='this.value = prompt("enter your name", "John Doe")' value=Prompt>
|
133
141
|
|
134
142
|
<h1 id="h1_id" class="h1_class" name="h1_name">h1's are cool</h1>
|
@@ -31,10 +31,18 @@ Feature: Page level actions
|
|
31
31
|
When I handle the alert
|
32
32
|
Then I should be able to get the alert's message
|
33
33
|
|
34
|
+
Scenario: Handling alert popups that reload the page
|
35
|
+
When I handle the alert that reloads the page
|
36
|
+
Then I should be able to get the alert's message
|
37
|
+
|
34
38
|
Scenario: Handling confirm popups
|
35
39
|
When I handle the confirm
|
36
40
|
Then I should be able to get the confirm message
|
37
41
|
|
42
|
+
Scenario: Handling confirm popups that reload the page
|
43
|
+
When I handle the confirm that reloads the page
|
44
|
+
Then I should be able to get the confirm message
|
45
|
+
|
38
46
|
Scenario: Handling prompt popups
|
39
47
|
When I handle the prompt
|
40
48
|
Then I should be able to get the message and default value
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -190,4 +190,25 @@ Then /^I should be able to flash it$/ do
|
|
190
190
|
@element.flash
|
191
191
|
end
|
192
192
|
|
193
|
+
class HoverPage
|
194
|
+
include PageObject
|
193
195
|
|
196
|
+
link(:hello)
|
197
|
+
end
|
198
|
+
|
199
|
+
Given /^I am on the hover page$/ do
|
200
|
+
@page = HoverPage.new(@browser)
|
201
|
+
@page.navigate_to UrlHelper.hover
|
202
|
+
end
|
203
|
+
|
204
|
+
When /^I hover over the hello link$/ do
|
205
|
+
@page.hello_element.hover
|
206
|
+
end
|
207
|
+
|
208
|
+
Then /^the font size should be "([^\"]*)"$/ do |font_size|
|
209
|
+
@page.hello_element.style('font-size').should == font_size if ENV['BROWSER'] == 'chrome'
|
210
|
+
end
|
211
|
+
|
212
|
+
Then /^I should know its id is "([^\"]*)"$/ do |id|
|
213
|
+
@element.id.should == id
|
214
|
+
end
|
@@ -23,6 +23,12 @@ When /^I handle the alert$/ do
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
When /^I handle the alert that reloads the page$/ do
|
27
|
+
@msg = @page.alert do
|
28
|
+
@page.alert_button_that_reloads
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
26
32
|
Then /^I should be able to get the alert\'s message$/ do
|
27
33
|
@msg.should == "I am an alert"
|
28
34
|
end
|
@@ -33,6 +39,12 @@ When /^I handle the confirm$/ do
|
|
33
39
|
end
|
34
40
|
end
|
35
41
|
|
42
|
+
When /^I handle the confirm that reloads the page$/ do
|
43
|
+
@msg = @page.confirm(true) do
|
44
|
+
@page.confirm_button_that_reloads
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
36
48
|
Then /^I should be able to get the confirm message$/ do
|
37
49
|
@msg.should == 'set the value'
|
38
50
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
|
2
|
+
When /^I retrieve the video element$/ do
|
3
|
+
@element = @page.video_id_element
|
4
|
+
end
|
5
|
+
|
6
|
+
When /^I search for the video element by "([^\"]*)"$/ do |how|
|
7
|
+
@element = @page.send "video_#{how}_element"
|
8
|
+
end
|
9
|
+
|
10
|
+
When /^I search for the video element by "([^\"]*)" and "([^\"]*)"$/ do |param1, param2|
|
11
|
+
@element = @page.send "video_#{param1}_#{param2}_element"
|
12
|
+
end
|
13
|
+
|
14
|
+
Then /^I should know the video is not autoplay$/ do
|
15
|
+
@element.should_not be_autoplay
|
16
|
+
end
|
17
|
+
|
18
|
+
Then /^I should know that the video is paused$/ do
|
19
|
+
@element.should be_paused
|
20
|
+
end
|
21
|
+
|
22
|
+
Then /^I should know that its height is (\d+) pixels$/ do |height|
|
23
|
+
@element.height.should == height.to_i
|
24
|
+
end
|
25
|
+
|
26
|
+
Then /^I should knot what its width is (\d+) pixels$/ do |width|
|
27
|
+
@element.width.should == width.to_i
|
28
|
+
end
|
29
|
+
|
30
|
+
Then /^I should know that it has not ended$/ do
|
31
|
+
@element.should_not be_ended
|
32
|
+
end
|
33
|
+
|
34
|
+
Then /^I should know that it is not seeking$/ do
|
35
|
+
@element.should_not be_seeking
|
36
|
+
end
|
37
|
+
|
38
|
+
Then /^I should know that it is not in a loop$/ do
|
39
|
+
@element.should_not be_loop
|
40
|
+
end
|
41
|
+
|
42
|
+
Then /^I should know that it is muted$/ do
|
43
|
+
@element.should_not be_muted
|
44
|
+
end
|
45
|
+
|
data/features/support/page.rb
CHANGED
@@ -255,7 +255,9 @@ class Page
|
|
255
255
|
paragraph(:p_name_index, :name => 'p_name', :index => 0)
|
256
256
|
|
257
257
|
button(:alert_button, :id => 'alert_button')
|
258
|
+
button(:alert_button_that_reloads, :id => 'alert_button_that_reloads')
|
258
259
|
button(:confirm_button, :id => 'confirm_button')
|
260
|
+
button(:confirm_button_that_reloads, :id => 'confirm_button_that_reloads')
|
259
261
|
button(:prompt_button, :id => 'prompt_button')
|
260
262
|
|
261
263
|
file_field(:file_field_id, :id => 'file_field_id')
|
@@ -302,6 +304,14 @@ class Page
|
|
302
304
|
audio(:audio_xpath, :xpath => '//audio')
|
303
305
|
audio(:audio_class_index, :class => 'audio', :index => 0)
|
304
306
|
audio(:audio_name_index, :name => 'audio', :index => 0)
|
307
|
+
|
308
|
+
video(:video_id, :id => 'video')
|
309
|
+
video(:video_name, :name => 'video')
|
310
|
+
video(:video_class, :class => 'video')
|
311
|
+
video(:video_index, :index => 0)
|
312
|
+
video(:video_xpath, :xpath => '//video')
|
313
|
+
video(:video_class_index, :class => 'video', :index => 0)
|
314
|
+
video(:video_name_index, :name => 'video', :index => 0)
|
305
315
|
|
306
316
|
element(:article_id, :article, :id => 'article_id')
|
307
317
|
element(:header_id, :header, :id => 'header_id')
|
@@ -4,8 +4,9 @@ module PageObject
|
|
4
4
|
@@browser = false
|
5
5
|
def self.get_browser
|
6
6
|
if !@@browser
|
7
|
-
|
8
|
-
|
7
|
+
target_browser = ENV['BROWSER'].to_sym
|
8
|
+
@@browser = Watir::Browser.new target_browser if ENV['DRIVER'] == 'WATIR'
|
9
|
+
@@browser = Selenium::WebDriver.for target_browser if ENV['DRIVER'] == 'SELENIUM'
|
9
10
|
end
|
10
11
|
@@browser
|
11
12
|
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
Feature: Support for video element
|
2
|
+
|
3
|
+
Background:
|
4
|
+
Given I am on the static elements page
|
5
|
+
|
6
|
+
Scenario: finding an video element
|
7
|
+
When I retrieve the video element
|
8
|
+
Then I should know it exists
|
9
|
+
And I should know it is visible
|
10
|
+
|
11
|
+
Scenario Outline: Locating a video element on the page
|
12
|
+
When I search for the video element by "<search_by>"
|
13
|
+
Then I should know it is visible
|
14
|
+
|
15
|
+
Examples:
|
16
|
+
| search_by |
|
17
|
+
| id |
|
18
|
+
| class |
|
19
|
+
| name |
|
20
|
+
| xpath |
|
21
|
+
| index |
|
22
|
+
|
23
|
+
Scenario Outline: Locating videos using multiple parameters
|
24
|
+
When I search for the video element by "<param1>" and "<param2>"
|
25
|
+
Then I should know it is visible
|
26
|
+
|
27
|
+
Examples:
|
28
|
+
| param1 | param2 |
|
29
|
+
| class | index |
|
30
|
+
| name | index |
|
31
|
+
|
32
|
+
Scenario: Should know if it is autoplay
|
33
|
+
When I retrieve the video element
|
34
|
+
Then I should know the video is not autoplay
|
35
|
+
|
36
|
+
Scenario: Should know if the controls are displayed
|
37
|
+
When I retrieve the video element
|
38
|
+
Then I should know that the controls are displayed
|
39
|
+
|
40
|
+
Scenario: Should know if it is paused
|
41
|
+
When I retrieve the video element
|
42
|
+
Then I should know that the video is paused
|
43
|
+
|
44
|
+
Scenario: Should know its duration
|
45
|
+
When I retrieve the video element
|
46
|
+
Then I should know that the duration is greater than 12 seconds
|
47
|
+
|
48
|
+
Scenario: Should know its volume
|
49
|
+
When I retrieve the video element
|
50
|
+
Then I should know that its volume is 1
|
51
|
+
|
52
|
+
Scenario: Should know its height and width
|
53
|
+
When I retrieve the video element
|
54
|
+
Then I should know that its height is 240 pixels
|
55
|
+
And I should knot what its width is 320 pixels
|
56
|
+
|
57
|
+
Scenario: Should know if it has ended
|
58
|
+
When I retrieve the video element
|
59
|
+
Then I should know that it has not ended
|
60
|
+
|
61
|
+
Scenario: Should know if it is seeking
|
62
|
+
When I retrieve the video element
|
63
|
+
Then I should know that it is not seeking
|
64
|
+
|
65
|
+
Scenario: Should know if it is in a loop
|
66
|
+
When I retrieve the video element
|
67
|
+
Then I should know that it is not in a loop
|
68
|
+
|
69
|
+
Scenario: Should know if it is muted
|
70
|
+
When I retrieve the video element
|
71
|
+
Then I should know that it is muted
|
72
|
+
|
data/lib/page-object.rb
CHANGED
@@ -3,6 +3,7 @@ require 'page-object/accessors'
|
|
3
3
|
require 'page-object/platforms'
|
4
4
|
require 'page-object/element_locators'
|
5
5
|
require 'page-object/nested_elements'
|
6
|
+
require 'page-object/page_factory'
|
6
7
|
require 'page-object/page_populator'
|
7
8
|
require 'page-object/javascript_framework_facade'
|
8
9
|
require 'page-object/indexed_properties'
|
@@ -1126,6 +1126,35 @@ module PageObject
|
|
1126
1126
|
end
|
1127
1127
|
end
|
1128
1128
|
|
1129
|
+
#
|
1130
|
+
# adds two methods - one to return the video element and another to check
|
1131
|
+
# the video's existence.
|
1132
|
+
#
|
1133
|
+
# @example
|
1134
|
+
# video(:movie, :id => 'video_id')
|
1135
|
+
# # will generate 'movie_element' and 'movie?' methods
|
1136
|
+
#
|
1137
|
+
# @param [Symbol] the name used for the generated methods
|
1138
|
+
# @param [Hash] identifier how we find a video element. You can use a multiple paramaters
|
1139
|
+
# by combining of any of the following except xpath. The valid keys are:
|
1140
|
+
# * :class => Watir and Selenium
|
1141
|
+
# * :id => Watir and Selenium
|
1142
|
+
# * :index => Watir and Selenium
|
1143
|
+
# * :name => Watir and Selenium
|
1144
|
+
# * :xpath => Watir and Selenium
|
1145
|
+
# @param optional block to be invoked when element method is called
|
1146
|
+
#
|
1147
|
+
def video(name, identifier={:index => 0}, &block)
|
1148
|
+
define_method("#{name}_element") do
|
1149
|
+
return call_block(&block) if block_given?
|
1150
|
+
platform.video_for(identifier.clone)
|
1151
|
+
end
|
1152
|
+
define_method("#{name}?") do
|
1153
|
+
return call_block(&block).exists? if block_given?
|
1154
|
+
platform.video_for(identifier.clone).exists?
|
1155
|
+
end
|
1156
|
+
end
|
1157
|
+
|
1129
1158
|
#
|
1130
1159
|
# adds three methods - one to retrieve the text of an element, another
|
1131
1160
|
# to retrieve an element, and another to check the element's existence.
|
@@ -971,6 +971,36 @@ module PageObject
|
|
971
971
|
platform.audios_for(identifier.clone)
|
972
972
|
end
|
973
973
|
|
974
|
+
#
|
975
|
+
# Finds a video element
|
976
|
+
#
|
977
|
+
# @param [Hash] identifier how we find a video. You can use a multiple paramaters
|
978
|
+
# by combining of any of the following except xpath. It defaults to {:index => 0}
|
979
|
+
# which will return the first file field. The valid keys are:
|
980
|
+
# * :class => Watir and Selenium
|
981
|
+
# * :id => Watir and Selenium
|
982
|
+
# * :index => Watir and Selenium
|
983
|
+
# * :name => Watir and Selenium
|
984
|
+
# * :xpath => Watir and Selenium
|
985
|
+
def video_element(identifier={:index => 0})
|
986
|
+
platform.video_for(identifier.clone)
|
987
|
+
end
|
988
|
+
|
989
|
+
#
|
990
|
+
# Finds all video elements that match the provided identifier
|
991
|
+
#
|
992
|
+
# @param [Hash] identifier how we find a video element. You can use a multiple paramaters
|
993
|
+
# by combining of any of the following except xpath. It defaults to and empty Hash
|
994
|
+
# which will return all file fields. The valid keys are:
|
995
|
+
# * :class => Watir and Selenium
|
996
|
+
# * :id => Watir and Selenium
|
997
|
+
# * :index => Watir and Selenium
|
998
|
+
# * :name => Watir and Selenium
|
999
|
+
# * :xpath => Watir and Selenium
|
1000
|
+
def video_elements(identifier={})
|
1001
|
+
platform.videos_for(identifier.clone)
|
1002
|
+
end
|
1003
|
+
|
974
1004
|
#
|
975
1005
|
# Finds an element
|
976
1006
|
#
|
data/lib/page-object/elements.rb
CHANGED
@@ -52,6 +52,8 @@ require 'page-object/elements/label'
|
|
52
52
|
require 'page-object/elements/file_field'
|
53
53
|
require 'page-object/elements/area'
|
54
54
|
require 'page-object/elements/canvas'
|
55
|
+
require 'page-object/elements/media'
|
55
56
|
require 'page-object/elements/audio'
|
57
|
+
require 'page-object/elements/video'
|
56
58
|
|
57
59
|
|
@@ -1,30 +1,8 @@
|
|
1
1
|
|
2
2
|
module PageObject
|
3
3
|
module Elements
|
4
|
-
class Audio <
|
4
|
+
class Audio < Media
|
5
5
|
|
6
|
-
def autoplay?
|
7
|
-
attribute(:autoplay)
|
8
|
-
end
|
9
|
-
|
10
|
-
def has_controls?
|
11
|
-
attribute(:controls)
|
12
|
-
end
|
13
|
-
|
14
|
-
def paused?
|
15
|
-
attribute(:paused)
|
16
|
-
end
|
17
|
-
|
18
|
-
def duration
|
19
|
-
duration = attribute(:duration)
|
20
|
-
return duration.to_f if duration
|
21
|
-
end
|
22
|
-
|
23
|
-
def volume
|
24
|
-
volume = attribute(:volume)
|
25
|
-
return volume.to_i if volume
|
26
|
-
end
|
27
|
-
|
28
6
|
end
|
29
7
|
::PageObject::Elements.type_to_class[:audio] = ::PageObject::Elements::Audio
|
30
8
|
end
|
@@ -105,7 +105,7 @@ module PageObject
|
|
105
105
|
protected
|
106
106
|
|
107
107
|
def self.should_build_watir_xpath identifier
|
108
|
-
['table', 'span', 'div', 'td', 'li', 'ul', 'ol', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'label', 'area', 'canvas', 'audio'].include? identifier[:tag_name] and identifier[:name]
|
108
|
+
['table', 'span', 'div', 'td', 'li', 'ul', 'ol', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'label', 'area', 'canvas', 'audio', 'video'].include? identifier[:tag_name] and identifier[:name]
|
109
109
|
end
|
110
110
|
|
111
111
|
def self.build_xpath_for identifier
|
@@ -0,0 +1,45 @@
|
|
1
|
+
|
2
|
+
module PageObject
|
3
|
+
module Elements
|
4
|
+
class Media < Element
|
5
|
+
|
6
|
+
def autoplay?
|
7
|
+
attribute(:autoplay)
|
8
|
+
end
|
9
|
+
|
10
|
+
def has_controls?
|
11
|
+
attribute(:controls)
|
12
|
+
end
|
13
|
+
|
14
|
+
def paused?
|
15
|
+
attribute(:paused)
|
16
|
+
end
|
17
|
+
|
18
|
+
def duration
|
19
|
+
duration = attribute(:duration)
|
20
|
+
return duration.to_f if duration
|
21
|
+
end
|
22
|
+
|
23
|
+
def volume
|
24
|
+
volume = attribute(:volume)
|
25
|
+
return volume.to_i if volume
|
26
|
+
end
|
27
|
+
|
28
|
+
def ended?
|
29
|
+
attribute(:ended)
|
30
|
+
end
|
31
|
+
|
32
|
+
def seeking?
|
33
|
+
attribute(:seeking)
|
34
|
+
end
|
35
|
+
|
36
|
+
def loop?
|
37
|
+
attribute(:loop)
|
38
|
+
end
|
39
|
+
|
40
|
+
def muted?
|
41
|
+
attribute(:muted)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module PageObject
|
2
|
+
module Elements
|
3
|
+
class Video < Media
|
4
|
+
|
5
|
+
def height
|
6
|
+
height = attribute(:height)
|
7
|
+
return height.to_i if height
|
8
|
+
end
|
9
|
+
|
10
|
+
def width
|
11
|
+
width = attribute(:width)
|
12
|
+
return width.to_i if width
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
::PageObject::Elements.type_to_class[:video] = ::PageObject::Elements::Video
|
17
|
+
end
|
18
|
+
end
|
@@ -228,5 +228,13 @@ module PageObject
|
|
228
228
|
def audio_elements(identifier={:index => 0})
|
229
229
|
@platform.audios_for(identifier)
|
230
230
|
end
|
231
|
+
|
232
|
+
def video_element(identifier={:index => 0})
|
233
|
+
@platform.video_for(identifier)
|
234
|
+
end
|
235
|
+
|
236
|
+
def video_elements(identifier={:index => 0})
|
237
|
+
@platform.video_for(identifier)
|
238
|
+
end
|
231
239
|
end
|
232
240
|
end
|
@@ -28,10 +28,10 @@ module PageObject
|
|
28
28
|
#
|
29
29
|
def flash
|
30
30
|
original_color = attribute('backgroundColor')
|
31
|
-
|
31
|
+
the_bridge = bridge
|
32
32
|
10.times do |n|
|
33
33
|
color = (n % 2 == 0) ? 'red' : original_color
|
34
|
-
|
34
|
+
the_bridge.executeScript("arguments[0].style.backgroundColor = '#{color}'", element)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -109,16 +109,22 @@ module PageObject
|
|
109
109
|
def fire_event(event_name)
|
110
110
|
event_name = event_name.to_s.sub(/^on/, '').downcase
|
111
111
|
script = "return (%s).apply(null, arguments)" % ATOMS.fetch(:fireEvent)
|
112
|
-
bridge = element.instance_variable_get(:@bridge)
|
113
112
|
bridge.executeScript(script, element, event_name)
|
114
113
|
end
|
115
114
|
|
115
|
+
#
|
116
|
+
# hover over the element
|
117
|
+
#
|
118
|
+
def hover
|
119
|
+
mouse = Selenium::WebDriver::Mouse.new(bridge)
|
120
|
+
mouse.move_to(element)
|
121
|
+
end
|
122
|
+
|
116
123
|
#
|
117
124
|
# find the parent element
|
118
125
|
#
|
119
126
|
def parent
|
120
127
|
script = "return (%s).apply(null, arguments)" % ATOMS.fetch(:getParentElement)
|
121
|
-
bridge = element.instance_variable_get(:@bridge)
|
122
128
|
parent = bridge.executeScript(script, element)
|
123
129
|
type = element.attribute(:type).to_s.downcase if parent.tag_name.to_sym == :input
|
124
130
|
cls = ::PageObject::Elements.element_class_for(parent.tag_name, type)
|
@@ -129,7 +135,6 @@ module PageObject
|
|
129
135
|
# Set the focus to the current element
|
130
136
|
#
|
131
137
|
def focus
|
132
|
-
bridge = element.instance_variable_get(:@bridge)
|
133
138
|
bridge.executeScript("return arguments[0].focus()", element)
|
134
139
|
end
|
135
140
|
|
@@ -233,6 +238,19 @@ module PageObject
|
|
233
238
|
def clear
|
234
239
|
element.clear
|
235
240
|
end
|
241
|
+
|
242
|
+
#
|
243
|
+
# get the id of the element
|
244
|
+
#
|
245
|
+
def id
|
246
|
+
attribute(:id)
|
247
|
+
end
|
248
|
+
|
249
|
+
private
|
250
|
+
|
251
|
+
def bridge
|
252
|
+
bridge = element.instance_variable_get(:@bridge)
|
253
|
+
end
|
236
254
|
end
|
237
255
|
end
|
238
256
|
end
|
@@ -70,9 +70,11 @@ module PageObject
|
|
70
70
|
# See PageObject#alert
|
71
71
|
#
|
72
72
|
def alert(frame=nil, &block)
|
73
|
-
@browser.execute_script "window.alert = function(msg) { window.__lastWatirAlert = msg; }"
|
74
73
|
yield
|
75
|
-
@browser.
|
74
|
+
alert = @browser.switch_to.alert
|
75
|
+
value = alert.text
|
76
|
+
alert.accept
|
77
|
+
value
|
76
78
|
end
|
77
79
|
|
78
80
|
#
|
@@ -80,9 +82,11 @@ module PageObject
|
|
80
82
|
# See PageObject#confirm
|
81
83
|
#
|
82
84
|
def confirm(response, frame=nil, &block)
|
83
|
-
@browser.execute_script "window.confirm = function(msg) { window.__lastWatirConfirm = msg; return #{!!response} }"
|
84
85
|
yield
|
85
|
-
@browser.
|
86
|
+
alert = @browser.switch_to.alert
|
87
|
+
value = alert.text
|
88
|
+
response ? alert.accept : alert.dismiss
|
89
|
+
value
|
86
90
|
end
|
87
91
|
|
88
92
|
#
|
@@ -914,6 +918,20 @@ module PageObject
|
|
914
918
|
find_selenium_elements(identifier, Elements::Audio, 'audio')
|
915
919
|
end
|
916
920
|
|
921
|
+
#
|
922
|
+
# platform method to retrieve a video element
|
923
|
+
#
|
924
|
+
def video_for(identifier)
|
925
|
+
find_selenium_element(identifier, Elements::Video, 'video')
|
926
|
+
end
|
927
|
+
|
928
|
+
#
|
929
|
+
# platform method to return an array of video elements
|
930
|
+
#
|
931
|
+
def videos_for(identifier)
|
932
|
+
find_selenium_elements(identifier, Elements::Video, 'video')
|
933
|
+
end
|
934
|
+
|
917
935
|
#
|
918
936
|
# platform method to retrieve a generic element
|
919
937
|
# See PageObject::Accessors#element
|
@@ -102,6 +102,13 @@ module PageObject
|
|
102
102
|
element.fire_event(event_name)
|
103
103
|
end
|
104
104
|
|
105
|
+
#
|
106
|
+
# hover over the element
|
107
|
+
#
|
108
|
+
def hover
|
109
|
+
element.hover
|
110
|
+
end
|
111
|
+
|
105
112
|
#
|
106
113
|
# find the parent element
|
107
114
|
#
|
@@ -197,6 +204,13 @@ module PageObject
|
|
197
204
|
def clear
|
198
205
|
element.clear
|
199
206
|
end
|
207
|
+
|
208
|
+
#
|
209
|
+
# get the id of the element
|
210
|
+
#
|
211
|
+
def id
|
212
|
+
element.id
|
213
|
+
end
|
200
214
|
end
|
201
215
|
end
|
202
216
|
end
|
@@ -71,9 +71,9 @@ module PageObject
|
|
71
71
|
#
|
72
72
|
def alert(frame=nil, &block)
|
73
73
|
switch_to_frame(frame)
|
74
|
-
@browser.wd.execute_script "window.alert = function(msg) { window.__lastWatirAlert = msg; }"
|
75
74
|
yield
|
76
|
-
value = @browser.
|
75
|
+
value = @browser.alert.text
|
76
|
+
@browser.alert.ok
|
77
77
|
switch_to_default_content(frame)
|
78
78
|
value
|
79
79
|
end
|
@@ -84,9 +84,9 @@ module PageObject
|
|
84
84
|
#
|
85
85
|
def confirm(response, frame=nil, &block)
|
86
86
|
switch_to_frame(frame)
|
87
|
-
@browser.wd.execute_script "window.confirm = function(msg) { window.__lastWatirConfirm = msg; return #{!!response} }"
|
88
87
|
yield
|
89
|
-
value = @browser.
|
88
|
+
value = @browser.alert.text
|
89
|
+
response ? @browser.alert.ok : @browser.alert.close
|
90
90
|
switch_to_default_content(frame)
|
91
91
|
value
|
92
92
|
end
|
@@ -855,6 +855,20 @@ module PageObject
|
|
855
855
|
find_watir_elements("audios(identifier)", Elements::Audio, identifier, 'audio')
|
856
856
|
end
|
857
857
|
|
858
|
+
#
|
859
|
+
# platform method to retrieve a video element
|
860
|
+
#
|
861
|
+
def video_for(identifier)
|
862
|
+
find_watir_element("video(identifier)", Elements::Video, identifier, 'video')
|
863
|
+
end
|
864
|
+
|
865
|
+
#
|
866
|
+
# platform method to retrieve an array of video elements
|
867
|
+
#
|
868
|
+
def videos_for(identifier)
|
869
|
+
find_watir_elements("videos(identifier)", Elements::Video, identifier, 'video')
|
870
|
+
end
|
871
|
+
|
858
872
|
#
|
859
873
|
# platform method to return a PageObject::Elements::Element element
|
860
874
|
# See PageObject::Accessors#elem
|
data/lib/page-object/version.rb
CHANGED
@@ -651,6 +651,28 @@ describe PageObject::ElementLocators do
|
|
651
651
|
watir_page_object.audio_elements
|
652
652
|
end
|
653
653
|
|
654
|
+
it "should find a video element" do
|
655
|
+
watir_browser.should_receive(:video).with(:id => 'blah').and_return(watir_browser)
|
656
|
+
element = watir_page_object.video_element(:id => 'blah')
|
657
|
+
element.should be_instance_of PageObject::Elements::Video
|
658
|
+
end
|
659
|
+
|
660
|
+
it "should find a video element using a default identifier" do
|
661
|
+
watir_browser.should_receive(:video).with(:index => 0).and_return(watir_browser)
|
662
|
+
watir_page_object.video_element
|
663
|
+
end
|
664
|
+
|
665
|
+
it "should find all video elements" do
|
666
|
+
watir_browser.should_receive(:videos).with(:id => 'blah').and_return([watir_browser])
|
667
|
+
elements = watir_page_object.video_elements(:id => 'blah')
|
668
|
+
elements[0].should be_instance_of PageObject::Elements::Video
|
669
|
+
end
|
670
|
+
|
671
|
+
it "should find all video elements with no identifier" do
|
672
|
+
watir_browser.should_receive(:videos).with({}).and_return([watir_browser])
|
673
|
+
watir_page_object.video_elements
|
674
|
+
end
|
675
|
+
|
654
676
|
it "should find an element" do
|
655
677
|
watir_browser.should_receive(:audio).with(:id => 'blah').and_return(watir_browser)
|
656
678
|
element = watir_page_object.element(:audio, :id => 'blah')
|
@@ -123,15 +123,17 @@ describe PageObject do
|
|
123
123
|
end
|
124
124
|
|
125
125
|
it "should override alert popup behavior" do
|
126
|
-
watir_browser.should_receive(:
|
127
|
-
watir_browser.should_receive(:
|
126
|
+
watir_browser.should_receive(:alert).twice.and_return(watir_browser)
|
127
|
+
watir_browser.should_receive(:text)
|
128
|
+
watir_browser.should_receive(:ok)
|
128
129
|
watir_page_object.alert do
|
129
130
|
end
|
130
131
|
end
|
131
132
|
|
132
133
|
it "should override confirm popup behavior" do
|
133
|
-
watir_browser.should_receive(:
|
134
|
-
watir_browser.should_receive(:
|
134
|
+
watir_browser.should_receive(:alert).twice.and_return(watir_browser)
|
135
|
+
watir_browser.should_receive(:text)
|
136
|
+
watir_browser.should_receive(:ok)
|
135
137
|
watir_page_object.confirm(true) do
|
136
138
|
end
|
137
139
|
end
|
@@ -233,13 +235,19 @@ describe PageObject do
|
|
233
235
|
end
|
234
236
|
|
235
237
|
it "should override alert popup behavior" do
|
236
|
-
selenium_browser.should_receive(:
|
238
|
+
selenium_browser.should_receive(:switch_to).and_return(selenium_browser)
|
239
|
+
selenium_browser.should_receive(:alert).and_return(selenium_browser)
|
240
|
+
selenium_browser.should_receive(:text)
|
241
|
+
selenium_browser.should_receive(:accept)
|
237
242
|
selenium_page_object.alert do
|
238
243
|
end
|
239
244
|
end
|
240
245
|
|
241
246
|
it "should override confirm popup behavior" do
|
242
|
-
selenium_browser.should_receive(:
|
247
|
+
selenium_browser.should_receive(:switch_to).and_return(selenium_browser)
|
248
|
+
selenium_browser.should_receive(:alert).and_return(selenium_browser)
|
249
|
+
selenium_browser.should_receive(:text)
|
250
|
+
selenium_browser.should_receive(:accept)
|
243
251
|
selenium_page_object.confirm(true) do
|
244
252
|
end
|
245
253
|
end
|
@@ -34,6 +34,7 @@ class SeleniumAccessorsTestPageObject
|
|
34
34
|
area(:img_area, :id => 'area')
|
35
35
|
canvas(:my_canvas, :id => 'canvas')
|
36
36
|
audio(:acdc, :id => 'audio_id')
|
37
|
+
video(:movie, :id => 'movie_id')
|
37
38
|
end
|
38
39
|
|
39
40
|
class SeleniumBlockPageObject
|
@@ -125,6 +126,9 @@ class SeleniumBlockPageObject
|
|
125
126
|
audio :acdc do |element|
|
126
127
|
'audio'
|
127
128
|
end
|
129
|
+
video :movie do |element|
|
130
|
+
'video'
|
131
|
+
end
|
128
132
|
end
|
129
133
|
|
130
134
|
describe PageObject::Accessors do
|
@@ -563,4 +567,16 @@ describe PageObject::Accessors do
|
|
563
567
|
end
|
564
568
|
end
|
565
569
|
end
|
570
|
+
|
571
|
+
describe "video accessors" do
|
572
|
+
context "when called on a page object" do
|
573
|
+
it "should generate accessor methods" do
|
574
|
+
selenium_page_object.should respond_to(:movie_element)
|
575
|
+
end
|
576
|
+
|
577
|
+
it "should call a block on the elmenet method when present" do
|
578
|
+
block_page_object.movie_element.should == "video"
|
579
|
+
end
|
580
|
+
end
|
581
|
+
end
|
566
582
|
end
|
@@ -34,6 +34,7 @@ class WatirAccessorsTestPageObject
|
|
34
34
|
area(:img_area, :id => 'area')
|
35
35
|
canvas(:my_canvas, :id => 'canvas_id')
|
36
36
|
audio(:acdc, :id => 'audio_id')
|
37
|
+
video(:movie, :id => 'video_id')
|
37
38
|
end
|
38
39
|
|
39
40
|
class WatirBlockPageObject
|
@@ -125,6 +126,9 @@ class WatirBlockPageObject
|
|
125
126
|
audio :acdc do |element|
|
126
127
|
"audio"
|
127
128
|
end
|
129
|
+
video :movie do |element|
|
130
|
+
"video"
|
131
|
+
end
|
128
132
|
end
|
129
133
|
|
130
134
|
describe PageObject::Accessors do
|
@@ -1086,4 +1090,16 @@ describe PageObject::Accessors do
|
|
1086
1090
|
end
|
1087
1091
|
end
|
1088
1092
|
end
|
1093
|
+
|
1094
|
+
describe "video accessors" do
|
1095
|
+
context "when called on a page object" do
|
1096
|
+
it "should generate accessor methods" do
|
1097
|
+
watir_page_object.should respond_to(:movie_element)
|
1098
|
+
end
|
1099
|
+
|
1100
|
+
it "should call a block on the element method when present" do
|
1101
|
+
block_page_object.movie_element.should == "video"
|
1102
|
+
end
|
1103
|
+
end
|
1104
|
+
end
|
1089
1105
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: page-object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: watir-webdriver
|
@@ -144,6 +144,7 @@ files:
|
|
144
144
|
- features/html/frame_2.html
|
145
145
|
- features/html/frame_3.html
|
146
146
|
- features/html/frames.html
|
147
|
+
- features/html/hover.html
|
147
148
|
- features/html/iframes.html
|
148
149
|
- features/html/images/circle.png
|
149
150
|
- features/html/images/submit.gif
|
@@ -175,8 +176,12 @@ files:
|
|
175
176
|
- features/page_level_actions.feature
|
176
177
|
- features/paragraph.feature
|
177
178
|
- features/radio_button.feature
|
179
|
+
- features/sample-app/public/04-Death_Becomes_Fur.mp4
|
180
|
+
- features/sample-app/public/04-Death_Becomes_Fur.oga
|
178
181
|
- features/sample-app/public/jquery-1.3.2.js
|
179
182
|
- features/sample-app/public/jquery.html
|
183
|
+
- features/sample-app/public/movie.mp4
|
184
|
+
- features/sample-app/public/movie.ogg
|
180
185
|
- features/sample-app/public/prototype-1.6.0.3.js
|
181
186
|
- features/sample-app/public/prototype.html
|
182
187
|
- features/sample-app/sample_app.rb
|
@@ -218,6 +223,7 @@ files:
|
|
218
223
|
- features/step_definitions/text_area_steps.rb
|
219
224
|
- features/step_definitions/text_field_steps.rb
|
220
225
|
- features/step_definitions/unordered_list_steps.rb
|
226
|
+
- features/step_definitions/video_steps.rb
|
221
227
|
- features/support/ajax_text_environment.rb
|
222
228
|
- features/support/env.rb
|
223
229
|
- features/support/hooks.rb
|
@@ -229,6 +235,7 @@ files:
|
|
229
235
|
- features/text_area.feature
|
230
236
|
- features/text_field.feature
|
231
237
|
- features/unordered_list.feature
|
238
|
+
- features/video.feature
|
232
239
|
- lib/page-object.rb
|
233
240
|
- lib/page-object/accessors.rb
|
234
241
|
- lib/page-object/core_ext/string.rb
|
@@ -249,6 +256,7 @@ files:
|
|
249
256
|
- lib/page-object/elements/label.rb
|
250
257
|
- lib/page-object/elements/link.rb
|
251
258
|
- lib/page-object/elements/list_item.rb
|
259
|
+
- lib/page-object/elements/media.rb
|
252
260
|
- lib/page-object/elements/option.rb
|
253
261
|
- lib/page-object/elements/ordered_list.rb
|
254
262
|
- lib/page-object/elements/paragraph.rb
|
@@ -261,6 +269,7 @@ files:
|
|
261
269
|
- lib/page-object/elements/text_area.rb
|
262
270
|
- lib/page-object/elements/text_field.rb
|
263
271
|
- lib/page-object/elements/unordered_list.rb
|
272
|
+
- lib/page-object/elements/video.rb
|
264
273
|
- lib/page-object/indexed_properties.rb
|
265
274
|
- lib/page-object/javascript/jquery.rb
|
266
275
|
- lib/page-object/javascript/prototype.rb
|
@@ -361,7 +370,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
361
370
|
version: '0'
|
362
371
|
segments:
|
363
372
|
- 0
|
364
|
-
hash:
|
373
|
+
hash: 2357863127966397985
|
365
374
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
366
375
|
none: false
|
367
376
|
requirements:
|
@@ -370,7 +379,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
370
379
|
version: '0'
|
371
380
|
segments:
|
372
381
|
- 0
|
373
|
-
hash:
|
382
|
+
hash: 2357863127966397985
|
374
383
|
requirements: []
|
375
384
|
rubyforge_project: page-object
|
376
385
|
rubygems_version: 1.8.24
|
@@ -397,6 +406,7 @@ test_files:
|
|
397
406
|
- features/html/frame_2.html
|
398
407
|
- features/html/frame_3.html
|
399
408
|
- features/html/frames.html
|
409
|
+
- features/html/hover.html
|
400
410
|
- features/html/iframes.html
|
401
411
|
- features/html/images/circle.png
|
402
412
|
- features/html/images/submit.gif
|
@@ -428,8 +438,12 @@ test_files:
|
|
428
438
|
- features/page_level_actions.feature
|
429
439
|
- features/paragraph.feature
|
430
440
|
- features/radio_button.feature
|
441
|
+
- features/sample-app/public/04-Death_Becomes_Fur.mp4
|
442
|
+
- features/sample-app/public/04-Death_Becomes_Fur.oga
|
431
443
|
- features/sample-app/public/jquery-1.3.2.js
|
432
444
|
- features/sample-app/public/jquery.html
|
445
|
+
- features/sample-app/public/movie.mp4
|
446
|
+
- features/sample-app/public/movie.ogg
|
433
447
|
- features/sample-app/public/prototype-1.6.0.3.js
|
434
448
|
- features/sample-app/public/prototype.html
|
435
449
|
- features/sample-app/sample_app.rb
|
@@ -471,6 +485,7 @@ test_files:
|
|
471
485
|
- features/step_definitions/text_area_steps.rb
|
472
486
|
- features/step_definitions/text_field_steps.rb
|
473
487
|
- features/step_definitions/unordered_list_steps.rb
|
488
|
+
- features/step_definitions/video_steps.rb
|
474
489
|
- features/support/ajax_text_environment.rb
|
475
490
|
- features/support/env.rb
|
476
491
|
- features/support/hooks.rb
|
@@ -482,6 +497,7 @@ test_files:
|
|
482
497
|
- features/text_area.feature
|
483
498
|
- features/text_field.feature
|
484
499
|
- features/unordered_list.feature
|
500
|
+
- features/video.feature
|
485
501
|
- spec/page-object/element_locators_spec.rb
|
486
502
|
- spec/page-object/elements/area_spec.rb
|
487
503
|
- spec/page-object/elements/button_spec.rb
|