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
data/page-object.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "page-object/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "page-object"
|
7
|
+
s.version = PageObject::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Jeff Morgan"]
|
10
|
+
s.email = ["jeff.morgan@leandog.com"]
|
11
|
+
s.homepage = "http://github.com/cheezy/page-object"
|
12
|
+
s.summary = %q{Page Object DSL for browser testing}
|
13
|
+
s.description = %q{Page Object DSL that works with both Watir and Selenium}
|
14
|
+
|
15
|
+
s.rubyforge_project = "page-object"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency 'watir-webdriver', '>= 0.2.3'
|
23
|
+
s.add_dependency 'selenium-webdriver', '>= 0.2.0'
|
24
|
+
|
25
|
+
s.add_development_dependency 'rspec', '>= 2.5.0'
|
26
|
+
s.add_development_dependency 'cucumber', '>= 0.10.2'
|
27
|
+
s.add_development_dependency 'yard', '>= 0.6.8'
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,297 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class TestPageObject
|
4
|
+
include PageObject
|
5
|
+
|
6
|
+
link(:google_search, {:link => 'Google Search'})
|
7
|
+
text_field(:first_name, {:id => 'first_name'})
|
8
|
+
select_list(:state, {:id => 'state'})
|
9
|
+
checkbox(:active, {:id => 'is_active_id'})
|
10
|
+
radio_button(:first, {:id => 'first_choice'})
|
11
|
+
button(:click_me, { :id => 'button_submit'})
|
12
|
+
end
|
13
|
+
|
14
|
+
describe PageObject::Accessors do
|
15
|
+
let(:watir_browser) { mock_watir_browser }
|
16
|
+
let(:selenium_browser) { mock_selenium_browser }
|
17
|
+
let(:watir_page_object) { TestPageObject.new(watir_browser) }
|
18
|
+
let(:selenium_page_object) { TestPageObject.new(selenium_browser) }
|
19
|
+
|
20
|
+
describe "link accessors" do
|
21
|
+
context "when called on a page object" do
|
22
|
+
it "should generate accessor methods" do
|
23
|
+
watir_page_object.should respond_to(:google_search)
|
24
|
+
watir_page_object.should respond_to(:google_search_link)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "Watir implementation" do
|
29
|
+
it "should select a link" do
|
30
|
+
watir_browser.stub_chain(:link, :click)
|
31
|
+
watir_page_object.google_search
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return a link element" do
|
35
|
+
watir_browser.should_receive(:link).and_return(watir_browser)
|
36
|
+
element = watir_page_object.google_search_link
|
37
|
+
element.should be_instance_of PageObject::Elements::Link
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "Selenium implementation" do
|
42
|
+
it "should select a link" do
|
43
|
+
selenium_browser.stub_chain(:find_element, :click)
|
44
|
+
selenium_page_object.google_search
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should return a link element" do
|
48
|
+
selenium_browser.should_receive(:find_element).and_return(selenium_browser)
|
49
|
+
element = selenium_page_object.google_search_link
|
50
|
+
element.should be_instance_of PageObject::Elements::Link
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
describe "text_field accessors" do
|
57
|
+
context "when called on a page object" do
|
58
|
+
it "should generate accessor methods" do
|
59
|
+
watir_page_object.should respond_to(:first_name)
|
60
|
+
watir_page_object.should respond_to(:first_name=)
|
61
|
+
watir_page_object.should respond_to(:first_name_text_field)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "Watir implementation" do
|
66
|
+
it "should get the text from the text field element" do
|
67
|
+
watir_browser.should_receive(:text_field).and_return(watir_browser)
|
68
|
+
watir_browser.should_receive(:value).and_return('Kim')
|
69
|
+
watir_page_object.first_name.should == 'Kim'
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should set some text on a text field element" do
|
73
|
+
watir_browser.should_receive(:text_field).and_return(watir_browser)
|
74
|
+
watir_browser.should_receive(:set).with('Kim')
|
75
|
+
watir_page_object.first_name = 'Kim'
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should retrieve a text field element" do
|
79
|
+
watir_browser.should_receive(:text_field).and_return(watir_browser)
|
80
|
+
element = watir_page_object.first_name_text_field
|
81
|
+
element.should be_instance_of PageObject::Elements::TextField
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "Selenium implementation" do
|
86
|
+
it "should get the text from the text field element" do
|
87
|
+
selenium_browser.should_receive(:find_element).and_return(selenium_browser)
|
88
|
+
selenium_browser.should_receive(:value).and_return('Katie')
|
89
|
+
selenium_page_object.first_name.should == 'Katie'
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should set some text on a text field element" do
|
93
|
+
selenium_browser.should_receive(:find_element).and_return(selenium_browser)
|
94
|
+
selenium_browser.should_receive(:send_keys).with('Katie')
|
95
|
+
selenium_page_object.first_name = 'Katie'
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should should retrieve a text field element" do
|
99
|
+
selenium_browser.should_receive(:find_element).and_return(selenium_browser)
|
100
|
+
element = selenium_page_object.first_name_text_field
|
101
|
+
element.should be_instance_of PageObject::Elements::TextField
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
describe "select_list accessors" do
|
108
|
+
context "when called on a page object" do
|
109
|
+
it "should generate accessor methods" do
|
110
|
+
watir_page_object.should respond_to :state
|
111
|
+
watir_page_object.should respond_to :state=
|
112
|
+
watir_page_object.should respond_to(:state_select_list)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context "Watir implementation" do
|
117
|
+
it "should get the current item from a select list" do
|
118
|
+
watir_browser.should_receive(:select_list).and_return watir_browser
|
119
|
+
watir_browser.should_receive(:value).and_return("OH")
|
120
|
+
watir_page_object.state.should == "OH"
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should set the current item of a select list" do
|
124
|
+
watir_browser.should_receive(:select_list).and_return watir_browser
|
125
|
+
watir_browser.should_receive(:select).with("OH")
|
126
|
+
watir_page_object.state = "OH"
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should retreive the select list element" do
|
130
|
+
watir_browser.should_receive(:select_list).and_return(watir_browser)
|
131
|
+
element = watir_page_object.state_select_list
|
132
|
+
element.should be_instance_of PageObject::Elements::SelectList
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context "Selenium implementation" do
|
137
|
+
it "should should get the current item from a select list" do
|
138
|
+
selenium_browser.should_receive(:find_element).and_return(selenium_browser)
|
139
|
+
selenium_browser.should_receive(:attribute).and_return("OH")
|
140
|
+
selenium_page_object.state.should == "OH"
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should set the current item of a select list" do
|
144
|
+
selenium_browser.should_receive(:find_element).and_return(selenium_browser)
|
145
|
+
selenium_browser.should_receive(:send_keys).with("OH")
|
146
|
+
selenium_page_object.state = "OH"
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should retrieve the select list element" do
|
150
|
+
selenium_browser.should_receive(:find_element).and_return(selenium_browser)
|
151
|
+
element = selenium_page_object.state_select_list
|
152
|
+
element.should be_instance_of PageObject::Elements::SelectList
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
|
158
|
+
describe "check_box accessors" do
|
159
|
+
context "when called on a page object" do
|
160
|
+
it "should generate accessor methods" do
|
161
|
+
watir_page_object.should respond_to :check_active
|
162
|
+
watir_page_object.should respond_to :uncheck_active
|
163
|
+
watir_page_object.should respond_to :active_checked?
|
164
|
+
watir_page_object.should respond_to(:active_checkbox)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
context "Watir implementation" do
|
169
|
+
it "should check a check box element" do
|
170
|
+
watir_browser.should_receive(:checkbox).and_return(watir_browser)
|
171
|
+
watir_browser.should_receive(:set)
|
172
|
+
watir_page_object.check_active
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should clear a check box element" do
|
176
|
+
watir_browser.should_receive(:checkbox).and_return(watir_browser)
|
177
|
+
watir_browser.should_receive(:clear)
|
178
|
+
watir_page_object.uncheck_active
|
179
|
+
end
|
180
|
+
|
181
|
+
it "should know if a check box element is selected" do
|
182
|
+
watir_browser.should_receive(:checkbox).and_return(watir_browser)
|
183
|
+
watir_browser.should_receive(:set?).and_return(true)
|
184
|
+
watir_page_object.active_checked?.should be_true
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should retrieve a checkbox element" do
|
188
|
+
watir_browser.should_receive(:checkbox).and_return(watir_browser)
|
189
|
+
element = watir_page_object.active_checkbox
|
190
|
+
element.should be_instance_of PageObject::Elements::CheckBox
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
context "Selenium implementation" do
|
195
|
+
it "should check a check box element" do
|
196
|
+
selenium_browser.should_receive(:find_element).twice.and_return(selenium_browser)
|
197
|
+
selenium_browser.should_receive(:selected?).and_return(false)
|
198
|
+
selenium_browser.should_receive(:toggle)
|
199
|
+
selenium_page_object.check_active
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should clear a check box element" do
|
203
|
+
selenium_browser.should_receive(:find_element).twice.and_return(selenium_browser)
|
204
|
+
selenium_browser.should_receive(:selected?).and_return(true)
|
205
|
+
selenium_browser.should_receive(:toggle)
|
206
|
+
selenium_page_object.uncheck_active
|
207
|
+
end
|
208
|
+
|
209
|
+
it "should know if a check box element is selected" do
|
210
|
+
selenium_browser.should_receive(:find_element).and_return(selenium_browser)
|
211
|
+
selenium_browser.should_receive(:selected?).and_return(true)
|
212
|
+
selenium_page_object.active_checked?.should be_true
|
213
|
+
end
|
214
|
+
|
215
|
+
it "should retrieve a checkbox element" do
|
216
|
+
selenium_browser.should_receive(:find_element).and_return(selenium_browser)
|
217
|
+
element = selenium_page_object.active_checkbox
|
218
|
+
element.should be_instance_of PageObject::Elements::CheckBox
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
|
224
|
+
describe "radio accessors" do
|
225
|
+
context "when called on a page object" do
|
226
|
+
it "should generate accessor methods" do
|
227
|
+
watir_page_object.should respond_to :select_first
|
228
|
+
watir_page_object.should respond_to :clear_first
|
229
|
+
watir_page_object.should respond_to :first_selected?
|
230
|
+
watir_page_object.should respond_to(:first_radio_button)
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
context "Watir implementation" do
|
235
|
+
it "should select a radio button" do
|
236
|
+
watir_browser.should_receive(:radio).and_return(watir_browser)
|
237
|
+
watir_browser.should_receive(:set)
|
238
|
+
watir_page_object.select_first
|
239
|
+
end
|
240
|
+
|
241
|
+
it "should clear a radio button" do
|
242
|
+
watir_browser.should_receive(:radio).and_return(watir_browser)
|
243
|
+
watir_browser.should_receive(:clear)
|
244
|
+
watir_page_object.clear_first
|
245
|
+
end
|
246
|
+
|
247
|
+
it "should determine if a radio is selected" do
|
248
|
+
watir_browser.should_receive(:radio).and_return(watir_browser)
|
249
|
+
watir_browser.should_receive(:set?)
|
250
|
+
watir_page_object.first_selected?
|
251
|
+
end
|
252
|
+
|
253
|
+
it "should retrieve a radio button element" do
|
254
|
+
watir_browser.should_receive(:radio).and_return(watir_browser)
|
255
|
+
element = watir_page_object.first_radio_button
|
256
|
+
element.should be_instance_of PageObject::Elements::RadioButton
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
context "Selenium implementation" do
|
261
|
+
it "should select a radio button" do
|
262
|
+
selenium_browser.should_receive(:find_element).twice.and_return(selenium_browser)
|
263
|
+
selenium_browser.should_receive(:selected?).and_return(false)
|
264
|
+
selenium_browser.should_receive(:click)
|
265
|
+
selenium_page_object.select_first
|
266
|
+
end
|
267
|
+
|
268
|
+
it "should clear a radio button" do
|
269
|
+
selenium_browser.should_receive(:find_element).twice.and_return(selenium_browser)
|
270
|
+
selenium_browser.should_receive(:selected?).and_return(true)
|
271
|
+
selenium_browser.should_receive(:click)
|
272
|
+
selenium_page_object.clear_first
|
273
|
+
end
|
274
|
+
|
275
|
+
it "should determine if a radio is selected" do
|
276
|
+
selenium_browser.should_receive(:find_element).and_return(selenium_browser)
|
277
|
+
selenium_browser.should_receive(:selected?).and_return(true)
|
278
|
+
selenium_page_object.first_selected?
|
279
|
+
end
|
280
|
+
|
281
|
+
it "should retrieve a radio button element" do
|
282
|
+
selenium_browser.should_receive(:find_element).and_return(selenium_browser)
|
283
|
+
element = selenium_page_object.first_radio_button
|
284
|
+
element.should be_instance_of PageObject::Elements::RadioButton
|
285
|
+
end
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
describe "button accessors" do
|
290
|
+
context "when called on a page object" do
|
291
|
+
it "should generate accessor methods" do
|
292
|
+
watir_page_object.should respond_to :click_me
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
end
|
297
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'page-object/elements'
|
3
|
+
|
4
|
+
describe PageObject::Elements::Button do
|
5
|
+
let(:button) { PageObject::Elements::Button }
|
6
|
+
|
7
|
+
context "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 = button.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 = button.selenium_identifier_for t => 'value'
|
18
|
+
key.should == t
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'page-object/elements'
|
3
|
+
|
4
|
+
describe PageObject::Elements::CheckBox do
|
5
|
+
let(:checkbox) { PageObject::Elements::CheckBox }
|
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 = checkbox.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 = checkbox.selenium_identifier_for t => 'value'
|
17
|
+
key.should == t
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'page-object/elements'
|
3
|
+
|
4
|
+
|
5
|
+
describe PageObject::Elements::Element do
|
6
|
+
let(:watir_driver) { double('watir') }
|
7
|
+
let(:selenium_driver) { double('selenium') }
|
8
|
+
let(:watir_element) { PageObject::Elements::Element.new(watir_driver, :platform => :watir) }
|
9
|
+
let(:selenium_element) { PageObject::Elements::Element.new(selenium_driver, :platform => :selenium) }
|
10
|
+
|
11
|
+
context "on a Watir page-object" do
|
12
|
+
it "should know when it is visible" do
|
13
|
+
watir_driver.should_receive(:present?).and_return(true)
|
14
|
+
watir_element.visible?.should == true
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should know when it is not visible" do
|
18
|
+
watir_driver.should_receive(:present?).and_return(false)
|
19
|
+
watir_element.visible?.should == false
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should know when it exists" do
|
23
|
+
watir_driver.should_receive(:exists?).and_return(true)
|
24
|
+
watir_element.exists?.should == true
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should know when it does not exist" do
|
28
|
+
watir_driver.should_receive(:exists?).and_return(false)
|
29
|
+
watir_element.exists?.should == false
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "on a Selenium page-object" do
|
34
|
+
it "should know when it is visible" do
|
35
|
+
selenium_driver.should_receive(:displayed?).and_return(true)
|
36
|
+
selenium_element.visible?.should == true
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should know when it is not visible" do
|
40
|
+
selenium_driver.should_receive(:displayed?).and_return(false)
|
41
|
+
selenium_element.visible?.should == false
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should know when it exists" do
|
45
|
+
selenium_element.exists?.should == true
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should know when it does not exist" do
|
49
|
+
selenium_element = PageObject::Elements::Element.new(nil, :platform => :selenium)
|
50
|
+
selenium_element.exists?.should == false
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'page-object/elements'
|
3
|
+
|
4
|
+
describe PageObject::Elements::Link do
|
5
|
+
let(:link) { PageObject::Elements::Link }
|
6
|
+
|
7
|
+
describe "when mapping how to find an element" do
|
8
|
+
it "should map watir types to same" do
|
9
|
+
[:class, :href, :id, :index, :name, :text, :xpath].each do |t|
|
10
|
+
identifier = link.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
|
+
[:link, :link_text].each do |t|
|
17
|
+
identifier = link.watir_identifier_for t => 'value'
|
18
|
+
identifier.keys.first.should == :text
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should map selenium types to same" do
|
23
|
+
[:class, :id, :link, :link_text, :name, :xpath].each do |t|
|
24
|
+
key, value = link.selenium_identifier_for t => 'value'
|
25
|
+
key.should == t
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should map watir types to selenium" do
|
30
|
+
key, value = link.selenium_identifier_for :text => 'value'
|
31
|
+
key.should == :link_text
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|