druid-ts 0.0.1 → 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/.gitignore +5 -0
- data/.rspec +1 -0
- data/.rvmrc +1 -0
- data/.travis.yml +1 -2
- data/ChangeLog +218 -0
- data/Gemfile +2 -1
- data/README.md +64 -7
- data/Rakefile +1 -1
- data/druid.gemspec +25 -0
- data/features/async.feature +18 -0
- data/features/button.feature +42 -1
- data/features/checkbox.feature +7 -1
- data/features/div.feature +6 -0
- data/features/element.feature +100 -0
- data/features/file_field.feature +35 -0
- data/features/form.feature +12 -6
- data/features/frames.feature +57 -0
- data/features/heading.feature +164 -0
- data/features/hidden_field.feature +6 -0
- data/features/html/async.html +18 -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/iframes.html +12 -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/nested_elements.html +52 -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/static_elements.html +29 -23
- data/features/image.feature +8 -0
- data/features/link.feature +5 -0
- data/features/list_item.feature +5 -0
- data/features/modal_dialog.feature +9 -0
- data/features/nested_elements.feature +105 -0
- data/features/ordered_list.feature +6 -0
- data/features/page_level_actions.feature +48 -0
- data/features/paragraph.feature +33 -0
- data/features/radio_button.feature +6 -0
- data/features/select_list.feature +6 -1
- data/features/span.feature +6 -1
- data/features/step_definations/async_steps.rb +63 -0
- data/features/step_definations/button_steps.rb +25 -1
- data/features/step_definations/checkbox_steps.rb +5 -1
- data/features/step_definations/div_steps.rb +6 -1
- data/features/step_definations/element_steps.rb +55 -1
- data/features/step_definations/file_field_steps.rb +27 -0
- data/features/step_definations/form_steps.rb +8 -0
- data/features/step_definations/frame_steps.rb +112 -0
- data/features/step_definations/heading_steps.rb +39 -0
- data/features/step_definations/hidden_field_steps.rb +7 -3
- data/features/step_definations/image_steps.rb +7 -3
- data/features/step_definations/link_steps.rb +8 -3
- data/features/step_definations/list_item_steps.rb +9 -1
- data/features/step_definations/modal_dialog_steps.rb +38 -0
- data/features/step_definations/nested_elements_steps.rb +196 -0
- data/features/step_definations/ordered_list_steps.rb +11 -3
- data/features/step_definations/page_level_actions_steps.rb +72 -0
- data/features/step_definations/paragraph_steps.rb +15 -0
- data/features/step_definations/radio_button_steps.rb +5 -1
- data/features/step_definations/select_list_steps.rb +10 -2
- data/features/step_definations/span_steps.rb +5 -1
- data/features/step_definations/table_cell_steps.rb +5 -1
- data/features/step_definations/table_steps.rb +17 -3
- data/features/step_definations/text_area_steps.rb +18 -2
- data/features/step_definations/text_field_steps.rb +9 -1
- data/features/step_definations/unordered_list_steps.rb +11 -3
- data/features/support/env.rb +0 -15
- data/features/support/hooks.rb +7 -0
- data/features/support/page.rb +98 -1
- data/features/support/persistent_browser.rb +15 -0
- data/features/support/url_helper.rb +24 -1
- data/features/table.feature +7 -0
- data/features/table_cell.feature +6 -0
- data/features/text_area.feature +11 -0
- data/features/text_field.feature +6 -1
- data/features/unordered_list.feature +6 -0
- data/lib/druid.rb +251 -3
- data/lib/druid/accessors.rb +446 -158
- data/lib/druid/assist.rb +394 -0
- data/lib/druid/core_ext/string.rb +5 -0
- data/lib/druid/element_locators.rb +405 -0
- data/lib/druid/elements.rb +28 -0
- data/lib/druid/elements/button.rb +6 -1
- data/lib/druid/elements/check_box.rb +26 -0
- data/lib/druid/elements/div.rb +3 -1
- data/lib/druid/elements/element.rb +170 -5
- data/lib/druid/elements/file_field.rb +18 -0
- data/lib/druid/elements/form.rb +11 -0
- data/lib/druid/elements/heading.rb +14 -0
- data/lib/druid/elements/hidden_field.rb +12 -2
- data/lib/druid/elements/image.rb +13 -0
- data/lib/druid/elements/link.rb +2 -0
- data/lib/druid/elements/list_item.rb +3 -1
- data/lib/druid/elements/option.rb +9 -0
- data/lib/druid/elements/ordered_list.rb +4 -5
- data/lib/druid/elements/paragraph.rb +9 -0
- data/lib/druid/elements/radio_button.rb +25 -0
- data/lib/druid/elements/select_list.rb +10 -1
- data/lib/druid/elements/span.rb +3 -1
- data/lib/druid/elements/table.rb +20 -1
- data/lib/druid/elements/table_cell.rb +7 -0
- data/lib/druid/elements/table_row.rb +5 -1
- data/lib/druid/elements/text_area.rb +15 -1
- data/lib/druid/elements/text_field.rb +11 -1
- data/lib/druid/elements/unordered_list.rb +5 -5
- data/lib/druid/nested_elements.rb +103 -0
- data/lib/druid/page_factory.rb +4 -4
- data/lib/druid/page_populator.rb +71 -0
- data/spec/druid/accessors_spec.rb +789 -0
- data/spec/druid/druid_spec.rb +130 -7
- data/spec/druid/element_locators_spec.rb +160 -0
- data/spec/druid/elements/button_spec.rb +31 -0
- data/spec/druid/elements/check_box_spec.rb +38 -0
- data/spec/druid/elements/div_spec.rb +19 -0
- data/spec/druid/elements/element_spec.rb +150 -0
- data/spec/druid/elements/file_field_spec.rb +27 -0
- data/spec/druid/elements/form_spec.rb +27 -0
- data/spec/druid/elements/heading_spec.rb +39 -0
- data/spec/druid/elements/hidden_field_spec.rb +24 -0
- data/spec/druid/elements/image_spec.rb +32 -0
- data/spec/druid/elements/link_spec.rb +26 -0
- data/spec/druid/elements/list_item_spec.rb +19 -0
- data/spec/druid/elements/option_spec.rb +10 -0
- data/spec/druid/elements/ordered_list_spec.rb +42 -0
- data/spec/druid/elements/page_factory_spec.rb +40 -0
- data/spec/druid/elements/paragraph_spec.rb +21 -0
- data/spec/druid/elements/radio_button_spec.rb +38 -0
- data/spec/druid/elements/select_list_spec.rb +37 -0
- data/spec/druid/elements/span_spec.rb +19 -0
- data/spec/druid/elements/table_cell_spec.rb +23 -0
- data/spec/druid/elements/table_row_spec.rb +41 -0
- data/spec/druid/elements/table_spec.rb +52 -0
- data/spec/druid/elements/text_area_spec.rb +31 -0
- data/spec/druid/elements/text_field_spec.rb +31 -0
- data/spec/druid/elements/unordered_list_spec.rb +42 -0
- data/spec/druid/nested_element_spec.rb +128 -0
- data/spec/druid/page_populator_spec.rb +92 -0
- data/spec/spec_helper.rb +2 -1
- metadata +147 -27
data/spec/druid/druid_spec.rb
CHANGED
@@ -5,8 +5,8 @@ class TestDruid
|
|
5
5
|
end
|
6
6
|
|
7
7
|
describe Druid do
|
8
|
-
let(:driver){mock_driver}
|
9
|
-
let(:druid){TestDruid.new
|
8
|
+
let(:driver) { mock_driver }
|
9
|
+
let(:druid) { TestDruid.new(driver) }
|
10
10
|
|
11
11
|
context "when created with a watir-webdriver browser" do
|
12
12
|
it "should include the Druid module" do
|
@@ -14,22 +14,145 @@ describe Druid do
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
context "when created with an object we do not understand" do
|
18
|
+
it "should throw an error" do
|
19
|
+
expect {
|
20
|
+
TestDruid.new("blah")
|
21
|
+
}.to raise_error 'expect Watir::Browser'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
17
25
|
describe "page level functionality" do
|
18
|
-
context "when using
|
26
|
+
context "when using PageObject" do
|
27
|
+
|
19
28
|
it "should display the page text" do
|
20
|
-
expect(
|
21
|
-
expect(druid.text).to eql "
|
29
|
+
expect(driver).to receive(:text).and_return("driver text")
|
30
|
+
expect(druid.text).to eql "driver text"
|
22
31
|
end
|
23
32
|
|
24
33
|
it "should display the html of the page" do
|
25
|
-
expect(
|
34
|
+
expect(driver).to receive(:html).and_return("<html>Some Sample HTML</html>")
|
26
35
|
expect(druid.html).to eql "<html>Some Sample HTML</html>"
|
27
36
|
end
|
28
37
|
|
29
38
|
it "should display the title of the page" do
|
30
|
-
expect(
|
39
|
+
expect(driver).to receive(:title).and_return("I am the title of a page")
|
31
40
|
expect(druid.title).to eql "I am the title of a page"
|
32
41
|
end
|
42
|
+
|
43
|
+
it "should be able to navigate to a page" do
|
44
|
+
expect(driver).to receive(:goto).with("www.baidu.com")
|
45
|
+
druid.navigate_to("www.baidu.com")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should know it's current url" do
|
49
|
+
expect(driver).to receive(:url).and_return("www.baidu.com")
|
50
|
+
expect(druid.current_url).to eql "www.baidu.com"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should wait until a block returns true" do
|
54
|
+
expect(driver).to receive(:wait_until).with(5, "too long")
|
55
|
+
druid.wait_until(5, "too long")
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should retrieve the text from alert popup" do
|
59
|
+
allow(driver).to receive_message_chain(:alert, :exists?).and_return(true)
|
60
|
+
allow(driver).to receive_message_chain(:alert, :text).and_return('I am an alert')
|
61
|
+
expect(driver).to receive_message_chain(:alert, :ok)
|
62
|
+
msg = druid.alert do
|
63
|
+
end
|
64
|
+
expect(msg).to eql 'I am an alert'
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should retrieve the text from confirm popup" do
|
68
|
+
allow(driver).to receive_message_chain(:alert, :exists?).and_return(true)
|
69
|
+
allow(driver).to receive_message_chain(:alert, :text).and_return('I am an confirm')
|
70
|
+
expect(driver).to receive_message_chain(:alert, :ok)
|
71
|
+
msg = druid.confirm(true) do
|
72
|
+
end
|
73
|
+
expect(msg).to eql 'I am an confirm'
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should retrieve the text from prompt popup" do
|
77
|
+
allow(driver).to receive_message_chain(:alert, :exists?).and_return(true)
|
78
|
+
allow(driver).to receive_message_chain(:alert, :text).and_return('I am an prompt')
|
79
|
+
allow(driver).to receive_message_chain(:alert, :set).with("blah")
|
80
|
+
expect(driver).to receive_message_chain(:alert, :ok)
|
81
|
+
msg = druid.prompt("blah") do
|
82
|
+
end
|
83
|
+
expect(msg).to eql "I am an prompt"
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should switch to a new window with a given title" do
|
87
|
+
expect(driver).to receive(:window).with(:title => "My Title").and_return(driver)
|
88
|
+
expect(driver).to receive(:use)
|
89
|
+
druid.attach_to_window(:title => "My Title")
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should switch to a new window with a given index" do
|
93
|
+
expect(driver).to receive(:window).with(:index => 1).and_return(driver)
|
94
|
+
expect(driver).to receive(:use)
|
95
|
+
druid.attach_to_window(:index => 1)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should switch to a new window witha given url" do
|
99
|
+
expect(driver).to receive(:window).with(:url => /success\.html/).and_return(driver)
|
100
|
+
expect(driver).to receive(:use)
|
101
|
+
druid.attach_to_window(:url => "success.html")
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should refresh the page contents" do
|
105
|
+
expect(driver).to receive(:refresh)
|
106
|
+
druid.refresh
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should know how to go back" do
|
110
|
+
expect(driver).to receive(:back)
|
111
|
+
druid.back
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should know how to go forward" do
|
115
|
+
expect(driver).to receive(:forward)
|
116
|
+
druid.forward
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should try a second time after sleeping when attach to window fails" do
|
120
|
+
expect(driver).to receive(:window).once.and_return(driver)
|
121
|
+
expect(driver).to receive(:use).once.and_throw "error"
|
122
|
+
expect(driver).to receive(:window).and_return(driver)
|
123
|
+
expect(driver).to receive(:use)
|
124
|
+
druid.attach_to_window(:value => 'tim')
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should call intialize_page if it exists" do
|
128
|
+
class CallbackPage
|
129
|
+
include Druid
|
130
|
+
attr_reader :initialize_page
|
131
|
+
|
132
|
+
def initialize_page
|
133
|
+
@initialize_page = true
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
page = CallbackPage.new(driver)
|
138
|
+
expect(page.initialize_page).to be true
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should convert a modal popup to a window" do
|
142
|
+
expect(driver).to receive(:execute_script)
|
143
|
+
druid.modal_dialog {}
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should know how to clear all of the cookies from the browser" do
|
147
|
+
expect(driver).to receive(:clear_cookies)
|
148
|
+
druid.clear_cookies
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should be able to save a screenshot" do
|
152
|
+
expect(driver).to receive_message_chain(:screenshot,:save)
|
153
|
+
druid.save_screenshot('tim.png')
|
154
|
+
end
|
155
|
+
|
33
156
|
end
|
34
157
|
end
|
35
158
|
|
@@ -0,0 +1,160 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class ElementLocatorsTestDruid
|
4
|
+
include Druid
|
5
|
+
end
|
6
|
+
|
7
|
+
describe Druid::ElementLocators do
|
8
|
+
let(:driver) { mock_driver }
|
9
|
+
let(:page) { ElementLocatorsTestDruid.new(driver) }
|
10
|
+
|
11
|
+
it "should find a button element" do
|
12
|
+
expect(driver).to receive(:button).with(:id => 'blah').and_return(driver)
|
13
|
+
button = page.button_element(:id => 'blah')
|
14
|
+
expect(button).to be_instance_of Druid::Elements::Button
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should find a text field element" do
|
18
|
+
expect(driver).to receive(:text_field).with(:id => 'blah').and_return(driver)
|
19
|
+
text_field = page.text_field_element(:id => 'blah')
|
20
|
+
expect(text_field).to be_instance_of Druid::Elements::TextField
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should find a hidden field element" do
|
24
|
+
expect(driver).to receive(:hidden).with(:id => 'blah').and_return(driver)
|
25
|
+
element = page.hidden_field_element(:id => 'blah')
|
26
|
+
expect(element).to be_instance_of Druid::Elements::HiddenField
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should find a text area element" do
|
30
|
+
expect(driver).to receive(:textarea).with(:id => 'blah').and_return(driver)
|
31
|
+
element = page.text_area_element(:id => "blah")
|
32
|
+
expect(element).to be_instance_of Druid::Elements::TextArea
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should find a select list element" do
|
36
|
+
expect(driver).to receive(:select_list).with(:id => 'blah').and_return(driver)
|
37
|
+
element = page.select_list_element(:id => "blah")
|
38
|
+
expect(element).to be_instance_of Druid::Elements::SelectList
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should find a link element" do
|
42
|
+
expect(driver).to receive(:link).with(:id => 'blah').and_return(driver)
|
43
|
+
element = page.link_element(:id => 'blah')
|
44
|
+
expect(element).to be_instance_of Druid::Elements::Link
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should find a check box element" do
|
48
|
+
expect(driver).to receive(:checkbox).with(:id => 'blah').and_return(driver)
|
49
|
+
element = page.checkbox_element(:id => 'blah')
|
50
|
+
expect(element).to be_instance_of Druid::Elements::CheckBox
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should find a radio button element" do
|
54
|
+
expect(driver).to receive(:radio).with(:id => 'blah').and_return(driver)
|
55
|
+
element = page.radio_button_element(:id => 'blah')
|
56
|
+
expect(element).to be_instance_of Druid::Elements::RadioButton
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should find a div element" do
|
60
|
+
expect(driver).to receive(:div).with(:id => 'blah').and_return(driver)
|
61
|
+
element = page.div_element(:id => 'blah')
|
62
|
+
expect(element).to be_instance_of Druid::Elements::Div
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should find a span element" do
|
66
|
+
expect(driver).to receive(:span).with(:id => 'blah').and_return(driver)
|
67
|
+
element = page.span_element(:id => 'blah')
|
68
|
+
expect(element).to be_instance_of Druid::Elements::Span
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should find a table element" do
|
72
|
+
expect(driver).to receive(:table).with(:id => 'blah').and_return(driver)
|
73
|
+
element = page.table_element(:id => 'blah')
|
74
|
+
expect(element).to be_instance_of Druid::Elements::Table
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should find a table cell element" do
|
78
|
+
expect(driver).to receive(:td).with(:id => 'blah').and_return(driver)
|
79
|
+
element = page.cell_element(:id => 'blah')
|
80
|
+
expect(element).to be_instance_of Druid::Elements::TableCell
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should find an image element" do
|
84
|
+
expect(driver).to receive(:image).with(:id => 'blah').and_return(driver)
|
85
|
+
element = page.image_element(:id => 'blah')
|
86
|
+
expect(element).to be_instance_of Druid::Elements::Image
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should find a form element" do
|
90
|
+
expect(driver).to receive(:form).with(:id => 'blah').and_return(driver)
|
91
|
+
element = page.form_element(:id => 'blah')
|
92
|
+
expect(element).to be_instance_of Druid::Elements::Form
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should find a list item element" do
|
96
|
+
expect(driver).to receive(:li).with(:id => 'blah').and_return(driver)
|
97
|
+
element = page.list_item_element(:id => 'blah')
|
98
|
+
expect(element).to be_instance_of Druid::Elements::ListItem
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should find an ordered list element" do
|
102
|
+
expect(driver).to receive(:ol).with(:id => 'blah').and_return(driver)
|
103
|
+
element = page.ordered_list_element(:id => 'blah')
|
104
|
+
expect(element).to be_instance_of Druid::Elements::OrderedList
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should find an unordered list element" do
|
108
|
+
expect(driver).to receive(:ul).with(:id => 'blah').and_return(driver)
|
109
|
+
element = page.unordered_list_element(:id => 'blah')
|
110
|
+
expect(element).to be_instance_of Druid::Elements::UnOrderedList
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should find a h1 element" do
|
114
|
+
expect(driver).to receive(:h1).with(:id => 'blah').and_return(driver)
|
115
|
+
element = page.h1_element(:id => 'blah')
|
116
|
+
expect(element).to be_instance_of Druid::Elements::Heading
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should find a h2 element" do
|
120
|
+
expect(driver).to receive(:h2).with(:id => 'blah').and_return(driver)
|
121
|
+
element = page.h2_element(:id => 'blah')
|
122
|
+
expect(element).to be_instance_of Druid::Elements::Heading
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should find a h3 element" do
|
126
|
+
expect(driver).to receive(:h3).with(:id => 'blah').and_return(driver)
|
127
|
+
element = page.h3_element(:id => 'blah')
|
128
|
+
expect(element).to be_instance_of Druid::Elements::Heading
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should find a h4 element" do
|
132
|
+
expect(driver).to receive(:h4).with(:id => 'blah').and_return(driver)
|
133
|
+
element = page.h4_element(:id => 'blah')
|
134
|
+
expect(element).to be_instance_of Druid::Elements::Heading
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should find a h5 element" do
|
138
|
+
expect(driver).to receive(:h5).with(:id => 'blah').and_return(driver)
|
139
|
+
element = page.h5_element(:id => 'blah')
|
140
|
+
expect(element).to be_instance_of Druid::Elements::Heading
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should find a h6 element" do
|
144
|
+
expect(driver).to receive(:h6).with(:id => 'blah').and_return(driver)
|
145
|
+
element = page.h6_element(:id => 'blah')
|
146
|
+
expect(element).to be_instance_of Druid::Elements::Heading
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should find a paragraph element" do
|
150
|
+
expect(driver).to receive(:p).with(:id => 'blah').and_return(driver)
|
151
|
+
element = page.paragraph_element(:id => 'blah')
|
152
|
+
expect(element).to be_instance_of Druid::Elements::Paragraph
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should find a file field element" do
|
156
|
+
expect(driver).to receive(:file_field).with(:id => 'blah').and_return(driver)
|
157
|
+
element = page.file_field_element(:id => 'blah')
|
158
|
+
expect(element).to be_instance_of Druid::Elements::FileField
|
159
|
+
end
|
160
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'druid/elements'
|
3
|
+
|
4
|
+
describe Druid::Elements::Button do
|
5
|
+
describe "when mapping how to find an element" do
|
6
|
+
it "should map watir types to same" do
|
7
|
+
[:class, :id, :index, :name, :value, :xpath, :src, :alt].each do |t|
|
8
|
+
identifier = Druid::Elements::Button.identifier_for t => 'value'
|
9
|
+
expect(identifier.keys.first).to eql t
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "interface" do
|
15
|
+
it "should register with type :submit" do
|
16
|
+
expect(Druid::Elements.element_class_for(:input, :submit)).to be Druid::Elements::Button
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should register with type :image" do
|
20
|
+
expect(Druid::Elements.element_class_for(:input, :image)).to be Druid::Elements::Button
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should register with type :button" do
|
24
|
+
expect(Druid::Elements.element_class_for(:input, :button)).to be Druid::Elements::Button
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should register with type :reset" do
|
28
|
+
expect(Druid::Elements.element_class_for(:input, :reset)).to be Druid::Elements::Button
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'druid/elements'
|
3
|
+
|
4
|
+
describe Druid::Elements::CheckBox do
|
5
|
+
describe "when mapping how to find an element" do
|
6
|
+
it "should map watir types to same" do
|
7
|
+
[:class, :id, :index, :name, :xpath, :value].each do |t|
|
8
|
+
identifier = Druid::Elements::CheckBox.identifier_for t => 'value'
|
9
|
+
expect(identifier.keys.first).to eql t
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "interface" do
|
15
|
+
let(:element) { double 'element' }
|
16
|
+
let(:checkbox) { Druid::Elements::CheckBox.new(element) }
|
17
|
+
|
18
|
+
it "should check" do
|
19
|
+
expect(element).to receive(:set)
|
20
|
+
checkbox.check
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should uncheck" do
|
24
|
+
expect(element).to receive(:clear)
|
25
|
+
checkbox.uncheck
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should know if it is checked" do
|
29
|
+
expect(element).to receive(:set?)
|
30
|
+
checkbox.checked?
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should register with type :checkbox" do
|
34
|
+
expect(Druid::Elements.element_class_for(:input, :checkbox)).to be Druid::Elements::CheckBox
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'druid/elements'
|
3
|
+
|
4
|
+
describe Druid::Elements::Div do
|
5
|
+
describe "when mapping how to find an element" do
|
6
|
+
it "should map watir types to same" do
|
7
|
+
[:class, :id, :text, :index, :xpath].each do |t|
|
8
|
+
identifier = Druid::Elements::Div.identifier_for t => 'value'
|
9
|
+
expect(identifier.keys.first).to eql t
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "interface" do
|
15
|
+
it "should register with tag :div" do
|
16
|
+
expect(Druid::Elements.element_class_for(:div)).to be Druid::Elements::Div
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
require 'druid/elements'
|
2
|
+
|
3
|
+
describe Druid::Elements::Element do
|
4
|
+
let(:we) { double('we') }
|
5
|
+
let(:element) { Druid::Elements::Element.new(we) }
|
6
|
+
|
7
|
+
context "when handling unknown requests" do
|
8
|
+
it "should delegate to the driver element" do
|
9
|
+
expect(we).to receive(:do_this)
|
10
|
+
element.do_this
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context "when building the identifiers" do
|
15
|
+
it "should build xpath when finding elements by name were not supported" do
|
16
|
+
['table', 'span', 'div', 'td', 'li', 'ol', 'ul'].each do |tag|
|
17
|
+
how = {:tag_name => tag, :name => 'blah'}
|
18
|
+
result = Druid::Elements::Element.identifier_for how
|
19
|
+
expect(result[:xpath]).to eql ".//#{tag}[@name='blah']"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "on a druid" do
|
25
|
+
it "should know when it is visible" do
|
26
|
+
expect(we).to receive(:visible?).and_return(true)
|
27
|
+
expect(element.visible?).to be true
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should know when it is not visible" do
|
31
|
+
expect(we).to receive(:visible?).and_return(false)
|
32
|
+
expect(element.visible?).to be false
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should know when it exists" do
|
36
|
+
expect(we).to receive(:exist?).and_return(true)
|
37
|
+
expect(element.exist?).to be true
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should know when it does not exist" do
|
41
|
+
expect(we).to receive(:exist?).and_return(false)
|
42
|
+
expect(element.exist?).to be false
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should be able to return the text contained in the element" do
|
46
|
+
expect(we).to receive(:text).and_return("my text")
|
47
|
+
expect(element.text).to eql "my text"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should know when it is equal to another" do
|
51
|
+
expect(we).to receive(:==).and_return(true)
|
52
|
+
expect(element == element).to be true
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should return its tag name" do
|
56
|
+
expect(we).to receive(:tag_name).and_return('h1')
|
57
|
+
expect(element.tag_name).to eql 'h1'
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should know its value" do
|
61
|
+
expect(we).to receive(:value).and_return('value')
|
62
|
+
expect(element.value).to eql 'value'
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should know how to retrieve the value of an attribute" do
|
66
|
+
expect(we).to receive(:attribute_value).with('class').and_return('tim')
|
67
|
+
expect(element.attribute('class')).to eql 'tim'
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should be clickable" do
|
71
|
+
expect(we).to receive(:click)
|
72
|
+
element.click
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should be able to block until it is present" do
|
76
|
+
expect(we).to receive(:wait_until_present).with(10)
|
77
|
+
element.when_present(10)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should return the element when it is present" do
|
81
|
+
expect(we).to receive(:wait_until_present).with(10)
|
82
|
+
expect(element.when_present(10)).to eq element
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should be able to block until it is visible" do
|
86
|
+
expect(Watir::Wait).to receive(:until).with(10, "Element was not visible in 10 seconds")
|
87
|
+
element.when_visible(10)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should return the element when it is visible" do
|
91
|
+
expect(Watir::Wait).to receive(:until).with(10, "Element was not visible in 10 seconds")
|
92
|
+
expect(element.when_visible(10)).to eq element
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should be able to block until it is not visible" do
|
96
|
+
expect(Watir::Wait).to receive(:while).with(10, "Element still visible after 10 seconds")
|
97
|
+
element.when_not_visible(10)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should return the element when it is not visible" do
|
101
|
+
expect(Watir::Wait).to receive(:while).with(10, "Element still visible after 10 seconds")
|
102
|
+
expect(element.when_not_visible(10)).to eq element
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should be able to block until a user define event fires true" do
|
106
|
+
expect(Watir::Wait).to receive(:until).with(10, "Element blah")
|
107
|
+
element.wait_until(10, "Element blah") {}
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should send keys to the element" do
|
111
|
+
expect(we).to receive(:send_keys).with([:control, 'a'])
|
112
|
+
element.send_keys([:control, 'a'])
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should clear its' contents" do
|
116
|
+
expect(we).to receive(:clear)
|
117
|
+
element.clear
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should be double clickable" do
|
121
|
+
expect(we).to receive(:double_click)
|
122
|
+
element.double_click
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should be right clickable" do
|
126
|
+
expect(we).to receive(:right_click)
|
127
|
+
element.right_click
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should get element's style" do
|
131
|
+
expect(we).to receive(:style).with('class').and_return('tim')
|
132
|
+
expect(element.style('class')).to eql "tim"
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should inspect element" do
|
136
|
+
expect(we).to receive(:inspect)
|
137
|
+
element.inspect
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should be able to fire event" do
|
141
|
+
expect(we).to receive(:fire_event).with('onclick')
|
142
|
+
element.fire_event('onclick')
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should be able to focus element" do
|
146
|
+
expect(we).to receive(:focus)
|
147
|
+
element.focus
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|