page-object 0.1.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +21 -1
- data/README.md +14 -13
- data/cucumber.yml +2 -2
- data/features/async.feature +11 -0
- data/features/html/static_elements.html +4 -0
- data/features/page_level_actions.feature +18 -6
- data/features/step_definitions/async_steps.rb +31 -0
- data/features/step_definitions/element_steps.rb +0 -1
- data/features/step_definitions/page_level_actions_steps.rb +39 -0
- data/features/support/page.rb +4 -0
- data/lib/page-object.rb +65 -0
- data/lib/page-object/platforms/selenium_element.rb +48 -0
- data/lib/page-object/platforms/watir_element.rb +42 -0
- data/lib/page-object/selenium_page_object.rb +42 -0
- data/lib/page-object/version.rb +1 -1
- data/lib/page-object/watir_page_object.rb +33 -0
- data/page-object.gemspec +1 -1
- data/spec/page-object/accessors_spec.rb +5 -5
- data/spec/page-object/elements/element_spec.rb +48 -0
- data/spec/page-object/page-object_spec.rb +50 -3
- data/spec/page-object/page_factory_spec.rb +5 -5
- data/spec/page-object/selenium_page_object_spec.rb +2 -2
- metadata +7 -3
data/ChangeLog
CHANGED
@@ -1,4 +1,24 @@
|
|
1
|
-
=== Version 0.
|
1
|
+
=== Version 0.2 / 2011-07-24
|
2
|
+
* Enhancements
|
3
|
+
* Async handling
|
4
|
+
* Added #wait_until to page object to support async events at page level
|
5
|
+
* Added the following methods to PageObject::Elements::Element
|
6
|
+
* #when_present
|
7
|
+
* #when_visible
|
8
|
+
* #when_not_visible
|
9
|
+
* #wait_until
|
10
|
+
* Handling popups
|
11
|
+
* Added #alert to page object to override default alert popup behavior
|
12
|
+
* Added #confirm to page object to override default confirm popup behavior
|
13
|
+
* Added #prompt to page object to override default prompt popup behaviorit "should override prompt popup behavior" do
|
14
|
+
watir_browser.should_receive(:prompt)
|
15
|
+
watir_page_object.prompt("blah") do
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
* Updated to use selenium-webdriver 2.1.0
|
20
|
+
|
21
|
+
=== Version 0.1.1 / 2011-07-16
|
2
22
|
* Enhancements
|
3
23
|
* Support for identifying hidden fields by text when using Selenium
|
4
24
|
* Support for identifying links by href when using Selenium
|
data/README.md
CHANGED
@@ -5,6 +5,19 @@
|
|
5
5
|
|
6
6
|
A simple gem that assists in creating flexible page objects for testing browser based appications. The goal is to facilitate creating abstraction layers in your tests to decouple the tests from the item they are testing and to provide a simple interface to the elements on a page. It works with both watir-webdriver and selenium-webdriver.
|
7
7
|
|
8
|
+
## Documentation
|
9
|
+
|
10
|
+
The project [wiki](https://github.com/cheezy/page-object/wiki/page-object) is the first place to go to learn about how to use page-object.
|
11
|
+
|
12
|
+
The rdocs for this project can be found at [rubydoc.info](http://rubydoc.info/github/cheezy/page-object/master/frames).
|
13
|
+
|
14
|
+
To see the changes from release to release please look at the [ChangeLog](https://raw.github.com/cheezy/page-object/master/ChangeLog)
|
15
|
+
|
16
|
+
To read about the motivation for this gem please read this [blog entry](http://www.cheezyworld.com/2010/11/19/ui-tests-introducing-a-simple-dsl/)
|
17
|
+
|
18
|
+
|
19
|
+
## Basic Usage
|
20
|
+
|
8
21
|
### Defining your page object
|
9
22
|
|
10
23
|
You define a new page object by including the PageObject module:
|
@@ -60,18 +73,6 @@ or
|
|
60
73
|
browser = Selenium::WebDriver.for :firefox
|
61
74
|
my_page_object = MyPageObject.new(browser)
|
62
75
|
|
63
|
-
## Documentation
|
64
|
-
|
65
|
-
The project [wiki](https://github.com/cheezy/page-object/wiki/page-object) is the first place to go to learn about how to use page-object.
|
66
|
-
|
67
|
-
The rdocs for this project can be found at [rubydoc.info](http://rubydoc.info/github/cheezy/page-object/master/frames).
|
68
|
-
|
69
|
-
If you wish to view the current tracker board you can view it on [Pivotal Tracker](https://www.pivotaltracker.com/projects/289099)
|
70
|
-
|
71
|
-
To see the changes from release to release please look at the [ChangeLog](https://raw.github.com/cheezy/page-object/master/ChangeLog)
|
72
|
-
|
73
|
-
To read about the motivation for this gem please read this [blog entry](http://www.cheezyworld.com/2010/11/19/ui-tests-introducing-a-simple-dsl/)
|
74
|
-
|
75
76
|
## Known Issues
|
76
77
|
|
77
78
|
See [http://github.com/cheezy/page-object/issues](http://github.com/cheezy/page-object/issues)
|
@@ -82,7 +83,7 @@ See [http://github.com/cheezy/page-object/issues](http://github.com/cheezy/page-
|
|
82
83
|
* Test drive your feature addition or bug fix. Adding specs is important and I will not accept a pull request that does not have tests.
|
83
84
|
* Make sure you describe your new feature with a cucumber scenario.
|
84
85
|
* Make sure you provide RDoc comments for any new public method you add. Remember, others will be using this gem.
|
85
|
-
* Commit, do not mess with
|
86
|
+
* Commit, do not mess with Rakefile, version, or ChangeLog.
|
86
87
|
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
87
88
|
* Send me a pull request. Bonus points for topic branches.
|
88
89
|
|
data/cucumber.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
default: DRIVER=WATIR --no-source --color --format pretty
|
1
|
+
default: DRIVER=WATIR --no-source --color --format pretty
|
2
2
|
watir: DRIVER=WATIR --no-source --color --format pretty --tags ~@selenium_only
|
3
3
|
selenium: DRIVER=SELENIUM --no-source --color --format pretty --tags ~@watir_only
|
4
4
|
watir_focus: DRIVER=WATIR --no-source --color --format pretty --tags @focus --tags ~@selenium_only
|
5
5
|
selenium_focus: DRIVER=SELENIUM --no-source --color --format pretty --tags @focus --tags ~@watir_only
|
6
|
-
autotest: DRIVER=
|
6
|
+
autotest: DRIVER=WATIR --no-source --color --format pretty --tags ~@selenium_only
|
7
7
|
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Feature: Handling Asynch calls
|
2
|
+
|
3
|
+
Background:
|
4
|
+
Given I am on the static elements page
|
5
|
+
|
6
|
+
Scenario: Link element methods
|
7
|
+
When I retrieve a link element
|
8
|
+
Then I should be able to wait until it is present
|
9
|
+
And I should be able to wait until it is visible
|
10
|
+
And I should be able to wait until it is not visible
|
11
|
+
And I should be able to wait until a block returns true
|
@@ -85,6 +85,10 @@
|
|
85
85
|
<a href="success.html">Hello</a>
|
86
86
|
<a href="success.html">Hello</a>
|
87
87
|
|
88
|
+
<h3>Alerts / Confirms / Prompts</h3>
|
89
|
+
<input id=alert_button type=button onclick="alert('I am an alert')" value=Alert>
|
90
|
+
<input id=confirm_button type=button onclick="this.value = confirm('set the value')" value=Confirm>
|
91
|
+
<input id=prompt_button type=button onclick='this.value = prompt("enter your name", "John Doe")' value=Prompt>
|
88
92
|
</body>
|
89
93
|
</html>
|
90
94
|
|
@@ -2,18 +2,30 @@ Feature: Page level actions
|
|
2
2
|
In order to act on pages from a web site
|
3
3
|
Testers will need to use the page object to encapsulate access
|
4
4
|
|
5
|
+
Background:
|
6
|
+
Given I am on the static elements page
|
7
|
+
|
5
8
|
|
6
9
|
Scenario: Getting the text from a web page
|
7
|
-
Given I am on the static elements page
|
8
10
|
Then the page should contain the text "Static Elements Page"
|
9
11
|
|
10
12
|
Scenario: Getting the html from a web page
|
11
|
-
Given I am on the static elements page
|
12
13
|
Then the page should contain the html "<title>Static Elements Page</title>"
|
13
14
|
|
14
15
|
Scenario: Getting the title from a web page
|
15
|
-
Given I am on the static elements page
|
16
16
|
Then the page should have the title "Static Elements Page"
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
|
18
|
+
Scenario: Waiting for something
|
19
|
+
Then I should be able to wait for a block to return true
|
20
|
+
|
21
|
+
Scenario: Handling alert popups
|
22
|
+
When I handle the alert
|
23
|
+
Then I should be able to get the alert's message
|
24
|
+
|
25
|
+
Scenario: Handling confirm popups
|
26
|
+
When I handle the confirm
|
27
|
+
Then I should be able to get the confirm message
|
28
|
+
|
29
|
+
Scenario: Handling prompt popups
|
30
|
+
When I handle the prompt
|
31
|
+
Then I should be able to get the message and default value
|
@@ -0,0 +1,31 @@
|
|
1
|
+
def success
|
2
|
+
|
3
|
+
end
|
4
|
+
|
5
|
+
Then /^I should be able to wait until it is present$/ do
|
6
|
+
@element.when_present do
|
7
|
+
success
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
Then /^I should be able to wait until it is visible$/ do
|
12
|
+
@element.when_visible do
|
13
|
+
success
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
Then /^I should be able to wait until it is not visible$/ do
|
18
|
+
begin
|
19
|
+
@element.when_not_visible do
|
20
|
+
fail
|
21
|
+
end
|
22
|
+
rescue
|
23
|
+
success
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
Then /^I should be able to wait until a block returns true$/ do
|
28
|
+
@element.wait_until do
|
29
|
+
@element.visible?
|
30
|
+
end
|
31
|
+
end
|
@@ -10,3 +10,42 @@ end
|
|
10
10
|
Then /^the page should have the title "([^\"]*)"$/ do |title|
|
11
11
|
@page.title.should include title
|
12
12
|
end
|
13
|
+
|
14
|
+
Then /^I should be able to wait for a block to return true$/ do
|
15
|
+
@page.google_search_id
|
16
|
+
@page.wait_until(10, "too long to display page") do
|
17
|
+
@page.text.include? 'Success'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
When /^I handle the alert$/ do
|
22
|
+
@msg = @page.alert do
|
23
|
+
@page.alert_button
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
Then /^I should be able to get the alert's message$/ do
|
28
|
+
@msg.should == "I am an alert"
|
29
|
+
end
|
30
|
+
|
31
|
+
When /^I handle the confirm$/ do
|
32
|
+
@msg = @page.confirm(true) do
|
33
|
+
@page.confirm_button
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
Then /^I should be able to get the confirm message$/ do
|
38
|
+
@msg.should == 'set the value'
|
39
|
+
end
|
40
|
+
|
41
|
+
When /^I handle the prompt$/ do
|
42
|
+
@msg = @page.prompt("Cheezy") do
|
43
|
+
@page.prompt_button
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
Then /^I should be able to get the message and default value$/ do
|
48
|
+
@msg[:message].should == "enter your name"
|
49
|
+
@msg[:default_value].should == 'John Doe'
|
50
|
+
end
|
51
|
+
|
data/features/support/page.rb
CHANGED
@@ -159,4 +159,8 @@ class Page
|
|
159
159
|
ordered_list(:ol_xpath, :xpath => '//ol')
|
160
160
|
ordered_list(:ol_class_index, :class => "ol_class", :index => 0)
|
161
161
|
ordered_list(:ol_name_index, :name => "ol_name", :index => 0)
|
162
|
+
|
163
|
+
button(:alert_button, :id => 'alert_button')
|
164
|
+
button(:confirm_button, :id => 'confirm_button')
|
165
|
+
button(:prompt_button, :id => 'prompt_button')
|
162
166
|
end
|
data/lib/page-object.rb
CHANGED
@@ -40,6 +40,7 @@ module PageObject
|
|
40
40
|
# Construct a new page object.
|
41
41
|
#
|
42
42
|
# @param [Watir::Browser or Selenium::WebDriver::Driver] the platform browser to use
|
43
|
+
# @param [bool] open the page if page_url is set
|
43
44
|
#
|
44
45
|
def initialize(browser, visit=false)
|
45
46
|
@browser = browser
|
@@ -81,6 +82,70 @@ module PageObject
|
|
81
82
|
def title
|
82
83
|
platform.title
|
83
84
|
end
|
85
|
+
|
86
|
+
#
|
87
|
+
# Wait until the block returns true or times out
|
88
|
+
#
|
89
|
+
# @example
|
90
|
+
# @page.wait_until(5, 'Success not found on page') do
|
91
|
+
# @page.text.include? 'Success'
|
92
|
+
# end
|
93
|
+
#
|
94
|
+
# @param [Numeric] the amount of time to wait for the block to return true.
|
95
|
+
# @param [String] the message to include with the error if we exceed the timeout duration.
|
96
|
+
# @param block the block to execute. It should return true when successful.
|
97
|
+
#
|
98
|
+
def wait_until(timeout = 30, message = nil, &block)
|
99
|
+
platform.wait_until(timeout, message, &block)
|
100
|
+
end
|
101
|
+
|
102
|
+
#
|
103
|
+
# Override the normal alert popup so it does not occurr.
|
104
|
+
#
|
105
|
+
# @example
|
106
|
+
# message = @page.alert do
|
107
|
+
# @page.button_that_causes_alert
|
108
|
+
# end
|
109
|
+
#
|
110
|
+
# @param block a block that has the call that will cause the alert to display
|
111
|
+
# @return [String] the message that was contained in the alert
|
112
|
+
#
|
113
|
+
def alert(&block)
|
114
|
+
platform.alert(&block)
|
115
|
+
end
|
116
|
+
|
117
|
+
#
|
118
|
+
# Override the normal confirm popup so it does not occurr.
|
119
|
+
#
|
120
|
+
# @example
|
121
|
+
# message = @popup.confirm(true) do
|
122
|
+
# @page.button_that_causes_confirm
|
123
|
+
# end
|
124
|
+
#
|
125
|
+
# @param [bool] what response you want to return back from the confirm popup
|
126
|
+
# @param block a block that has the call that will cause the confirm to display
|
127
|
+
# @return [String] the message that was prompted in the confirm
|
128
|
+
#
|
129
|
+
def confirm(response, &block)
|
130
|
+
platform.confirm(response, &block)
|
131
|
+
end
|
132
|
+
|
133
|
+
#
|
134
|
+
# Override the normal promp popup so it does not occurr.
|
135
|
+
#
|
136
|
+
# @example
|
137
|
+
# message = @popup.prompt("Some Value") do
|
138
|
+
# @page.button_that_causes_prompt
|
139
|
+
# end
|
140
|
+
#
|
141
|
+
# @param [string] the value returned to the caller of the prompt
|
142
|
+
# @param block a block that has the call that will cause the prompt to display
|
143
|
+
# @return [Hash] A has containing two keys - :message contains the prompt message and
|
144
|
+
# :default_value contains the default value for the prompt if provided
|
145
|
+
#
|
146
|
+
def prompt(answer, &block)
|
147
|
+
platform.prompt(answer, &block)
|
148
|
+
end
|
84
149
|
|
85
150
|
private
|
86
151
|
|
@@ -89,6 +89,54 @@ module PageObject
|
|
89
89
|
def click
|
90
90
|
@element.click
|
91
91
|
end
|
92
|
+
|
93
|
+
#
|
94
|
+
# Waits until the element is present
|
95
|
+
#
|
96
|
+
# @param [Integer] (defaults to: 5) seconds to wait before timing out
|
97
|
+
#
|
98
|
+
def when_present(timeout=5)
|
99
|
+
wait = Selenium::WebDriver::Wait.new({:timeout => timeout, :message => "Element not present in #{timeout} seconds"})
|
100
|
+
wait.until do
|
101
|
+
self.exists?
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
#
|
106
|
+
# Waits until the element is visible
|
107
|
+
#
|
108
|
+
# @param [Integer] (defaults to: 5) seconds to wait before timing out
|
109
|
+
#
|
110
|
+
def when_visible(timeout=5)
|
111
|
+
wait = Selenium::WebDriver::Wait.new({:timeout => timeout, :message => "Element not present in #{timeout} seconds"})
|
112
|
+
wait.until do
|
113
|
+
self.visible?
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
#
|
118
|
+
# Waits until the element is not visible
|
119
|
+
#
|
120
|
+
# @param [Integer] (defaults to: 5) seconds to wait before timing out
|
121
|
+
#
|
122
|
+
def when_not_visible(timeout=5)
|
123
|
+
wait = Selenium::WebDriver::Wait.new({:timeout => timeout, :message => "Element not present in #{timeout} seconds"})
|
124
|
+
wait.until do
|
125
|
+
not self.visible?
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
#
|
130
|
+
# Waits until the block returns true
|
131
|
+
#
|
132
|
+
# @param [Integer] (defaults to: 5) seconds to wait before timing out
|
133
|
+
# @param [String] the message to display if the event timeouts
|
134
|
+
# @param the block to execute when the event occurrs
|
135
|
+
#
|
136
|
+
def wait_until(timeout=5, message=nil, &block)
|
137
|
+
wait = Selenium::WebDriver::Wait.new({:timeout => timeout, :message => message})
|
138
|
+
wait.until &block
|
139
|
+
end
|
92
140
|
end
|
93
141
|
end
|
94
142
|
end
|
@@ -89,6 +89,48 @@ module PageObject
|
|
89
89
|
def click
|
90
90
|
@element.click
|
91
91
|
end
|
92
|
+
|
93
|
+
#
|
94
|
+
# Waits until the element is present
|
95
|
+
#
|
96
|
+
# @param [Integer] (defaults to: 5) seconds to wait before timing out
|
97
|
+
#
|
98
|
+
def when_present(timeout=5)
|
99
|
+
@element.wait_until_present(timeout)
|
100
|
+
end
|
101
|
+
|
102
|
+
#
|
103
|
+
# Waits until the element is visible
|
104
|
+
#
|
105
|
+
# @param [Integer] (defaults to: 5) seconds to wait before timing out
|
106
|
+
#
|
107
|
+
def when_visible(timeout=5)
|
108
|
+
Watir::Wait.until(timeout, "Element was not visible in #{timeout} seconds") do
|
109
|
+
visible?
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
#
|
114
|
+
# Waits until the element is not visible
|
115
|
+
#
|
116
|
+
# @param [Integer] (defaults to: 5) seconds to wait before timing out
|
117
|
+
#
|
118
|
+
def when_not_visible(timeout=5)
|
119
|
+
Watir::Wait.while(timeout, "Element still visible after #{timeout} seconds") do
|
120
|
+
visible?
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
#
|
125
|
+
# Waits until the block returns true
|
126
|
+
#
|
127
|
+
# @param [Integer] (defaults to: 5) seconds to wait before timing out
|
128
|
+
# @param [String] the message to display if the event timeouts
|
129
|
+
# @param the block to execute when the event occurrs
|
130
|
+
#
|
131
|
+
def wait_until(timeout=5, message=nil, &block)
|
132
|
+
Watir::Wait.until(timeout, message, &block)
|
133
|
+
end
|
92
134
|
end
|
93
135
|
end
|
94
136
|
end
|
@@ -43,6 +43,48 @@ module PageObject
|
|
43
43
|
@browser.title
|
44
44
|
end
|
45
45
|
|
46
|
+
#
|
47
|
+
# platform method to wait for a block to return true
|
48
|
+
# See PageObject#wait_until
|
49
|
+
#
|
50
|
+
def wait_until(timeout, message = nil, &block)
|
51
|
+
wait = Selenium::WebDriver::Wait.new({:timeout => timeout, :message => message})
|
52
|
+
wait.until &block
|
53
|
+
end
|
54
|
+
|
55
|
+
#
|
56
|
+
# platform method to handle an alert popup
|
57
|
+
# See PageObject#alert
|
58
|
+
#
|
59
|
+
def alert(&block)
|
60
|
+
@browser.execute_script "window.alert = function(msg) { window.__lastWatirAlert = msg; }"
|
61
|
+
yield
|
62
|
+
@browser.execute_script "return window.__lastWatirAlert"
|
63
|
+
end
|
64
|
+
|
65
|
+
#
|
66
|
+
# platform method to handle a confirm popup
|
67
|
+
# See PageObject#confirm
|
68
|
+
#
|
69
|
+
def confirm(response, &block)
|
70
|
+
@browser.execute_script "window.confirm = function(msg) { window.__lastWatirConfirm = msg; return #{!!response} }"
|
71
|
+
yield
|
72
|
+
@browser.execute_script "return window.__lastWatirConfirm"
|
73
|
+
end
|
74
|
+
|
75
|
+
#
|
76
|
+
# platform method to handle a prompt popup
|
77
|
+
# See PageObject#prompt
|
78
|
+
#
|
79
|
+
def prompt(answer, &block)
|
80
|
+
@browser.execute_script "window.prompt = function(text, value) { window.__lastWatirPrompt = { message: text, default_value: value }; return #{answer.to_json}; }"
|
81
|
+
yield
|
82
|
+
result = @browser.execute_script "return window.__lastWatirPrompt"
|
83
|
+
|
84
|
+
result && result.dup.each_key { |k| result[k.to_sym] = result.delete(k)}
|
85
|
+
result
|
86
|
+
end
|
87
|
+
|
46
88
|
#
|
47
89
|
# platform method to get the value stored in a text field
|
48
90
|
# See PageObject::Accessors#text_field
|
data/lib/page-object/version.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
require 'watir-webdriver/extensions/alerts'
|
1
2
|
require 'page-object/elements'
|
2
3
|
|
4
|
+
|
3
5
|
module PageObject
|
4
6
|
#
|
5
7
|
# Watir implementation of the page object platform driver. You should not use the
|
@@ -42,6 +44,37 @@ module PageObject
|
|
42
44
|
def title
|
43
45
|
@browser.title
|
44
46
|
end
|
47
|
+
|
48
|
+
#
|
49
|
+
# platform method to wait for a block to return true
|
50
|
+
# See PageObject#wait_until
|
51
|
+
def wait_until(timeout, message = nil, &block)
|
52
|
+
@browser.wait_until(timeout, message, &block)
|
53
|
+
end
|
54
|
+
|
55
|
+
#
|
56
|
+
# platform method to handle an alert popup
|
57
|
+
# See PageObject#alert
|
58
|
+
#
|
59
|
+
def alert(&block)
|
60
|
+
@browser.alert(&block)
|
61
|
+
end
|
62
|
+
|
63
|
+
#
|
64
|
+
# platform method to handle a confirm popup
|
65
|
+
# See PageObject#confirm
|
66
|
+
#
|
67
|
+
def confirm(response, &block)
|
68
|
+
@browser.confirm(response, &block)
|
69
|
+
end
|
70
|
+
|
71
|
+
#
|
72
|
+
# platform method to handle a prompt popup
|
73
|
+
# See PageObject#prompt
|
74
|
+
#
|
75
|
+
def prompt(answer, &block)
|
76
|
+
@browser.prompt(answer, &block)
|
77
|
+
end
|
45
78
|
|
46
79
|
#
|
47
80
|
# platform method to get the value stored in a text field
|
data/page-object.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.require_paths = ["lib"]
|
21
21
|
|
22
22
|
s.add_dependency 'watir-webdriver', '>= 0.2.6'
|
23
|
-
s.add_dependency 'selenium-webdriver', '>= 2.0
|
23
|
+
s.add_dependency 'selenium-webdriver', '>= 2.1.0'
|
24
24
|
|
25
25
|
s.add_development_dependency 'rspec', '>= 2.6.0'
|
26
26
|
s.add_development_dependency 'cucumber', '>= 1.0.0'
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class AccessorsTestPageObject
|
4
4
|
include PageObject
|
5
5
|
|
6
6
|
page_url "http://apple.com"
|
@@ -50,19 +50,19 @@ end
|
|
50
50
|
describe PageObject::Accessors do
|
51
51
|
let(:watir_browser) { mock_watir_browser }
|
52
52
|
let(:selenium_browser) { mock_selenium_browser }
|
53
|
-
let(:watir_page_object) {
|
54
|
-
let(:selenium_page_object) {
|
53
|
+
let(:watir_page_object) { AccessorsTestPageObject.new(watir_browser) }
|
54
|
+
let(:selenium_page_object) { AccessorsTestPageObject.new(selenium_browser) }
|
55
55
|
let(:block_page_object) { BlockPageObject.new(watir_browser) }
|
56
56
|
|
57
57
|
describe "goto a page" do
|
58
58
|
it "should navigate to a page when requested" do
|
59
59
|
watir_browser.should_receive(:goto)
|
60
|
-
page =
|
60
|
+
page = AccessorsTestPageObject.new(watir_browser, true)
|
61
61
|
end
|
62
62
|
|
63
63
|
it "should not navigate to a page when not requested" do
|
64
64
|
watir_browser.should_not_receive(:goto)
|
65
|
-
page =
|
65
|
+
page = AccessorsTestPageObject.new(watir_browser)
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should not navigate to a page when 'page_url' not specified" do
|
@@ -132,6 +132,26 @@ describe PageObject::Elements::Element do
|
|
132
132
|
watir_driver.should_receive(:click)
|
133
133
|
watir_element.click
|
134
134
|
end
|
135
|
+
|
136
|
+
it "should be able to block until it is present" do
|
137
|
+
watir_driver.should_receive(:wait_until_present).with(10)
|
138
|
+
watir_element.when_present(10)
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should be able to block until it is visible" do
|
142
|
+
Watir::Wait.should_receive(:until).with(10, "Element was not visible in 10 seconds")
|
143
|
+
watir_element.when_visible(10)
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should be able to block until it is not visible" do
|
147
|
+
Watir::Wait.should_receive(:while).with(10, "Element still visible after 10 seconds")
|
148
|
+
watir_element.when_not_visible(10)
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should be able to block until a user define event fires true" do
|
152
|
+
Watir::Wait.should_receive(:until).with(10, "Element blah")
|
153
|
+
watir_element.wait_until(10, "Element blah") {}
|
154
|
+
end
|
135
155
|
end
|
136
156
|
|
137
157
|
context "when using Selenium" do
|
@@ -183,5 +203,33 @@ describe PageObject::Elements::Element do
|
|
183
203
|
selenium_driver.should_receive(:click)
|
184
204
|
selenium_element.click
|
185
205
|
end
|
206
|
+
|
207
|
+
it "should be able to block until it is present" do
|
208
|
+
wait = double('wait')
|
209
|
+
Selenium::WebDriver::Wait.should_receive(:new).and_return(wait)
|
210
|
+
wait.should_receive(:until)
|
211
|
+
selenium_element.when_present(10)
|
212
|
+
end
|
213
|
+
|
214
|
+
it "should be able to block until it is visible" do
|
215
|
+
wait = double('wait')
|
216
|
+
Selenium::WebDriver::Wait.should_receive(:new).and_return(wait)
|
217
|
+
wait.should_receive(:until)
|
218
|
+
selenium_element.when_visible(10)
|
219
|
+
end
|
220
|
+
|
221
|
+
it "should be able to block until it is not visible" do
|
222
|
+
wait = double('wait')
|
223
|
+
Selenium::WebDriver::Wait.should_receive(:new).and_return(wait)
|
224
|
+
wait.should_receive(:until)
|
225
|
+
selenium_element.when_not_visible(10)
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should be able to block until a user define event fires true" do
|
229
|
+
wait = double('wait')
|
230
|
+
Selenium::WebDriver::Wait.should_receive(:new).and_return(wait)
|
231
|
+
wait.should_receive(:until)
|
232
|
+
selenium_element.wait_until(10, "Element blah") {}
|
233
|
+
end
|
186
234
|
end
|
187
235
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class PageObjectTestPageObject
|
4
4
|
include PageObject
|
5
5
|
end
|
6
6
|
|
7
7
|
describe PageObject do
|
8
8
|
let(:watir_browser) { mock_watir_browser }
|
9
9
|
let(:selenium_browser) { mock_selenium_browser }
|
10
|
-
let(:watir_page_object) {
|
11
|
-
let(:selenium_page_object) {
|
10
|
+
let(:watir_page_object) { PageObjectTestPageObject.new(watir_browser) }
|
11
|
+
let(:selenium_page_object) { PageObjectTestPageObject.new(selenium_browser) }
|
12
12
|
|
13
13
|
context "when created with a watir-webdriver browser" do
|
14
14
|
it "should include the WatirPageObject module" do
|
@@ -51,6 +51,29 @@ describe PageObject do
|
|
51
51
|
watir_browser.should_receive(:goto).with("cheezyworld.com")
|
52
52
|
watir_page_object.navigate_to("cheezyworld.com")
|
53
53
|
end
|
54
|
+
|
55
|
+
it "should wait until a block returns true" do
|
56
|
+
watir_browser.should_receive(:wait_until).with(5, "too long")
|
57
|
+
watir_page_object.wait_until(5, "too long")
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should override alert popup behavior" do
|
61
|
+
watir_browser.should_receive(:alert)
|
62
|
+
watir_page_object.alert do
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should override confirm popup behavior" do
|
67
|
+
watir_browser.should_receive(:confirm)
|
68
|
+
watir_page_object.confirm(true) do
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should override prompt popup behavior" do
|
73
|
+
watir_browser.should_receive(:prompt)
|
74
|
+
watir_page_object.prompt("blah") do
|
75
|
+
end
|
76
|
+
end
|
54
77
|
end
|
55
78
|
|
56
79
|
context "when using SeleniumPageObject" do
|
@@ -73,6 +96,30 @@ describe PageObject do
|
|
73
96
|
selenium_browser.stub_chain(:navigate, :to).with('cheezyworld.com')
|
74
97
|
selenium_page_object.navigate_to('cheezyworld.com')
|
75
98
|
end
|
99
|
+
|
100
|
+
it "should wait until a block returns true" do
|
101
|
+
wait = double('wait')
|
102
|
+
Selenium::WebDriver::Wait.should_receive(:new).with({:timeout => 5, :message => 'too long'}).and_return(wait)
|
103
|
+
wait.should_receive(:until)
|
104
|
+
selenium_page_object.wait_until(5, 'too long')
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should override alert popup behavior" do
|
108
|
+
selenium_browser.should_receive(:execute_script).twice
|
109
|
+
selenium_page_object.alert do
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should override confirm popup behavior" do
|
114
|
+
selenium_browser.should_receive(:execute_script).twice
|
115
|
+
selenium_page_object.confirm(true) do
|
116
|
+
end
|
117
|
+
end
|
118
|
+
it "should override prompt popup behavior" do
|
119
|
+
selenium_browser.should_receive(:execute_script).twice
|
120
|
+
selenium_page_object.prompt("blah") do
|
121
|
+
end
|
122
|
+
end
|
76
123
|
end
|
77
124
|
end
|
78
125
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'page-object/page_factory'
|
3
3
|
|
4
|
-
class
|
4
|
+
class FactoryTestPageObject
|
5
5
|
include PageObject
|
6
6
|
page_url "http://google.com"
|
7
7
|
end
|
@@ -20,15 +20,15 @@ describe PageObject::PageFactory do
|
|
20
20
|
|
21
21
|
it "should create a new page object and execute a block" do
|
22
22
|
@world.browser.should_not_receive(:goto)
|
23
|
-
@world.on_page
|
24
|
-
page.should be_instance_of
|
23
|
+
@world.on_page FactoryTestPageObject do |page|
|
24
|
+
page.should be_instance_of FactoryTestPageObject
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should create and visit a new page" do
|
29
29
|
@world.browser.should_receive(:goto)
|
30
|
-
@world.visit_page
|
31
|
-
page.should be_instance_of
|
30
|
+
@world.visit_page FactoryTestPageObject do |page|
|
31
|
+
page.should be_instance_of FactoryTestPageObject
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -2,13 +2,13 @@ require 'spec_helper'
|
|
2
2
|
require 'page-object/selenium_page_object'
|
3
3
|
require 'page-object/elements'
|
4
4
|
|
5
|
-
class
|
5
|
+
class SeleniumTestPageObject
|
6
6
|
include PageObject
|
7
7
|
end
|
8
8
|
|
9
9
|
describe PageObject::SeleniumPageObject do
|
10
10
|
let(:selenium_browser) { mock_selenium_browser }
|
11
|
-
let(:selenium_page_object) {
|
11
|
+
let(:selenium_page_object) { SeleniumTestPageObject.new(selenium_browser) }
|
12
12
|
|
13
13
|
context "when building identifiers hash" do
|
14
14
|
it "should add tag_name when identifying by text for hidden_field" do
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: page-object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: "0.2"
|
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-07-
|
13
|
+
date: 2011-07-24 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: watir-webdriver
|
@@ -31,7 +31,7 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: 2.0
|
34
|
+
version: 2.1.0
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: *id002
|
37
37
|
- !ruby/object:Gem::Dependency
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- README.md
|
88
88
|
- Rakefile
|
89
89
|
- cucumber.yml
|
90
|
+
- features/async.feature
|
90
91
|
- features/button.feature
|
91
92
|
- features/check_box.feature
|
92
93
|
- features/div.feature
|
@@ -105,6 +106,7 @@ files:
|
|
105
106
|
- features/select_list.feature
|
106
107
|
- features/span.feature
|
107
108
|
- features/step_definitions/accessor_steps.rb
|
109
|
+
- features/step_definitions/async_steps.rb
|
108
110
|
- features/step_definitions/element_steps.rb
|
109
111
|
- features/step_definitions/page_level_actions_steps.rb
|
110
112
|
- features/step_definitions/page_traversal_steps.rb
|
@@ -214,6 +216,7 @@ signing_key:
|
|
214
216
|
specification_version: 3
|
215
217
|
summary: Page Object DSL for browser testing
|
216
218
|
test_files:
|
219
|
+
- features/async.feature
|
217
220
|
- features/button.feature
|
218
221
|
- features/check_box.feature
|
219
222
|
- features/div.feature
|
@@ -232,6 +235,7 @@ test_files:
|
|
232
235
|
- features/select_list.feature
|
233
236
|
- features/span.feature
|
234
237
|
- features/step_definitions/accessor_steps.rb
|
238
|
+
- features/step_definitions/async_steps.rb
|
235
239
|
- features/step_definitions/element_steps.rb
|
236
240
|
- features/step_definitions/page_level_actions_steps.rb
|
237
241
|
- features/step_definitions/page_traversal_steps.rb
|