watir 6.2.1 → 6.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +3 -7
- data/CHANGES.md +8 -0
- data/Rakefile +1 -3
- data/lib/watir/browser.rb +7 -7
- data/lib/watir/elements/element.rb +21 -5
- data/lib/watir/elements/iframe.rb +11 -2
- data/lib/watir/elements/image.rb +3 -2
- data/lib/watir/elements/select.rb +25 -4
- data/lib/watir/extensions/select_text.rb +3 -2
- data/lib/watir/locators/element/selector_builder.rb +1 -1
- data/lib/watir/locators/element/selector_builder/xpath.rb +14 -0
- data/lib/watirspec/rake_tasks.rb +2 -2
- data/spec/element_locator_spec.rb +14 -2
- data/spec/watirspec/after_hooks_spec.rb +39 -41
- data/spec/watirspec/alert_spec.rb +64 -66
- data/spec/watirspec/cookies_spec.rb +103 -105
- data/spec/watirspec/elements/div_spec.rb +1 -3
- data/spec/watirspec/elements/element_spec.rb +15 -2
- data/spec/watirspec/elements/filefield_spec.rb +33 -38
- data/spec/watirspec/elements/frame_spec.rb +5 -7
- data/spec/watirspec/elements/iframe_spec.rb +5 -7
- data/spec/watirspec/elements/select_list_spec.rb +26 -20
- data/spec/watirspec/relaxed_locate_spec.rb +8 -1
- data/spec/watirspec/window_switching_spec.rb +7 -9
- data/spec/watirspec_helper.rb +0 -4
- data/support/travis.sh +0 -26
- data/watir.gemspec +2 -1
- metadata +16 -2
@@ -1,147 +1,145 @@
|
|
1
1
|
require "watirspec_helper"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
after { browser.cookies.clear }
|
3
|
+
describe "Browser#cookies" do
|
4
|
+
after { browser.cookies.clear }
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
it 'gets an empty list of cookies' do
|
7
|
+
browser.goto WatirSpec.url_for 'collections.html' # no cookie set.
|
8
|
+
expect(browser.cookies.to_a).to eq []
|
9
|
+
end
|
11
10
|
|
12
|
-
|
13
|
-
|
11
|
+
it "gets any cookies set" do
|
12
|
+
browser.goto set_cookie_url
|
14
13
|
|
15
|
-
|
14
|
+
verify_cookies_count 1
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
cookie = browser.cookies.to_a.first
|
17
|
+
expect(cookie[:name]).to eq 'monster'
|
18
|
+
expect(cookie[:value]).to eq '1'
|
19
|
+
end
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
describe '#[]' do
|
22
|
+
before do
|
23
|
+
browser.goto set_cookie_url
|
24
|
+
verify_cookies_count 1
|
25
|
+
end
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
it 'returns cookie by symbol name' do
|
28
|
+
cookie = browser.cookies[:monster]
|
29
|
+
expect(cookie[:name]).to eq('monster')
|
30
|
+
expect(cookie[:value]).to eq('1')
|
31
|
+
end
|
33
32
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
33
|
+
it 'returns cookie by string name' do
|
34
|
+
cookie = browser.cookies['monster']
|
35
|
+
expect(cookie[:name]).to eq('monster')
|
36
|
+
expect(cookie[:value]).to eq('1')
|
37
|
+
end
|
39
38
|
|
40
|
-
|
41
|
-
|
42
|
-
end
|
39
|
+
it 'returns nil if there is no cookie with such name' do
|
40
|
+
expect(browser.cookies[:non_monster]).to eq(nil)
|
43
41
|
end
|
42
|
+
end
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
not_compliant_on :internet_explorer do
|
45
|
+
it 'adds a cookie' do
|
46
|
+
browser.goto set_cookie_url
|
47
|
+
verify_cookies_count 1
|
49
48
|
|
50
|
-
|
51
|
-
|
49
|
+
browser.cookies.add 'foo', 'bar'
|
50
|
+
verify_cookies_count 2
|
52
51
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
52
|
+
compliant_on :safari do
|
53
|
+
$browser.close
|
54
|
+
$browser = WatirSpec.new_browser
|
57
55
|
end
|
58
56
|
end
|
57
|
+
end
|
59
58
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
59
|
+
# TODO - Split this up into multiple tests or figure out which parts are not compliant
|
60
|
+
not_compliant_on :chrome, :internet_explorer, :safari, :firefox do
|
61
|
+
it 'adds a cookie with options' do
|
62
|
+
browser.goto set_cookie_url
|
64
63
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
64
|
+
expires = Time.now + 10000
|
65
|
+
options = {path: "/set_cookie",
|
66
|
+
secure: true,
|
67
|
+
expires: expires}
|
69
68
|
|
70
|
-
|
71
|
-
|
72
|
-
|
69
|
+
browser.cookies.add 'a', 'b', options
|
70
|
+
cookie = browser.cookies.to_a.find { |e| e[:name] == 'a' }
|
71
|
+
expect(cookie).to_not be_nil
|
73
72
|
|
74
|
-
|
75
|
-
|
73
|
+
expect(cookie[:name]).to eq 'a'
|
74
|
+
expect(cookie[:value]).to eq 'b'
|
76
75
|
|
77
|
-
|
78
|
-
|
76
|
+
expect(cookie[:path]).to eq "/set_cookie"
|
77
|
+
expect(cookie[:secure]).to be true
|
79
78
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
end
|
79
|
+
expect(cookie[:expires]).to be_kind_of(Time)
|
80
|
+
# a few ms slack
|
81
|
+
expect((cookie[:expires]).to_i).to be_within(2).of(expires.to_i)
|
84
82
|
end
|
83
|
+
end
|
85
84
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
85
|
+
not_compliant_on :internet_explorer do
|
86
|
+
it 'removes a cookie' do
|
87
|
+
browser.goto set_cookie_url
|
88
|
+
verify_cookies_count 1
|
90
89
|
|
91
|
-
|
92
|
-
|
93
|
-
|
90
|
+
browser.cookies.delete 'monster'
|
91
|
+
verify_cookies_count 0
|
92
|
+
end
|
94
93
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
94
|
+
bug "https://code.google.com/p/selenium/issues/detail?id=5487", :safari do
|
95
|
+
it 'clears all cookies' do
|
96
|
+
browser.goto set_cookie_url
|
97
|
+
browser.cookies.add 'foo', 'bar'
|
98
|
+
verify_cookies_count 2
|
100
99
|
|
101
|
-
|
102
|
-
|
103
|
-
end
|
100
|
+
browser.cookies.clear
|
101
|
+
verify_cookies_count 0
|
104
102
|
end
|
105
103
|
end
|
104
|
+
end
|
106
105
|
|
107
|
-
|
108
|
-
|
106
|
+
not_compliant_on :internet_explorer do
|
107
|
+
let(:file) { "#{Dir.tmpdir}/cookies" }
|
109
108
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
109
|
+
before do
|
110
|
+
browser.goto set_cookie_url
|
111
|
+
browser.cookies.save file
|
112
|
+
end
|
114
113
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
end
|
114
|
+
describe '#save' do
|
115
|
+
it 'saves cookies to file' do
|
116
|
+
expect(IO.read(file)).to eq(browser.cookies.to_a.to_yaml)
|
119
117
|
end
|
118
|
+
end
|
120
119
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
120
|
+
describe '#load' do
|
121
|
+
it 'loads cookies from file' do
|
122
|
+
browser.cookies.clear
|
123
|
+
browser.cookies.load file
|
124
|
+
expected = browser.cookies.to_a
|
125
|
+
actual = YAML.load(IO.read(file))
|
127
126
|
|
128
|
-
|
129
|
-
|
130
|
-
|
127
|
+
# https://code.google.com/p/selenium/issues/detail?id=6834
|
128
|
+
expected.each { |cookie| cookie.delete(:expires) }
|
129
|
+
actual.each { |cookie| cookie.delete(:expires) }
|
131
130
|
|
132
|
-
|
133
|
-
end
|
131
|
+
expect(actual).to eq(expected)
|
134
132
|
end
|
135
133
|
end
|
134
|
+
end
|
136
135
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
136
|
+
def set_cookie_url
|
137
|
+
# add timestamp to url to avoid caching in IE8
|
138
|
+
WatirSpec.url_for('set_cookie/index.html') + "?t=#{Time.now.to_i + Time.now.usec}"
|
139
|
+
end
|
141
140
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
end
|
141
|
+
def verify_cookies_count expected_size
|
142
|
+
cookies = browser.cookies.to_a
|
143
|
+
expect(cookies.size).to eq(expected_size), "expected #{expected_size} cookies, got #{cookies.size}: #{cookies.inspect}"
|
146
144
|
end
|
147
145
|
end
|
@@ -166,9 +166,7 @@ describe "Div" do
|
|
166
166
|
it "fires the oncontextmenu event" do
|
167
167
|
browser.goto(WatirSpec.url_for("right_click.html"))
|
168
168
|
browser.div(id: "click").right_click
|
169
|
-
|
170
|
-
expect(messages.first).to eq 'right-clicked'
|
171
|
-
end
|
169
|
+
expect(messages.first).to eq 'right-clicked'
|
172
170
|
end
|
173
171
|
end
|
174
172
|
end
|
@@ -249,6 +249,20 @@ describe "Element" do
|
|
249
249
|
end
|
250
250
|
end
|
251
251
|
|
252
|
+
context "attribute presence" do
|
253
|
+
before { browser.goto WatirSpec.url_for("data_attributes.html") }
|
254
|
+
|
255
|
+
it "finds element by attribute presence" do
|
256
|
+
expect(browser.p(data_type: true)).to exist
|
257
|
+
expect(browser.p(class: true)).not_to exist
|
258
|
+
end
|
259
|
+
|
260
|
+
it "finds element by attribute absence" do
|
261
|
+
expect(browser.p(data_type: false)).not_to exist
|
262
|
+
expect(browser.p(class: false)).to exist
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
252
266
|
it "doesn't raise when called on nested elements" do
|
253
267
|
expect(browser.div(id: 'no_such_div').link(id: 'no_such_id')).to_not exist
|
254
268
|
end
|
@@ -277,8 +291,7 @@ describe "Element" do
|
|
277
291
|
bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1255906", :firefox do
|
278
292
|
describe '#send_keys' do
|
279
293
|
before(:each) do
|
280
|
-
|
281
|
-
@c = Selenium::WebDriver::Platform.mac? && !phantom ? :command : :control
|
294
|
+
@c = Selenium::WebDriver::Platform.mac? ? :command : :control
|
282
295
|
browser.goto(WatirSpec.url_for('keylogger.html'))
|
283
296
|
end
|
284
297
|
|
@@ -110,20 +110,18 @@ describe "FileField" do
|
|
110
110
|
describe "#set" do
|
111
111
|
not_compliant_on :safari do
|
112
112
|
bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1260233", :firefox do
|
113
|
-
|
114
|
-
|
115
|
-
browser.goto WatirSpec.url_for("forms_with_input_elements.html")
|
113
|
+
it "is able to set a file path in the field and click the upload button and fire the onchange event" do
|
114
|
+
browser.goto WatirSpec.url_for("forms_with_input_elements.html")
|
116
115
|
|
117
|
-
|
118
|
-
|
116
|
+
path = File.expand_path(__FILE__)
|
117
|
+
element = browser.file_field(name: "new_user_portrait")
|
119
118
|
|
120
|
-
|
119
|
+
element.set path
|
121
120
|
|
122
|
-
|
123
|
-
|
121
|
+
expect(element.value).to include(File.basename(path)) # only some browser will return the full path
|
122
|
+
expect(messages.first).to include(File.basename(path))
|
124
123
|
|
125
|
-
|
126
|
-
end
|
124
|
+
browser.button(name: "new_user_submit").click
|
127
125
|
end
|
128
126
|
|
129
127
|
it "raises an error if the file does not exist" do
|
@@ -135,41 +133,38 @@ describe "FileField" do
|
|
135
133
|
end
|
136
134
|
end
|
137
135
|
|
136
|
+
not_compliant_on :safari do
|
137
|
+
describe "#value=" do
|
138
|
+
bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1260233", :firefox do
|
139
|
+
it "is able to set a file path in the field and click the upload button and fire the onchange event" do
|
140
|
+
browser.goto WatirSpec.url_for("forms_with_input_elements.html")
|
138
141
|
|
139
|
-
|
140
|
-
|
141
|
-
describe "#value=" do
|
142
|
-
bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1260233", :firefox do
|
143
|
-
it "is able to set a file path in the field and click the upload button and fire the onchange event" do
|
144
|
-
browser.goto WatirSpec.url_for("forms_with_input_elements.html")
|
145
|
-
|
146
|
-
path = File.expand_path(__FILE__)
|
147
|
-
element = browser.file_field(name: "new_user_portrait")
|
142
|
+
path = File.expand_path(__FILE__)
|
143
|
+
element = browser.file_field(name: "new_user_portrait")
|
148
144
|
|
149
|
-
|
150
|
-
|
151
|
-
|
145
|
+
element.value = path
|
146
|
+
expect(element.value).to include(File.basename(path)) # only some browser will return the full path
|
147
|
+
end
|
152
148
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
149
|
+
not_compliant_on :internet_explorer do
|
150
|
+
bug "Raises File not found error - File Bug Report", :firefox do
|
151
|
+
it "does not raise an error if the file does not exist" do
|
152
|
+
path = File.join(Dir.tmpdir, 'unlikely-to-exist')
|
153
|
+
browser.file_field.value = path
|
158
154
|
|
159
|
-
|
160
|
-
|
155
|
+
expected = path
|
156
|
+
expected.gsub!("/", "\\") if Selenium::WebDriver::Platform.windows?
|
161
157
|
|
162
|
-
|
163
|
-
end
|
158
|
+
expect(browser.file_field.value).to include(File.basename(expected)) # only some browser will return the full path
|
164
159
|
end
|
160
|
+
end
|
165
161
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
end
|
162
|
+
not_compliant_on %i(chrome windows) do
|
163
|
+
bug "Raises File not found error - File Bug Report", :firefox do
|
164
|
+
it "does not alter its argument" do
|
165
|
+
value = '/foo/bar'
|
166
|
+
browser.file_field.value = value
|
167
|
+
expect(value).to eq '/foo/bar'
|
173
168
|
end
|
174
169
|
end
|
175
170
|
end
|
@@ -50,15 +50,13 @@ describe "Frame" do
|
|
50
50
|
expect(browser.frame(xpath: "//frame[@id='no_such_id']")).to_not exist
|
51
51
|
end
|
52
52
|
|
53
|
-
bug "https://
|
54
|
-
|
55
|
-
|
56
|
-
browser.goto(WatirSpec.url_for("nested_frames.html"))
|
53
|
+
bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1255946", :firefox do
|
54
|
+
it "handles nested frames" do
|
55
|
+
browser.goto(WatirSpec.url_for("nested_frames.html"))
|
57
56
|
|
58
|
-
|
57
|
+
browser.frame(id: "two").frame(id: "three").link(id: "four").click
|
59
58
|
|
60
|
-
|
61
|
-
end
|
59
|
+
Watir::Wait.until { browser.title == "definition_lists" }
|
62
60
|
end
|
63
61
|
end
|
64
62
|
|
@@ -82,15 +82,13 @@ describe "IFrame" do
|
|
82
82
|
end
|
83
83
|
|
84
84
|
|
85
|
-
bug "https://
|
86
|
-
|
87
|
-
|
88
|
-
browser.goto(WatirSpec.url_for("nested_iframes.html"))
|
85
|
+
bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1255946", :firefox do
|
86
|
+
it "handles nested iframes" do
|
87
|
+
browser.goto(WatirSpec.url_for("nested_iframes.html"))
|
89
88
|
|
90
|
-
|
89
|
+
browser.iframe(id: "two").iframe(id: "three").link(id: "four").click
|
91
90
|
|
92
|
-
|
93
|
-
end
|
91
|
+
Watir::Wait.until { browser.title == "definition_lists" }
|
94
92
|
end
|
95
93
|
end
|
96
94
|
|
@@ -102,6 +102,18 @@ describe "SelectList" do
|
|
102
102
|
expect { browser.select_list(index: 1337).value }.to raise_unknown_object_exception
|
103
103
|
end
|
104
104
|
end
|
105
|
+
|
106
|
+
describe "#text" do
|
107
|
+
it "returns the text of the selected option" do
|
108
|
+
expect(browser.select_list(index: 0).text).to eq "Norway"
|
109
|
+
browser.select_list(index: 0).select(/Sweden/)
|
110
|
+
expect(browser.select_list(index: 0).text).to eq "Sweden"
|
111
|
+
end
|
112
|
+
|
113
|
+
it "raises UnknownObjectException if the select list doesn't exist" do
|
114
|
+
expect { browser.select_list(index: 1337).text }.to raise_unknown_object_exception
|
115
|
+
end
|
116
|
+
end
|
105
117
|
|
106
118
|
describe "#respond_to?" do
|
107
119
|
it "returns true for all attribute methods" do
|
@@ -189,12 +201,10 @@ describe "SelectList" do
|
|
189
201
|
end
|
190
202
|
|
191
203
|
not_compliant_on :safari do
|
192
|
-
bug "
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
expect(messages.size).to eq 2
|
197
|
-
end
|
204
|
+
bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1255957", :firefox do
|
205
|
+
it "fires onchange event" do
|
206
|
+
browser.select_list(name: "new_user_languages").clear
|
207
|
+
expect(messages.size).to eq 2
|
198
208
|
end
|
199
209
|
end
|
200
210
|
|
@@ -305,23 +315,19 @@ describe "SelectList" do
|
|
305
315
|
end
|
306
316
|
|
307
317
|
not_compliant_on :safari do
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
expect(messages).to eq ['changed language']
|
312
|
-
end
|
318
|
+
it "fires onchange event when selecting an item" do
|
319
|
+
browser.select_list(id: "new_user_languages").select("Danish")
|
320
|
+
expect(messages).to eq ['changed language']
|
313
321
|
end
|
314
322
|
|
315
|
-
bug "
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
expect(messages.size).to eq 3
|
323
|
+
bug "https://bugzilla.mozilla.org/show_bug.cgi?id=1255957", :firefox do
|
324
|
+
it "doesn't fire onchange event when selecting an already selected item" do
|
325
|
+
browser.select_list(id: "new_user_languages").clear # removes the two pre-selected options
|
326
|
+
browser.select_list(id: "new_user_languages").select("English")
|
327
|
+
expect(messages.size).to eq 3
|
321
328
|
|
322
|
-
|
323
|
-
|
324
|
-
end
|
329
|
+
browser.select_list(id: "new_user_languages").select("English")
|
330
|
+
expect(messages.size).to eq 3
|
325
331
|
end
|
326
332
|
end
|
327
333
|
end
|