page-object 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/Gemfile +3 -0
- data/LICENSE +20 -0
- data/README.md +87 -0
- data/Rakefile +51 -0
- data/cucumber.yml +5 -0
- data/features/check_box.feature +39 -0
- data/features/html/static_elements.html +34 -0
- data/features/link.feature +42 -0
- data/features/page_level_actions.feature +19 -0
- data/features/radio_button.feature +40 -0
- data/features/select_list.feature +40 -0
- data/features/step_definitions/accessor_steps.rb +88 -0
- data/features/step_definitions/element_steps.rb +28 -0
- data/features/step_definitions/page_level_actions_steps.rb +12 -0
- data/features/step_definitions/page_traversal_steps.rb +5 -0
- data/features/support/env.rb +18 -0
- data/features/support/page.rb +45 -0
- data/features/support/url_helper.rb +16 -0
- data/features/text_field.feature +39 -0
- data/lib/page-object.rb +52 -0
- data/lib/page-object/accessors.rb +171 -0
- data/lib/page-object/elements.rb +8 -0
- data/lib/page-object/elements/button.rb +15 -0
- data/lib/page-object/elements/check_box.rb +15 -0
- data/lib/page-object/elements/element.rb +52 -0
- data/lib/page-object/elements/link.rb +34 -0
- data/lib/page-object/elements/radio_button.rb +15 -0
- data/lib/page-object/elements/select_list.rb +21 -0
- data/lib/page-object/elements/text_field.rb +33 -0
- data/lib/page-object/selenium_element.rb +12 -0
- data/lib/page-object/selenium_page_object.rb +190 -0
- data/lib/page-object/version.rb +3 -0
- data/lib/page-object/watir_element.rb +12 -0
- data/lib/page-object/watir_page_object.rb +190 -0
- data/page-object.gemspec +29 -0
- data/spec/page-object/accessors_spec.rb +297 -0
- data/spec/page-object/elements/button_spec.rb +23 -0
- data/spec/page-object/elements/check_box_spec.rb +21 -0
- data/spec/page-object/elements/element_spec.rb +54 -0
- data/spec/page-object/elements/link_spec.rb +34 -0
- data/spec/page-object/elements/radio_button_spec.rb +21 -0
- data/spec/page-object/elements/select_list_spec.rb +22 -0
- data/spec/page-object/elements/text_field_spec.rb +32 -0
- data/spec/page-object/page-object_spec.rb +78 -0
- data/spec/spec_helper.rb +31 -0
- metadata +179 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'page-object/elements'
|
3
|
+
|
4
|
+
describe PageObject::Elements::RadioButton do
|
5
|
+
let(:radiobutton) { PageObject::Elements::RadioButton }
|
6
|
+
|
7
|
+
describe "when mapping how to find an element" do
|
8
|
+
it "should map watir types to same" do
|
9
|
+
[:class, :id, :index, :name, :xpath].each do |t|
|
10
|
+
identifier = radiobutton.watir_identifier_for t => 'value'
|
11
|
+
identifier.keys.first.should == t
|
12
|
+
end
|
13
|
+
end
|
14
|
+
it "should map selenium types to same" do
|
15
|
+
[:class, :id, :name, :xpath].each do |t|
|
16
|
+
key, value = radiobutton.selenium_identifier_for t => 'value'
|
17
|
+
key.should == t
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'page-object/elements'
|
3
|
+
|
4
|
+
describe PageObject::Elements::SelectList do
|
5
|
+
let(:selectlist) { PageObject::Elements::SelectList }
|
6
|
+
|
7
|
+
describe "when mapping how to find an element" do
|
8
|
+
it "should map watir types to same" do
|
9
|
+
[:class, :id, :index, :name, :text, :value, :xpath].each do |t|
|
10
|
+
identifier = selectlist.watir_identifier_for t => 'value'
|
11
|
+
identifier.keys.first.should == t
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should map selenium types to same" do
|
16
|
+
[:class, :id, :name, :xpath].each do |t|
|
17
|
+
key, value = selectlist.selenium_identifier_for t => 'value'
|
18
|
+
key.should == t
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'page-object/elements'
|
3
|
+
|
4
|
+
describe PageObject::Elements::TextField do
|
5
|
+
let(:textfield) { PageObject::Elements::TextField }
|
6
|
+
|
7
|
+
describe "when mapping how to find an element" do
|
8
|
+
it "should map watir types to same" do
|
9
|
+
[:class, :id, :index, :name, :tag_name, :text, :value, :xpath].each do |t|
|
10
|
+
identifier = textfield.watir_identifier_for t => 'value'
|
11
|
+
identifier.keys.first.should == t
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should map selenium types to watir" do
|
16
|
+
identifier = textfield.watir_identifier_for :css => 'value'
|
17
|
+
identifier.keys.first.should == :tag_name
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should map selenium types to same" do
|
21
|
+
[:class, :css, :id, :name, :xpath].each do |t|
|
22
|
+
key, value = textfield.selenium_identifier_for t => 'value'
|
23
|
+
key.should == t
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should map watir types to selenium" do
|
28
|
+
key, value = textfield.selenium_identifier_for :tag_name => 'value'
|
29
|
+
key.should == :css
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class TestPageObject
|
4
|
+
include PageObject
|
5
|
+
end
|
6
|
+
|
7
|
+
describe PageObject do
|
8
|
+
let(:watir_browser) { mock_watir_browser }
|
9
|
+
let(:selenium_browser) { mock_selenium_browser }
|
10
|
+
let(:watir_page_object) { TestPageObject.new(watir_browser) }
|
11
|
+
let(:selenium_page_object) { TestPageObject.new(selenium_browser) }
|
12
|
+
|
13
|
+
context "when created with a watir-webdriver browser" do
|
14
|
+
it "should include the WatirPageObject module" do
|
15
|
+
watir_page_object.platform.should be_kind_of PageObject::WatirPageObject
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when created with a selenium browser" do
|
20
|
+
it "should include the SeleniumPageObject module" do
|
21
|
+
selenium_page_object.platform.should be_kind_of PageObject::SeleniumPageObject
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "when created with an object we do not understand" do
|
26
|
+
it "should throw an error" do
|
27
|
+
expect {
|
28
|
+
TestPageObject.new("blah")
|
29
|
+
}.to raise_error
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "page level functionality" do
|
34
|
+
context "when using WatirPageObject" do
|
35
|
+
it "should display the page text" do
|
36
|
+
watir_browser.should_receive(:text).and_return("browser text")
|
37
|
+
watir_page_object.text.should == "browser text"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should display the html of the page" do
|
41
|
+
watir_browser.should_receive(:html).and_return("<html>Some Sample HTML</html>")
|
42
|
+
watir_page_object.html.should == "<html>Some Sample HTML</html>"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should display the title of the page" do
|
46
|
+
watir_browser.should_receive(:title).and_return("I am the title of a page")
|
47
|
+
watir_page_object.title.should == "I am the title of a page"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should be able to navigate to a page" do
|
51
|
+
watir_browser.should_receive(:goto).with("cheezyworld.com")
|
52
|
+
watir_page_object.navigate_to("cheezyworld.com")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when using SeleniumPageObject" do
|
57
|
+
it "should display the page text" do
|
58
|
+
selenium_browser.stub_chain(:find_element, :text).and_return("browser text")
|
59
|
+
selenium_page_object.text.should == "browser text"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should display the html of the page" do
|
63
|
+
selenium_browser.should_receive(:page_source).and_return("<html>Some Sample HTML</html>")
|
64
|
+
selenium_page_object.html.should == "<html>Some Sample HTML</html>"
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should display the title of the page" do
|
68
|
+
selenium_browser.should_receive(:title).and_return("I am the title of a page")
|
69
|
+
selenium_page_object.title.should == "I am the title of a page"
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should be able to navigate to a page" do
|
73
|
+
selenium_browser.stub_chain(:navigate, :to).with('cheezyworld.com')
|
74
|
+
selenium_page_object.navigate_to('cheezyworld.com')
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
|
5
|
+
if ENV['coverage']
|
6
|
+
raise "simplecov only works on Ruby 1.9" unless RUBY_VERSION =~ /^1\.9/
|
7
|
+
|
8
|
+
require 'simplecov'
|
9
|
+
SimpleCov.start { add_filter "spec/" }
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'rspec'
|
13
|
+
require 'watir-webdriver'
|
14
|
+
require 'selenium-webdriver'
|
15
|
+
|
16
|
+
require 'page-object'
|
17
|
+
|
18
|
+
def mock_watir_browser
|
19
|
+
watir_browser = double('watir')
|
20
|
+
watir_browser.should_receive(:is_a?).with(Watir::Browser).and_return(true)
|
21
|
+
watir_browser
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def mock_selenium_browser
|
26
|
+
selenium_browser = double('selenium')
|
27
|
+
selenium_browser.should_receive(:is_a?).with(Watir::Browser).and_return(false)
|
28
|
+
selenium_browser.should_receive(:is_a?).with(Selenium::WebDriver::Driver).and_return(true)
|
29
|
+
selenium_browser
|
30
|
+
end
|
31
|
+
|
metadata
ADDED
@@ -0,0 +1,179 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: page-object
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jeff Morgan
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-05-22 00:00:00 -04:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: watir-webdriver
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.2.3
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: selenium-webdriver
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 0.2.0
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: rspec
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.5.0
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: cucumber
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 0.10.2
|
58
|
+
type: :development
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: yard
|
62
|
+
prerelease: false
|
63
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.6.8
|
69
|
+
type: :development
|
70
|
+
version_requirements: *id005
|
71
|
+
description: Page Object DSL that works with both Watir and Selenium
|
72
|
+
email:
|
73
|
+
- jeff.morgan@leandog.com
|
74
|
+
executables: []
|
75
|
+
|
76
|
+
extensions: []
|
77
|
+
|
78
|
+
extra_rdoc_files: []
|
79
|
+
|
80
|
+
files:
|
81
|
+
- .gitignore
|
82
|
+
- Gemfile
|
83
|
+
- LICENSE
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- cucumber.yml
|
87
|
+
- features/check_box.feature
|
88
|
+
- features/html/static_elements.html
|
89
|
+
- features/link.feature
|
90
|
+
- features/page_level_actions.feature
|
91
|
+
- features/radio_button.feature
|
92
|
+
- features/select_list.feature
|
93
|
+
- features/step_definitions/accessor_steps.rb
|
94
|
+
- features/step_definitions/element_steps.rb
|
95
|
+
- features/step_definitions/page_level_actions_steps.rb
|
96
|
+
- features/step_definitions/page_traversal_steps.rb
|
97
|
+
- features/support/env.rb
|
98
|
+
- features/support/page.rb
|
99
|
+
- features/support/url_helper.rb
|
100
|
+
- features/text_field.feature
|
101
|
+
- lib/page-object.rb
|
102
|
+
- lib/page-object/accessors.rb
|
103
|
+
- lib/page-object/elements.rb
|
104
|
+
- lib/page-object/elements/button.rb
|
105
|
+
- lib/page-object/elements/check_box.rb
|
106
|
+
- lib/page-object/elements/element.rb
|
107
|
+
- lib/page-object/elements/link.rb
|
108
|
+
- lib/page-object/elements/radio_button.rb
|
109
|
+
- lib/page-object/elements/select_list.rb
|
110
|
+
- lib/page-object/elements/text_field.rb
|
111
|
+
- lib/page-object/selenium_element.rb
|
112
|
+
- lib/page-object/selenium_page_object.rb
|
113
|
+
- lib/page-object/version.rb
|
114
|
+
- lib/page-object/watir_element.rb
|
115
|
+
- lib/page-object/watir_page_object.rb
|
116
|
+
- page-object.gemspec
|
117
|
+
- spec/page-object/accessors_spec.rb
|
118
|
+
- spec/page-object/elements/button_spec.rb
|
119
|
+
- spec/page-object/elements/check_box_spec.rb
|
120
|
+
- spec/page-object/elements/element_spec.rb
|
121
|
+
- spec/page-object/elements/link_spec.rb
|
122
|
+
- spec/page-object/elements/radio_button_spec.rb
|
123
|
+
- spec/page-object/elements/select_list_spec.rb
|
124
|
+
- spec/page-object/elements/text_field_spec.rb
|
125
|
+
- spec/page-object/page-object_spec.rb
|
126
|
+
- spec/spec_helper.rb
|
127
|
+
has_rdoc: true
|
128
|
+
homepage: http://github.com/cheezy/page-object
|
129
|
+
licenses: []
|
130
|
+
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options: []
|
133
|
+
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: "0"
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
none: false
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: "0"
|
148
|
+
requirements: []
|
149
|
+
|
150
|
+
rubyforge_project: page-object
|
151
|
+
rubygems_version: 1.6.2
|
152
|
+
signing_key:
|
153
|
+
specification_version: 3
|
154
|
+
summary: Page Object DSL for browser testing
|
155
|
+
test_files:
|
156
|
+
- features/check_box.feature
|
157
|
+
- features/html/static_elements.html
|
158
|
+
- features/link.feature
|
159
|
+
- features/page_level_actions.feature
|
160
|
+
- features/radio_button.feature
|
161
|
+
- features/select_list.feature
|
162
|
+
- features/step_definitions/accessor_steps.rb
|
163
|
+
- features/step_definitions/element_steps.rb
|
164
|
+
- features/step_definitions/page_level_actions_steps.rb
|
165
|
+
- features/step_definitions/page_traversal_steps.rb
|
166
|
+
- features/support/env.rb
|
167
|
+
- features/support/page.rb
|
168
|
+
- features/support/url_helper.rb
|
169
|
+
- features/text_field.feature
|
170
|
+
- spec/page-object/accessors_spec.rb
|
171
|
+
- spec/page-object/elements/button_spec.rb
|
172
|
+
- spec/page-object/elements/check_box_spec.rb
|
173
|
+
- spec/page-object/elements/element_spec.rb
|
174
|
+
- spec/page-object/elements/link_spec.rb
|
175
|
+
- spec/page-object/elements/radio_button_spec.rb
|
176
|
+
- spec/page-object/elements/select_list_spec.rb
|
177
|
+
- spec/page-object/elements/text_field_spec.rb
|
178
|
+
- spec/page-object/page-object_spec.rb
|
179
|
+
- spec/spec_helper.rb
|