page-object 1.1.1 → 1.2.0
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.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/ChangeLog +9 -0
- data/Gemfile +1 -0
- data/features/section.feature +4 -0
- data/features/step_definitions/section_steps.rb +10 -1
- data/lib/page-object.rb +16 -8
- data/lib/page-object/accessors.rb +2 -2
- data/lib/page-object/elements/button.rb +0 -7
- data/lib/page-object/elements/canvas.rb +1 -13
- data/lib/page-object/elements/check_box.rb +0 -12
- data/lib/page-object/elements/element.rb +52 -9
- data/lib/page-object/elements/file_field.rb +0 -12
- data/lib/page-object/elements/form.rb +0 -12
- data/lib/page-object/elements/image.rb +0 -12
- data/lib/page-object/elements/link.rb +0 -12
- data/lib/page-object/elements/ordered_list.rb +0 -13
- data/lib/page-object/elements/radio_button.rb +0 -12
- data/lib/page-object/elements/select_list.rb +0 -13
- data/lib/page-object/elements/table.rb +0 -13
- data/lib/page-object/elements/table_row.rb +0 -13
- data/lib/page-object/elements/text_area.rb +0 -14
- data/lib/page-object/elements/text_field.rb +0 -12
- data/lib/page-object/elements/unordered_list.rb +0 -12
- data/lib/page-object/elements/video.rb +0 -10
- data/lib/page-object/platforms/selenium_webdriver/element.rb +1 -1
- data/lib/page-object/platforms/selenium_webdriver/page_object.rb +26 -5
- data/lib/page-object/platforms/selenium_webdriver/select_list.rb +1 -1
- data/lib/page-object/platforms/selenium_webdriver/table.rb +1 -1
- data/lib/page-object/platforms/selenium_webdriver/table_row.rb +1 -1
- data/lib/page-object/platforms/watir_webdriver/element.rb +9 -2
- data/lib/page-object/platforms/watir_webdriver/ordered_list.rb +1 -1
- data/lib/page-object/platforms/watir_webdriver/page_object.rb +25 -4
- data/lib/page-object/platforms/watir_webdriver/select_list.rb +1 -1
- data/lib/page-object/platforms/watir_webdriver/table.rb +1 -1
- data/lib/page-object/platforms/watir_webdriver/table_row.rb +1 -1
- data/lib/page-object/platforms/watir_webdriver/unordered_list.rb +1 -1
- data/lib/page-object/section_collection.rb +16 -0
- data/lib/page-object/version.rb +1 -1
- data/lib/page-object/widgets.rb +14 -36
- data/spec/page-object/elements/canvas_spec.rb +3 -2
- data/spec/page-object/elements/ordered_list_spec.rb +2 -2
- data/spec/page-object/elements/select_list_spec.rb +2 -2
- data/spec/page-object/elements/unordered_list_spec.rb +2 -2
- data/spec/page-object/elements/video_spec.rb +12 -6
- data/spec/page-object/page-object_spec.rb +51 -23
- data/spec/page-object/page_section_spec.rb +9 -2
- data/spec/page-object/watir_accessors_spec.rb +1 -0
- metadata +4 -4
- data/lib/page-object/sections.rb +0 -29
@@ -22,17 +22,18 @@ describe PageObject::Elements::Canvas do
|
|
22
22
|
|
23
23
|
context "implementation" do
|
24
24
|
let(:canvas_element) { double('canvas_element') }
|
25
|
+
let(:wd) { double('wd') }
|
25
26
|
|
26
27
|
context "when using selenium" do
|
27
28
|
let(:selenium_canvas) { PageObject::Elements::Canvas.new(canvas_element, :platform => :selenium_webdriver) }
|
28
29
|
|
29
30
|
it "should know its width" do
|
30
|
-
expect(canvas_element).to receive(:
|
31
|
+
expect(canvas_element).to receive(:size).and_return({'width' => 400})
|
31
32
|
expect(selenium_canvas.width).to eql 400
|
32
33
|
end
|
33
34
|
|
34
35
|
it "should know its height" do
|
35
|
-
expect(canvas_element).to receive(:
|
36
|
+
expect(canvas_element).to receive(:size).and_return({'height' => 100})
|
36
37
|
expect(selenium_canvas.height).to eql 100
|
37
38
|
end
|
38
39
|
end
|
@@ -30,14 +30,14 @@ describe PageObject::Elements::OrderedList do
|
|
30
30
|
context "for watir" do
|
31
31
|
it "should return a list item when indexed" do
|
32
32
|
ol = PageObject::Elements::OrderedList.new(ol_element, :platform => :watir_webdriver)
|
33
|
-
expect(ol_element).to receive(:
|
33
|
+
expect(ol_element).to receive(:ols).
|
34
34
|
and_return([ol_element, ol_element])
|
35
35
|
ol[1]
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should know how many list items it contains" do
|
39
39
|
ol = PageObject::Elements::OrderedList.new(ol_element, :platform => :watir_webdriver)
|
40
|
-
expect(ol_element).to receive(:
|
40
|
+
expect(ol_element).to receive(:ols).and_return([ol_element])
|
41
41
|
expect(ol.items).to eql 1
|
42
42
|
end
|
43
43
|
|
@@ -43,12 +43,12 @@ describe PageObject::Elements::SelectList do
|
|
43
43
|
let(:watir_sel_list) { PageObject::Elements::SelectList.new(sel_list, :platform => :watir_webdriver) }
|
44
44
|
|
45
45
|
it "should return an option when indexed" do
|
46
|
-
expect(sel_list).to receive(:
|
46
|
+
expect(sel_list).to receive(:options).with(no_args).and_return(opts)
|
47
47
|
expect(watir_sel_list[0]).to be_instance_of PageObject::Elements::Option
|
48
48
|
end
|
49
49
|
|
50
50
|
it "should return an array of options" do
|
51
|
-
expect(sel_list).to receive(:
|
51
|
+
expect(sel_list).to receive(:options).with(no_args).and_return(opts)
|
52
52
|
expect(watir_sel_list.options.size).to eql 2
|
53
53
|
end
|
54
54
|
|
@@ -30,14 +30,14 @@ describe PageObject::Elements::UnorderedList do
|
|
30
30
|
context "for watir" do
|
31
31
|
it "should return a list item when indexed" do
|
32
32
|
ul = PageObject::Elements::UnorderedList.new(ul_element, :platform => :watir_webdriver)
|
33
|
-
allow(ul_element).to receive(:
|
33
|
+
allow(ul_element).to receive(:uls).and_return(ul_element)
|
34
34
|
expect(ul_element).to receive(:[])
|
35
35
|
ul[1]
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should know how many items it contains" do
|
39
39
|
ul = PageObject::Elements::UnorderedList.new(ul_element, :platform => :watir_webdriver)
|
40
|
-
allow(ul_element).to receive(:
|
40
|
+
allow(ul_element).to receive(:uls).and_return([ul_element])
|
41
41
|
expect(ul.items).to eql 1
|
42
42
|
end
|
43
43
|
|
@@ -1,27 +1,33 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'page-object/elements'
|
3
3
|
|
4
|
-
describe PageObject::Elements::
|
4
|
+
describe PageObject::Elements::Video do
|
5
5
|
|
6
|
-
let(:video) { PageObject::Elements::Video.new(
|
6
|
+
let(:video) { PageObject::Elements::Video.new(platform, :platform => :watir_webdriver) }
|
7
|
+
let(:platform) { double('platform')}
|
8
|
+
let(:wd) { double('wd') }
|
9
|
+
|
10
|
+
before do
|
11
|
+
allow(platform).to receive(:wd).and_return wd
|
12
|
+
end
|
7
13
|
|
8
14
|
it "should return height when present" do
|
9
|
-
expect(
|
15
|
+
expect(wd).to receive(:size).and_return('height' => 20)
|
10
16
|
expect(video.height).to eq(20)
|
11
17
|
end
|
12
18
|
|
13
19
|
it "should not return height when not present" do
|
14
|
-
expect(
|
20
|
+
expect(wd).to receive(:size).and_return({})
|
15
21
|
expect(video.height).to eq(nil)
|
16
22
|
end
|
17
23
|
|
18
24
|
it "should return width when present" do
|
19
|
-
expect(
|
25
|
+
expect(wd).to receive(:size).and_return('width' => 20)
|
20
26
|
expect(video.width).to eq(20)
|
21
27
|
end
|
22
28
|
|
23
29
|
it "should not return width when not present" do
|
24
|
-
expect(
|
30
|
+
expect(wd).to receive(:size).and_return({})
|
25
31
|
expect(video.width).to eq(nil)
|
26
32
|
end
|
27
33
|
end
|
@@ -86,17 +86,17 @@ describe PageObject do
|
|
86
86
|
expect(selenium_page_object.platform).to be_kind_of PageObject::Platforms::SeleniumWebDriver::PageObject
|
87
87
|
end
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
context "when created with a non_bundled adapter" do
|
91
91
|
let(:custom_adapter) { mock_adapter(:custom_browser, CustomPlatform) }
|
92
|
-
|
92
|
+
|
93
93
|
it "should be an instance of whatever that objects adapter is" do
|
94
94
|
mock_adapters({:custom_adapter=>custom_adapter})
|
95
95
|
custom_page_object = PageObjectTestPageObject.new(:custom_browser)
|
96
96
|
expect(custom_page_object.platform).to be custom_adapter.create_page_object
|
97
97
|
end
|
98
98
|
end
|
99
|
-
|
99
|
+
|
100
100
|
context "when created with an object we do not understand" do
|
101
101
|
it "should throw an error" do
|
102
102
|
expect {
|
@@ -112,17 +112,17 @@ describe PageObject do
|
|
112
112
|
expect(watir_page_object.platform).to receive(:attach_to_window)
|
113
113
|
watir_page_object.attach_to_window("blah")
|
114
114
|
end
|
115
|
-
|
115
|
+
|
116
116
|
it "should call initialize_page if it exists" do
|
117
117
|
class CallbackPage
|
118
118
|
include PageObject
|
119
119
|
attr_reader :initialize_page_called
|
120
|
-
|
120
|
+
|
121
121
|
def initialize_page
|
122
122
|
@initialize_page_called = true
|
123
123
|
end
|
124
124
|
end
|
125
|
-
|
125
|
+
|
126
126
|
@page = CallbackPage.new(watir_browser)
|
127
127
|
expect(@page.initialize_page_called).to be true
|
128
128
|
end
|
@@ -165,8 +165,36 @@ describe PageObject do
|
|
165
165
|
expect(watir_browser).to receive(:type).and_return(:submit)
|
166
166
|
expect(watir_page_object.element_with_focus.class).to eql PageObject::Elements::Button
|
167
167
|
end
|
168
|
+
|
169
|
+
context "when sent a missing method" do
|
170
|
+
it "should not respond to it if the @root_element doesn't exist" do
|
171
|
+
# nil responds to `to_i`, @root_element is nil, but the page object doesn't respond
|
172
|
+
expect(nil).to respond_to :to_i
|
173
|
+
expect(watir_page_object.instance_variable_get(:@root_element)).to be nil
|
174
|
+
expect(watir_page_object).not_to respond_to :to_i
|
175
|
+
expect { watir_page_object.to_i }.to raise_error NoMethodError
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should respond to it if the @root_element exists and responds" do
|
179
|
+
# sanity checks
|
180
|
+
expect(watir_page_object.instance_variable_get(:@root_element)).to be nil
|
181
|
+
expect(watir_page_object).not_to respond_to :bar
|
182
|
+
expect(watir_page_object).not_to respond_to :baz
|
183
|
+
# set @root_element
|
184
|
+
class Foo; def bar; :bar_called; end; private; def baz; end; end
|
185
|
+
watir_page_object.instance_variable_set(:@root_element, Foo.new)
|
186
|
+
# test
|
187
|
+
expect(watir_page_object).to respond_to :bar
|
188
|
+
expect(watir_page_object).not_to respond_to :baz
|
189
|
+
expect(watir_page_object.bar).to eq :bar_called
|
190
|
+
expect { watir_page_object.baz }.to raise_error NoMethodError
|
191
|
+
# can't get to private methods
|
192
|
+
expect(watir_page_object.respond_to?(:baz, true)).to be false
|
193
|
+
expect { watir_page_object.send(:baz) }.to raise_error NoMethodError
|
194
|
+
end
|
195
|
+
end
|
168
196
|
end
|
169
|
-
|
197
|
+
|
170
198
|
context "when using WatirPageObject" do
|
171
199
|
it "should display the page text" do
|
172
200
|
expect(watir_browser).to receive(:element).and_return(watir_browser)
|
@@ -235,24 +263,24 @@ describe PageObject do
|
|
235
263
|
expect(watir_browser).to receive(:execute_script).and_return("abc")
|
236
264
|
expect(watir_page_object.execute_script("333")).to eql "abc"
|
237
265
|
end
|
238
|
-
|
266
|
+
|
239
267
|
it "should convert a modal popup to a window" do
|
240
268
|
expect(watir_browser).to receive(:execute_script)
|
241
269
|
watir_page_object.modal_dialog {}
|
242
270
|
end
|
243
|
-
|
271
|
+
|
244
272
|
it "should switch to a new window with a given title" do
|
245
273
|
expect(watir_browser).to receive(:window).with(:title => /My\ Title/).and_return(watir_browser)
|
246
274
|
expect(watir_browser).to receive(:use)
|
247
275
|
watir_page_object.attach_to_window(:title => "My Title")
|
248
276
|
end
|
249
|
-
|
277
|
+
|
250
278
|
it "should switch to a new window with a given url" do
|
251
279
|
expect(watir_browser).to receive(:window).with(:url => /success\.html/).and_return(watir_browser)
|
252
280
|
expect(watir_browser).to receive(:use)
|
253
281
|
watir_page_object.attach_to_window(:url => "success.html")
|
254
282
|
end
|
255
|
-
|
283
|
+
|
256
284
|
it "should refresh the page contents" do
|
257
285
|
expect(watir_browser).to receive(:refresh)
|
258
286
|
watir_page_object.refresh
|
@@ -267,18 +295,18 @@ describe PageObject do
|
|
267
295
|
expect(watir_browser).to receive(:forward)
|
268
296
|
watir_page_object.forward
|
269
297
|
end
|
270
|
-
|
298
|
+
|
271
299
|
it "should know its' current url" do
|
272
300
|
expect(watir_browser).to receive(:url).and_return("cheezyworld.com")
|
273
301
|
expect(watir_page_object.current_url).to eql "cheezyworld.com"
|
274
302
|
end
|
275
|
-
|
303
|
+
|
276
304
|
it "should know how to clear all of the cookies from the browser" do
|
277
305
|
expect(watir_browser).to receive(:cookies).and_return(watir_browser)
|
278
306
|
expect(watir_browser).to receive(:clear)
|
279
307
|
watir_page_object.clear_cookies
|
280
308
|
end
|
281
|
-
|
309
|
+
|
282
310
|
it "should be able to save a screenshot" do
|
283
311
|
expect(watir_browser).to receive(:wd).and_return(watir_browser)
|
284
312
|
expect(watir_browser).to receive(:save_screenshot)
|
@@ -342,12 +370,12 @@ describe PageObject do
|
|
342
370
|
selenium_page_object.prompt("blah") do
|
343
371
|
end
|
344
372
|
end
|
345
|
-
|
373
|
+
|
346
374
|
it "should convert a modal popup to a window" do
|
347
375
|
expect(selenium_browser).to receive(:execute_script)
|
348
376
|
selenium_page_object.modal_dialog {}
|
349
377
|
end
|
350
|
-
|
378
|
+
|
351
379
|
it "should execute javascript on the browser" do
|
352
380
|
expect(selenium_browser).to receive(:execute_script).and_return("abc")
|
353
381
|
expect(selenium_page_object.execute_script("333")).to eql "abc"
|
@@ -360,7 +388,7 @@ describe PageObject do
|
|
360
388
|
expect(selenium_browser).to receive(:title).and_return("My Title")
|
361
389
|
selenium_page_object.attach_to_window(:title => "My Title")
|
362
390
|
end
|
363
|
-
|
391
|
+
|
364
392
|
it "should switch to a new window with a given url" do
|
365
393
|
expect(selenium_browser).to receive(:window_handles).and_return(["win1"])
|
366
394
|
expect(selenium_browser).to receive(:switch_to).twice.and_return(selenium_browser)
|
@@ -368,36 +396,36 @@ describe PageObject do
|
|
368
396
|
expect(selenium_browser).to receive(:current_url).and_return("page.html")
|
369
397
|
selenium_page_object.attach_to_window(:url => "page.html")
|
370
398
|
end
|
371
|
-
|
399
|
+
|
372
400
|
it "should refresh the page contents" do
|
373
401
|
expect(selenium_browser).to receive(:navigate).and_return(selenium_browser)
|
374
402
|
expect(selenium_browser).to receive(:refresh)
|
375
403
|
selenium_page_object.refresh
|
376
404
|
end
|
377
|
-
|
405
|
+
|
378
406
|
it "should know how to go back" do
|
379
407
|
expect(selenium_browser).to receive(:navigate).and_return(selenium_browser)
|
380
408
|
expect(selenium_browser).to receive(:back)
|
381
409
|
selenium_page_object.back
|
382
410
|
end
|
383
|
-
|
411
|
+
|
384
412
|
it "should know how to go forward" do
|
385
413
|
expect(selenium_browser).to receive(:navigate).and_return(selenium_browser)
|
386
414
|
expect(selenium_browser).to receive(:forward)
|
387
415
|
selenium_page_object.forward
|
388
416
|
end
|
389
|
-
|
417
|
+
|
390
418
|
it "should know its' current url" do
|
391
419
|
expect(selenium_browser).to receive(:current_url).and_return("cheezyworld.com")
|
392
420
|
expect(selenium_page_object.current_url).to eql "cheezyworld.com"
|
393
421
|
end
|
394
|
-
|
422
|
+
|
395
423
|
it "should clear all of the cookies from the browser" do
|
396
424
|
expect(selenium_browser).to receive(:manage).and_return(selenium_browser)
|
397
425
|
expect(selenium_browser).to receive(:delete_all_cookies)
|
398
426
|
selenium_page_object.clear_cookies
|
399
427
|
end
|
400
|
-
|
428
|
+
|
401
429
|
it "should be able to save a screenshot" do
|
402
430
|
expect(selenium_browser).to receive(:save_screenshot)
|
403
431
|
selenium_page_object.save_screenshot("test.png")
|
@@ -53,7 +53,14 @@ describe PageObject::SectionCollection do
|
|
53
53
|
ContainedItem = Struct.new(:type, :name)
|
54
54
|
let(:section_collection) do
|
55
55
|
contained_items = [ContainedItem.new(:sandwich, :reuben), ContainedItem.new(:soup, :lobster_bisque), ContainedItem.new(:sandwich, :dagwood)]
|
56
|
-
PageObject::SectionCollection
|
56
|
+
PageObject::SectionCollection[*contained_items]
|
57
|
+
end
|
58
|
+
it 'should inherit from Array' do
|
59
|
+
expect(PageObject::SectionCollection.superclass).to eq Array
|
60
|
+
end
|
61
|
+
it 'should have functioning array methods' do
|
62
|
+
expect(section_collection.methods).to include *Array.instance_methods
|
63
|
+
expect(section_collection.last.type).to eq :sandwich
|
57
64
|
end
|
58
65
|
it 'should be indexed to the sections' do
|
59
66
|
expect(section_collection[0]).to be_an_instance_of ContainedItem
|
@@ -70,4 +77,4 @@ describe PageObject::SectionCollection do
|
|
70
77
|
it 'should find all sections matching a value' do
|
71
78
|
expect(section_collection.select_by(type: :sandwich).map(&:type)).to eq [:sandwich, :sandwich]
|
72
79
|
end
|
73
|
-
end
|
80
|
+
end
|
@@ -284,6 +284,7 @@ describe PageObject::Accessors do
|
|
284
284
|
|
285
285
|
def mock_driver_for(tag)
|
286
286
|
expect(watir_browser).to receive(tag).with(:index => 0).and_return(watir_browser)
|
287
|
+
allow(watir_browser).to receive(:exists?).with(no_args)
|
287
288
|
end
|
288
289
|
|
289
290
|
it "should work with a text_field" do
|
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: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Morgan
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-06-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: watir-webdriver
|
@@ -357,7 +357,7 @@ files:
|
|
357
357
|
- lib/page-object/platforms/watir_webdriver/text_area.rb
|
358
358
|
- lib/page-object/platforms/watir_webdriver/text_field.rb
|
359
359
|
- lib/page-object/platforms/watir_webdriver/unordered_list.rb
|
360
|
-
- lib/page-object/
|
360
|
+
- lib/page-object/section_collection.rb
|
361
361
|
- lib/page-object/version.rb
|
362
362
|
- lib/page-object/widgets.rb
|
363
363
|
- page-object.gemspec
|
@@ -431,7 +431,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
431
431
|
version: '0'
|
432
432
|
requirements: []
|
433
433
|
rubyforge_project: page-object
|
434
|
-
rubygems_version: 2.
|
434
|
+
rubygems_version: 2.5.1
|
435
435
|
signing_key:
|
436
436
|
specification_version: 4
|
437
437
|
summary: Page Object DSL for browser testing
|
data/lib/page-object/sections.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
module PageObject
|
2
|
-
class SectionCollection
|
3
|
-
include Enumerable
|
4
|
-
|
5
|
-
def initialize sections
|
6
|
-
@sections = sections
|
7
|
-
end
|
8
|
-
|
9
|
-
def each &block
|
10
|
-
@sections.each &block
|
11
|
-
end
|
12
|
-
|
13
|
-
def [] index
|
14
|
-
@sections[index]
|
15
|
-
end
|
16
|
-
|
17
|
-
def find_by values_hash
|
18
|
-
@sections.find {|section|
|
19
|
-
values_hash.all? {|method,value| value === section.public_send(method)}
|
20
|
-
}
|
21
|
-
end
|
22
|
-
|
23
|
-
def select_by values_hash
|
24
|
-
SectionCollection.new @sections.select {|section|
|
25
|
-
values_hash.all? {|method,value| value === section.public_send(method)}
|
26
|
-
}
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|