page-object 0.6.5 → 0.6.6
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/ChangeLog +9 -0
- data/features/async.feature +5 -0
- data/features/html/async.html +9 -1
- data/features/html/static_elements.html +1 -1
- data/features/span.feature +1 -0
- data/features/step_definitions/async_steps.rb +10 -0
- data/features/support/page.rb +1 -0
- data/lib/page-object/elements/span.rb +2 -2
- data/lib/page-object/platforms/selenium_webdriver/page_object.rb +18 -1
- data/lib/page-object/platforms/selenium_webdriver/surrogate_selenium_element.rb +42 -0
- data/lib/page-object/version.rb +1 -1
- data/lib/page-object.rb +1 -1
- data/page-object.gemspec +2 -2
- data/spec/page-object/elements/span_spec.rb +2 -2
- data/spec/page-object/page_populator_spec.rb +8 -7
- data/spec/page-object/platforms/selenium_webdriver/selenium_page_object_spec.rb +29 -1
- metadata +17 -17
- data/lib/page-object/platforms/selenium_webdriver/null_selenium_element.rb +0 -28
data/ChangeLog
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
=== Version 0.6.6 / 2012-4-26
|
2
|
+
* Enhancements
|
3
|
+
* Added ability to find span's by title
|
4
|
+
* Changed order of initialization so initialize_page is called after goto
|
5
|
+
* Updated to use watir-webdriver 0.5.5
|
6
|
+
* Updated to use selenium-webdriver 2.21.2
|
7
|
+
* Fixes
|
8
|
+
* Fixed the problem with determining the existance of an Selenium element
|
9
|
+
|
1
10
|
=== Version 0.6.5 / 2012-4-12
|
2
11
|
* Enhancements
|
3
12
|
* Added a page level element method to return a generic Element object
|
data/features/async.feature
CHANGED
@@ -16,3 +16,8 @@ Feature: Handling Asynch calls
|
|
16
16
|
Scenario: Wait until something is not visible
|
17
17
|
Given I am on the async elements page
|
18
18
|
Then I should be able to wait until the button becomes invisible
|
19
|
+
|
20
|
+
Scenario: Wait for an element to appear on the page
|
21
|
+
Given I am on the async elements page
|
22
|
+
When I add a button a few seconds from now
|
23
|
+
Then I should be able to click it when it gets added
|
data/features/html/async.html
CHANGED
@@ -9,12 +9,20 @@
|
|
9
9
|
function hide() {
|
10
10
|
document.getElementById("target").style.display="none";
|
11
11
|
}
|
12
|
-
|
12
|
+
|
13
|
+
function addDiv() {
|
14
|
+
var button = document.createElement("input");
|
15
|
+
button.setAttribute("type", "button");
|
16
|
+
button.setAttribute("value", "New Button")
|
17
|
+
document.body.appendChild(button);
|
18
|
+
}
|
19
|
+
</script>
|
13
20
|
</head>
|
14
21
|
<body>
|
15
22
|
<input type="button" id="target" value="Target"/>
|
16
23
|
<input type="button" onclick="setTimeout(function() {hide();}, 2000);" value="Hide Button"/>
|
17
24
|
<input type="button" onclick="setTimeout(function() {unhide();}, 2000);" value="Unhide Button"/>
|
25
|
+
<input type="button" onclick="setTimeout(function() {addDiv();}, 2000);" value="Create Button"/>
|
18
26
|
</body>
|
19
27
|
</html>
|
20
28
|
|
data/features/span.feature
CHANGED
@@ -35,6 +35,8 @@ class AsyncPage
|
|
35
35
|
button(:target, :value => 'Target')
|
36
36
|
button(:hide, :value => 'Hide Button')
|
37
37
|
button(:unhide, :value => 'Unhide Button')
|
38
|
+
button(:create_button, :value => 'Create Button')
|
39
|
+
button(:created_button, :value => 'New Button')
|
38
40
|
end
|
39
41
|
|
40
42
|
Given /^I am on the async elements page$/ do
|
@@ -60,3 +62,11 @@ Then /^I should be able to wait until the button becomes invisible$/ do
|
|
60
62
|
@page.target_element.attribute("block").should == "none"
|
61
63
|
end
|
62
64
|
end
|
65
|
+
|
66
|
+
When /^I add a button a few seconds from now$/ do
|
67
|
+
@page.create_button
|
68
|
+
end
|
69
|
+
|
70
|
+
Then /^I should be able to click it when it gets added$/ do
|
71
|
+
@page.created_button_element.when_present.click
|
72
|
+
end
|
data/features/support/page.rb
CHANGED
@@ -100,6 +100,7 @@ class Page
|
|
100
100
|
span(:span_class, :class => 'span_class')
|
101
101
|
span(:span_index, :index => 0)
|
102
102
|
span(:span_text, :text => 'My alert')
|
103
|
+
span(:span_title, :title => 'span_title')
|
103
104
|
span(:span_xpath, :xpath => '//span')
|
104
105
|
span(:span_class_index, :class => "span_class", :index => 0)
|
105
106
|
span(:span_name_index, :name => "span_name", :index => 0)
|
@@ -5,11 +5,11 @@ module PageObject
|
|
5
5
|
protected
|
6
6
|
|
7
7
|
def self.watir_finders
|
8
|
-
[:class, :id, :index, :text, :xpath]
|
8
|
+
[:class, :id, :index, :text, :title, :xpath]
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.selenium_finders
|
12
|
-
[:class, :id, :name, :text, :xpath, :index]
|
12
|
+
[:class, :id, :name, :text, :title, :xpath, :index]
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'page-object/elements'
|
2
2
|
require 'page-object/core_ext/string'
|
3
|
+
require 'page-object/platforms/selenium_webdriver/surrogate_selenium_element'
|
3
4
|
|
4
5
|
module PageObject
|
5
6
|
module Platforms
|
@@ -886,7 +887,12 @@ module PageObject
|
|
886
887
|
def find_selenium_element(identifier, type, tag, other=nil)
|
887
888
|
how, what, frame_identifiers = parse_identifiers(identifier, type, tag, other)
|
888
889
|
switch_to_frame(frame_identifiers)
|
889
|
-
|
890
|
+
begin
|
891
|
+
element = @browser.find_element(how, what)
|
892
|
+
rescue Selenium::WebDriver::Error::NoSuchElementError
|
893
|
+
@browser.switch_to.default_content unless frame_identifiers.nil?
|
894
|
+
return build_null_object(identifier, type, tag, other)
|
895
|
+
end
|
890
896
|
@browser.switch_to.default_content unless frame_identifiers.nil?
|
891
897
|
type.new(element, :platform => :selenium_webdriver)
|
892
898
|
end
|
@@ -899,6 +905,16 @@ module PageObject
|
|
899
905
|
elements.map { |element| type.new(element, :platform => :selenium_webdriver) }
|
900
906
|
end
|
901
907
|
|
908
|
+
def build_null_object(identifier, type, tag, other)
|
909
|
+
null_element = SurrogateSeleniumElement.new
|
910
|
+
null_element.identifier = identifier
|
911
|
+
null_element.type = type
|
912
|
+
null_element.tag = tag
|
913
|
+
null_element.other = other
|
914
|
+
null_element.platform = self
|
915
|
+
Elements::Element.new(null_element, :platform => :selenium_webdriver)
|
916
|
+
end
|
917
|
+
|
902
918
|
def parse_identifiers(identifier, element, tag_name=nil, additional=nil)
|
903
919
|
frame_identifiers = identifier.delete(:frame)
|
904
920
|
identifier = add_tagname_if_needed identifier, tag_name, additional if tag_name
|
@@ -932,6 +948,7 @@ module PageObject
|
|
932
948
|
return false if identifier[:text] and ['div', 'span', 'td', 'label'].include? tag
|
933
949
|
return false if identifier[:title] and tag == 'input' and additional[:type] == 'text'
|
934
950
|
return false if identifier[:title] and tag == 'input' and additional[:type] == 'file'
|
951
|
+
return false if identifier[:title] and tag == 'span'
|
935
952
|
return false if identifier[:value] and tag == 'input' and
|
936
953
|
['radio', 'submit', 'image', 'button', 'reset', 'checkbox', 'hidden'].include? additional[:type]
|
937
954
|
true
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module PageObject
|
2
|
+
module Platforms
|
3
|
+
module SeleniumWebDriver
|
4
|
+
class SurrogateSeleniumElement
|
5
|
+
attr_accessor :identifier, :type, :tag, :other, :platform
|
6
|
+
|
7
|
+
def exists?
|
8
|
+
attempt_to_find_element unless @element
|
9
|
+
@element ? (not @element.element.nil?) : false
|
10
|
+
end
|
11
|
+
|
12
|
+
def visible?
|
13
|
+
attempt_to_find_element unless @element
|
14
|
+
@element ? @element.element.displayed? : false
|
15
|
+
end
|
16
|
+
|
17
|
+
def nil?
|
18
|
+
attempt_to_find_element unless @element
|
19
|
+
@element ? @element.element.nil? : true
|
20
|
+
end
|
21
|
+
|
22
|
+
def displayed?
|
23
|
+
attempt_to_find_element unless @element
|
24
|
+
@element ? @element.element.displayed? : false
|
25
|
+
end
|
26
|
+
|
27
|
+
def method_missing(meth, *args)
|
28
|
+
return @element.send(meth, *args) if @element
|
29
|
+
$stderr.puts "You are calling #{meth} on an element that does not yet exist."
|
30
|
+
raise Selenium::WebDriver::Error::NoSuchElementError
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def attempt_to_find_element
|
36
|
+
@element = platform.send(:find_selenium_element, identifier, type, tag, other) unless @element
|
37
|
+
@element = nil if @element.element.instance_of?(::PageObject::Platforms::SeleniumWebDriver::SurrogateSeleniumElement)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/page-object/version.rb
CHANGED
data/lib/page-object.rb
CHANGED
@@ -55,8 +55,8 @@ module PageObject
|
|
55
55
|
def initialize(browser, visit=false)
|
56
56
|
@browser = browser
|
57
57
|
include_platform_driver(browser)
|
58
|
-
initialize_page if respond_to?(:initialize_page)
|
59
58
|
goto if visit && respond_to?(:goto)
|
59
|
+
initialize_page if respond_to?(:initialize_page)
|
60
60
|
end
|
61
61
|
|
62
62
|
# @private
|
data/page-object.gemspec
CHANGED
@@ -19,8 +19,8 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
20
20
|
s.require_paths = ["lib"]
|
21
21
|
|
22
|
-
s.add_dependency 'watir-webdriver', '>= 0.5.
|
23
|
-
s.add_dependency 'selenium-webdriver', '>= 2.21.
|
22
|
+
s.add_dependency 'watir-webdriver', '>= 0.5.5'
|
23
|
+
s.add_dependency 'selenium-webdriver', '>= 2.21.2'
|
24
24
|
|
25
25
|
s.add_development_dependency 'rspec', '>= 2.6.0'
|
26
26
|
s.add_development_dependency 'cucumber', '>= 1.1.0'
|
@@ -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, :text, :xpath].each do |t|
|
9
|
+
[:class, :id, :index, :text, :title, :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, :text, :xpath].each do |t|
|
16
|
+
[:class, :id, :index, :name, :text, :title, :xpath].each do |t|
|
17
17
|
key, value = span.selenium_identifier_for t => 'value'
|
18
18
|
key.should == t
|
19
19
|
end
|
@@ -21,11 +21,18 @@ describe PageObject::PagePopulator do
|
|
21
21
|
page_object.populate_page_with('tf' => 'value')
|
22
22
|
end
|
23
23
|
|
24
|
-
it "should not set a value if it is not found on the page" do
|
24
|
+
it "should not set a value in a text field if it is not found on the page" do
|
25
25
|
browser.should_not_receive(:text_field)
|
26
26
|
page_object.populate_page_with('coffee' => 'value')
|
27
27
|
end
|
28
28
|
|
29
|
+
it "should not populate a text field when it is disabled" do
|
30
|
+
page_object.should_not_receive(:tf=)
|
31
|
+
page_object.should_receive(:tf_element).and_return(browser)
|
32
|
+
browser.should_receive(:enabled?).and_return(false)
|
33
|
+
page_object.populate_page_with('tf' => true)
|
34
|
+
end
|
35
|
+
|
29
36
|
it "should set a value in a text area" do
|
30
37
|
page_object.should_receive(:ta=).with('value')
|
31
38
|
page_object.stub(:is_enabled?).and_return(true)
|
@@ -82,10 +89,4 @@ describe PageObject::PagePopulator do
|
|
82
89
|
page_object.populate_page_with('rb' => true)
|
83
90
|
end
|
84
91
|
|
85
|
-
it "should not populate a text field when it is disabled" do
|
86
|
-
page_object.should_not_receive(:tf=)
|
87
|
-
page_object.should_receive(:tf_element).and_return(browser)
|
88
|
-
browser.should_receive(:enabled?).and_return(false)
|
89
|
-
page_object.populate_page_with('tf' => true)
|
90
|
-
end
|
91
92
|
end
|
@@ -37,4 +37,32 @@ describe PageObject::Platforms::SeleniumWebDriver::PageObject do
|
|
37
37
|
selenium_page_object.platform.div_for(:text => 'foo')
|
38
38
|
end
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
|
+
context "when trying to find an element that does not exist" do
|
42
|
+
it "should return a surogate selenium object" do
|
43
|
+
selenium_browser.should_receive(:find_element).and_raise(Selenium::WebDriver::Error::NoSuchElementError)
|
44
|
+
page = SeleniumTestPageObject.new(selenium_browser)
|
45
|
+
element = page.link_element(:text => 'blah')
|
46
|
+
element.element.should be_instance_of PageObject::Platforms::SeleniumWebDriver::SurrogateSeleniumElement
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should know it is not exist" do
|
50
|
+
selenium_browser.should_receive(:find_element).twice.and_raise(Selenium::WebDriver::Error::NoSuchElementError)
|
51
|
+
page = SeleniumTestPageObject.new(selenium_browser)
|
52
|
+
page.link_element(:text => 'blah').element.exists?.should be_false
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should know it is not visible" do
|
56
|
+
selenium_browser.should_receive(:find_element).twice.and_raise(Selenium::WebDriver::Error::NoSuchElementError)
|
57
|
+
page = SeleniumTestPageObject.new(selenium_browser)
|
58
|
+
page.link_element(:text => 'blah').element.should_not be_visible
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should raise an error when actions are requested" do
|
62
|
+
selenium_browser.should_receive(:find_element).and_raise(Selenium::WebDriver::Error::NoSuchElementError)
|
63
|
+
page = SeleniumTestPageObject.new(selenium_browser)
|
64
|
+
element = page.link_element(:text => 'blah')
|
65
|
+
expect { element.text }.to raise_error
|
66
|
+
end
|
67
|
+
end
|
68
|
+
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.6.
|
4
|
+
version: 0.6.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,33 +9,33 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: watir-webdriver
|
16
|
-
requirement: &
|
16
|
+
requirement: &70181129846920 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.5.
|
21
|
+
version: 0.5.5
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70181129846920
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: selenium-webdriver
|
27
|
-
requirement: &
|
27
|
+
requirement: &70181129845600 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 2.21.
|
32
|
+
version: 2.21.2
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70181129845600
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70181129844800 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 2.6.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70181129844800
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: cucumber
|
49
|
-
requirement: &
|
49
|
+
requirement: &70181129844060 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.1.0
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70181129844060
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: yard
|
60
|
-
requirement: &
|
60
|
+
requirement: &70181129843560 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 0.7.2
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70181129843560
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rack
|
71
|
-
requirement: &
|
71
|
+
requirement: &70181129843100 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '1.0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70181129843100
|
80
80
|
description: Page Object DSL that works with both Watir and Selenium
|
81
81
|
email:
|
82
82
|
- jeff.morgan@leandog.com
|
@@ -232,11 +232,11 @@ files:
|
|
232
232
|
- lib/page-object/platforms/selenium_webdriver/form.rb
|
233
233
|
- lib/page-object/platforms/selenium_webdriver/image.rb
|
234
234
|
- lib/page-object/platforms/selenium_webdriver/link.rb
|
235
|
-
- lib/page-object/platforms/selenium_webdriver/null_selenium_element.rb
|
236
235
|
- lib/page-object/platforms/selenium_webdriver/ordered_list.rb
|
237
236
|
- lib/page-object/platforms/selenium_webdriver/page_object.rb
|
238
237
|
- lib/page-object/platforms/selenium_webdriver/radio_button.rb
|
239
238
|
- lib/page-object/platforms/selenium_webdriver/select_list.rb
|
239
|
+
- lib/page-object/platforms/selenium_webdriver/surrogate_selenium_element.rb
|
240
240
|
- lib/page-object/platforms/selenium_webdriver/table.rb
|
241
241
|
- lib/page-object/platforms/selenium_webdriver/table_row.rb
|
242
242
|
- lib/page-object/platforms/selenium_webdriver/text_area.rb
|
@@ -1,28 +0,0 @@
|
|
1
|
-
module PageObject
|
2
|
-
module Platforms
|
3
|
-
module SeleniumWebDriver
|
4
|
-
class NullSeleniumElement
|
5
|
-
def exists?
|
6
|
-
false
|
7
|
-
end
|
8
|
-
|
9
|
-
def visible?
|
10
|
-
false
|
11
|
-
end
|
12
|
-
|
13
|
-
def nil?
|
14
|
-
true
|
15
|
-
end
|
16
|
-
|
17
|
-
def displayed?
|
18
|
-
false
|
19
|
-
end
|
20
|
-
|
21
|
-
def method_missing(meth, *args)
|
22
|
-
$stderr.puts "You are calling #{meth} on an element that does not yet exist."
|
23
|
-
raise Selenium::WebDriver::Error::NoSuchElementError
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|