page-object 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +10 -0
- data/features/button.feature +13 -3
- data/features/html/indexed_property.html +3 -0
- data/features/html/static_elements.html +2 -0
- data/features/indexed_property.feature +20 -1
- data/features/section.feature +132 -0
- data/features/step_definitions/accessor_steps.rb +4 -0
- data/features/step_definitions/button_steps.rb +5 -0
- data/features/step_definitions/indexed_property_steps.rb +36 -2
- data/features/step_definitions/section_steps.rb +268 -0
- data/lib/page-object.rb +19 -7
- data/lib/page-object/accessors.rb +48 -0
- data/lib/page-object/elements/element.rb +4 -4
- data/lib/page-object/indexed_properties.rb +7 -3
- data/lib/page-object/loads_platform.rb +24 -5
- data/lib/page-object/platforms/selenium_webdriver.rb +14 -2
- data/lib/page-object/platforms/selenium_webdriver/button.rb +3 -3
- data/lib/page-object/platforms/selenium_webdriver/element.rb +1 -1
- data/lib/page-object/platforms/selenium_webdriver/page_object.rb +50 -0
- data/lib/page-object/platforms/watir_webdriver.rb +15 -3
- data/lib/page-object/platforms/watir_webdriver/element.rb +1 -1
- data/lib/page-object/platforms/watir_webdriver/page_object.rb +30 -0
- data/lib/page-object/sections.rb +29 -0
- data/lib/page-object/version.rb +1 -1
- data/page-object.gemspec +3 -3
- data/spec/page-object/elements/button_spec.rb +14 -0
- data/spec/page-object/elements/selenium_element_spec.rb +5 -0
- data/spec/page-object/elements/watir_element_spec.rb +4 -0
- data/spec/page-object/loads_platform_spec.rb +3 -3
- data/spec/page-object/page-object_spec.rb +1 -0
- data/spec/page-object/page_section_spec.rb +73 -0
- data/spec/spec_helper.rb +3 -1
- metadata +15 -6
data/page-object.gemspec
CHANGED
@@ -6,8 +6,8 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.name = "page-object"
|
7
7
|
s.version = PageObject::VERSION
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = ["Jeff Morgan"]
|
10
|
-
s.email = ["jeff.morgan@leandog.com"]
|
9
|
+
s.authors = ["Jeff Morgan", 'Dane Andersen']
|
10
|
+
s.email = ["jeff.morgan@leandog.com", 'dane.andersen@gmail.com']
|
11
11
|
s.license = 'MIT'
|
12
12
|
s.homepage = "http://github.com/cheezy/page-object"
|
13
13
|
s.summary = %q{Page Object DSL for browser testing}
|
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.add_dependency 'selenium-webdriver', '>= 2.44.0'
|
25
25
|
s.add_dependency 'page_navigation', '>= 0.9'
|
26
26
|
|
27
|
-
s.add_development_dependency 'rspec'
|
27
|
+
s.add_development_dependency 'rspec', '~> 3.1.0'
|
28
28
|
s.add_development_dependency 'cucumber', '>= 1.3.0'
|
29
29
|
s.add_development_dependency 'yard', '>= 0.7.2'
|
30
30
|
s.add_development_dependency 'rack', '>= 1.0'
|
@@ -44,6 +44,20 @@ describe PageObject::Elements::Button do
|
|
44
44
|
button = PageObject::Elements::Button.new(button_element, :platform => :selenium_webdriver)
|
45
45
|
expect(lambda { button.text }).to raise_error
|
46
46
|
end
|
47
|
+
|
48
|
+
it "should return text for a button tag button" do
|
49
|
+
allow(button_element).to receive(:tag_name).and_return('button')
|
50
|
+
allow(button_element).to receive(:text).and_return('button?')
|
51
|
+
button = PageObject::Elements::Button.new(button_element, :platform => :selenium_webdriver)
|
52
|
+
expect(button.text).to eq 'button?'
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should return text for an input tag button" do
|
56
|
+
allow(button_element).to receive(:tag_name).and_return('input')
|
57
|
+
allow(button_element).to receive(:attribute).with('value').and_return('button!')
|
58
|
+
button = PageObject::Elements::Button.new(button_element, :platform => :selenium_webdriver)
|
59
|
+
expect(button.text).to eq 'button!'
|
60
|
+
end
|
47
61
|
end
|
48
62
|
end
|
49
63
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'spec_helper'
|
1
2
|
require 'page-object/elements'
|
2
3
|
require 'selenium-webdriver'
|
3
4
|
|
@@ -46,6 +47,10 @@ describe "Element for Selenium" do
|
|
46
47
|
expect(@selenium_element).to eq @selenium_element
|
47
48
|
end
|
48
49
|
|
50
|
+
it "should know when it is not equal to another" do
|
51
|
+
expect(@selenium_element).not_to eq 'not an element'
|
52
|
+
end
|
53
|
+
|
49
54
|
it "should return its tag name" do
|
50
55
|
expect(@selenium_driver).to receive(:tag_name).and_return("h1")
|
51
56
|
expect(@selenium_element.tag_name).to eql "h1"
|
@@ -42,6 +42,10 @@ describe "Element for Watir" do
|
|
42
42
|
expect(watir_element).to eq watir_element
|
43
43
|
end
|
44
44
|
|
45
|
+
it "should know when it is not equal to another" do
|
46
|
+
expect(watir_element).not_to eq 'not an element'
|
47
|
+
end
|
48
|
+
|
45
49
|
it "should return its tag name" do
|
46
50
|
expect(watir_driver).to receive(:tag_name).and_return("h1")
|
47
51
|
expect(watir_element.tag_name).to eql "h1"
|
@@ -34,19 +34,19 @@ describe TestLoadsPlatform do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
context "When an unknow object is passed in" do
|
37
|
-
let(:basic_message) { 'Unable to pick a platform for the provided browser
|
37
|
+
let(:basic_message) { 'Unable to pick a platform for the provided browser or element:' }
|
38
38
|
|
39
39
|
it "should throw an exception" do
|
40
40
|
expect {
|
41
41
|
subject.load_platform("browser", {})
|
42
|
-
}.to raise_error(basic_message)
|
42
|
+
}.to raise_error("#{basic_message} \"browser\".")
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should notify when the browser is nil" do
|
46
46
|
begin
|
47
47
|
subject.load_platform(nil, {})
|
48
48
|
rescue Exception => e
|
49
|
-
expect(e.message).to eql "#{basic_message}
|
49
|
+
expect(e.message).to eql "#{basic_message} nil.\nnil was passed to the PageObject constructor instead of a valid browser or element object."
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
@@ -169,6 +169,7 @@ describe PageObject do
|
|
169
169
|
|
170
170
|
context "when using WatirPageObject" do
|
171
171
|
it "should display the page text" do
|
172
|
+
expect(watir_browser).to receive(:element).and_return(watir_browser)
|
172
173
|
expect(watir_browser).to receive(:text).and_return("browser text")
|
173
174
|
expect(watir_page_object.text).to eql "browser text"
|
174
175
|
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'page-object/elements'
|
3
|
+
|
4
|
+
class Container
|
5
|
+
include PageObject
|
6
|
+
end
|
7
|
+
class SectionsPage
|
8
|
+
include PageObject
|
9
|
+
|
10
|
+
page_section(:container, Container, :id => 'blah')
|
11
|
+
page_sections(:containers, Container, :class => 'foo')
|
12
|
+
end
|
13
|
+
|
14
|
+
describe PageObject::Accessors do
|
15
|
+
context 'when using watir' do
|
16
|
+
let(:watir_browser) { mock_watir_browser }
|
17
|
+
let(:watir_page_object) { SectionsPage.new(watir_browser) }
|
18
|
+
|
19
|
+
it 'it should find a page section' do
|
20
|
+
expect(watir_browser).to receive(:element).with(:id => 'blah').and_return(watir_browser)
|
21
|
+
section = watir_page_object.container
|
22
|
+
expect(section).to be_instance_of Container
|
23
|
+
end
|
24
|
+
it 'it should find page sections' do
|
25
|
+
expect(watir_browser).to receive(:elements).with(:class => 'foo').and_return([watir_browser, watir_browser])
|
26
|
+
sections = watir_page_object.containers
|
27
|
+
expect(sections).to be_instance_of(PageObject::SectionCollection)
|
28
|
+
sections.each do |section|
|
29
|
+
expect(section).to be_instance_of(Container)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
context 'when using selenium' do
|
34
|
+
let(:selenium_browser) { mock_selenium_browser }
|
35
|
+
let(:selenium_page_object) { SectionsPage.new(selenium_browser) }
|
36
|
+
|
37
|
+
it 'it should find a page section' do
|
38
|
+
expect(selenium_browser).to receive(:find_element).with(:id, 'blah').and_return(selenium_browser)
|
39
|
+
section = selenium_page_object.container
|
40
|
+
expect(section).to be_instance_of Container
|
41
|
+
end
|
42
|
+
it 'it should find page sections' do
|
43
|
+
expect(selenium_browser).to receive(:find_elements).with(:class, 'foo').and_return([selenium_browser, selenium_browser])
|
44
|
+
sections = selenium_page_object.containers
|
45
|
+
expect(sections).to be_instance_of(PageObject::SectionCollection)
|
46
|
+
sections.each do |section|
|
47
|
+
expect(section).to be_instance_of(Container)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
describe PageObject::SectionCollection do
|
53
|
+
ContainedItem = Struct.new(:type, :name)
|
54
|
+
let(:section_collection) do
|
55
|
+
contained_items = [ContainedItem.new(:sandwich, :reuben), ContainedItem.new(:soup, :lobster_bisque), ContainedItem.new(:sandwich, :dagwood)]
|
56
|
+
PageObject::SectionCollection.new(contained_items)
|
57
|
+
end
|
58
|
+
it 'should be indexed to the sections' do
|
59
|
+
expect(section_collection[0]).to be_an_instance_of ContainedItem
|
60
|
+
expect(section_collection[-1]).to be_an_instance_of ContainedItem
|
61
|
+
end
|
62
|
+
it 'should be able to iterate over the sections' do
|
63
|
+
section_collection.each do |section|
|
64
|
+
expect(section).to be_an_instance_of ContainedItem
|
65
|
+
end
|
66
|
+
end
|
67
|
+
it 'should find a section by one of its values' do
|
68
|
+
expect(section_collection.find_by(name: :dagwood).name).to eq :dagwood
|
69
|
+
end
|
70
|
+
it 'should find all sections matching a value' do
|
71
|
+
expect(section_collection.select_by(type: :sandwich).map(&:type)).to eq [:sandwich, :sandwich]
|
72
|
+
end
|
73
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -25,7 +25,7 @@ end
|
|
25
25
|
|
26
26
|
def mock_selenium_browser
|
27
27
|
selenium_browser = double('selenium')
|
28
|
-
allow(selenium_browser).to receive(:is_a?).with(
|
28
|
+
allow(selenium_browser).to receive(:is_a?).with(anything).and_return(false)
|
29
29
|
allow(selenium_browser).to receive(:is_a?).with(Selenium::WebDriver::Driver).and_return(true)
|
30
30
|
selenium_browser
|
31
31
|
end
|
@@ -36,6 +36,8 @@ def mock_adapter(browser, page_object)
|
|
36
36
|
allow(adapter).to receive(:is_for?).with(anything()).and_return false
|
37
37
|
allow(adapter).to receive(:is_for?).with(browser).and_return true
|
38
38
|
allow(adapter).to receive(:create_page_object).and_return page_object
|
39
|
+
allow(adapter).to receive(:root_element_for).and_return browser
|
40
|
+
allow(adapter).to receive(:browser_for).and_return browser
|
39
41
|
adapter
|
40
42
|
end
|
41
43
|
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: page-object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Morgan
|
8
|
+
- Dane Andersen
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2015-05-02 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: watir-webdriver
|
@@ -56,16 +57,16 @@ dependencies:
|
|
56
57
|
name: rspec
|
57
58
|
requirement: !ruby/object:Gem::Requirement
|
58
59
|
requirements:
|
59
|
-
- - "
|
60
|
+
- - "~>"
|
60
61
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
62
|
+
version: 3.1.0
|
62
63
|
type: :development
|
63
64
|
prerelease: false
|
64
65
|
version_requirements: !ruby/object:Gem::Requirement
|
65
66
|
requirements:
|
66
|
-
- - "
|
67
|
+
- - "~>"
|
67
68
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
69
|
+
version: 3.1.0
|
69
70
|
- !ruby/object:Gem::Dependency
|
70
71
|
name: cucumber
|
71
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -111,6 +112,7 @@ dependencies:
|
|
111
112
|
description: Page Object DSL that works with both Watir and Selenium
|
112
113
|
email:
|
113
114
|
- jeff.morgan@leandog.com
|
115
|
+
- dane.andersen@gmail.com
|
114
116
|
executables: []
|
115
117
|
extensions: []
|
116
118
|
extra_rdoc_files: []
|
@@ -193,6 +195,7 @@ files:
|
|
193
195
|
- features/sample-app/public/prototype-1.6.0.3.js
|
194
196
|
- features/sample-app/public/prototype.html
|
195
197
|
- features/sample-app/sample_app.rb
|
198
|
+
- features/section.feature
|
196
199
|
- features/select_list.feature
|
197
200
|
- features/span.feature
|
198
201
|
- features/step_definitions/accessor_steps.rb
|
@@ -227,6 +230,7 @@ files:
|
|
227
230
|
- features/step_definitions/paragraph_steps.rb
|
228
231
|
- features/step_definitions/radio_button_group_steps.rb
|
229
232
|
- features/step_definitions/radio_button_steps.rb
|
233
|
+
- features/step_definitions/section_steps.rb
|
230
234
|
- features/step_definitions/select_list_steps.rb
|
231
235
|
- features/step_definitions/span_steps.rb
|
232
236
|
- features/step_definitions/table_cell_steps.rb
|
@@ -330,6 +334,7 @@ files:
|
|
330
334
|
- lib/page-object/platforms/watir_webdriver/text_area.rb
|
331
335
|
- lib/page-object/platforms/watir_webdriver/text_field.rb
|
332
336
|
- lib/page-object/platforms/watir_webdriver/unordered_list.rb
|
337
|
+
- lib/page-object/sections.rb
|
333
338
|
- lib/page-object/version.rb
|
334
339
|
- lib/page-object/widgets.rb
|
335
340
|
- page-object.gemspec
|
@@ -371,6 +376,7 @@ files:
|
|
371
376
|
- spec/page-object/page-object_spec.rb
|
372
377
|
- spec/page-object/page_factory_spec.rb
|
373
378
|
- spec/page-object/page_populator_spec.rb
|
379
|
+
- spec/page-object/page_section_spec.rb
|
374
380
|
- spec/page-object/platforms/selenium_webdriver/selenium_page_object_spec.rb
|
375
381
|
- spec/page-object/platforms/selenium_webdriver_spec.rb
|
376
382
|
- spec/page-object/platforms/watir_webdriver/watir_page_object_spec.rb
|
@@ -470,6 +476,7 @@ test_files:
|
|
470
476
|
- features/sample-app/public/prototype-1.6.0.3.js
|
471
477
|
- features/sample-app/public/prototype.html
|
472
478
|
- features/sample-app/sample_app.rb
|
479
|
+
- features/section.feature
|
473
480
|
- features/select_list.feature
|
474
481
|
- features/span.feature
|
475
482
|
- features/step_definitions/accessor_steps.rb
|
@@ -504,6 +511,7 @@ test_files:
|
|
504
511
|
- features/step_definitions/paragraph_steps.rb
|
505
512
|
- features/step_definitions/radio_button_group_steps.rb
|
506
513
|
- features/step_definitions/radio_button_steps.rb
|
514
|
+
- features/step_definitions/section_steps.rb
|
507
515
|
- features/step_definitions/select_list_steps.rb
|
508
516
|
- features/step_definitions/span_steps.rb
|
509
517
|
- features/step_definitions/table_cell_steps.rb
|
@@ -563,6 +571,7 @@ test_files:
|
|
563
571
|
- spec/page-object/page-object_spec.rb
|
564
572
|
- spec/page-object/page_factory_spec.rb
|
565
573
|
- spec/page-object/page_populator_spec.rb
|
574
|
+
- spec/page-object/page_section_spec.rb
|
566
575
|
- spec/page-object/platforms/selenium_webdriver/selenium_page_object_spec.rb
|
567
576
|
- spec/page-object/platforms/selenium_webdriver_spec.rb
|
568
577
|
- spec/page-object/platforms/watir_webdriver/watir_page_object_spec.rb
|