page-object 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +15 -5
- data/features/ordered_list.feature +2 -0
- data/features/select_list.feature +0 -2
- data/features/span.feature +1 -1
- data/features/step_definitions/accessor_steps.rb +29 -0
- data/features/table.feature +4 -1
- data/features/unordered_list.feature +2 -0
- data/lib/page-object.rb +2 -1
- data/lib/page-object/accessors.rb +64 -34
- data/lib/page-object/elements/ordered_list.rb +16 -0
- data/lib/page-object/elements/table.rb +16 -0
- data/lib/page-object/elements/table_row.rb +16 -0
- data/lib/page-object/elements/unordered_list.rb +17 -0
- data/lib/page-object/page_factory.rb +50 -0
- data/lib/page-object/platforms/selenium_ordered_list.rb +15 -2
- data/lib/page-object/platforms/selenium_table.rb +16 -2
- data/lib/page-object/platforms/selenium_table_row.rb +15 -2
- data/lib/page-object/platforms/selenium_unordered_list.rb +15 -2
- data/lib/page-object/platforms/watir_ordered_list.rb +14 -2
- data/lib/page-object/platforms/watir_table.rb +9 -0
- data/lib/page-object/platforms/watir_table_row.rb +8 -1
- data/lib/page-object/platforms/watir_unordered_list.rb +15 -2
- data/lib/page-object/version.rb +1 -1
- data/spec/page-object/accessors_spec.rb +111 -0
- data/spec/page-object/elements/ordered_list_spec.rb +38 -2
- data/spec/page-object/elements/table_row_spec.rb +39 -5
- data/spec/page-object/elements/table_spec.rb +39 -8
- data/spec/page-object/elements/unordered_list_spec.rb +38 -2
- data/spec/page-object/page_factory_spec.rb +34 -0
- metadata +5 -2
@@ -27,17 +27,53 @@ describe PageObject::Elements::OrderedList do
|
|
27
27
|
it "should return a list item when indexed" do
|
28
28
|
ol = PageObject::Elements::OrderedList.new(ol_element, :platform => :watir)
|
29
29
|
ol_element.stub(:wd).and_return(ol_element)
|
30
|
-
ol_element.
|
30
|
+
ol_element.should_receive(:find_elements).with(:xpath, ".//child::li").and_return(ol_element)
|
31
|
+
ol_element.stub(:[]).and_return(ol_element)
|
31
32
|
ol[1].should be_instance_of PageObject::Elements::ListItem
|
32
33
|
end
|
34
|
+
|
35
|
+
it "should know how many list items it contains" do
|
36
|
+
ol = PageObject::Elements::OrderedList.new(ol_element, :platform => :watir)
|
37
|
+
ol_element.stub(:wd).and_return(ol_element)
|
38
|
+
ol_element.should_receive(:find_elements).with(:xpath, ".//child::li").and_return(ol_element)
|
39
|
+
ol_element.stub(:[]).and_return(ol_element)
|
40
|
+
ol_element.stub(:size).and_return(5)
|
41
|
+
ol.items.should == 5
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should iterate over the list items" do
|
45
|
+
ol = PageObject::Elements::OrderedList.new(ol_element, :platform => :watir)
|
46
|
+
ol.should_receive(:items).and_return(5)
|
47
|
+
ol.stub(:[])
|
48
|
+
count = 0
|
49
|
+
ol.each { |item| count += 1 }
|
50
|
+
count.should == 5
|
51
|
+
end
|
33
52
|
end
|
34
53
|
|
35
54
|
context "for selenium" do
|
36
55
|
it "should return a list item when indexed" do
|
37
56
|
ol = PageObject::Elements::OrderedList.new(ol_element, :platform => :selenium)
|
38
|
-
ol_element.should_receive(:
|
57
|
+
ol_element.should_receive(:find_elements).with(:xpath, ".//child::li").and_return(ol_element)
|
58
|
+
ol_element.should_receive(:[]).and_return(ol_element)
|
39
59
|
ol[1].should be_instance_of PageObject::Elements::ListItem
|
40
60
|
end
|
61
|
+
|
62
|
+
it "should know how many list items it contains" do
|
63
|
+
ol = PageObject::Elements::OrderedList.new(ol_element, :platform => :selenium)
|
64
|
+
ol_element.should_receive(:find_elements).with(:xpath, ".//child::li").and_return(ol_element)
|
65
|
+
ol_element.should_receive(:size).and_return(5)
|
66
|
+
ol.items.should == 5
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should iterate over the list items" do
|
70
|
+
ol = PageObject::Elements::OrderedList.new(ol_element, :platform => :selenium)
|
71
|
+
ol.should_receive(:items).and_return(5)
|
72
|
+
ol.stub(:[])
|
73
|
+
count = 0
|
74
|
+
ol.each { |item| count += 1 }
|
75
|
+
count.should == 5
|
76
|
+
end
|
41
77
|
end
|
42
78
|
end
|
43
79
|
end
|
@@ -8,18 +8,52 @@ describe PageObject::Elements::TableRow do
|
|
8
8
|
describe "interface" do
|
9
9
|
context "for selenium" do
|
10
10
|
it "should return a table cell when indexed" do
|
11
|
-
|
12
|
-
table_row_driver.should_receive(:
|
13
|
-
|
11
|
+
table_row = PageObject::Elements::TableRow.new(table_row_driver, :platform => :selenium)
|
12
|
+
table_row_driver.should_receive(:find_elements).with(:xpath, ".//child::td|th").and_return(table_cell)
|
13
|
+
table_cell.should_receive(:[]).and_return(table_cell)
|
14
|
+
table_row[0].should be_instance_of PageObject::Elements::TableCell
|
14
15
|
end
|
16
|
+
|
17
|
+
it "should retrun the number of columns" do
|
18
|
+
table_row = PageObject::Elements::TableRow.new(table_row_driver, :platform => :selenium)
|
19
|
+
table_row_driver.should_receive(:find_elements).with(:xpath, ".//child::td|th").and_return(table_row_driver)
|
20
|
+
table_row_driver.should_receive(:size).and_return(3)
|
21
|
+
table_row.columns.should == 3
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should iterate over the table columns" do
|
25
|
+
table_row = PageObject::Elements::TableRow.new(table_row_driver, :platform => :selenium)
|
26
|
+
table_row.should_receive(:columns).and_return(2)
|
27
|
+
table_row.stub(:[]).and_return(table_row_driver)
|
28
|
+
count = 0
|
29
|
+
table_row.each { |e| count += 1 }
|
30
|
+
count.should == 2
|
31
|
+
end
|
15
32
|
end
|
16
33
|
|
17
34
|
context "for watir" do
|
18
35
|
it "should return a table cell when indexed" do
|
19
|
-
|
36
|
+
table_row = PageObject::Elements::TableRow.new(table_row_driver, :platform => :watir)
|
20
37
|
table_row_driver.should_receive(:[]).with(1).and_return(table_cell)
|
21
|
-
|
38
|
+
table_row[1].should be_instance_of PageObject::Elements::TableCell
|
22
39
|
end
|
40
|
+
|
41
|
+
it "should return the number of columns" do
|
42
|
+
table_row = PageObject::Elements::TableRow.new(table_row_driver, :platform => :watir)
|
43
|
+
table_row_driver.should_receive(:wd).and_return(table_row_driver)
|
44
|
+
table_row_driver.should_receive(:find_elements).with(:xpath, ".//child::td|th").and_return(table_row_driver)
|
45
|
+
table_row_driver.should_receive(:size).and_return(3)
|
46
|
+
table_row.columns.should == 3
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should iterate over the table columns" do
|
50
|
+
table_row = PageObject::Elements::TableRow.new(table_row_driver, :platform => :watir)
|
51
|
+
table_row.should_receive(:columns).and_return(2)
|
52
|
+
table_row.stub(:[])
|
53
|
+
count = 0
|
54
|
+
table_row.each { |e| count += 1 }
|
55
|
+
count.should == 2
|
56
|
+
end
|
23
57
|
end
|
24
58
|
end
|
25
59
|
end
|
@@ -22,23 +22,54 @@ describe PageObject::Elements::Table do
|
|
22
22
|
let(:table_element) { double('table_element') }
|
23
23
|
|
24
24
|
before(:each) do
|
25
|
-
table_element.stub(:[])
|
26
|
-
table_element.stub(:
|
25
|
+
table_element.stub(:[]).and_return(table_element)
|
26
|
+
table_element.stub(:find_elements).and_return(table_element)
|
27
27
|
end
|
28
28
|
|
29
29
|
context "for watir" do
|
30
30
|
it "should return a table row when indexed" do
|
31
|
-
|
32
|
-
table_element.stub(:[]).with(1)
|
33
|
-
|
31
|
+
watir_table = PageObject::Elements::Table.new(table_element, :platform => :watir)
|
32
|
+
table_element.stub(:[]).with(1).and_return(table_element)
|
33
|
+
watir_table[1].should be_instance_of PageObject::Elements::TableRow
|
34
34
|
end
|
35
|
+
|
36
|
+
it "should return the number of rows" do
|
37
|
+
watir_table = PageObject::Elements::Table.new(table_element, :platform => :watir)
|
38
|
+
table_element.stub(:wd).and_return(table_element)
|
39
|
+
table_element.should_receive(:find_elements).with(:xpath, ".//child::tr").and_return(table_element)
|
40
|
+
table_element.should_receive(:size).and_return(2)
|
41
|
+
watir_table.rows.should == 2
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should iterate over the table rows" do
|
45
|
+
watir_table = PageObject::Elements::Table.new(table_element, :platform => :watir)
|
46
|
+
watir_table.should_receive(:rows).and_return(2)
|
47
|
+
count = 0
|
48
|
+
watir_table.each { |e| count += 1 }
|
49
|
+
count.should == 2
|
50
|
+
end
|
35
51
|
end
|
36
52
|
|
37
53
|
context "for selenium" do
|
38
54
|
it "should return a table row when indexed" do
|
39
|
-
|
40
|
-
table_element.
|
41
|
-
|
55
|
+
selenium_table = PageObject::Elements::Table.new(table_element, :platform => :selenium)
|
56
|
+
table_element.should_receive(:find_elements).with(:xpath, ".//child::tr").and_return(table_element)
|
57
|
+
selenium_table[1].should be_instance_of PageObject::Elements::TableRow
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should return the number of rows" do
|
61
|
+
selenium_table = PageObject::Elements::Table.new(table_element, :platform => :selenium)
|
62
|
+
table_element.should_receive(:find_elements).with(:xpath, ".//child::tr").and_return(table_element)
|
63
|
+
table_element.should_receive(:size).and_return(2)
|
64
|
+
selenium_table.rows.should == 2
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should iterate over the table rows" do
|
68
|
+
selenium_table = PageObject::Elements::Table.new(table_element, :platform => :selenium)
|
69
|
+
selenium_table.should_receive(:rows).and_return(2)
|
70
|
+
count = 0
|
71
|
+
selenium_table.each { |e| count += 1 }
|
72
|
+
count.should == 2
|
42
73
|
end
|
43
74
|
end
|
44
75
|
end
|
@@ -27,17 +27,53 @@ describe PageObject::Elements::UnorderedList do
|
|
27
27
|
it "should return a list item when indexed" do
|
28
28
|
ul = PageObject::Elements::UnorderedList.new(ul_element, :platform => :watir)
|
29
29
|
ul_element.stub(:wd).and_return(ul_element)
|
30
|
-
ul_element.stub(:
|
30
|
+
ul_element.stub(:find_elements).and_return(ul_element)
|
31
|
+
ul_element.stub(:[])
|
31
32
|
ul[1].should be_instance_of PageObject::Elements::ListItem
|
32
33
|
end
|
34
|
+
|
35
|
+
it "should know how many items it contains" do
|
36
|
+
ul = PageObject::Elements::UnorderedList.new(ul_element, :platform => :watir)
|
37
|
+
ul_element.stub(:wd).and_return(ul_element)
|
38
|
+
ul_element.stub(:find_elements).and_return(ul_element)
|
39
|
+
ul_element.stub(:size).and_return(5)
|
40
|
+
ul.items.should == 5
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should know how to iterate over the items" do
|
44
|
+
ul = PageObject::Elements::UnorderedList.new(ul_element, :platform => :watir)
|
45
|
+
ul.should_receive(:items).and_return(5)
|
46
|
+
ul.stub(:[])
|
47
|
+
count = 0
|
48
|
+
ul.each { |item| count += 1 }
|
49
|
+
count.should == 5
|
50
|
+
end
|
33
51
|
end
|
34
52
|
|
35
53
|
context "for selenium" do
|
36
54
|
it "should return a list item when indexed" do
|
37
55
|
ul = PageObject::Elements::UnorderedList.new(ul_element, :platform => :selenium)
|
38
|
-
ul_element.should_receive(:
|
56
|
+
ul_element.should_receive(:find_elements).and_return(ul_element)
|
57
|
+
ul_element.stub(:[])
|
39
58
|
ul[1].should be_instance_of PageObject::Elements::ListItem
|
40
59
|
end
|
60
|
+
|
61
|
+
it "should know how many items it contains" do
|
62
|
+
ul = PageObject::Elements::UnorderedList.new(ul_element, :platform => :selenium)
|
63
|
+
ul_element.should_receive(:find_elements).and_return(ul_element)
|
64
|
+
ul_element.should_receive(:size).and_return(5)
|
65
|
+
ul.items.should == 5
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should know how to iterate over the items" do
|
69
|
+
ul = PageObject::Elements::UnorderedList.new(ul_element, :platform => :selenium)
|
70
|
+
ul.should_receive(:items).and_return(5)
|
71
|
+
ul.stub(:[])
|
72
|
+
count = 0
|
73
|
+
ul.each { |item| count += 1 }
|
74
|
+
count.should == 5
|
75
|
+
|
76
|
+
end
|
41
77
|
end
|
42
78
|
end
|
43
79
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'page-object/page_factory'
|
3
|
+
|
4
|
+
class TestPageObject
|
5
|
+
include PageObject
|
6
|
+
page_url "http://google.com"
|
7
|
+
end
|
8
|
+
|
9
|
+
class TestWorld
|
10
|
+
include PageObject::PageFactory
|
11
|
+
|
12
|
+
attr_accessor :browser
|
13
|
+
end
|
14
|
+
|
15
|
+
describe PageObject::PageFactory do
|
16
|
+
before(:each) do
|
17
|
+
@world = TestWorld.new
|
18
|
+
@world.browser = mock_watir_browser
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should create a new page object and execute a block" do
|
22
|
+
@world.browser.should_not_receive(:goto)
|
23
|
+
@world.on_page TestPageObject do |page|
|
24
|
+
page.should be_instance_of TestPageObject
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should create and visit a new page" do
|
29
|
+
@world.browser.should_receive(:goto)
|
30
|
+
@world.visit_page TestPageObject do |page|
|
31
|
+
page.should be_instance_of TestPageObject
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: page-object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jeff Morgan
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-06-
|
13
|
+
date: 2011-06-15 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: watir-webdriver
|
@@ -138,6 +138,7 @@ files:
|
|
138
138
|
- lib/page-object/elements/text_area.rb
|
139
139
|
- lib/page-object/elements/text_field.rb
|
140
140
|
- lib/page-object/elements/unordered_list.rb
|
141
|
+
- lib/page-object/page_factory.rb
|
141
142
|
- lib/page-object/platforms/selenium_button.rb
|
142
143
|
- lib/page-object/platforms/selenium_element.rb
|
143
144
|
- lib/page-object/platforms/selenium_form.rb
|
@@ -178,6 +179,7 @@ files:
|
|
178
179
|
- spec/page-object/elements/text_field_spec.rb
|
179
180
|
- spec/page-object/elements/unordered_list_spec.rb
|
180
181
|
- spec/page-object/page-object_spec.rb
|
182
|
+
- spec/page-object/page_factory_spec.rb
|
181
183
|
- spec/spec_helper.rb
|
182
184
|
homepage: http://github.com/cheezy/page-object
|
183
185
|
licenses: []
|
@@ -257,4 +259,5 @@ test_files:
|
|
257
259
|
- spec/page-object/elements/text_field_spec.rb
|
258
260
|
- spec/page-object/elements/unordered_list_spec.rb
|
259
261
|
- spec/page-object/page-object_spec.rb
|
262
|
+
- spec/page-object/page_factory_spec.rb
|
260
263
|
- spec/spec_helper.rb
|