druid-s 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/.rspec +1 -0
- data/.rvmrc +1 -0
- data/.travis.yml +27 -0
- data/ChangeLog +541 -0
- data/Gemfile +8 -0
- data/README.md +78 -0
- data/Rakefile +33 -0
- data/cucumber.yml +6 -0
- data/druid.gemspec +30 -0
- data/features/area.feature +33 -0
- data/features/async.feature +16 -0
- data/features/audio.feature +61 -0
- data/features/bold.feature +20 -0
- data/features/button.feature +81 -0
- data/features/canvas.feature +34 -0
- data/features/checkbox.feature +48 -0
- data/features/div.feature +45 -0
- data/features/element.feature +281 -0
- data/features/file_field.feature +38 -0
- data/features/form.feature +37 -0
- data/features/frames.feature +76 -0
- data/features/generic_elements.feature +29 -0
- data/features/heading.feature +160 -0
- data/features/hidden_field.feature +39 -0
- data/features/html/async.html +31 -0
- data/features/html/frame_1.html +18 -0
- data/features/html/frame_2.html +16 -0
- data/features/html/frame_3.html +14 -0
- data/features/html/frames.html +12 -0
- data/features/html/hover.html +11 -0
- data/features/html/iframes.html +12 -0
- data/features/html/images/circle.png +0 -0
- data/features/html/images/img_pulpit.jpg +0 -0
- data/features/html/modal.html +17 -0
- data/features/html/modal_1.html +38 -0
- data/features/html/modal_2.html +27 -0
- data/features/html/multi_elements.html +145 -0
- data/features/html/nested_elements.html +75 -0
- data/features/html/nested_frame_1.html +1 -0
- data/features/html/nested_frame_2.html +11 -0
- data/features/html/nested_frame_3.html +14 -0
- data/features/html/nested_frames.html +10 -0
- data/features/html/planets.gif +0 -0
- data/features/html/static_elements.html +203 -0
- data/features/html/success.html +8 -0
- data/features/html/sun.gif +0 -0
- data/features/html/sun.html +7 -0
- data/features/image.feature +47 -0
- data/features/italic.feature +20 -0
- data/features/javascript.feature +28 -0
- data/features/label.feature +43 -0
- data/features/link.feature +56 -0
- data/features/list_item.feature +37 -0
- data/features/modal_dialog.feature +9 -0
- data/features/multi_elements.feature +498 -0
- data/features/nested_elements.feature +121 -0
- data/features/ordered_list.feature +46 -0
- data/features/page_level_actions.feature +116 -0
- data/features/paragraph.feature +33 -0
- data/features/populate_page_with.feature +25 -0
- data/features/radio_button.feature +51 -0
- data/features/radio_button_group.feature +28 -0
- data/features/sample-app/public/04-Death_Becomes_Fur.mp4 +0 -0
- data/features/sample-app/public/04-Death_Becomes_Fur.oga +0 -0
- data/features/sample-app/public/audio_video.html +19 -0
- data/features/sample-app/public/jquery-1.3.2.js +4376 -0
- data/features/sample-app/public/jquery.html +28 -0
- data/features/sample-app/public/movie.mp4 +0 -0
- data/features/sample-app/public/movie.ogg +0 -0
- data/features/sample-app/public/prototype-1.6.0.3.js +4320 -0
- data/features/sample-app/public/prototype.html +32 -0
- data/features/sample-app/sample_app.rb +35 -0
- data/features/section.feature +132 -0
- data/features/select_list.feature +84 -0
- data/features/span.feature +43 -0
- data/features/step_definations/area_steps.rb +23 -0
- data/features/step_definations/async_steps.rb +80 -0
- data/features/step_definations/audio_steps.rb +47 -0
- data/features/step_definations/bold_steps.rb +11 -0
- data/features/step_definations/button_steps.rb +52 -0
- data/features/step_definations/canvas_steps.rb +19 -0
- data/features/step_definations/checkbox_steps.rb +39 -0
- data/features/step_definations/div_steps.rb +28 -0
- data/features/step_definations/element_steps.rb +217 -0
- data/features/step_definations/file_field_steps.rb +31 -0
- data/features/step_definations/form_steps.rb +23 -0
- data/features/step_definations/frame_steps.rb +189 -0
- data/features/step_definations/generic_element_steps.rb +31 -0
- data/features/step_definations/heading_steps.rb +39 -0
- data/features/step_definations/hidden_field_steps.rb +27 -0
- data/features/step_definations/image_steps.rb +35 -0
- data/features/step_definations/italic_steps.rb +11 -0
- data/features/step_definations/javasript_steps.rb +52 -0
- data/features/step_definations/label_steps.rb +19 -0
- data/features/step_definations/link_steps.rb +42 -0
- data/features/step_definations/list_item_steps.rb +24 -0
- data/features/step_definations/modal_dialog_steps.rb +38 -0
- data/features/step_definations/multi_elements_steps.rb +557 -0
- data/features/step_definations/nested_elements_steps.rb +219 -0
- data/features/step_definations/ordered_list_steps.rb +49 -0
- data/features/step_definations/page_level_actions_steps.rb +172 -0
- data/features/step_definations/page_traversal_steps.rb +4 -0
- data/features/step_definations/paragraph_steps.rb +19 -0
- data/features/step_definations/populate_page_with_steps.rb +3 -0
- data/features/step_definations/radio_button_group_steps.rb +32 -0
- data/features/step_definations/radio_button_steps.rb +31 -0
- data/features/step_definations/section_steps.rb +271 -0
- data/features/step_definations/select_list_steps.rb +91 -0
- data/features/step_definations/span_steps.rb +23 -0
- data/features/step_definations/table_cell_steps.rb +27 -0
- data/features/step_definations/table_row_steps.rb +23 -0
- data/features/step_definations/table_steps.rb +109 -0
- data/features/step_definations/text_area_steps.rb +39 -0
- data/features/step_definations/text_field_steps.rb +39 -0
- data/features/step_definations/unordered_list_steps.rb +27 -0
- data/features/step_definations/video_steps.rb +27 -0
- data/features/support/ajax_test_environment.rb +26 -0
- data/features/support/audio_video_page.rb +23 -0
- data/features/support/env.rb +5 -0
- data/features/support/hooks.rb +3 -0
- data/features/support/page.rb +372 -0
- data/features/support/persistent_browser.rb +58 -0
- data/features/support/targets/firefox14_osx.rb +5 -0
- data/features/support/targets/firefox14_windows7.rb +5 -0
- data/features/support/url_helper.rb +50 -0
- data/features/table.feature +127 -0
- data/features/table_cell.feature +42 -0
- data/features/table_row.feature +30 -0
- data/features/text_area.feature +44 -0
- data/features/text_field.feature +53 -0
- data/features/unordered_list.feature +46 -0
- data/features/video.feature +66 -0
- data/lib/druid/accessors.rb +1082 -0
- data/lib/druid/assist.rb +653 -0
- data/lib/druid/element_locators.rb +21 -0
- data/lib/druid/elements/area.rb +9 -0
- data/lib/druid/elements/audio.rb +9 -0
- data/lib/druid/elements/bold.rb +8 -0
- data/lib/druid/elements/button.rb +12 -0
- data/lib/druid/elements/canvas.rb +9 -0
- data/lib/druid/elements/check_box.rb +9 -0
- data/lib/druid/elements/div.rb +9 -0
- data/lib/druid/elements/element.rb +187 -0
- data/lib/druid/elements/file_field.rb +9 -0
- data/lib/druid/elements/form.rb +9 -0
- data/lib/druid/elements/heading.rb +14 -0
- data/lib/druid/elements/hidden_field.rb +9 -0
- data/lib/druid/elements/image.rb +9 -0
- data/lib/druid/elements/italic.rb +9 -0
- data/lib/druid/elements/label.rb +8 -0
- data/lib/druid/elements/link.rb +9 -0
- data/lib/druid/elements/list_item.rb +9 -0
- data/lib/druid/elements/media.rb +11 -0
- data/lib/druid/elements/option.rb +9 -0
- data/lib/druid/elements/ordered_list.rb +29 -0
- data/lib/druid/elements/paragraph.rb +9 -0
- data/lib/druid/elements/radio_button.rb +9 -0
- data/lib/druid/elements/select_list.rb +30 -0
- data/lib/druid/elements/span.rb +9 -0
- data/lib/druid/elements/table.rb +92 -0
- data/lib/druid/elements/table_cell.rb +11 -0
- data/lib/druid/elements/table_row.rb +50 -0
- data/lib/druid/elements/text_area.rb +10 -0
- data/lib/druid/elements/text_field.rb +11 -0
- data/lib/druid/elements/unordered_list.rb +32 -0
- data/lib/druid/elements/video.rb +8 -0
- data/lib/druid/elements.rb +55 -0
- data/lib/druid/javascript/angularjs.rb +12 -0
- data/lib/druid/javascript/jquery.rb +12 -0
- data/lib/druid/javascript/prototype.rb +12 -0
- data/lib/druid/javascript/yui.rb +19 -0
- data/lib/druid/javascript_framework_facade.rb +76 -0
- data/lib/druid/locator_generator.rb +181 -0
- data/lib/druid/nested_elements.rb +56 -0
- data/lib/druid/page_factory.rb +115 -0
- data/lib/druid/page_populator.rb +104 -0
- data/lib/druid/section_collection.rb +17 -0
- data/lib/druid/version.rb +3 -0
- data/lib/druid.rb +452 -0
- data/spec/druid/accessors_spec.rb +1209 -0
- data/spec/druid/druid_spec.rb +295 -0
- data/spec/druid/element_locators_spec.rb +750 -0
- data/spec/druid/elements/bold_spec.rb +12 -0
- data/spec/druid/elements/button_spec.rb +23 -0
- data/spec/druid/elements/check_box_spec.rb +14 -0
- data/spec/druid/elements/div_spec.rb +10 -0
- data/spec/druid/elements/element_spec.rb +250 -0
- data/spec/druid/elements/file_field_spec.rb +13 -0
- data/spec/druid/elements/form_spec.rb +18 -0
- data/spec/druid/elements/heading_spec.rb +30 -0
- data/spec/druid/elements/hidden_field_spec.rb +10 -0
- data/spec/druid/elements/image_spec.rb +23 -0
- data/spec/druid/elements/itatic_spec.rb +11 -0
- data/spec/druid/elements/label_spec.rb +10 -0
- data/spec/druid/elements/link_spec.rb +10 -0
- data/spec/druid/elements/list_item_spec.rb +10 -0
- data/spec/druid/elements/media_spec.rb +12 -0
- data/spec/druid/elements/option_spec.rb +21 -0
- data/spec/druid/elements/ordered_list_spec.rb +38 -0
- data/spec/druid/elements/page_factory_spec.rb +40 -0
- data/spec/druid/elements/paragraph_spec.rb +12 -0
- data/spec/druid/elements/radio_button_spec.rb +14 -0
- data/spec/druid/elements/select_list_spec.rb +51 -0
- data/spec/druid/elements/span_spec.rb +10 -0
- data/spec/druid/elements/table_cell_spec.rb +14 -0
- data/spec/druid/elements/table_row_spec.rb +34 -0
- data/spec/druid/elements/table_spec.rb +47 -0
- data/spec/druid/elements/text_area_spec.rb +13 -0
- data/spec/druid/elements/text_field_spec.rb +22 -0
- data/spec/druid/elements/unordered_list_spec.rb +39 -0
- data/spec/druid/javascript_framework_facade_spec.rb +59 -0
- data/spec/druid/nested_element_spec.rb +128 -0
- data/spec/druid/page_factory_spec.rb +235 -0
- data/spec/druid/page_populator_spec.rb +173 -0
- data/spec/druid/page_section_spec.rb +70 -0
- data/spec/spec_helper.rb +9 -0
- metadata +517 -0
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'druid/elements'
|
3
|
+
|
4
|
+
describe Druid::Elements::TableCell do
|
5
|
+
describe "interface" do
|
6
|
+
it "should register with tag_name :td" do
|
7
|
+
expect(Druid::Elements.element_class_for(:td)).to be Druid::Elements::TableCell
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should register with tag_name :th" do
|
11
|
+
expect(Druid::Elements.element_class_for(:th)).to be Druid::Elements::TableCell
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'druid/elements'
|
3
|
+
|
4
|
+
describe Druid::Elements::TableRow do
|
5
|
+
let(:table_cell) { double('table_cell') }
|
6
|
+
let(:element) { double 'element' }
|
7
|
+
let(:table_row) { Druid::Elements::TableRow.new(element) }
|
8
|
+
|
9
|
+
describe "interface" do
|
10
|
+
|
11
|
+
before(:each) do
|
12
|
+
allow(element).to receive(:find_elements).and_return(element)
|
13
|
+
allow(element).to receive(:cells).and_return(Array.new(2, Watir::TableCell))
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should return a table cell when indexed" do
|
17
|
+
expect(table_row[1]).to be_instance_of Druid::Elements::TableCell
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should return the number of columns" do
|
21
|
+
expect(table_row.columns).to eql 2
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should iterate over the table columns" do
|
25
|
+
count = 0
|
26
|
+
table_row.each{ count += 1}
|
27
|
+
expect(count).to eql 2
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should register with tag_name :tr" do
|
31
|
+
expect(Druid::Elements.element_class_for(:tr)).to be Druid::Elements::TableRow
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'druid/elements'
|
3
|
+
|
4
|
+
describe Druid::Elements::Table do
|
5
|
+
describe "interface" do
|
6
|
+
let(:element) { double('element')}
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
allow(element).to receive(:rows).and_return(Array.new(2, Watir::TableRow))
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should register with tag_name :table" do
|
13
|
+
expect(Druid::Elements.element_class_for(:table)).to eql Druid::Elements::Table
|
14
|
+
end
|
15
|
+
|
16
|
+
context "for sub methods" do
|
17
|
+
|
18
|
+
let(:table) { Druid::Elements::Table.new(element) }
|
19
|
+
|
20
|
+
it "should return a table row" do
|
21
|
+
expect(table[1]).to be_instance_of Druid::Elements::TableRow
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should return the number of rows" do
|
25
|
+
expect(table.rows).to eql 2
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should iterate over the table rows" do
|
29
|
+
count = 0
|
30
|
+
table.each do
|
31
|
+
count += 1
|
32
|
+
end
|
33
|
+
expect(count).to eql 2
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return the first row" do
|
37
|
+
expect(table.first_row).to be_instance_of Druid::Elements::TableRow
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should return the last row" do
|
41
|
+
expect(table.last_row).to be_instance_of Druid::Elements::TableRow
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'druid/elements'
|
3
|
+
|
4
|
+
describe Druid::Elements::TextArea do
|
5
|
+
describe "interface" do
|
6
|
+
let(:element) { double "element" }
|
7
|
+
let(:text_area) { Druid::Elements::TextArea.new(element) }
|
8
|
+
|
9
|
+
it "should register with tag_name :textarea" do
|
10
|
+
expect(Druid::Elements.element_class_for(:textarea)).to be Druid::Elements::TextArea
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'druid/elements'
|
3
|
+
|
4
|
+
describe Druid::Elements::TextField do
|
5
|
+
describe "interface" do
|
6
|
+
let(:element) { double 'element' }
|
7
|
+
let(:text_field) { Druid::Elements::TextField.new(element) }
|
8
|
+
|
9
|
+
it "should register with type :text" do
|
10
|
+
expect(Druid::Elements.element_class_for(:input, :text)).to be Druid::Elements::TextField
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should register with type :password" do
|
14
|
+
expect(Druid::Elements.element_class_for(:input, :password)).to be Druid::Elements::TextField
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should append text" do
|
18
|
+
expect(element).to receive(:append).with('abc')
|
19
|
+
text_field.append('abc')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'druid/elements'
|
3
|
+
|
4
|
+
describe Druid::Elements::UnOrderedList do
|
5
|
+
let(:ul) { Druid::Elements::UnOrderedList.new(ul_element) }
|
6
|
+
|
7
|
+
describe "interface" do
|
8
|
+
let(:ul_element) { double('ul_element').as_null_object }
|
9
|
+
let(:li_element) { double('li_element').as_null_object }
|
10
|
+
|
11
|
+
it "should register with tag_name :ul" do
|
12
|
+
expect(Druid::Elements.element_class_for(:ul)).to be Druid::Elements::UnOrderedList
|
13
|
+
end
|
14
|
+
|
15
|
+
context "for sub method" do
|
16
|
+
before(:each) do
|
17
|
+
allow(ul_element).to receive(:children).and_return([li_element, li_element])
|
18
|
+
allow(li_element).to receive(:tag_name).and_return(:li)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should return a list item when indexed" do
|
22
|
+
expect(ul[1]).to be_instance_of Druid::Elements::ListItem
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should know how many items it contains" do
|
26
|
+
expect(ul.items).to eql 2
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should know how to iterate over the items" do
|
30
|
+
count = 0
|
31
|
+
ul.each { count += 1 }
|
32
|
+
expect(count).to eql 2
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'druid/javascript/jquery'
|
3
|
+
|
4
|
+
class TestClass
|
5
|
+
include Druid::JavascriptFrameworkFacade
|
6
|
+
end
|
7
|
+
|
8
|
+
describe Druid::JavascriptFrameworkFacade do
|
9
|
+
let(:facade) { Druid::JavascriptFrameworkFacade }
|
10
|
+
|
11
|
+
it "should allow the selection of a javascript framework" do
|
12
|
+
facade.framework = :jquery
|
13
|
+
expect(facade.framework).to eql :jquery
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should register the jQuery script builder" do
|
17
|
+
facade.framework = :jquery
|
18
|
+
expect(facade.script_builder).to eql Druid::Javascript::JQuery
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should return script for pending requests in jQuery" do
|
22
|
+
facade.framework = :jquery
|
23
|
+
expect(facade.pending_requests).to eql 'return jQuery.active'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should register the Prototype script builder" do
|
27
|
+
facade.framework = :prototype
|
28
|
+
expect(facade.script_builder).to eql Druid::Javascript::Prototype
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should return script for pending requests in Prototype" do
|
32
|
+
facade.framework = :prototype
|
33
|
+
expect(facade.pending_requests).to eql "return Ajax.activeRequestCount"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should not allow you to set the framework to one it does not know about" do
|
37
|
+
expect{ facade.framework = :blah }.to raise_error "You specified the Javascript framework blah and it is unknown to the system"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should allow you to add a new javascript framework" do
|
41
|
+
module GoodFake
|
42
|
+
def self.pending_requests
|
43
|
+
"fake"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
facade.add_framework(:blah, GoodFake)
|
48
|
+
facade.framework = :blah
|
49
|
+
expect(facade.pending_requests).to eql "fake"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should not allow you to add a new javascript framework that is invalid" do
|
53
|
+
module BadFake
|
54
|
+
def self.blah
|
55
|
+
end
|
56
|
+
end
|
57
|
+
expect{ facade.add_framework(:blah, BadFake) }.to raise_error "The Javascript framework you provided does not implement the necessary methods"
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'druid/elements'
|
3
|
+
|
4
|
+
describe "Element with nested elements" do
|
5
|
+
let(:we) { double 'we'}
|
6
|
+
let(:element) { Druid::Elements::Element.new(we) }
|
7
|
+
let(:driver) { driver = element}
|
8
|
+
|
9
|
+
it "should find nested links" do
|
10
|
+
expect(we).to receive(:link).with(:id => 'blah').and_return(we)
|
11
|
+
element.link_element(:id => 'blah')
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should find nested buttons" do
|
15
|
+
expect(we).to receive(:button).with(:id => 'blah').and_return(we)
|
16
|
+
element.button_element(:id => 'blah')
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should find nested text fields" do
|
20
|
+
expect(we).to receive(:text_field).with(:id => 'blah').and_return(we)
|
21
|
+
element.text_field_element(:id => 'blah')
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should find nested hidden fields" do
|
25
|
+
expect(we).to receive(:hidden).and_return(we)
|
26
|
+
element.hidden_field_element
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should find nested text areas" do
|
30
|
+
expect(we).to receive(:textarea).and_return(we)
|
31
|
+
element.text_area_element
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should find nested select list" do
|
35
|
+
expect(we).to receive(:select_list).and_return(we)
|
36
|
+
element.select_list_element
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should find a nested checkbox" do
|
40
|
+
expect(we).to receive(:checkbox).and_return(we)
|
41
|
+
element.checkbox_element
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should find a nested radio button" do
|
45
|
+
expect(we).to receive(:radio).and_return(we)
|
46
|
+
element.radio_button_element
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should find a nested div" do
|
50
|
+
expect(we).to receive(:div).and_return(we)
|
51
|
+
element.div_element
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should find a nested span" do
|
55
|
+
expect(we).to receive(:span).and_return(we)
|
56
|
+
element.span_element
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should find a nested table" do
|
60
|
+
expect(we).to receive(:table).and_return(we)
|
61
|
+
element.table_element
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should find a nested cell" do
|
65
|
+
expect(we).to receive(:td).and_return(we)
|
66
|
+
element.cell_element
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should find a nested image" do
|
70
|
+
expect(we).to receive(:image).and_return(we)
|
71
|
+
element.image_element
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should find a nested form" do
|
75
|
+
expect(we).to receive(:form).and_return(we)
|
76
|
+
element.form_element
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should find a nested ordered list" do
|
80
|
+
expect(we).to receive(:ol).and_return(we)
|
81
|
+
element.ordered_list_element
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should find a nested unordered list" do
|
85
|
+
expect(we).to receive(:ul).and_return(we)
|
86
|
+
element.unordered_list_element
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should find a nested list item" do
|
90
|
+
expect(we).to receive(:li).and_return(we)
|
91
|
+
element.list_item_element
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should find a nested h1" do
|
95
|
+
expect(we).to receive(:h1).and_return(we)
|
96
|
+
element.h1_element
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should find a nested h2" do
|
100
|
+
expect(we).to receive(:h2).and_return(we)
|
101
|
+
element.h2_element
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should find a nested h3" do
|
105
|
+
expect(we).to receive(:h3).and_return(we)
|
106
|
+
element.h3_element
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should find a nested h4" do
|
110
|
+
expect(we).to receive(:h4).and_return(we)
|
111
|
+
element.h4_element
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should find a nested h5" do
|
115
|
+
expect(we).to receive(:h5).and_return(we)
|
116
|
+
element.h5_element
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should find a nested h6" do
|
120
|
+
expect(we).to receive(:h6).and_return(we)
|
121
|
+
element.h6_element
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should find a nested paragraph" do
|
125
|
+
expect(we).to receive(:p).and_return(we)
|
126
|
+
element.paragraph_element
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,235 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'druid/page_factory'
|
3
|
+
|
4
|
+
class FactoryTestDruid
|
5
|
+
include Druid
|
6
|
+
page_url "http://google.com"
|
7
|
+
end
|
8
|
+
|
9
|
+
class TestPageWithDirectUrl
|
10
|
+
include Druid
|
11
|
+
direct_url "http://google.com"
|
12
|
+
end
|
13
|
+
|
14
|
+
class AnotherPage
|
15
|
+
include Druid
|
16
|
+
end
|
17
|
+
|
18
|
+
class YetAnotherPage
|
19
|
+
include Druid
|
20
|
+
end
|
21
|
+
|
22
|
+
module ContainingModule
|
23
|
+
class PageInsideModule
|
24
|
+
include Druid
|
25
|
+
page_url "http://google.co.uk"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class WorldSuper
|
30
|
+
attr_reader :super_called
|
31
|
+
def on_page(cls, params={}, visit=false, &block)
|
32
|
+
@super_called = true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class TestWorld < WorldSuper
|
37
|
+
include Druid::PageFactory
|
38
|
+
attr_accessor :driver
|
39
|
+
attr_accessor :current_page
|
40
|
+
end
|
41
|
+
|
42
|
+
describe Druid::PageFactory do
|
43
|
+
|
44
|
+
let(:world) { TestWorld.new }
|
45
|
+
let(:driver) do
|
46
|
+
world.driver = mock_driver
|
47
|
+
driver = world.driver
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should call super when non druid class passed" do
|
51
|
+
class NoDruid
|
52
|
+
end
|
53
|
+
world.on(NoDruid)
|
54
|
+
expect(world.super_called).to be true
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should create a new page object and execute a block" do
|
58
|
+
expect(driver).not_to receive(:goto)
|
59
|
+
world.on_page FactoryTestDruid do |page|
|
60
|
+
expect(page).to be_instance_of FactoryTestDruid
|
61
|
+
end
|
62
|
+
world.on_page "FactoryTestDruid" do |page|
|
63
|
+
expect(page).to be_instance_of FactoryTestDruid
|
64
|
+
end
|
65
|
+
world.on_page "ContainingModule::PageInsideModule" do |page|
|
66
|
+
expect(page).to be_instance_of ContainingModule::PageInsideModule
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should create a new page object and execute a block using 'on'" do
|
71
|
+
expect(driver).not_to receive(:goto)
|
72
|
+
world.on FactoryTestDruid do |page|
|
73
|
+
expect(page).to be_instance_of FactoryTestDruid
|
74
|
+
end
|
75
|
+
world.on "FactoryTestDruid" do |page|
|
76
|
+
expect(page).to be_instance_of FactoryTestDruid
|
77
|
+
end
|
78
|
+
world.on "ContainingModule::PageInsideModule" do |page|
|
79
|
+
expect(page).to be_instance_of ContainingModule::PageInsideModule
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should create and visit a new page" do
|
84
|
+
expect(driver).to receive(:goto).exactly(3).times
|
85
|
+
world.visit_page FactoryTestDruid do |page|
|
86
|
+
expect(page).to be_instance_of FactoryTestDruid
|
87
|
+
end
|
88
|
+
world.visit_page "FactoryTestDruid" do |page|
|
89
|
+
expect(page).to be_instance_of FactoryTestDruid
|
90
|
+
end
|
91
|
+
world.visit_page "ContainingModule::PageInsideModule" do |page|
|
92
|
+
expect(page).to be_instance_of ContainingModule::PageInsideModule
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should merge params with the class level params if provided when visiting" do
|
97
|
+
expect(driver).to receive(:goto)
|
98
|
+
FactoryTestDruid.params = {:initial => :value}
|
99
|
+
world.visit_page(FactoryTestDruid, :using_params => {:new_value => :merged})
|
100
|
+
merged = FactoryTestDruid.instance_variable_get("@merged_params")
|
101
|
+
expect(merged[:initial]).to eql :value
|
102
|
+
expect(merged[:new_value]).to eql :merged
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should use the params in the url when they are provided" do
|
106
|
+
class PageUsingParams
|
107
|
+
include Druid
|
108
|
+
page_url "http://google.com/<%=params[:value]%>"
|
109
|
+
end
|
110
|
+
expect(driver).to receive(:goto).with("http://google.com/Druid")
|
111
|
+
world.visit_page(PageUsingParams, :using_params => {:value => 'Druid'})
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should use the params as well as interpolated values" do
|
115
|
+
class PageUsingParamsAndInterpolated
|
116
|
+
include Druid
|
117
|
+
page_url "http://google.com/#{1+2}/<%=params[:value]%>"
|
118
|
+
end
|
119
|
+
expect(driver).to receive(:goto).with("http://google.com/3/Druid")
|
120
|
+
world.visit_page(PageUsingParamsAndInterpolated, :using_params => {:value => 'Druid'})
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should create and visit a new page using 'visit'" do
|
124
|
+
expect(driver).to receive(:goto).exactly(3).times
|
125
|
+
world.visit FactoryTestDruid do |page|
|
126
|
+
expect(page).to be_instance_of FactoryTestDruid
|
127
|
+
end
|
128
|
+
world.visit "FactoryTestDruid" do |page|
|
129
|
+
expect(page).to be_instance_of FactoryTestDruid
|
130
|
+
end
|
131
|
+
world.visit "ContainingModule::PageInsideModule" do |page|
|
132
|
+
expect(page).to be_instance_of ContainingModule::PageInsideModule
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should create and visit a new page when url is defined as 'direct_url'" do
|
137
|
+
expect(driver).to receive(:goto)
|
138
|
+
world.visit TestPageWithDirectUrl do |page|
|
139
|
+
expect(page).to be_instance_of TestPageWithDirectUrl
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should set an instance variable that can be used outside of the block" do
|
144
|
+
expect(driver).not_to receive(:goto)
|
145
|
+
page = world.on_page FactoryTestDruid
|
146
|
+
current_page = world.instance_variable_get "@current_page"
|
147
|
+
expect(current_page).to be page
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should not execute block if page is not @current_page" do
|
151
|
+
world.instance_variable_set "@current_page", TestPageWithDirectUrl.new(driver)
|
152
|
+
world.if_page(FactoryTestDruid) do |page|
|
153
|
+
fail
|
154
|
+
end
|
155
|
+
world.if_page("FactoryTestDruid") do |page|
|
156
|
+
fail
|
157
|
+
end
|
158
|
+
world.if_page("ContainingModule::PageInsideModule") do |page|
|
159
|
+
fail
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should return the @current_page if asking for another page" do
|
164
|
+
expected = TestPageWithDirectUrl.new(driver)
|
165
|
+
world.instance_variable_set "@current_page", expected
|
166
|
+
expect(world.if_page(FactoryTestDruid)).to be expected
|
167
|
+
expect(world.if_page("FactoryTestDruid")).to be expected
|
168
|
+
expect(world.if_page("ContainingModule::PageInsideModule")).to be expected
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should execute the block when we ask if it is the correct page" do
|
172
|
+
world.instance_variable_set "@current_page", FactoryTestDruid.new(driver)
|
173
|
+
done = false
|
174
|
+
world.if_page(FactoryTestDruid) do |page|
|
175
|
+
expect(page).to be_instance_of FactoryTestDruid
|
176
|
+
done = true
|
177
|
+
end
|
178
|
+
expect(done).to be true
|
179
|
+
done = false
|
180
|
+
world.if_page("FactoryTestDruid") do |page|
|
181
|
+
expect(page).to be_instance_of FactoryTestDruid
|
182
|
+
done = true
|
183
|
+
end
|
184
|
+
expect(done).to be true
|
185
|
+
done = false
|
186
|
+
world.instance_variable_set "@current_page", ContainingModule::PageInsideModule.new(driver)
|
187
|
+
world.if_page("ContainingModule::PageInsideModule") do |page|
|
188
|
+
expect(page).to be_instance_of ContainingModule::PageInsideModule
|
189
|
+
done = true
|
190
|
+
end
|
191
|
+
expect(done).to be true
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should raise an error when you do not provide a default route" do
|
195
|
+
expect { Druid::PageFactory.routes = {:another => []} }.to raise_error 'You must provide a :default route'
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should store the routes" do
|
199
|
+
routes = ['a', 'b', 'c']
|
200
|
+
Druid::PageFactory.routes = {:default => routes}
|
201
|
+
expect(Druid::PageFactory.routes[:default]).to eql routes
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should navigate to a page calling the default methods" do
|
205
|
+
pages = [[FactoryTestDruid, :a_method], [AnotherPage, :b_method]]
|
206
|
+
Druid::PageFactory.routes = {:default => pages}
|
207
|
+
fake_page = double('a_page')
|
208
|
+
expect(FactoryTestDruid).to receive(:new).with(driver,false).and_return(fake_page)
|
209
|
+
expect(fake_page).to receive(:a_method)
|
210
|
+
expect(world.navigate_to(AnotherPage).class).to eql AnotherPage
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should pass parameters to methods when navigating" do
|
214
|
+
pages = [[FactoryTestDruid, :a_method, 'blah'], [AnotherPage, :b_method]]
|
215
|
+
Druid::PageFactory.routes = {:default => pages}
|
216
|
+
fake_page = double('a_page')
|
217
|
+
expect(FactoryTestDruid).to receive(:new).with(driver,false).and_return(fake_page)
|
218
|
+
expect(fake_page).to receive(:a_method).with('blah')
|
219
|
+
expect(world.navigate_to(AnotherPage).class).to eql AnotherPage
|
220
|
+
end
|
221
|
+
|
222
|
+
it "should fail when it does not find a proper route" do
|
223
|
+
Druid::PageFactory.routes = {:default => ['a'], :another => ['b']}
|
224
|
+
expect{world.navigate_to(AnotherPage, :using => :no_route)}.to raise_error 'PageFactory route :no_route not found'
|
225
|
+
end
|
226
|
+
|
227
|
+
it "should fail when no default method specified" do
|
228
|
+
Druid::PageFactory.routes = {:default => [[FactoryTestDruid, :a_method], [AnotherPage, :b_method]]}
|
229
|
+
fake_page = double('a_page')
|
230
|
+
expect(FactoryTestDruid).to receive(:new).and_return(fake_page)
|
231
|
+
expect(fake_page).to receive(:respond_to?).with(:a_method).and_return(false)
|
232
|
+
expect{world.navigate_to(AnotherPage)}.to raise_error "Navigation method 'a_method' not defined on FactoryTestDruid."
|
233
|
+
end
|
234
|
+
|
235
|
+
end
|