watir 6.0.0.beta5 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -2
- data/CHANGES.md +10 -1
- data/Gemfile +4 -0
- data/README.md +37 -23
- data/Rakefile +6 -10
- data/appveyor.yml +13 -0
- data/lib/watir.rb +20 -21
- data/lib/watir/alert.rb +21 -5
- data/lib/watir/browser.rb +9 -3
- data/lib/watir/elements/checkbox.rb +0 -1
- data/lib/watir/elements/element.rb +92 -50
- data/lib/watir/elements/form.rb +1 -2
- data/lib/watir/elements/iframe.rb +6 -2
- data/lib/watir/elements/image.rb +1 -1
- data/lib/watir/elements/option.rb +0 -1
- data/lib/watir/elements/radio.rb +0 -1
- data/lib/watir/elements/select.rb +1 -10
- data/lib/watir/extensions/select_text.rb +1 -1
- data/lib/watir/legacy_wait.rb +126 -0
- data/lib/watir/locators/text_field/locator.rb +0 -3
- data/lib/watir/locators/text_field/selector_builder.rb +1 -4
- data/lib/watir/locators/text_field/selector_builder/xpath.rb +0 -2
- data/lib/watir/locators/text_field/validator.rb +1 -9
- data/lib/watir/row_container.rb +1 -1
- data/lib/watir/user_editable.rb +7 -5
- data/lib/watir/wait.rb +56 -135
- data/lib/watir/wait/timer.rb +29 -2
- data/lib/watir/window.rb +11 -1
- data/lib/watirspec.rb +81 -0
- data/lib/watirspec/guards.rb +58 -0
- data/lib/watirspec/implementation.rb +33 -0
- data/lib/watirspec/rake_tasks.rb +115 -0
- data/lib/watirspec/runner.rb +53 -0
- data/lib/watirspec/server.rb +99 -0
- data/lib/watirspec/server/app.rb +62 -0
- data/spec/browser_spec.rb +5 -5
- data/spec/click_spec.rb +1 -1
- data/spec/container_spec.rb +1 -1
- data/spec/element_locator_spec.rb +1 -1
- data/spec/element_spec.rb +20 -34
- data/spec/implementation_spec.rb +24 -0
- data/spec/input_spec.rb +1 -1
- data/spec/spec_helper.rb +35 -3
- data/spec/special_chars_spec.rb +1 -1
- data/spec/watirspec/.gitignore +2 -0
- data/spec/watirspec/after_hooks_spec.rb +179 -0
- data/spec/watirspec/alert_spec.rb +101 -0
- data/spec/watirspec/browser_spec.rb +291 -0
- data/spec/watirspec/cookies_spec.rb +147 -0
- data/spec/watirspec/drag_and_drop_spec.rb +49 -0
- data/spec/watirspec/element_hidden_spec.rb +65 -0
- data/spec/watirspec/elements/area_spec.rb +76 -0
- data/spec/watirspec/elements/areas_spec.rb +42 -0
- data/spec/watirspec/elements/button_spec.rb +270 -0
- data/spec/watirspec/elements/buttons_spec.rb +55 -0
- data/spec/watirspec/elements/checkbox_spec.rb +279 -0
- data/spec/watirspec/elements/checkboxes_spec.rb +44 -0
- data/spec/watirspec/elements/collections_spec.rb +16 -0
- data/spec/watirspec/elements/dd_spec.rb +126 -0
- data/spec/watirspec/elements/dds_spec.rb +42 -0
- data/spec/watirspec/elements/del_spec.rb +128 -0
- data/spec/watirspec/elements/dels_spec.rb +40 -0
- data/spec/watirspec/elements/div_spec.rb +199 -0
- data/spec/watirspec/elements/divs_spec.rb +42 -0
- data/spec/watirspec/elements/dl_spec.rb +144 -0
- data/spec/watirspec/elements/dls_spec.rb +43 -0
- data/spec/watirspec/elements/dt_spec.rb +126 -0
- data/spec/watirspec/elements/dts_spec.rb +42 -0
- data/spec/watirspec/elements/element_spec.rb +361 -0
- data/spec/watirspec/elements/elements_spec.rb +15 -0
- data/spec/watirspec/elements/em_spec.rb +100 -0
- data/spec/watirspec/elements/ems_spec.rb +43 -0
- data/spec/watirspec/elements/filefield_spec.rb +181 -0
- data/spec/watirspec/elements/filefields_spec.rb +43 -0
- data/spec/watirspec/elements/font_spec.rb +29 -0
- data/spec/watirspec/elements/form_spec.rb +70 -0
- data/spec/watirspec/elements/forms_spec.rb +44 -0
- data/spec/watirspec/elements/frame_spec.rb +121 -0
- data/spec/watirspec/elements/frames_spec.rb +41 -0
- data/spec/watirspec/elements/hidden_spec.rb +102 -0
- data/spec/watirspec/elements/hiddens_spec.rb +43 -0
- data/spec/watirspec/elements/hn_spec.rb +96 -0
- data/spec/watirspec/elements/hns_spec.rb +38 -0
- data/spec/watirspec/elements/iframe_spec.rb +174 -0
- data/spec/watirspec/elements/iframes_spec.rb +47 -0
- data/spec/watirspec/elements/image_spec.rb +164 -0
- data/spec/watirspec/elements/images_spec.rb +40 -0
- data/spec/watirspec/elements/ins_spec.rb +129 -0
- data/spec/watirspec/elements/inses_spec.rb +40 -0
- data/spec/watirspec/elements/label_spec.rb +79 -0
- data/spec/watirspec/elements/labels_spec.rb +40 -0
- data/spec/watirspec/elements/li_spec.rb +115 -0
- data/spec/watirspec/elements/link_spec.rb +174 -0
- data/spec/watirspec/elements/links_spec.rb +44 -0
- data/spec/watirspec/elements/lis_spec.rb +42 -0
- data/spec/watirspec/elements/map_spec.rb +79 -0
- data/spec/watirspec/elements/maps_spec.rb +41 -0
- data/spec/watirspec/elements/meta_spec.rb +23 -0
- data/spec/watirspec/elements/metas_spec.rb +40 -0
- data/spec/watirspec/elements/ol_spec.rb +89 -0
- data/spec/watirspec/elements/ols_spec.rb +40 -0
- data/spec/watirspec/elements/option_spec.rb +152 -0
- data/spec/watirspec/elements/p_spec.rb +115 -0
- data/spec/watirspec/elements/pre_spec.rb +115 -0
- data/spec/watirspec/elements/pres_spec.rb +40 -0
- data/spec/watirspec/elements/ps_spec.rb +40 -0
- data/spec/watirspec/elements/radio_spec.rb +263 -0
- data/spec/watirspec/elements/radios_spec.rb +43 -0
- data/spec/watirspec/elements/select_list_spec.rb +379 -0
- data/spec/watirspec/elements/select_lists_spec.rb +46 -0
- data/spec/watirspec/elements/span_spec.rb +129 -0
- data/spec/watirspec/elements/spans_spec.rb +40 -0
- data/spec/watirspec/elements/strong_spec.rb +92 -0
- data/spec/watirspec/elements/strongs_spec.rb +43 -0
- data/spec/watirspec/elements/table_nesting_spec.rb +51 -0
- data/spec/watirspec/elements/table_spec.rb +146 -0
- data/spec/watirspec/elements/tables_spec.rb +42 -0
- data/spec/watirspec/elements/tbody_spec.rb +96 -0
- data/spec/watirspec/elements/tbodys_spec.rb +62 -0
- data/spec/watirspec/elements/td_spec.rb +71 -0
- data/spec/watirspec/elements/tds_spec.rb +53 -0
- data/spec/watirspec/elements/text_field_spec.rb +302 -0
- data/spec/watirspec/elements/text_fields_spec.rb +44 -0
- data/spec/watirspec/elements/textarea_spec.rb +26 -0
- data/spec/watirspec/elements/textareas_spec.rb +24 -0
- data/spec/watirspec/elements/tfoot_spec.rb +91 -0
- data/spec/watirspec/elements/tfoots_spec.rb +68 -0
- data/spec/watirspec/elements/thead_spec.rb +91 -0
- data/spec/watirspec/elements/theads_spec.rb +68 -0
- data/spec/watirspec/elements/tr_spec.rb +80 -0
- data/spec/watirspec/elements/trs_spec.rb +61 -0
- data/spec/watirspec/elements/ul_spec.rb +79 -0
- data/spec/watirspec/elements/uls_spec.rb +39 -0
- data/spec/watirspec/html/alerts.html +12 -0
- data/spec/watirspec/html/aria_attributes.html +9 -0
- data/spec/watirspec/html/class_locator.html +8 -0
- data/spec/watirspec/html/clicks.html +19 -0
- data/spec/watirspec/html/closeable.html +13 -0
- data/spec/watirspec/html/collections.html +15 -0
- data/spec/watirspec/html/css/jquery-ui-1.8.17.custom.css +287 -0
- data/spec/watirspec/html/data_attributes.html +9 -0
- data/spec/watirspec/html/definition_lists.html +48 -0
- data/spec/watirspec/html/drag_and_drop.html +106 -0
- data/spec/watirspec/html/font.html +10 -0
- data/spec/watirspec/html/forms_with_input_elements.html +170 -0
- data/spec/watirspec/html/frame_1.html +22 -0
- data/spec/watirspec/html/frame_2.html +16 -0
- data/spec/watirspec/html/frames.html +11 -0
- data/spec/watirspec/html/hover.html +12 -0
- data/spec/watirspec/html/iframe_1.html +22 -0
- data/spec/watirspec/html/iframes.html +12 -0
- data/spec/watirspec/html/images.html +28 -0
- data/spec/watirspec/html/images/1.gif +0 -0
- data/spec/watirspec/html/images/2.gif +0 -0
- data/spec/watirspec/html/images/3.gif +0 -0
- data/spec/watirspec/html/images/button.png +0 -0
- data/spec/watirspec/html/images/circle.png +0 -0
- data/spec/watirspec/html/images/map.gif +0 -0
- data/spec/watirspec/html/images/map2.gif +0 -0
- data/spec/watirspec/html/images/minus.gif +0 -0
- data/spec/watirspec/html/images/originaltriangle.png +0 -0
- data/spec/watirspec/html/images/plus.gif +0 -0
- data/spec/watirspec/html/images/square.png +0 -0
- data/spec/watirspec/html/images/triangle.png +0 -0
- data/spec/watirspec/html/inner_outer.html +5 -0
- data/spec/watirspec/html/javascript/helpers.js +16 -0
- data/spec/watirspec/html/javascript/jquery-1.7.1.min.js +4 -0
- data/spec/watirspec/html/javascript/jquery-ui-1.8.17.custom.min.js +68 -0
- data/spec/watirspec/html/keylogger.html +15 -0
- data/spec/watirspec/html/modal_dialog.html +9 -0
- data/spec/watirspec/html/multiple_ids.html +14 -0
- data/spec/watirspec/html/nested_frame_1.html +1 -0
- data/spec/watirspec/html/nested_frame_2.html +9 -0
- data/spec/watirspec/html/nested_frame_3.html +14 -0
- data/spec/watirspec/html/nested_frames.html +10 -0
- data/spec/watirspec/html/nested_iframe_2.html +12 -0
- data/spec/watirspec/html/nested_iframes.html +9 -0
- data/spec/watirspec/html/nested_tables.html +203 -0
- data/spec/watirspec/html/non_control_elements.html +135 -0
- data/spec/watirspec/html/removed_element.html +24 -0
- data/spec/watirspec/html/right_click.html +11 -0
- data/spec/watirspec/html/special_chars.html +12 -0
- data/spec/watirspec/html/tables.html +121 -0
- data/spec/watirspec/html/timeout_window_location.html +19 -0
- data/spec/watirspec/html/uneven_table.html +20 -0
- data/spec/watirspec/html/wait.html +65 -0
- data/spec/watirspec/html/watirspec.css +0 -0
- data/spec/watirspec/html/window_switching.html +12 -0
- data/spec/watirspec/relaxed_locate_spec.rb +214 -0
- data/spec/watirspec/screenshot_spec.rb +29 -0
- data/spec/watirspec/wait_spec.rb +304 -0
- data/spec/watirspec/window_switching_spec.rb +411 -0
- data/spec/{implementation.rb → watirspec_helper.rb} +13 -13
- data/support/appveyor.cmd +9 -0
- data/support/doctest_helper.rb +5 -1
- data/support/travis.sh +0 -1
- data/watir.gemspec +3 -4
- metadata +323 -30
- data/.gitmodules +0 -3
@@ -0,0 +1,38 @@
|
|
1
|
+
require "watirspec_helper"
|
2
|
+
|
3
|
+
describe ["H1s", "H2s", "H3s", "H4s", "H5s", "H6s"] do
|
4
|
+
before :each do
|
5
|
+
browser.goto(WatirSpec.url_for("non_control_elements.html"))
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "with selectors" do
|
9
|
+
it "returns the matching elements" do
|
10
|
+
expect(browser.h1s(class: "primary").to_a).to eq [browser.h1(class: "primary")]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#length" do
|
15
|
+
it "returns the number of h1s" do
|
16
|
+
expect(browser.h2s.length).to eq 9
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#[]" do
|
21
|
+
it "returns the h1 at the given index" do
|
22
|
+
expect(browser.h1s[0].id).to eq "first_header"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#each" do
|
27
|
+
it "iterates through header collections correctly" do
|
28
|
+
lengths = (1..6).collect do |i|
|
29
|
+
collection = browser.send(:"h#{i}s")
|
30
|
+
collection.each_with_index do |h, index|
|
31
|
+
expect(h.id).to eq browser.send(:"h#{i}", :index, index).id
|
32
|
+
end
|
33
|
+
collection.length
|
34
|
+
end
|
35
|
+
expect(lengths).to eq [2, 9, 2, 1, 1, 2]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,174 @@
|
|
1
|
+
require "watirspec_helper"
|
2
|
+
|
3
|
+
#
|
4
|
+
# TODO: fix duplication with frame_spec
|
5
|
+
#
|
6
|
+
|
7
|
+
describe "IFrame" do
|
8
|
+
|
9
|
+
before :each do
|
10
|
+
browser.goto(WatirSpec.url_for("iframes.html"))
|
11
|
+
end
|
12
|
+
|
13
|
+
bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1255906", :firefox do
|
14
|
+
it "handles crossframe javascript" do
|
15
|
+
browser.goto WatirSpec.url_for("iframes.html")
|
16
|
+
|
17
|
+
expect(browser.iframe(id: "iframe_1").text_field(name: 'senderElement').value).to eq 'send_this_value'
|
18
|
+
expect(browser.iframe(id: "iframe_2").text_field(name: 'recieverElement').value).to eq 'old_value'
|
19
|
+
browser.iframe(id: "iframe_1").button(id: 'send').click
|
20
|
+
expect(browser.iframe(id: "iframe_2").text_field(name: 'recieverElement').value).to eq 'send_this_value'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#exist?" do
|
25
|
+
it "returns true if the iframe exists" do
|
26
|
+
expect(browser.iframe(id: "iframe_1")).to exist
|
27
|
+
expect(browser.iframe(name: "iframe1")).to exist
|
28
|
+
expect(browser.iframe(index: 0)).to exist
|
29
|
+
expect(browser.iframe(class: "half")).to exist
|
30
|
+
expect(browser.iframe(xpath: "//iframe[@id='iframe_1']")).to exist
|
31
|
+
expect(browser.iframe(src: "iframe_1.html")).to exist
|
32
|
+
expect(browser.iframe(id: /iframe/)).to exist
|
33
|
+
expect(browser.iframe(name: /iframe/)).to exist
|
34
|
+
expect(browser.iframe(src: /iframe_1/)).to exist
|
35
|
+
expect(browser.iframe(class: /half/)).to exist
|
36
|
+
end
|
37
|
+
|
38
|
+
it "returns the first iframe if given no args" do
|
39
|
+
expect(browser.iframe).to exist
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns false if the iframe doesn't exist" do
|
43
|
+
expect(browser.iframe(id: "no_such_id")).to_not exist
|
44
|
+
expect(browser.iframe(name: "no_such_text")).to_not exist
|
45
|
+
expect(browser.iframe(index: 1337)).to_not exist
|
46
|
+
expect(browser.iframe(src: "no_such_src")).to_not exist
|
47
|
+
expect(browser.iframe(class: "no_such_class")).to_not exist
|
48
|
+
expect(browser.iframe(id: /no_such_id/)).to_not exist
|
49
|
+
expect(browser.iframe(name: /no_such_text/)).to_not exist
|
50
|
+
expect(browser.iframe(src: /no_such_src/)).to_not exist
|
51
|
+
expect(browser.iframe(class: /no_such_class/)).to_not exist
|
52
|
+
expect(browser.iframe(xpath: "//iframe[@id='no_such_id']")).to_not exist
|
53
|
+
end
|
54
|
+
|
55
|
+
it "returns false if an element in an iframe does exist" do
|
56
|
+
expect(browser.iframe.element(css: "#senderElement")).to exist
|
57
|
+
expect(browser.iframe.element(id: "senderElement")).to exist
|
58
|
+
end
|
59
|
+
|
60
|
+
it "returns true if an element in an iframe does not exist" do
|
61
|
+
expect(browser.iframe.element(css: "#no_such_id")).to_not exist
|
62
|
+
expect(browser.iframe.element(id: "no_such_id")).to_not exist
|
63
|
+
end
|
64
|
+
|
65
|
+
it "returns true if an element outside an iframe exists after checking for one inside that does exist" do
|
66
|
+
existing_element = browser.element(css: "#iframe_1")
|
67
|
+
expect(existing_element).to exist
|
68
|
+
expect(browser.iframe.element(css: "#senderElement")).to exist
|
69
|
+
expect(existing_element).to exist
|
70
|
+
end
|
71
|
+
|
72
|
+
it "returns true if an element outside an iframe exists after checking for one inside that does not exist" do
|
73
|
+
existing_element = browser.element(css: "#iframe_1")
|
74
|
+
expect(existing_element).to exist
|
75
|
+
expect(browser.iframe.element(css: "#no_such_id")).to_not exist
|
76
|
+
expect(existing_element).to exist
|
77
|
+
end
|
78
|
+
|
79
|
+
it "returns true if an element exists in a frame generated in a collection" do
|
80
|
+
nested_element = browser.body.iframes.first.div
|
81
|
+
expect(nested_element).to exist
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
bug "https://github.com/detro/ghostdriver/issues/159", :phantomjs do
|
86
|
+
bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1255946", :firefox do
|
87
|
+
it "handles nested iframes" do
|
88
|
+
browser.goto(WatirSpec.url_for("nested_iframes.html"))
|
89
|
+
|
90
|
+
browser.iframe(id: "two").iframe(id: "three").link(id: "four").click
|
91
|
+
|
92
|
+
Watir::Wait.until { browser.title == "definition_lists" }
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
it "raises TypeError when 'what' argument is invalid" do
|
98
|
+
expect { browser.iframe(id: 3.14).exists? }.to raise_error(TypeError)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
|
102
|
+
expect { browser.iframe(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'handles all locators for element which do not exist' do
|
107
|
+
expect(browser.iframe(index: 0).div(id: 'invalid')).to_not exist
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'switches between iframe and parent when needed' do
|
111
|
+
browser.iframe(id: "iframe_1").elements.each do |element|
|
112
|
+
element.text
|
113
|
+
browser.h1.text
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'switches back to top level browsing context' do
|
118
|
+
# Point driver to browsing context of first iframe
|
119
|
+
browser.iframes.first.ps.to_a
|
120
|
+
|
121
|
+
expect(browser.h1s.first.text).to be == 'Iframes'
|
122
|
+
end
|
123
|
+
|
124
|
+
it "raises UnknownFrameException when accessing elements inside non-existing iframe" do
|
125
|
+
expect { browser.iframe(name: "no_such_name").p(index: 0).id }.to raise_unknown_frame_exception
|
126
|
+
end
|
127
|
+
|
128
|
+
it "raises UnknownFrameException when accessing a non-existing iframe" do
|
129
|
+
expect { browser.iframe(name: "no_such_name").id }.to raise_unknown_frame_exception
|
130
|
+
end
|
131
|
+
|
132
|
+
it "raises UnknownFrameException when accessing a non-existing subframe" do
|
133
|
+
expect { browser.iframe(name: "iframe1").iframe(name: "no_such_name").id }.to raise_unknown_frame_exception
|
134
|
+
end
|
135
|
+
|
136
|
+
it "raises UnknownObjectException when accessing a non-existing element inside an existing iframe" do
|
137
|
+
expect { browser.iframe(index: 0).p(index: 1337).id }.to raise_unknown_object_exception
|
138
|
+
end
|
139
|
+
|
140
|
+
it "raises NoMethodError when trying to access attributes it doesn't have" do
|
141
|
+
expect { browser.iframe(index: 0).foo }.to raise_error(NoMethodError)
|
142
|
+
end
|
143
|
+
|
144
|
+
bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1255906", :firefox do
|
145
|
+
it "is able to set a field" do
|
146
|
+
browser.iframe(index: 0).text_field(name: 'senderElement').set("new value")
|
147
|
+
expect(browser.iframe(index: 0).text_field(name: 'senderElement').value).to eq "new value"
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
describe "#execute_script" do
|
152
|
+
it "executes the given javascript in the specified frame" do
|
153
|
+
frame = browser.iframe(index: 0)
|
154
|
+
expect(frame.div(id: 'set_by_js').text).to eq ""
|
155
|
+
frame.execute_script(%Q{document.getElementById('set_by_js').innerHTML = 'Art consists of limitation. The most beautiful part of every picture is the frame.'})
|
156
|
+
expect(frame.div(id: 'set_by_js').text).to eq "Art consists of limitation. The most beautiful part of every picture is the frame."
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe "#html" do
|
161
|
+
it "returns the full HTML source of the iframe" do
|
162
|
+
browser.goto WatirSpec.url_for("iframes.html")
|
163
|
+
expect(browser.iframe.html.downcase).to include("<title>iframe 1</title>")
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
describe "#text" do
|
168
|
+
it "returns the text inside the iframe" do
|
169
|
+
browser.goto WatirSpec.url_for("iframes.html")
|
170
|
+
expect(browser.iframe.text).to include("Frame 1")
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "watirspec_helper"
|
2
|
+
|
3
|
+
describe "IFrames" do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
browser.goto(WatirSpec.url_for("iframes.html"))
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "with selectors" do
|
10
|
+
it "returns the matching elements" do
|
11
|
+
expect(browser.iframes(id: "iframe_2").to_a).to eq [browser.iframe(id: "iframe_2")]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "eql?" do
|
16
|
+
it "matches equality of iframe with that from a collection" do
|
17
|
+
expect(browser.iframes.last).to eq browser.iframe(id: "iframe_2")
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#length" do
|
23
|
+
it "returns the correct number of iframes" do
|
24
|
+
expect(browser.iframes.length).to eq 2
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#[]" do
|
29
|
+
it "returns the iframe at the given index" do
|
30
|
+
expect(browser.iframes[0].id).to eq "iframe_1"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#each" do
|
35
|
+
it "iterates through frames correctly" do
|
36
|
+
count = 0
|
37
|
+
|
38
|
+
browser.iframes.each_with_index do |f, index|
|
39
|
+
expect(f.name).to eq browser.iframe(index: index).name
|
40
|
+
expect(f.id).to eq browser.iframe(index: index).id
|
41
|
+
count += 1
|
42
|
+
end
|
43
|
+
|
44
|
+
expect(count).to be > 0
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,164 @@
|
|
1
|
+
require "watirspec_helper"
|
2
|
+
|
3
|
+
describe "Image" do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
browser.goto(WatirSpec.url_for("images.html"))
|
7
|
+
end
|
8
|
+
|
9
|
+
# Exists method
|
10
|
+
describe "#exists?" do
|
11
|
+
it "returns true when the image exists" do
|
12
|
+
expect(browser.image(id: 'square')).to exist
|
13
|
+
expect(browser.image(id: /square/)).to exist
|
14
|
+
expect(browser.image(src: 'images/circle.png')).to exist
|
15
|
+
expect(browser.image(src: /circle/)).to exist
|
16
|
+
expect(browser.image(alt: 'circle')).to exist
|
17
|
+
expect(browser.image(alt: /cir/)).to exist
|
18
|
+
expect(browser.image(title: 'Circle')).to exist
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns the first image if given no args" do
|
22
|
+
expect(browser.image).to exist
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns false when the image doesn't exist" do
|
26
|
+
expect(browser.image(id: 'no_such_id')).to_not exist
|
27
|
+
expect(browser.image(id: /no_such_id/)).to_not exist
|
28
|
+
expect(browser.image(src: 'no_such_src')).to_not exist
|
29
|
+
expect(browser.image(src: /no_such_src/)).to_not exist
|
30
|
+
expect(browser.image(alt: 'no_such_alt')).to_not exist
|
31
|
+
expect(browser.image(alt: /no_such_alt/)).to_not exist
|
32
|
+
expect(browser.image(title: 'no_such_title')).to_not exist
|
33
|
+
expect(browser.image(title: /no_such_title/)).to_not exist
|
34
|
+
end
|
35
|
+
|
36
|
+
it "raises TypeError when 'what' argument is invalid" do
|
37
|
+
expect { browser.image(id: 3.14).exists? }.to raise_error(TypeError)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
|
41
|
+
expect { browser.image(no_such_how: 'some_value').exists? }.to raise_error(Watir::Exception::MissingWayOfFindingObjectException)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Attribute methods
|
46
|
+
describe "#alt" do
|
47
|
+
it "returns the alt attribute of the image if the image exists" do
|
48
|
+
expect(browser.image(id: 'square').alt).to eq "square"
|
49
|
+
expect(browser.image(title: 'Circle').alt).to eq 'circle'
|
50
|
+
end
|
51
|
+
|
52
|
+
it "returns an empty string if the image exists and the attribute doesn't" do
|
53
|
+
expect(browser.image(index: 0).alt).to eq ""
|
54
|
+
end
|
55
|
+
|
56
|
+
it "raises UnknownObjectException if the image doesn't exist" do
|
57
|
+
expect { browser.image(index: 1337).alt }.to raise_unknown_object_exception
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "#id" do
|
62
|
+
it "returns the id attribute of the image if the image exists" do
|
63
|
+
expect(browser.image(title: 'Square').id).to eq 'square'
|
64
|
+
end
|
65
|
+
|
66
|
+
it "returns an empty string if the image exists and the attribute doesn't" do
|
67
|
+
expect(browser.image(index: 0).id).to eq ""
|
68
|
+
end
|
69
|
+
|
70
|
+
it "raises UnknownObjectException if the image doesn't exist" do
|
71
|
+
expect { browser.image(index: 1337).id }.to raise_unknown_object_exception
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "#src" do
|
76
|
+
it "returns the src attribute of the image if the image exists" do
|
77
|
+
expect(browser.image(id: 'square').src).to include("square.png")
|
78
|
+
end
|
79
|
+
|
80
|
+
it "returns an empty string if the image exists and the attribute doesn't" do
|
81
|
+
expect(browser.image(index: 0).src).to eq ""
|
82
|
+
end
|
83
|
+
|
84
|
+
it "raises UnknownObjectException if the image doesn't exist" do
|
85
|
+
expect { browser.image(index: 1337).src }.to raise_unknown_object_exception
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "#title" do
|
90
|
+
it "returns the title attribute of the image if the image exists" do
|
91
|
+
expect(browser.image(id: 'square').title).to eq 'Square'
|
92
|
+
end
|
93
|
+
|
94
|
+
it "returns an empty string if the image exists and the attribute doesn't" do
|
95
|
+
expect(browser.image(index: 0).title).to eq ""
|
96
|
+
end
|
97
|
+
|
98
|
+
it "raises UnknownObjectException if the image doesn't exist" do
|
99
|
+
expect { browser.image(index: 1337).title }.to raise_unknown_object_exception
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe "#respond_to?" do
|
104
|
+
it "returns true for all attribute methods" do
|
105
|
+
expect(browser.image(index: 0)).to respond_to(:class_name)
|
106
|
+
expect(browser.image(index: 0)).to respond_to(:id)
|
107
|
+
expect(browser.image(index: 0)).to respond_to(:style)
|
108
|
+
expect(browser.image(index: 0)).to respond_to(:text)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# Manipulation methods
|
113
|
+
describe "#click" do
|
114
|
+
it "raises UnknownObjectException when the image doesn't exist" do
|
115
|
+
expect { browser.image(id: 'missing_attribute').click }.to raise_unknown_object_exception
|
116
|
+
expect { browser.image(class: 'missing_attribute').click }.to raise_unknown_object_exception
|
117
|
+
expect { browser.image(src: 'missing_attribute').click }.to raise_unknown_object_exception
|
118
|
+
expect { browser.image(alt: 'missing_attribute').click }.to raise_unknown_object_exception
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "#height" do
|
123
|
+
it "returns the height of the image if the image exists" do
|
124
|
+
expect(browser.image(id: 'square').height).to eq 88
|
125
|
+
end
|
126
|
+
|
127
|
+
it "raises UnknownObjectException if the image doesn't exist" do
|
128
|
+
expect { browser.image(index: 1337).height }.to raise_unknown_object_exception
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "#width" do
|
133
|
+
it "returns the width of the image if the image exists" do
|
134
|
+
expect(browser.image(id: 'square').width).to eq 88
|
135
|
+
end
|
136
|
+
|
137
|
+
it "raises UnknownObjectException if the image doesn't exist" do
|
138
|
+
expect { browser.image(index: 1337).width }.to raise_unknown_object_exception
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
# Other
|
143
|
+
bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1297339", :firefox do
|
144
|
+
describe "#loaded?" do
|
145
|
+
it "returns true if the image has been loaded" do
|
146
|
+
expect(browser.image(title: 'Circle')).to be_loaded
|
147
|
+
expect(browser.image(alt: 'circle')).to be_loaded
|
148
|
+
expect(browser.image(alt: /circle/)).to be_loaded
|
149
|
+
end
|
150
|
+
|
151
|
+
it "returns false if the image has not been loaded" do
|
152
|
+
expect(browser.image(id: 'no_such_file')).to_not be_loaded
|
153
|
+
end
|
154
|
+
|
155
|
+
it "raises UnknownObjectException if the image doesn't exist" do
|
156
|
+
expect { browser.image(id: 'no_such_image').loaded? }.to raise_unknown_object_exception
|
157
|
+
expect { browser.image(src: 'no_such_image').loaded? }.to raise_unknown_object_exception
|
158
|
+
expect { browser.image(alt: 'no_such_image').loaded? }.to raise_unknown_object_exception
|
159
|
+
expect { browser.image(index: 1337).loaded? }.to raise_unknown_object_exception
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "watirspec_helper"
|
2
|
+
|
3
|
+
describe "Images" do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
browser.goto(WatirSpec.url_for("images.html"))
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "with selectors" do
|
10
|
+
it "returns the matching elements" do
|
11
|
+
expect(browser.images(alt: "circle").to_a).to eq [browser.image(alt: "circle")]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#length" do
|
16
|
+
it "returns the number of images" do
|
17
|
+
expect(browser.images.length).to eq 10
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#[]" do
|
22
|
+
it "returns the image at the given index" do
|
23
|
+
expect(browser.images[5].id).to eq "square"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#each" do
|
28
|
+
it "iterates through images correctly" do
|
29
|
+
count = 0
|
30
|
+
|
31
|
+
browser.images.each_with_index do |c, index|
|
32
|
+
expect(c.id).to eq browser.image(index: index).id
|
33
|
+
count += 1
|
34
|
+
end
|
35
|
+
|
36
|
+
expect(count).to be > 0
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|