page-object 0.2 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.rvmrc +1 -1
- data/ChangeLog +12 -6
- data/README.md +1 -1
- data/Rakefile +3 -19
- data/features/async.feature +8 -8
- data/features/button.feature +7 -7
- data/features/check_box.feature +8 -8
- data/features/div.feature +7 -6
- data/features/element_attributes.feature +14 -14
- data/features/form.feature +5 -5
- data/features/frames.feature +12 -0
- data/features/hidden_field.feature +5 -5
- data/features/html/frame_1.html +18 -0
- data/features/html/frame_2.html +16 -0
- data/features/html/frames.html +11 -0
- data/features/html/iframes.html +12 -0
- data/features/html/static_elements.html +50 -42
- data/features/html/success.html +5 -5
- data/features/image.feature +11 -11
- data/features/link.feature +1 -1
- data/features/list_item.feature +5 -5
- data/features/ordered_list.feature +6 -6
- data/features/page_level_actions.feature +16 -5
- data/features/radio_button.feature +12 -12
- data/features/select_list.feature +12 -12
- data/features/span.feature +5 -5
- data/features/step_definitions/accessor_steps.rb +2 -2
- data/features/step_definitions/async_steps.rb +1 -1
- data/features/step_definitions/element_steps.rb +1 -1
- data/features/step_definitions/frames_steps.rb +21 -0
- data/features/step_definitions/page_level_actions_steps.rb +24 -2
- data/features/step_definitions/page_traversal_steps.rb +0 -1
- data/features/support/env.rb +20 -6
- data/features/support/page.rb +14 -11
- data/features/support/url_helper.rb +4 -0
- data/features/table.feature +9 -9
- data/features/table_cell.feature +6 -6
- data/features/text_area.feature +6 -6
- data/features/text_field.feature +7 -7
- data/features/unordered_list.feature +6 -6
- data/lib/page-object.rb +40 -16
- data/lib/page-object/accessors.rb +15 -15
- data/lib/page-object/elements.rb +0 -1
- data/lib/page-object/elements/button.rb +24 -24
- data/lib/page-object/elements/div.rb +8 -3
- data/lib/page-object/elements/element.rb +27 -28
- data/lib/page-object/elements/form.rb +7 -7
- data/lib/page-object/elements/hidden_field.rb +5 -5
- data/lib/page-object/elements/image.rb +8 -8
- data/lib/page-object/elements/link.rb +9 -9
- data/lib/page-object/elements/list_item.rb +1 -1
- data/lib/page-object/elements/option.rb +1 -1
- data/lib/page-object/elements/ordered_list.rb +13 -13
- data/lib/page-object/elements/select_list.rb +6 -6
- data/lib/page-object/elements/span.rb +2 -2
- data/lib/page-object/elements/table.rb +11 -11
- data/lib/page-object/elements/table_row.rb +9 -9
- data/lib/page-object/elements/text_area.rb +4 -4
- data/lib/page-object/elements/text_field.rb +4 -4
- data/lib/page-object/elements/unordered_list.rb +13 -13
- data/lib/page-object/loads_platform.rb +24 -0
- data/lib/page-object/page_factory.rb +3 -3
- data/lib/page-object/platforms.rb +18 -0
- data/lib/page-object/platforms/selenium.rb +16 -0
- data/lib/page-object/platforms/selenium/button.rb +15 -0
- data/lib/page-object/platforms/selenium/element.rb +168 -0
- data/lib/page-object/platforms/selenium/form.rb +16 -0
- data/lib/page-object/platforms/selenium/image.rb +28 -0
- data/lib/page-object/platforms/selenium/link.rb +16 -0
- data/lib/page-object/platforms/selenium/ordered_list.rb +33 -0
- data/lib/page-object/platforms/selenium/page_object.rb +524 -0
- data/lib/page-object/platforms/selenium/select_list.rb +32 -0
- data/lib/page-object/platforms/selenium/table.rb +40 -0
- data/lib/page-object/platforms/selenium/table_row.rb +32 -0
- data/lib/page-object/platforms/selenium/unordered_list.rb +33 -0
- data/lib/page-object/platforms/watir.rb +16 -0
- data/lib/page-object/platforms/watir/element.rb +154 -0
- data/lib/page-object/platforms/watir/form.rb +16 -0
- data/lib/page-object/platforms/watir/image.rb +22 -0
- data/lib/page-object/platforms/watir/ordered_list.rb +32 -0
- data/lib/page-object/{watir_page_object.rb → platforms/watir/page_object.rb} +62 -35
- data/lib/page-object/platforms/watir/select_list.rb +33 -0
- data/lib/page-object/platforms/watir/table.rb +27 -0
- data/lib/page-object/platforms/watir/table_row.rb +24 -0
- data/lib/page-object/platforms/watir/unordered_list.rb +33 -0
- data/lib/page-object/version.rb +1 -1
- data/page-object.gemspec +13 -13
- data/spec/page-object/accessors_spec.rb +142 -108
- data/spec/page-object/elements/button_spec.rb +33 -33
- data/spec/page-object/elements/check_box_spec.rb +1 -1
- data/spec/page-object/elements/div_spec.rb +3 -3
- data/spec/page-object/elements/element_spec.rb +51 -41
- data/spec/page-object/elements/form_spec.rb +3 -3
- data/spec/page-object/elements/hidden_field_spec.rb +3 -3
- data/spec/page-object/elements/image_spec.rb +7 -7
- data/spec/page-object/elements/link_spec.rb +8 -8
- data/spec/page-object/elements/list_item_spec.rb +1 -1
- data/spec/page-object/elements/ordered_list_spec.rb +9 -9
- data/spec/page-object/elements/radio_button_spec.rb +1 -1
- data/spec/page-object/elements/select_list_spec.rb +2 -2
- data/spec/page-object/elements/span_spec.rb +1 -1
- data/spec/page-object/elements/table_row_spec.rb +6 -6
- data/spec/page-object/elements/table_spec.rb +9 -9
- data/spec/page-object/elements/text_area_spec.rb +3 -3
- data/spec/page-object/elements/text_field_spec.rb +3 -3
- data/spec/page-object/elements/unordered_list_spec.rb +10 -10
- data/spec/page-object/loads_platform_spec.rb +38 -0
- data/spec/page-object/page-object_spec.rb +70 -10
- data/spec/page-object/page_factory_spec.rb +3 -3
- data/spec/page-object/{selenium_page_object_spec.rb → platforms/selenium/selenium_page_object_spec.rb} +10 -3
- data/spec/page-object/platforms/selenium_spec.rb +26 -0
- data/spec/page-object/platforms/watir_spec.rb +27 -0
- data/spec/spec_helper.rb +18 -5
- metadata +48 -26
- data/lib/page-object/platforms/selenium_button.rb +0 -13
- data/lib/page-object/platforms/selenium_element.rb +0 -142
- data/lib/page-object/platforms/selenium_form.rb +0 -14
- data/lib/page-object/platforms/selenium_image.rb +0 -26
- data/lib/page-object/platforms/selenium_link.rb +0 -13
- data/lib/page-object/platforms/selenium_ordered_list.rb +0 -31
- data/lib/page-object/platforms/selenium_select_list.rb +0 -29
- data/lib/page-object/platforms/selenium_table.rb +0 -38
- data/lib/page-object/platforms/selenium_table_row.rb +0 -29
- data/lib/page-object/platforms/selenium_unordered_list.rb +0 -31
- data/lib/page-object/platforms/watir_element.rb +0 -136
- data/lib/page-object/platforms/watir_form.rb +0 -14
- data/lib/page-object/platforms/watir_image.rb +0 -20
- data/lib/page-object/platforms/watir_ordered_list.rb +0 -30
- data/lib/page-object/platforms/watir_select_list.rb +0 -30
- data/lib/page-object/platforms/watir_table.rb +0 -24
- data/lib/page-object/platforms/watir_table_row.rb +0 -22
- data/lib/page-object/platforms/watir_unordered_list.rb +0 -31
- data/lib/page-object/selenium_page_object.rb +0 -486
@@ -3,7 +3,7 @@ require 'page-object/elements'
|
|
3
3
|
|
4
4
|
describe PageObject::Elements::Link do
|
5
5
|
let(:link) { PageObject::Elements::Link }
|
6
|
-
|
6
|
+
|
7
7
|
describe "when mapping how to find an element" do
|
8
8
|
it "should map watir types to same" do
|
9
9
|
[:class, :href, :id, :index, :name, :text, :xpath].each do |t|
|
@@ -11,35 +11,35 @@ describe PageObject::Elements::Link do
|
|
11
11
|
identifier.keys.first.should == t
|
12
12
|
end
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
it "should map selenium types to watir" do
|
16
16
|
[:link, :link_text].each do |t|
|
17
17
|
identifier = link.watir_identifier_for t => 'value'
|
18
18
|
identifier.keys.first.should == :text
|
19
19
|
end
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
it "should map selenium types to same" do
|
23
23
|
[:class, :id, :link, :link_text, :name, :xpath, :index].each do |t|
|
24
24
|
key, value = link.selenium_identifier_for t => 'value'
|
25
25
|
key.should == t
|
26
26
|
end
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
it "should map watir types to selenium" do
|
30
30
|
key, value = link.selenium_identifier_for :text => 'value'
|
31
31
|
key.should == :link_text
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
describe "interface" do
|
36
36
|
let(:link_element) { double('link_element') }
|
37
|
-
|
37
|
+
|
38
38
|
context "for selenium" do
|
39
39
|
it "should return error when asked for its' value" do
|
40
40
|
link = PageObject::Elements::Link.new(link_element, :platform => :selenium)
|
41
|
-
lambda {link.value}.should raise_error
|
42
|
-
end
|
41
|
+
lambda { link.value }.should raise_error
|
42
|
+
end
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
@@ -3,7 +3,7 @@ require 'page-object/elements'
|
|
3
3
|
|
4
4
|
describe PageObject::Elements::ListItem do
|
5
5
|
let(:list_item) { PageObject::Elements::ListItem }
|
6
|
-
|
6
|
+
|
7
7
|
describe "when mapping how to find an element" do
|
8
8
|
it "should map watir types to same" do
|
9
9
|
[:class, :id, :index, :xpath].each do |t|
|
@@ -3,7 +3,7 @@ require 'page-object/elements'
|
|
3
3
|
|
4
4
|
describe PageObject::Elements::OrderedList do
|
5
5
|
let(:ol) { PageObject::Elements::OrderedList }
|
6
|
-
|
6
|
+
|
7
7
|
describe "when mapping how to find an element" do
|
8
8
|
it "should map watir types to same" do
|
9
9
|
[:class, :id, :index, :xpath].each do |t|
|
@@ -19,10 +19,10 @@ describe PageObject::Elements::OrderedList do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
describe "interface" do
|
24
24
|
let(:ol_element) { double('ol_element') }
|
25
|
-
|
25
|
+
|
26
26
|
context "for watir" do
|
27
27
|
it "should return a list item when indexed" do
|
28
28
|
ol = PageObject::Elements::OrderedList.new(ol_element, :platform => :watir)
|
@@ -31,7 +31,7 @@ describe PageObject::Elements::OrderedList do
|
|
31
31
|
ol_element.stub(:[]).and_return(ol_element)
|
32
32
|
ol[1].should be_instance_of PageObject::Elements::ListItem
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
it "should know how many list items it contains" do
|
36
36
|
ol = PageObject::Elements::OrderedList.new(ol_element, :platform => :watir)
|
37
37
|
ol_element.stub(:wd).and_return(ol_element)
|
@@ -40,7 +40,7 @@ describe PageObject::Elements::OrderedList do
|
|
40
40
|
ol_element.stub(:size).and_return(5)
|
41
41
|
ol.items.should == 5
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
it "should iterate over the list items" do
|
45
45
|
ol = PageObject::Elements::OrderedList.new(ol_element, :platform => :watir)
|
46
46
|
ol.should_receive(:items).and_return(5)
|
@@ -49,8 +49,8 @@ describe PageObject::Elements::OrderedList do
|
|
49
49
|
ol.each { |item| count += 1 }
|
50
50
|
count.should == 5
|
51
51
|
end
|
52
|
-
end
|
53
|
-
|
52
|
+
end
|
53
|
+
|
54
54
|
context "for selenium" do
|
55
55
|
it "should return a list item when indexed" do
|
56
56
|
ol = PageObject::Elements::OrderedList.new(ol_element, :platform => :selenium)
|
@@ -58,14 +58,14 @@ describe PageObject::Elements::OrderedList do
|
|
58
58
|
ol_element.should_receive(:[]).and_return(ol_element)
|
59
59
|
ol[1].should be_instance_of PageObject::Elements::ListItem
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
it "should know how many list items it contains" do
|
63
63
|
ol = PageObject::Elements::OrderedList.new(ol_element, :platform => :selenium)
|
64
64
|
ol_element.should_receive(:find_elements).with(:xpath, ".//child::li").and_return(ol_element)
|
65
65
|
ol_element.should_receive(:size).and_return(5)
|
66
66
|
ol.items.should == 5
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
it "should iterate over the list items" do
|
70
70
|
ol = PageObject::Elements::OrderedList.new(ol_element, :platform => :selenium)
|
71
71
|
ol.should_receive(:items).and_return(5)
|
@@ -3,7 +3,7 @@ require 'page-object/elements'
|
|
3
3
|
|
4
4
|
describe PageObject::Elements::RadioButton do
|
5
5
|
let(:radiobutton) { PageObject::Elements::RadioButton }
|
6
|
-
|
6
|
+
|
7
7
|
describe "when mapping how to find an element" do
|
8
8
|
it "should map watir types to same" do
|
9
9
|
[:class, :id, :index, :name, :xpath].each do |t|
|
@@ -3,7 +3,7 @@ require 'page-object/elements'
|
|
3
3
|
|
4
4
|
describe PageObject::Elements::SelectList do
|
5
5
|
let(:selectlist) { PageObject::Elements::SelectList }
|
6
|
-
|
6
|
+
|
7
7
|
describe "when mapping how to find an element" do
|
8
8
|
it "should map watir types to same" do
|
9
9
|
[:class, :id, :index, :name, :text, :value, :xpath].each do |t|
|
@@ -28,7 +28,7 @@ describe PageObject::Elements::SelectList do
|
|
28
28
|
sel_list.stub(:find_elements).and_return(sel_list)
|
29
29
|
sel_list.stub(:each)
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
context "for watir" do
|
33
33
|
it "should return an option when indexed" do
|
34
34
|
watir_sel_list = PageObject::Elements::SelectList.new(sel_list, :platform => :watir)
|
@@ -13,7 +13,7 @@ describe PageObject::Elements::TableRow do
|
|
13
13
|
table_cell.should_receive(:[]).and_return(table_cell)
|
14
14
|
table_row[0].should be_instance_of PageObject::Elements::TableCell
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
it "should retrun the number of columns" do
|
18
18
|
table_row = PageObject::Elements::TableRow.new(table_row_driver, :platform => :selenium)
|
19
19
|
table_row_driver.should_receive(:find_elements).with(:xpath, ".//child::td|th").and_return(table_row_driver)
|
@@ -28,16 +28,16 @@ describe PageObject::Elements::TableRow do
|
|
28
28
|
count = 0
|
29
29
|
table_row.each { |e| count += 1 }
|
30
30
|
count.should == 2
|
31
|
-
end
|
31
|
+
end
|
32
32
|
end
|
33
33
|
|
34
34
|
context "for watir" do
|
35
35
|
before(:each) do
|
36
36
|
table_row_driver.stub(:find_elements).and_return(table_row_driver)
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
it "should return a table cell when indexed" do
|
40
|
-
table_row = PageObject::Elements::TableRow.new(table_row_driver, :platform => :watir)
|
40
|
+
table_row = PageObject::Elements::TableRow.new(table_row_driver, :platform => :watir)
|
41
41
|
table_row_driver.should_receive(:[]).with(1).and_return(table_cell)
|
42
42
|
table_row[1].should be_instance_of PageObject::Elements::TableCell
|
43
43
|
end
|
@@ -57,7 +57,7 @@ describe PageObject::Elements::TableRow do
|
|
57
57
|
count = 0
|
58
58
|
table_row.each { |e| count += 1 }
|
59
59
|
count.should == 2
|
60
|
-
end
|
61
|
-
end
|
60
|
+
end
|
61
|
+
end
|
62
62
|
end
|
63
63
|
end
|
@@ -17,22 +17,22 @@ describe PageObject::Elements::Table do
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
describe "interface" do
|
22
22
|
let(:table_element) { double('table_element') }
|
23
|
-
|
23
|
+
|
24
24
|
before(:each) do
|
25
25
|
table_element.stub(:[]).and_return(table_element)
|
26
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
31
|
watir_table = PageObject::Elements::Table.new(table_element, :platform => :watir)
|
32
32
|
table_element.stub(:[]).with(1).and_return(table_element)
|
33
33
|
watir_table[1].should be_instance_of PageObject::Elements::TableRow
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
it "should return the number of rows" do
|
37
37
|
watir_table = PageObject::Elements::Table.new(table_element, :platform => :watir)
|
38
38
|
table_element.stub(:wd).and_return(table_element)
|
@@ -47,8 +47,8 @@ describe PageObject::Elements::Table do
|
|
47
47
|
count = 0
|
48
48
|
watir_table.each { |e| count += 1 }
|
49
49
|
count.should == 2
|
50
|
-
end
|
51
|
-
end
|
50
|
+
end
|
51
|
+
end
|
52
52
|
|
53
53
|
context "for selenium" do
|
54
54
|
it "should return a table row when indexed" do
|
@@ -56,14 +56,14 @@ describe PageObject::Elements::Table do
|
|
56
56
|
table_element.should_receive(:find_elements).with(:xpath, ".//child::tr").and_return(table_element)
|
57
57
|
selenium_table[1].should be_instance_of PageObject::Elements::TableRow
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
it "should return the number of rows" do
|
61
61
|
selenium_table = PageObject::Elements::Table.new(table_element, :platform => :selenium)
|
62
62
|
table_element.should_receive(:find_elements).with(:xpath, ".//child::tr").and_return(table_element)
|
63
63
|
table_element.should_receive(:size).and_return(2)
|
64
64
|
selenium_table.rows.should == 2
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
it "should iterate over the table rows" do
|
68
68
|
selenium_table = PageObject::Elements::Table.new(table_element, :platform => :selenium)
|
69
69
|
selenium_table.should_receive(:rows).and_return(2)
|
@@ -71,6 +71,6 @@ describe PageObject::Elements::Table do
|
|
71
71
|
selenium_table.each { |e| count += 1 }
|
72
72
|
count.should == 2
|
73
73
|
end
|
74
|
-
end
|
74
|
+
end
|
75
75
|
end
|
76
76
|
end
|
@@ -3,7 +3,7 @@ require 'page-object/elements'
|
|
3
3
|
|
4
4
|
describe PageObject::Elements::TextArea do
|
5
5
|
let(:textarea) { PageObject::Elements::TextArea }
|
6
|
-
|
6
|
+
|
7
7
|
describe "when mapping how to find an element" do
|
8
8
|
it "should map watir types to same" do
|
9
9
|
[:class, :id, :index, :name, :tag_name, :xpath].each do |t|
|
@@ -16,14 +16,14 @@ describe PageObject::Elements::TextArea do
|
|
16
16
|
identifier = textarea.watir_identifier_for :css => 'value'
|
17
17
|
identifier.keys.first.should == :tag_name
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
it "should map selenium types to same" do
|
21
21
|
[:class, :css, :id, :name, :xpath, :index].each do |t|
|
22
22
|
key, value = textarea.selenium_identifier_for t => 'value'
|
23
23
|
key.should == t
|
24
24
|
end
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
it "should map watir types to selenium" do
|
28
28
|
key, value = textarea.selenium_identifier_for :tag_name => 'value'
|
29
29
|
key.should == :css
|
@@ -3,7 +3,7 @@ require 'page-object/elements'
|
|
3
3
|
|
4
4
|
describe PageObject::Elements::TextField do
|
5
5
|
let(:textfield) { PageObject::Elements::TextField }
|
6
|
-
|
6
|
+
|
7
7
|
describe "when mapping how to find an element" do
|
8
8
|
it "should map watir types to same" do
|
9
9
|
[:class, :id, :index, :name, :tag_name, :xpath].each do |t|
|
@@ -16,14 +16,14 @@ describe PageObject::Elements::TextField do
|
|
16
16
|
identifier = textfield.watir_identifier_for :css => 'value'
|
17
17
|
identifier.keys.first.should == :tag_name
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
it "should map selenium types to same" do
|
21
21
|
[:class, :css, :id, :name, :xpath, :index].each do |t|
|
22
22
|
key, value = textfield.selenium_identifier_for t => 'value'
|
23
23
|
key.should == t
|
24
24
|
end
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
it "should map watir types to selenium" do
|
28
28
|
key, value = textfield.selenium_identifier_for :tag_name => 'value'
|
29
29
|
key.should == :css
|
@@ -3,7 +3,7 @@ require 'page-object/elements'
|
|
3
3
|
|
4
4
|
describe PageObject::Elements::UnorderedList do
|
5
5
|
let(:ul) { PageObject::Elements::UnorderedList }
|
6
|
-
|
6
|
+
|
7
7
|
describe "when mapping how to find an element" do
|
8
8
|
it "should map watir types to same" do
|
9
9
|
[:class, :id, :index, :xpath].each do |t|
|
@@ -19,10 +19,10 @@ describe PageObject::Elements::UnorderedList do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
describe "interface" do
|
24
24
|
let(:ul_element) { double('ul_element') }
|
25
|
-
|
25
|
+
|
26
26
|
context "for watir" do
|
27
27
|
it "should return a list item when indexed" do
|
28
28
|
ul = PageObject::Elements::UnorderedList.new(ul_element, :platform => :watir)
|
@@ -31,7 +31,7 @@ describe PageObject::Elements::UnorderedList do
|
|
31
31
|
ul_element.stub(:[])
|
32
32
|
ul[1].should be_instance_of PageObject::Elements::ListItem
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
it "should know how many items it contains" do
|
36
36
|
ul = PageObject::Elements::UnorderedList.new(ul_element, :platform => :watir)
|
37
37
|
ul_element.stub(:wd).and_return(ul_element)
|
@@ -39,7 +39,7 @@ describe PageObject::Elements::UnorderedList do
|
|
39
39
|
ul_element.stub(:size).and_return(5)
|
40
40
|
ul.items.should == 5
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
it "should know how to iterate over the items" do
|
44
44
|
ul = PageObject::Elements::UnorderedList.new(ul_element, :platform => :watir)
|
45
45
|
ul.should_receive(:items).and_return(5)
|
@@ -48,8 +48,8 @@ describe PageObject::Elements::UnorderedList do
|
|
48
48
|
ul.each { |item| count += 1 }
|
49
49
|
count.should == 5
|
50
50
|
end
|
51
|
-
end
|
52
|
-
|
51
|
+
end
|
52
|
+
|
53
53
|
context "for selenium" do
|
54
54
|
it "should return a list item when indexed" do
|
55
55
|
ul = PageObject::Elements::UnorderedList.new(ul_element, :platform => :selenium)
|
@@ -57,14 +57,14 @@ describe PageObject::Elements::UnorderedList do
|
|
57
57
|
ul_element.stub(:[])
|
58
58
|
ul[1].should be_instance_of PageObject::Elements::ListItem
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
it "should know how many items it contains" do
|
62
62
|
ul = PageObject::Elements::UnorderedList.new(ul_element, :platform => :selenium)
|
63
63
|
ul_element.should_receive(:find_elements).and_return(ul_element)
|
64
64
|
ul_element.should_receive(:size).and_return(5)
|
65
65
|
ul.items.should == 5
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
it "should know how to iterate over the items" do
|
69
69
|
ul = PageObject::Elements::UnorderedList.new(ul_element, :platform => :selenium)
|
70
70
|
ul.should_receive(:items).and_return(5)
|
@@ -72,7 +72,7 @@ describe PageObject::Elements::UnorderedList do
|
|
72
72
|
count = 0
|
73
73
|
ul.each { |item| count += 1 }
|
74
74
|
count.should == 5
|
75
|
-
|
75
|
+
|
76
76
|
end
|
77
77
|
end
|
78
78
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
class TestLoadsPlatform
|
3
|
+
include PageObject::LoadsPlatform
|
4
|
+
end
|
5
|
+
describe TestLoadsPlatform do
|
6
|
+
let(:subject) { TestLoadsPlatform.new }
|
7
|
+
let(:adapters) { {} }
|
8
|
+
context "when browser x is registered with platform nom_nom_nom" do
|
9
|
+
let(:browser_x) { double('browser') }
|
10
|
+
before { adapters[:browser_x] = mock_adapter(browser_x, :nom_nom_nom) }
|
11
|
+
|
12
|
+
it "returns platform nom_nom_nom when asked about browser_x" do
|
13
|
+
subject.load_platform(browser_x, adapters).should == :nom_nom_nom
|
14
|
+
end
|
15
|
+
context "when browser a is registered with platform boom_boom_boom" do
|
16
|
+
let(:browser_a) { double('browser') }
|
17
|
+
before { adapters[:browser_a] = mock_adapter(browser_a, :boom_boom_boom) }
|
18
|
+
it "should return platform nom_nom_nom when asked about browser_x" do
|
19
|
+
subject.load_platform(browser_x, adapters).should == :nom_nom_nom
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
context "when browser a is registered with platform boom_boom_boom" do
|
24
|
+
let(:browser_n) { double('browser') }
|
25
|
+
before { adapters[:browser_n] = mock_adapter(browser_n, :boom_boom_boom) }
|
26
|
+
it "should return platform boom_boom_boom" do
|
27
|
+
subject.load_platform(browser_n, adapters).should == :boom_boom_boom
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "When an unknow object is passed in" do
|
32
|
+
it "should throw an exception" do
|
33
|
+
expect {
|
34
|
+
subject.load_platform("browser")
|
35
|
+
}.to raise_error
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -4,12 +4,13 @@ class PageObjectTestPageObject
|
|
4
4
|
include PageObject
|
5
5
|
end
|
6
6
|
|
7
|
+
class CustomPlatform
|
8
|
+
end
|
7
9
|
describe PageObject do
|
8
10
|
let(:watir_browser) { mock_watir_browser }
|
9
11
|
let(:selenium_browser) { mock_selenium_browser }
|
10
12
|
let(:watir_page_object) { PageObjectTestPageObject.new(watir_browser) }
|
11
13
|
let(:selenium_page_object) { PageObjectTestPageObject.new(selenium_browser) }
|
12
|
-
|
13
14
|
context "when created with a watir-webdriver browser" do
|
14
15
|
it "should include the WatirPageObject module" do
|
15
16
|
watir_page_object.platform.should be_kind_of PageObject::WatirPageObject
|
@@ -18,10 +19,17 @@ describe PageObject do
|
|
18
19
|
|
19
20
|
context "when created with a selenium browser" do
|
20
21
|
it "should include the SeleniumPageObject module" do
|
21
|
-
selenium_page_object.platform.should be_kind_of PageObject::
|
22
|
+
selenium_page_object.platform.should be_kind_of Object::PageObject::Platforms::Selenium::PageObject
|
23
|
+
end
|
24
|
+
end
|
25
|
+
context "when created with a non_bundled adapter" do
|
26
|
+
let(:custom_adapter) { mock_adapter(:custom_browser, CustomPlatform) }
|
27
|
+
it "should be an instance of whatever that objects adapter is" do
|
28
|
+
mock_adapters({:custom_adapter=>custom_adapter})
|
29
|
+
custom_page_object = PageObjectTestPageObject.new(:custom_browser)
|
30
|
+
custom_page_object.platform.should be custom_adapter.create_page_object
|
22
31
|
end
|
23
32
|
end
|
24
|
-
|
25
33
|
context "when created with an object we do not understand" do
|
26
34
|
it "should throw an error" do
|
27
35
|
expect {
|
@@ -51,29 +59,53 @@ describe PageObject do
|
|
51
59
|
watir_browser.should_receive(:goto).with("cheezyworld.com")
|
52
60
|
watir_page_object.navigate_to("cheezyworld.com")
|
53
61
|
end
|
54
|
-
|
62
|
+
|
55
63
|
it "should wait until a block returns true" do
|
56
64
|
watir_browser.should_receive(:wait_until).with(5, "too long")
|
57
65
|
watir_page_object.wait_until(5, "too long")
|
58
66
|
end
|
59
|
-
|
67
|
+
|
60
68
|
it "should override alert popup behavior" do
|
61
69
|
watir_browser.should_receive(:alert)
|
62
70
|
watir_page_object.alert do
|
63
71
|
end
|
64
72
|
end
|
65
|
-
|
73
|
+
|
66
74
|
it "should override confirm popup behavior" do
|
67
75
|
watir_browser.should_receive(:confirm)
|
68
76
|
watir_page_object.confirm(true) do
|
69
77
|
end
|
70
78
|
end
|
71
|
-
|
79
|
+
|
72
80
|
it "should override prompt popup behavior" do
|
73
81
|
watir_browser.should_receive(:prompt)
|
74
82
|
watir_page_object.prompt("blah") do
|
75
83
|
end
|
76
84
|
end
|
85
|
+
|
86
|
+
it "should switch to a new window with a given title" do
|
87
|
+
watir_browser.should_receive(:window).with(:title => /My\ Title/).and_return(watir_browser)
|
88
|
+
watir_browser.should_receive(:use)
|
89
|
+
watir_page_object.attach_to_window(:title => "My Title")
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should switch to a new window with a given url" do
|
93
|
+
watir_browser.should_receive(:window).with(:url => /success\.html/).and_return(watir_browser)
|
94
|
+
watir_browser.should_receive(:use)
|
95
|
+
watir_page_object.attach_to_window(:url => "success.html")
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should switch to a new frame by index" do
|
99
|
+
watir_browser.should_receive(:wd).and_return(watir_browser)
|
100
|
+
watir_browser.should_receive(:switch_to).and_return(watir_browser)
|
101
|
+
watir_browser.should_receive(:frame).with(0)
|
102
|
+
watir_page_object.switch_to_frame(0)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should refresh the page contents" do
|
106
|
+
watir_browser.should_receive(:refresh)
|
107
|
+
watir_page_object.refresh
|
108
|
+
end
|
77
109
|
end
|
78
110
|
|
79
111
|
context "when using SeleniumPageObject" do
|
@@ -91,12 +123,12 @@ describe PageObject do
|
|
91
123
|
selenium_browser.should_receive(:title).and_return("I am the title of a page")
|
92
124
|
selenium_page_object.title.should == "I am the title of a page"
|
93
125
|
end
|
94
|
-
|
126
|
+
|
95
127
|
it "should be able to navigate to a page" do
|
96
128
|
selenium_browser.stub_chain(:navigate, :to).with('cheezyworld.com')
|
97
129
|
selenium_page_object.navigate_to('cheezyworld.com')
|
98
130
|
end
|
99
|
-
|
131
|
+
|
100
132
|
it "should wait until a block returns true" do
|
101
133
|
wait = double('wait')
|
102
134
|
Selenium::WebDriver::Wait.should_receive(:new).with({:timeout => 5, :message => 'too long'}).and_return(wait)
|
@@ -109,7 +141,7 @@ describe PageObject do
|
|
109
141
|
selenium_page_object.alert do
|
110
142
|
end
|
111
143
|
end
|
112
|
-
|
144
|
+
|
113
145
|
it "should override confirm popup behavior" do
|
114
146
|
selenium_browser.should_receive(:execute_script).twice
|
115
147
|
selenium_page_object.confirm(true) do
|
@@ -120,6 +152,34 @@ describe PageObject do
|
|
120
152
|
selenium_page_object.prompt("blah") do
|
121
153
|
end
|
122
154
|
end
|
155
|
+
|
156
|
+
it "should switch to a new window with a given title" do
|
157
|
+
selenium_browser.should_receive(:window_handles).and_return(["win1"])
|
158
|
+
selenium_browser.should_receive(:switch_to).and_return(selenium_browser)
|
159
|
+
selenium_browser.should_receive(:window).with("win1").and_return(selenium_browser)
|
160
|
+
selenium_browser.should_receive(:title).and_return("My Title")
|
161
|
+
selenium_page_object.attach_to_window(:title => "My Title")
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should switch to a new window with a given url" do
|
165
|
+
selenium_browser.should_receive(:window_handles).and_return(["win1"])
|
166
|
+
selenium_browser.should_receive(:switch_to).and_return(selenium_browser)
|
167
|
+
selenium_browser.should_receive(:window).with("win1").and_return(selenium_browser)
|
168
|
+
selenium_browser.should_receive(:current_url).and_return("page.html")
|
169
|
+
selenium_page_object.attach_to_window(:url => "page.html")
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should switch to a new frame by index" do
|
173
|
+
selenium_browser.should_receive(:switch_to).and_return(selenium_browser)
|
174
|
+
selenium_browser.should_receive(:frame).with(0)
|
175
|
+
selenium_page_object.switch_to_frame(0)
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should refresh the page contents" do
|
179
|
+
selenium_browser.should_receive(:navigate).and_return(selenium_browser)
|
180
|
+
selenium_browser.should_receive(:refresh)
|
181
|
+
selenium_page_object.refresh
|
182
|
+
end
|
123
183
|
end
|
124
184
|
end
|
125
185
|
end
|