capybara-webkit 1.12.0 → 1.13.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 -3
- data/Appraisals +3 -2
- data/Gemfile.lock +26 -18
- data/NEWS.md +9 -0
- data/README.md +4 -1
- data/capybara-webkit.gemspec +1 -1
- data/gemfiles/{2.11.gemfile → 2.12.gemfile} +1 -1
- data/gemfiles/2.7.gemfile +1 -0
- data/lib/capybara/webkit/browser.rb +25 -1
- data/lib/capybara/webkit/configuration.rb +4 -1
- data/lib/capybara/webkit/driver.rb +4 -0
- data/lib/capybara/webkit/errors.rb +9 -0
- data/lib/capybara/webkit/matchers.rb +5 -3
- data/lib/capybara/webkit/node.rb +1 -1
- data/lib/capybara/webkit/version.rb +1 -1
- data/spec/browser_spec.rb +22 -8
- data/spec/capybara_webkit_builder_spec.rb +4 -4
- data/spec/connection_spec.rb +3 -4
- data/spec/cookie_jar_spec.rb +10 -10
- data/spec/driver_rendering_spec.rb +14 -14
- data/spec/driver_resize_window_spec.rb +8 -8
- data/spec/driver_spec.rb +388 -349
- data/spec/errors_spec.rb +1 -1
- data/spec/integration/session_spec.rb +31 -31
- data/spec/selenium_compatibility_spec.rb +1 -1
- data/spec/server_spec.rb +11 -11
- data/spec/spec_helper.rb +11 -4
- data/spec/support/app_runner.rb +1 -0
- data/spec/support/matchers/include_response.rb +2 -2
- metadata +6 -6
data/spec/cookie_jar_spec.rb
CHANGED
@@ -4,7 +4,7 @@ require 'capybara/webkit/cookie_jar'
|
|
4
4
|
describe Capybara::Webkit::CookieJar do
|
5
5
|
let(:browser) {
|
6
6
|
browser = double("Browser")
|
7
|
-
browser.
|
7
|
+
allow(browser).to receive(:get_cookies) { [
|
8
8
|
"cookie1=1; domain=.example.org; path=/",
|
9
9
|
"cookie1=2; domain=.example.org; path=/dir1/",
|
10
10
|
"cookie1=3; domain=.facebook.com; path=/",
|
@@ -17,32 +17,32 @@ describe Capybara::Webkit::CookieJar do
|
|
17
17
|
|
18
18
|
describe "#find" do
|
19
19
|
it "returns a cookie object" do
|
20
|
-
subject.find("cookie1", "www.facebook.com").domain.
|
20
|
+
expect(subject.find("cookie1", "www.facebook.com").domain).to eq ".facebook.com"
|
21
21
|
end
|
22
22
|
|
23
23
|
it "returns the right cookie for every given domain/path" do
|
24
|
-
subject.find("cookie1", "example.org").value.
|
25
|
-
subject.find("cookie1", "www.facebook.com").value.
|
26
|
-
subject.find("cookie2", "sub1.example.org").value.
|
24
|
+
expect(subject.find("cookie1", "example.org").value).to eq "1"
|
25
|
+
expect(subject.find("cookie1", "www.facebook.com").value).to eq "3"
|
26
|
+
expect(subject.find("cookie2", "sub1.example.org").value).to eq "4"
|
27
27
|
end
|
28
28
|
|
29
29
|
it "does not return a cookie from other domain" do
|
30
|
-
subject.find("cookie2", "www.example.org").
|
30
|
+
expect(subject.find("cookie2", "www.example.org")).to eq nil
|
31
31
|
end
|
32
32
|
|
33
33
|
it "respects path precedence rules" do
|
34
|
-
subject.find("cookie1", "www.example.org").value.
|
35
|
-
subject.find("cookie1", "www.example.org", "/dir1/123").value.
|
34
|
+
expect(subject.find("cookie1", "www.example.org").value).to eq "1"
|
35
|
+
expect(subject.find("cookie1", "www.example.org", "/dir1/123").value).to eq "2"
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
describe "#[]" do
|
40
40
|
it "returns the first matching cookie's value" do
|
41
|
-
subject["cookie1", "example.org"].
|
41
|
+
expect(subject["cookie1", "example.org"]).to eq "1"
|
42
42
|
end
|
43
43
|
|
44
44
|
it "returns nil if no cookie is found" do
|
45
|
-
subject["notexisting"].
|
45
|
+
expect(subject["notexisting"]).to eq nil
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -34,16 +34,16 @@ describe Capybara::Webkit::Driver, "rendering an image" do
|
|
34
34
|
before { render({}) }
|
35
35
|
|
36
36
|
it "should be a PNG" do
|
37
|
-
@image[:format].
|
37
|
+
expect(@image[:format]).to eq "PNG"
|
38
38
|
end
|
39
39
|
|
40
40
|
it "width default to 1000px (with 15px less for the scrollbar)" do
|
41
|
-
@image[:width].
|
42
|
-
@image[:width].
|
41
|
+
expect(@image[:width]).to be < 1001
|
42
|
+
expect(@image[:width]).to be > 1000-17
|
43
43
|
end
|
44
44
|
|
45
45
|
it "height should be at least 10px" do
|
46
|
-
@image[:height].
|
46
|
+
expect(@image[:height]).to be >= 10
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -51,16 +51,16 @@ describe Capybara::Webkit::Driver, "rendering an image" do
|
|
51
51
|
before { render(:width => 500, :height => 400) }
|
52
52
|
|
53
53
|
it "width should match the width given" do
|
54
|
-
@image[:width].
|
54
|
+
expect(@image[:width]).to eq 500
|
55
55
|
end
|
56
56
|
|
57
57
|
it "height should match the height given" do
|
58
|
-
@image[:height].
|
58
|
+
expect(@image[:height]).to eq 400
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should reset window dimensions to their default value" do
|
62
|
-
driver.evaluate_script('window.innerWidth').
|
63
|
-
driver.evaluate_script('window.innerHeight').
|
62
|
+
expect(driver.evaluate_script('window.innerWidth')).to eq 1680
|
63
|
+
expect(driver.evaluate_script('window.innerHeight')).to eq 1050
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
@@ -68,16 +68,16 @@ describe Capybara::Webkit::Driver, "rendering an image" do
|
|
68
68
|
before { render(:width => 50, :height => 10) }
|
69
69
|
|
70
70
|
it "width should be greater than the width given" do
|
71
|
-
@image[:width].
|
71
|
+
expect(@image[:width]).to be > 50
|
72
72
|
end
|
73
73
|
|
74
74
|
it "height should be greater than the height given" do
|
75
|
-
@image[:height].
|
75
|
+
expect(@image[:height]).to be > 10
|
76
76
|
end
|
77
77
|
|
78
78
|
it "should restore viewport dimensions after rendering" do
|
79
|
-
driver.evaluate_script('window.innerWidth').
|
80
|
-
driver.evaluate_script('window.innerHeight').
|
79
|
+
expect(driver.evaluate_script('window.innerWidth')).to eq 1680
|
80
|
+
expect(driver.evaluate_script('window.innerHeight')).to eq 1050
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
@@ -86,8 +86,8 @@ describe Capybara::Webkit::Driver, "rendering an image" do
|
|
86
86
|
|
87
87
|
it "should restore viewport dimensions after rendering" do
|
88
88
|
render({})
|
89
|
-
driver.evaluate_script('window.innerWidth').
|
90
|
-
driver.evaluate_script('window.innerHeight').
|
89
|
+
expect(driver.evaluate_script('window.innerWidth')).to eq 800
|
90
|
+
expect(driver.evaluate_script('window.innerHeight')).to eq 600
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
@@ -27,23 +27,23 @@ describe Capybara::Webkit::Driver, "#resize_window(width, height)" do
|
|
27
27
|
driver.visit("#{AppRunner.app_host}/")
|
28
28
|
|
29
29
|
driver.resize_window(800, 600)
|
30
|
-
driver.html.
|
30
|
+
expect(driver.html).to include("[800x600]")
|
31
31
|
|
32
32
|
driver.resize_window(300, 100)
|
33
|
-
driver.html.
|
33
|
+
expect(driver.html).to include("[300x100]")
|
34
34
|
end
|
35
35
|
|
36
36
|
it "resizes the window to the specified size even before the document has loaded" do
|
37
37
|
driver.resize_window(800, 600)
|
38
38
|
driver.visit("#{AppRunner.app_host}/")
|
39
|
-
driver.html.
|
39
|
+
expect(driver.html).to include("[800x600]")
|
40
40
|
end
|
41
41
|
|
42
42
|
it "resets the window to the default size when the driver is reset" do
|
43
43
|
driver.resize_window(800, 600)
|
44
44
|
driver.reset!
|
45
45
|
driver.visit("#{AppRunner.app_host}/")
|
46
|
-
driver.html.
|
46
|
+
expect(driver.html).to include(DEFAULT_DIMENTIONS)
|
47
47
|
end
|
48
48
|
|
49
49
|
it "resizes windows by handle" do
|
@@ -54,8 +54,8 @@ describe Capybara::Webkit::Driver, "#resize_window(width, height)" do
|
|
54
54
|
driver.resize_window_to(driver.window_handles.first, 800, 600)
|
55
55
|
driver.resize_window_to(driver.window_handles.last, 400, 300)
|
56
56
|
|
57
|
-
driver.window_size(driver.window_handles.first).
|
58
|
-
driver.window_size(driver.window_handles.last).
|
57
|
+
expect(driver.window_size(driver.window_handles.first)).to eq [800, 600]
|
58
|
+
expect(driver.window_size(driver.window_handles.last)).to eq [400, 300]
|
59
59
|
end
|
60
60
|
|
61
61
|
it "maximizes a window" do
|
@@ -64,7 +64,7 @@ describe Capybara::Webkit::Driver, "#resize_window(width, height)" do
|
|
64
64
|
driver.maximize_window(driver.current_window_handle)
|
65
65
|
width, height = *driver.window_size(driver.current_window_handle)
|
66
66
|
|
67
|
-
width.
|
68
|
-
height.
|
67
|
+
expect(width).to be > 400
|
68
|
+
expect(height).to be > 300
|
69
69
|
end
|
70
70
|
end
|
data/spec/driver_spec.rb
CHANGED
@@ -90,13 +90,13 @@ describe Capybara::Webkit::Driver do
|
|
90
90
|
|
91
91
|
it "finds frames by index" do
|
92
92
|
driver.within_frame(0) do
|
93
|
-
driver.find_xpath("//*[contains(., 'goodbye')]").
|
93
|
+
expect(driver.find_xpath("//*[contains(., 'goodbye')]")).not_to be_empty
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
97
|
it "finds frames by id" do
|
98
98
|
driver.within_frame("f") do
|
99
|
-
driver.find_xpath("//*[contains(., 'goodbye')]").
|
99
|
+
expect(driver.find_xpath("//*[contains(., 'goodbye')]")).not_to be_empty
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
@@ -104,7 +104,7 @@ describe Capybara::Webkit::Driver do
|
|
104
104
|
frame = driver.find_xpath('//iframe').first
|
105
105
|
element = double(Capybara::Node::Base, base: frame)
|
106
106
|
driver.within_frame(element) do
|
107
|
-
driver.find_xpath("//*[contains(., 'goodbye')]").
|
107
|
+
expect(driver.find_xpath("//*[contains(., 'goodbye')]")).not_to be_empty
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
@@ -112,7 +112,7 @@ describe Capybara::Webkit::Driver do
|
|
112
112
|
frame = driver.find_xpath('//iframe').first
|
113
113
|
element = double(Capybara::Node::Base, base: frame)
|
114
114
|
driver.switch_to_frame(element)
|
115
|
-
driver.find_xpath("//*[contains(., 'goodbye')]").
|
115
|
+
expect(driver.find_xpath("//*[contains(., 'goodbye')]")).not_to be_empty
|
116
116
|
driver.switch_to_frame(:parent)
|
117
117
|
end
|
118
118
|
|
@@ -121,8 +121,8 @@ describe Capybara::Webkit::Driver do
|
|
121
121
|
element = double(Capybara::Node::Base, base: frame)
|
122
122
|
driver.switch_to_frame(element)
|
123
123
|
driver.switch_to_frame(:parent)
|
124
|
-
driver.find_xpath("//*[contains(., 'greeting')]").
|
125
|
-
driver.find_xpath("//*[contains(., 'goodbye')]").
|
124
|
+
expect(driver.find_xpath("//*[contains(., 'greeting')]")).not_to be_empty
|
125
|
+
expect(driver.find_xpath("//*[contains(., 'goodbye')]")).to be_empty
|
126
126
|
end
|
127
127
|
|
128
128
|
it "can switch to the top frame" do
|
@@ -132,11 +132,11 @@ describe Capybara::Webkit::Driver do
|
|
132
132
|
frame2 = driver.find_xpath('//iframe[@id="g"]').first
|
133
133
|
element2 = double(Capybara::Node::Base, base: frame2)
|
134
134
|
driver.switch_to_frame(element2)
|
135
|
-
driver.find_xpath("//div[contains(., 'In frame 2')]").
|
135
|
+
expect(driver.find_xpath("//div[contains(., 'In frame 2')]")).not_to be_empty
|
136
136
|
driver.switch_to_frame(:top)
|
137
|
-
driver.find_xpath("//*[contains(., 'greeting')]").
|
138
|
-
driver.find_xpath("//*[contains(., 'goodbye')]").
|
139
|
-
driver.find_xpath("//div[contains(., 'In frame 2')]").
|
137
|
+
expect(driver.find_xpath("//*[contains(., 'greeting')]")).not_to be_empty
|
138
|
+
expect(driver.find_xpath("//*[contains(., 'goodbye')]")).to be_empty
|
139
|
+
expect(driver.find_xpath("//div[contains(., 'In frame 2')]")).to be_empty
|
140
140
|
end
|
141
141
|
|
142
142
|
it "raises error for missing frame by index" do
|
@@ -151,42 +151,42 @@ describe Capybara::Webkit::Driver do
|
|
151
151
|
|
152
152
|
it "returns an attribute's value" do
|
153
153
|
driver.within_frame("f") do
|
154
|
-
driver.find_xpath("//p").first["id"].
|
154
|
+
expect(driver.find_xpath("//p").first["id"]).to eq "farewell"
|
155
155
|
end
|
156
156
|
end
|
157
157
|
|
158
158
|
it "returns an attribute's innerHTML" do
|
159
|
-
driver.find_xpath('//body').first.inner_html.
|
159
|
+
expect(driver.find_xpath('//body').first.inner_html).to match %r{<iframe.*</iframe>.*<script.*</script>.*}m
|
160
160
|
end
|
161
161
|
|
162
162
|
it "receive an attribute's innerHTML" do
|
163
163
|
driver.find_xpath('//body').first.inner_html = 'foobar'
|
164
|
-
driver.find_xpath("//body[contains(., 'foobar')]").
|
164
|
+
expect(driver.find_xpath("//body[contains(., 'foobar')]")).not_to be_empty
|
165
165
|
end
|
166
166
|
|
167
167
|
it "returns a node's text" do
|
168
168
|
driver.within_frame("f") do
|
169
|
-
driver.find_xpath("//p").first.visible_text.
|
169
|
+
expect(driver.find_xpath("//p").first.visible_text).to eq "goodbye"
|
170
170
|
end
|
171
171
|
end
|
172
172
|
|
173
173
|
it "returns the current URL" do
|
174
174
|
driver.within_frame("f") do
|
175
|
-
driver.current_url.
|
175
|
+
expect(driver.current_url).to eq driver_url(driver, "/iframe")
|
176
176
|
end
|
177
177
|
end
|
178
178
|
|
179
179
|
it "evaluates Javascript" do
|
180
180
|
driver.within_frame("f") do
|
181
181
|
result = driver.evaluate_script(%<document.getElementById('farewell').innerText>)
|
182
|
-
result.
|
182
|
+
expect(result).to eq "goodbye"
|
183
183
|
end
|
184
184
|
end
|
185
185
|
|
186
186
|
it "executes Javascript" do
|
187
187
|
driver.within_frame("f") do
|
188
188
|
driver.execute_script(%<document.getElementById('farewell').innerHTML = 'yo'>)
|
189
|
-
driver.find_xpath("//p[contains(., 'yo')]").
|
189
|
+
expect(driver.find_xpath("//p[contains(., 'yo')]")).not_to be_empty
|
190
190
|
end
|
191
191
|
end
|
192
192
|
|
@@ -195,24 +195,24 @@ describe Capybara::Webkit::Driver do
|
|
195
195
|
|
196
196
|
driver.within_frame("f") {}
|
197
197
|
|
198
|
-
driver.current_url.
|
198
|
+
expect(driver.current_url).to eq original_url
|
199
199
|
end
|
200
200
|
|
201
201
|
it "returns the headers for the page" do
|
202
202
|
driver.within_frame("f") do
|
203
|
-
driver.response_headers['X-Redirected'].
|
203
|
+
expect(driver.response_headers['X-Redirected']).to eq "true"
|
204
204
|
end
|
205
205
|
end
|
206
206
|
|
207
207
|
it "returns the status code for the page" do
|
208
208
|
driver.within_frame("f") do
|
209
|
-
driver.status_code.
|
209
|
+
expect(driver.status_code).to eq 200
|
210
210
|
end
|
211
211
|
end
|
212
212
|
|
213
213
|
it "returns the document title" do
|
214
214
|
driver.within_frame("f") do
|
215
|
-
driver.title.
|
215
|
+
expect(driver.title).to eq "Title"
|
216
216
|
end
|
217
217
|
end
|
218
218
|
end
|
@@ -281,35 +281,35 @@ describe Capybara::Webkit::Driver do
|
|
281
281
|
it "should redirect without content type" do
|
282
282
|
visit("/form")
|
283
283
|
driver.find_xpath("//input").first.click
|
284
|
-
driver.find_xpath("//p").first.visible_text.
|
284
|
+
expect(driver.find_xpath("//p").first.visible_text).to eq ""
|
285
285
|
end
|
286
286
|
|
287
287
|
it "returns the current URL when changed by pushState after a redirect" do
|
288
288
|
visit("/redirect-me")
|
289
|
-
driver.current_url.
|
289
|
+
expect(driver.current_url).to eq driver_url(driver, "/target")
|
290
290
|
driver.execute_script("window.history.pushState({}, '', '/pushed-after-redirect')")
|
291
|
-
driver.current_url.
|
291
|
+
expect(driver.current_url).to eq driver_url(driver, "/pushed-after-redirect")
|
292
292
|
end
|
293
293
|
|
294
294
|
it "returns the current URL when changed by replaceState after a redirect" do
|
295
295
|
visit("/redirect-me")
|
296
|
-
driver.current_url.
|
296
|
+
expect(driver.current_url).to eq driver_url(driver, "/target")
|
297
297
|
driver.execute_script("window.history.replaceState({}, '', '/replaced-after-redirect')")
|
298
|
-
driver.current_url.
|
298
|
+
expect(driver.current_url).to eq driver_url(driver, "/replaced-after-redirect")
|
299
299
|
end
|
300
300
|
|
301
301
|
it "should make headers available through response_headers" do
|
302
302
|
visit('/redirect-me')
|
303
|
-
driver.response_headers['X-Redirected'].
|
303
|
+
expect(driver.response_headers['X-Redirected']).to eq "true"
|
304
304
|
visit('/target')
|
305
|
-
driver.response_headers['X-Redirected'].
|
305
|
+
expect(driver.response_headers['X-Redirected']).to eq "false"
|
306
306
|
end
|
307
307
|
|
308
308
|
it "should make the status code available through status_code" do
|
309
309
|
visit('/redirect-me')
|
310
|
-
driver.status_code.
|
310
|
+
expect(driver.status_code).to eq 200
|
311
311
|
visit('/target')
|
312
|
-
driver.status_code.
|
312
|
+
expect(driver.status_code).to eq 200
|
313
313
|
end
|
314
314
|
end
|
315
315
|
|
@@ -326,15 +326,15 @@ describe Capybara::Webkit::Driver do
|
|
326
326
|
before { visit("/") }
|
327
327
|
|
328
328
|
it "renders unsupported content types gracefully" do
|
329
|
-
driver.html.
|
329
|
+
expect(driver.html).to match /css/
|
330
330
|
end
|
331
331
|
|
332
332
|
it "sets the response headers with respect to the unsupported request" do
|
333
|
-
driver.response_headers["Content-Type"].
|
333
|
+
expect(driver.response_headers["Content-Type"]).to eq "text/css"
|
334
334
|
end
|
335
335
|
|
336
336
|
it "does not wrap the content in HTML tags" do
|
337
|
-
driver.html.
|
337
|
+
expect(driver.html).not_to match /<html>/
|
338
338
|
end
|
339
339
|
end
|
340
340
|
|
@@ -355,7 +355,7 @@ describe Capybara::Webkit::Driver do
|
|
355
355
|
before { visit("/") }
|
356
356
|
|
357
357
|
it "does not strip HTML tags" do
|
358
|
-
driver.html.
|
358
|
+
expect(driver.html).to match /<html>/
|
359
359
|
end
|
360
360
|
end
|
361
361
|
|
@@ -373,7 +373,7 @@ describe Capybara::Webkit::Driver do
|
|
373
373
|
|
374
374
|
it "should return the binary content" do
|
375
375
|
src = driver.html.force_encoding('binary')
|
376
|
-
src.
|
376
|
+
expect(src).to eq "Hello\xFF\xFF\xFF\xFFWorld".force_encoding('binary')
|
377
377
|
end
|
378
378
|
end
|
379
379
|
|
@@ -417,28 +417,28 @@ describe Capybara::Webkit::Driver do
|
|
417
417
|
it "doesn't return text if the ancestor is hidden" do
|
418
418
|
visit("/")
|
419
419
|
|
420
|
-
driver.find_css("#hidden-ancestor div").first.text.
|
420
|
+
expect(driver.find_css("#hidden-ancestor div").first.text).to eq ''
|
421
421
|
end
|
422
422
|
|
423
423
|
it "handles anchor tags" do
|
424
424
|
visit("#test")
|
425
|
-
driver.find_xpath("//*[contains(., 'hello')]").
|
425
|
+
expect(driver.find_xpath("//*[contains(., 'hello')]")).not_to be_empty
|
426
426
|
visit("#test")
|
427
|
-
driver.find_xpath("//*[contains(., 'hello')]").
|
427
|
+
expect(driver.find_xpath("//*[contains(., 'hello')]")).not_to be_empty
|
428
428
|
end
|
429
429
|
|
430
430
|
it "finds content after loading a URL" do
|
431
|
-
driver.find_xpath("//*[contains(., 'hello')]").
|
431
|
+
expect(driver.find_xpath("//*[contains(., 'hello')]")).not_to be_empty
|
432
432
|
end
|
433
433
|
|
434
434
|
it "has an empty page after reseting" do
|
435
435
|
driver.reset!
|
436
|
-
driver.find_xpath("//*[contains(., 'hello')]").
|
436
|
+
expect(driver.find_xpath("//*[contains(., 'hello')]")).to be_empty
|
437
437
|
end
|
438
438
|
|
439
439
|
it "has a blank location after reseting" do
|
440
440
|
driver.reset!
|
441
|
-
driver.current_url.
|
441
|
+
expect(driver.current_url).to eq "about:blank"
|
442
442
|
end
|
443
443
|
|
444
444
|
it "raises an error for an invalid xpath query" do
|
@@ -452,119 +452,119 @@ describe Capybara::Webkit::Driver do
|
|
452
452
|
end
|
453
453
|
|
454
454
|
it "returns an attribute's value" do
|
455
|
-
driver.find_xpath("//p").first["id"].
|
455
|
+
expect(driver.find_xpath("//p").first["id"]).to eq "greeting"
|
456
456
|
end
|
457
457
|
|
458
458
|
it "parses xpath with quotes" do
|
459
|
-
driver.find_xpath('//*[contains(., "hello")]').
|
459
|
+
expect(driver.find_xpath('//*[contains(., "hello")]')).not_to be_empty
|
460
460
|
end
|
461
461
|
|
462
462
|
it "returns a node's visible text" do
|
463
|
-
driver.find_xpath("//*[@id='hidden-text']").first.visible_text.
|
463
|
+
expect(driver.find_xpath("//*[@id='hidden-text']").first.visible_text).to eq "Some of this text is"
|
464
464
|
end
|
465
465
|
|
466
466
|
it "normalizes a node's text" do
|
467
|
-
driver.find_xpath("//div[contains(@class, 'normalize')]").first.visible_text.
|
467
|
+
expect(driver.find_xpath("//div[contains(@class, 'normalize')]").first.visible_text).to eq "Spaces not normalized"
|
468
468
|
end
|
469
469
|
|
470
470
|
it "returns all of a node's text" do
|
471
|
-
driver.find_xpath("//*[@id='hidden-text']").first.all_text.
|
471
|
+
expect(driver.find_xpath("//*[@id='hidden-text']").first.all_text).to eq "Some of this text is hidden!"
|
472
472
|
end
|
473
473
|
|
474
474
|
it "returns the current URL" do
|
475
475
|
visit "/hello/world?success=true"
|
476
|
-
driver.current_url.
|
476
|
+
expect(driver.current_url).to eq driver_url(driver, "/hello/world?success=true")
|
477
477
|
end
|
478
478
|
|
479
479
|
it "returns the current URL when changed by pushState" do
|
480
480
|
driver.execute_script("window.history.pushState({}, '', '/pushed')")
|
481
|
-
driver.current_url.
|
481
|
+
expect(driver.current_url).to eq driver_url(driver, "/pushed")
|
482
482
|
end
|
483
483
|
|
484
484
|
it "returns the current URL when changed by replaceState" do
|
485
485
|
driver.execute_script("window.history.replaceState({}, '', '/replaced')")
|
486
|
-
driver.current_url.
|
486
|
+
expect(driver.current_url).to eq driver_url(driver, "/replaced")
|
487
487
|
end
|
488
488
|
|
489
489
|
it "does not double-encode URLs" do
|
490
490
|
visit("/hello/world?success=%25true")
|
491
|
-
driver.current_url.
|
491
|
+
expect(driver.current_url).to match /success=\%25true/
|
492
492
|
end
|
493
493
|
|
494
494
|
it "returns the current URL with encoded characters" do
|
495
495
|
visit("/hello/world?success[value]=true")
|
496
496
|
current_url = Rack::Utils.unescape(driver.current_url)
|
497
|
-
current_url.
|
497
|
+
expect(current_url).to include('success[value]=true')
|
498
498
|
end
|
499
499
|
|
500
500
|
it "visits a page with an anchor" do
|
501
501
|
visit("/hello#display_none")
|
502
|
-
driver.current_url.
|
502
|
+
expect(driver.current_url).to match /hello#display_none/
|
503
503
|
end
|
504
504
|
|
505
505
|
it "evaluates Javascript and returns a string" do
|
506
506
|
result = driver.evaluate_script(%<document.getElementById('greeting').innerText>)
|
507
|
-
result.
|
507
|
+
expect(result).to eq "hello"
|
508
508
|
end
|
509
509
|
|
510
510
|
it "evaluates Javascript and returns an array" do
|
511
511
|
result = driver.evaluate_script(%<["hello", "world"]>)
|
512
|
-
result.
|
512
|
+
expect(result).to eq %w(hello world)
|
513
513
|
end
|
514
514
|
|
515
515
|
it "evaluates Javascript and returns an int" do
|
516
516
|
result = driver.evaluate_script(%<123>)
|
517
|
-
result.
|
517
|
+
expect(result).to eq 123
|
518
518
|
end
|
519
519
|
|
520
520
|
it "evaluates Javascript and returns a float" do
|
521
521
|
result = driver.evaluate_script(%<1.5>)
|
522
|
-
result.
|
522
|
+
expect(result).to eq 1.5
|
523
523
|
end
|
524
524
|
|
525
525
|
it "evaluates Javascript and returns null" do
|
526
526
|
result = driver.evaluate_script(%<(function () {})()>)
|
527
|
-
result.
|
527
|
+
expect(result).to eq nil
|
528
528
|
end
|
529
529
|
|
530
530
|
it "evaluates Infinity and returns null" do
|
531
531
|
result = driver.evaluate_script(%<Infinity>)
|
532
|
-
result.
|
532
|
+
expect(result).to eq nil
|
533
533
|
end
|
534
534
|
|
535
535
|
it "evaluates Javascript and returns a date" do
|
536
536
|
result = driver.evaluate_script(%<new Date("2016-04-01T00:00:00Z")>)
|
537
|
-
result.
|
537
|
+
expect(result).to eq "2016-04-01T00:00:00Z"
|
538
538
|
end
|
539
539
|
|
540
540
|
it "evaluates Javascript and returns an object" do
|
541
541
|
result = driver.evaluate_script(%<({ 'one' : 1 })>)
|
542
|
-
result.
|
542
|
+
expect(result).to eq 'one' => 1
|
543
543
|
end
|
544
544
|
|
545
545
|
it "evaluates Javascript and returns true" do
|
546
546
|
result = driver.evaluate_script(%<true>)
|
547
|
-
result.
|
547
|
+
expect(result).to be true
|
548
548
|
end
|
549
549
|
|
550
550
|
it "evaluates Javascript and returns false" do
|
551
551
|
result = driver.evaluate_script(%<false>)
|
552
|
-
result.
|
552
|
+
expect(result).to be false
|
553
553
|
end
|
554
554
|
|
555
555
|
it "evaluates Javascript and returns an escaped string" do
|
556
556
|
result = driver.evaluate_script(%<'"'>)
|
557
|
-
result.
|
557
|
+
expect(result).to eq "\""
|
558
558
|
end
|
559
559
|
|
560
560
|
it "evaluates Javascript with multiple lines" do
|
561
561
|
result = driver.evaluate_script("[1,\n2]")
|
562
|
-
result.
|
562
|
+
expect(result).to eq [1, 2]
|
563
563
|
end
|
564
564
|
|
565
565
|
it "executes Javascript" do
|
566
566
|
driver.execute_script(%<document.getElementById('greeting').innerHTML = 'yo'>)
|
567
|
-
driver.find_xpath("//p[contains(., 'yo')]").
|
567
|
+
expect(driver.find_xpath("//p[contains(., 'yo')]")).not_to be_empty
|
568
568
|
end
|
569
569
|
|
570
570
|
it "raises an error for failing Javascript" do
|
@@ -574,65 +574,64 @@ describe Capybara::Webkit::Driver do
|
|
574
574
|
|
575
575
|
it "passes arguments to executed Javascript" do
|
576
576
|
driver.execute_script(%<document.getElementById('greeting').innerHTML = arguments[0]>, "My argument")
|
577
|
-
driver.find_xpath("//p[contains(., 'My argument')]").
|
577
|
+
expect(driver.find_xpath("//p[contains(., 'My argument')]")).not_to be_empty
|
578
578
|
end
|
579
579
|
|
580
580
|
it "passes multiple arguments to executed Javascript" do
|
581
581
|
driver.execute_script(
|
582
582
|
%<document.getElementById('greeting').innerHTML = arguments[0] + arguments[1] + arguments[2].color>,
|
583
583
|
"random", 4, {color: 'red'})
|
584
|
-
driver.find_xpath("//p[contains(., 'random4red')]").
|
584
|
+
expect(driver.find_xpath("//p[contains(., 'random4red')]")).not_to be_empty
|
585
585
|
end
|
586
586
|
|
587
587
|
it "passes page elements to executed Javascript" do
|
588
588
|
greeting = driver.find_xpath("//p[@id='greeting']").first
|
589
589
|
driver.execute_script(%<arguments[0].innerHTML = arguments[1]>, greeting, "new content")
|
590
|
-
driver.find_xpath("//p[@id='greeting'][contains(., 'new content')]").
|
590
|
+
expect(driver.find_xpath("//p[@id='greeting'][contains(., 'new content')]")).not_to be_empty
|
591
591
|
end
|
592
592
|
|
593
593
|
it "passes arguments to evaaluated Javascript" do
|
594
|
-
driver.evaluate_script(%<arguments[0]>, 3).
|
594
|
+
expect(driver.evaluate_script(%<arguments[0]>, 3)).to eq 3
|
595
595
|
end
|
596
596
|
|
597
597
|
it "passes multiple arguments to evaluated Javascript" do
|
598
|
-
driver.evaluate_script(%<arguments[0] + arguments[1] + arguments[2].num>, 3, 4, {num: 5}).
|
598
|
+
expect(driver.evaluate_script(%<arguments[0] + arguments[1] + arguments[2].num>, 3, 4, {num: 5})).to eq 12
|
599
599
|
end
|
600
600
|
|
601
601
|
it "passes page elements to evaluated Javascript" do
|
602
602
|
greeting = driver.find_xpath("//p[@id='greeting']").first
|
603
|
-
driver.evaluate_script(%<arguments[1].innerHTML = arguments[0]; arguments[2]>, "newer content", greeting, 7).
|
604
|
-
driver.find_xpath("//p[@id='greeting'][contains(., 'newer content')]").
|
603
|
+
expect(driver.evaluate_script(%<arguments[1].innerHTML = arguments[0]; arguments[2]>, "newer content", greeting, 7)).to eq 7
|
604
|
+
expect(driver.find_xpath("//p[@id='greeting'][contains(., 'newer content')]")).not_to be_empty
|
605
605
|
end
|
606
606
|
|
607
607
|
it "doesn't raise an error for Javascript that doesn't return anything" do
|
608
|
-
|
609
|
-
should_not raise_error
|
608
|
+
expect { driver.execute_script(%<(function () { "returns nothing" })()>) }.not_to raise_error
|
610
609
|
end
|
611
610
|
|
612
611
|
it "returns a node's tag name" do
|
613
|
-
driver.find_xpath("//p").first.tag_name.
|
612
|
+
expect(driver.find_xpath("//p").first.tag_name).to eq "p"
|
614
613
|
end
|
615
614
|
|
616
615
|
it "reads disabled property" do
|
617
|
-
driver.find_xpath("//input").first.
|
616
|
+
expect(driver.find_xpath("//input").first).to be_disabled
|
618
617
|
end
|
619
618
|
|
620
619
|
it "reads checked property" do
|
621
|
-
driver.find_xpath("//input[@id='checktest']").first.
|
620
|
+
expect(driver.find_xpath("//input[@id='checktest']").first).to be_checked
|
622
621
|
end
|
623
622
|
|
624
623
|
it "finds visible elements" do
|
625
|
-
driver.find_xpath("//p").first.
|
626
|
-
driver.find_xpath("//*[@id='invisible']").first.
|
627
|
-
driver.find_xpath("//*[@id='invisible_with_visibility']").first.
|
624
|
+
expect(driver.find_xpath("//p").first).to be_visible
|
625
|
+
expect(driver.find_xpath("//*[@id='invisible']").first).not_to be_visible
|
626
|
+
expect(driver.find_xpath("//*[@id='invisible_with_visibility']").first).not_to be_visible
|
628
627
|
end
|
629
628
|
|
630
629
|
it "returns the document title" do
|
631
|
-
driver.title.
|
630
|
+
expect(driver.title).to eq "Title"
|
632
631
|
end
|
633
632
|
|
634
633
|
it "finds elements by CSS" do
|
635
|
-
driver.find_css("p").first.visible_text.
|
634
|
+
expect(driver.find_css("p").first.visible_text).to eq "hello"
|
636
635
|
end
|
637
636
|
end
|
638
637
|
|
@@ -652,7 +651,7 @@ describe Capybara::Webkit::Driver do
|
|
652
651
|
before { visit("/") }
|
653
652
|
|
654
653
|
it "should handle text for svg elements" do
|
655
|
-
driver.find_xpath("//*[@id='navy_text']").first.visible_text.
|
654
|
+
expect(driver.find_xpath("//*[@id='navy_text']").first.visible_text).to eq "In the navy!"
|
656
655
|
end
|
657
656
|
end
|
658
657
|
|
@@ -670,7 +669,7 @@ describe Capybara::Webkit::Driver do
|
|
670
669
|
before { visit("/") }
|
671
670
|
|
672
671
|
it "has no visible text" do
|
673
|
-
driver.find_xpath("/html").first.text.
|
672
|
+
expect(driver.find_xpath("/html").first.text).to be_empty
|
674
673
|
end
|
675
674
|
end
|
676
675
|
|
@@ -699,34 +698,34 @@ describe Capybara::Webkit::Driver do
|
|
699
698
|
it "collects messages logged to the console" do
|
700
699
|
url = driver_url(driver, "/")
|
701
700
|
message = driver.console_messages.first
|
702
|
-
message.
|
703
|
-
[6, 7].
|
704
|
-
driver.console_messages.length.
|
701
|
+
expect(message).to include :source => url, :message => "hello"
|
702
|
+
expect([6, 7]).to include message[:line_number]
|
703
|
+
expect(driver.console_messages.length).to eq 5
|
705
704
|
end
|
706
705
|
|
707
706
|
it "logs errors to the console" do
|
708
|
-
driver.error_messages.length.
|
707
|
+
expect(driver.error_messages.length).to eq 1
|
709
708
|
end
|
710
709
|
|
711
710
|
it "supports multi-line console messages" do
|
712
711
|
message = driver.console_messages[2]
|
713
|
-
message[:message].
|
712
|
+
expect(message[:message]).to eq "hello\nnewline"
|
714
713
|
end
|
715
714
|
|
716
715
|
it "empties the array when reset" do
|
717
716
|
driver.reset!
|
718
|
-
driver.console_messages.
|
717
|
+
expect(driver.console_messages).to be_empty
|
719
718
|
end
|
720
719
|
|
721
720
|
it "supports console messages from an unknown source" do
|
722
721
|
driver.execute_script("console.log('hello')")
|
723
|
-
driver.console_messages.last[:message].
|
724
|
-
driver.console_messages.last[:source].
|
725
|
-
driver.console_messages.last[:line_number].
|
722
|
+
expect(driver.console_messages.last[:message]).to eq 'hello'
|
723
|
+
expect(driver.console_messages.last[:source]).to be_nil
|
724
|
+
expect(driver.console_messages.last[:line_number]).to be_nil
|
726
725
|
end
|
727
726
|
|
728
727
|
it "escapes unicode console messages" do
|
729
|
-
driver.console_messages[3][:message].
|
728
|
+
expect(driver.console_messages[3][:message]).to eq '𝄞'
|
730
729
|
end
|
731
730
|
end
|
732
731
|
|
@@ -821,14 +820,14 @@ describe Capybara::Webkit::Driver do
|
|
821
820
|
alert_message = driver.accept_modal(:alert) do
|
822
821
|
visit("/")
|
823
822
|
end
|
824
|
-
alert_message.
|
823
|
+
expect(alert_message).to eq "Alert Text\nGoes Here"
|
825
824
|
end
|
826
825
|
|
827
826
|
it 'accepts an alert modal if it matches' do
|
828
827
|
alert_message = driver.accept_modal(:alert, text: "Alert Text\nGoes Here") do
|
829
828
|
visit("/")
|
830
829
|
end
|
831
|
-
alert_message.
|
830
|
+
expect(alert_message).to eq "Alert Text\nGoes Here"
|
832
831
|
end
|
833
832
|
|
834
833
|
it 'raises an error when accepting an alert modal that does not match' do
|
@@ -856,7 +855,7 @@ describe Capybara::Webkit::Driver do
|
|
856
855
|
alert_message = driver.accept_modal(:alert) do
|
857
856
|
driver.find_xpath("//input").first.click
|
858
857
|
end
|
859
|
-
alert_message.
|
858
|
+
expect(alert_message).to eq "Alert Text\nGoes Here"
|
860
859
|
end
|
861
860
|
|
862
861
|
it 'times out waiting for an async alert modal' do
|
@@ -878,13 +877,13 @@ describe Capybara::Webkit::Driver do
|
|
878
877
|
|
879
878
|
it "should let me read my alert messages" do
|
880
879
|
visit("/")
|
881
|
-
driver.alert_messages.first.
|
880
|
+
expect(driver.alert_messages.first).to eq "Alert Text\nGoes Here"
|
882
881
|
end
|
883
882
|
|
884
883
|
it "empties the array when reset" do
|
885
884
|
visit("/")
|
886
885
|
driver.reset!
|
887
|
-
driver.alert_messages.
|
886
|
+
expect(driver.alert_messages).to be_empty
|
888
887
|
end
|
889
888
|
|
890
889
|
it "clears alerts from ajax requests in between sessions" do
|
@@ -892,7 +891,7 @@ describe Capybara::Webkit::Driver do
|
|
892
891
|
driver.find("//input").first.click
|
893
892
|
driver.reset!
|
894
893
|
sleep 0.5
|
895
|
-
driver.alert_messages.
|
894
|
+
expect(driver.alert_messages).to eq([])
|
896
895
|
expect { visit("/") }.not_to raise_error
|
897
896
|
end
|
898
897
|
end
|
@@ -941,14 +940,14 @@ describe Capybara::Webkit::Driver do
|
|
941
940
|
driver.accept_modal(:confirm) do
|
942
941
|
driver.find_xpath("//input").first.click
|
943
942
|
end
|
944
|
-
driver.console_messages.first[:message].
|
943
|
+
expect(driver.console_messages.first[:message]).to eq "hello"
|
945
944
|
end
|
946
945
|
|
947
946
|
it 'dismisses a confirm modal that does not match' do
|
948
947
|
begin
|
949
948
|
driver.accept_modal(:confirm, text: 'No?') do
|
950
949
|
driver.find_xpath("//input").first.click
|
951
|
-
driver.console_messages.first[:message].
|
950
|
+
expect(driver.console_messages.first[:message]).to eq "goodbye"
|
952
951
|
end
|
953
952
|
rescue Capybara::ModalNotFound
|
954
953
|
end
|
@@ -966,7 +965,7 @@ describe Capybara::Webkit::Driver do
|
|
966
965
|
driver.dismiss_modal(:confirm) do
|
967
966
|
driver.find_xpath("//input").first.click
|
968
967
|
end
|
969
|
-
driver.console_messages.first[:message].
|
968
|
+
expect(driver.console_messages.first[:message]).to eq "goodbye"
|
970
969
|
end
|
971
970
|
|
972
971
|
it 'raises an error when dismissing a confirm modal that does not match' do
|
@@ -982,7 +981,7 @@ describe Capybara::Webkit::Driver do
|
|
982
981
|
confirm_message = driver.accept_modal(:confirm) do
|
983
982
|
driver.find_css("input[name=test_async]").first.click
|
984
983
|
end
|
985
|
-
confirm_message.
|
984
|
+
expect(confirm_message).to eq "Yes?"
|
986
985
|
end
|
987
986
|
|
988
987
|
it 'allows the nesting of dismiss and accept' do
|
@@ -991,7 +990,7 @@ describe Capybara::Webkit::Driver do
|
|
991
990
|
driver.find_css("input[name=test_complex]").first.click
|
992
991
|
end
|
993
992
|
end
|
994
|
-
driver.console_messages.first[:message].
|
993
|
+
expect(driver.console_messages.first[:message]).to eq "goodbye"
|
995
994
|
end
|
996
995
|
|
997
996
|
it 'raises an error when an unexpected modal is displayed' do
|
@@ -1006,7 +1005,7 @@ describe Capybara::Webkit::Driver do
|
|
1006
1005
|
begin
|
1007
1006
|
driver.accept_modal(:prompt) do
|
1008
1007
|
driver.find_xpath("//input").first.click
|
1009
|
-
driver.console_messages.first[:message].
|
1008
|
+
expect(driver.console_messages.first[:message]).to eq "goodbye"
|
1010
1009
|
end
|
1011
1010
|
rescue Capybara::ModalNotFound
|
1012
1011
|
end
|
@@ -1014,31 +1013,31 @@ describe Capybara::Webkit::Driver do
|
|
1014
1013
|
|
1015
1014
|
it "should default to accept the confirm" do
|
1016
1015
|
driver.find_xpath("//input").first.click
|
1017
|
-
driver.console_messages.first[:message].
|
1016
|
+
expect(driver.console_messages.first[:message]).to eq "hello"
|
1018
1017
|
end
|
1019
1018
|
|
1020
1019
|
it "can dismiss the confirm" do
|
1021
1020
|
driver.dismiss_js_confirms!
|
1022
1021
|
driver.find_xpath("//input").first.click
|
1023
|
-
driver.console_messages.first[:message].
|
1022
|
+
expect(driver.console_messages.first[:message]).to eq "goodbye"
|
1024
1023
|
end
|
1025
1024
|
|
1026
1025
|
it "can accept the confirm explicitly" do
|
1027
1026
|
driver.dismiss_js_confirms!
|
1028
1027
|
driver.accept_js_confirms!
|
1029
1028
|
driver.find_xpath("//input").first.click
|
1030
|
-
driver.console_messages.first[:message].
|
1029
|
+
expect(driver.console_messages.first[:message]).to eq "hello"
|
1031
1030
|
end
|
1032
1031
|
|
1033
1032
|
it "should collect the javascript confirm dialog contents" do
|
1034
1033
|
driver.find_xpath("//input").first.click
|
1035
|
-
driver.confirm_messages.first.
|
1034
|
+
expect(driver.confirm_messages.first).to eq "Yes?"
|
1036
1035
|
end
|
1037
1036
|
|
1038
1037
|
it "empties the array when reset" do
|
1039
1038
|
driver.find_xpath("//input").first.click
|
1040
1039
|
driver.reset!
|
1041
|
-
driver.confirm_messages.
|
1040
|
+
expect(driver.confirm_messages).to be_empty
|
1042
1041
|
end
|
1043
1042
|
|
1044
1043
|
it "resets to the default of accepting confirms" do
|
@@ -1046,12 +1045,12 @@ describe Capybara::Webkit::Driver do
|
|
1046
1045
|
driver.reset!
|
1047
1046
|
visit("/")
|
1048
1047
|
driver.find_xpath("//input").first.click
|
1049
|
-
driver.console_messages.first[:message].
|
1048
|
+
expect(driver.console_messages.first[:message]).to eq "hello"
|
1050
1049
|
end
|
1051
1050
|
|
1052
1051
|
it "supports multi-line confirmation messages" do
|
1053
1052
|
driver.execute_script("confirm('Hello\\nnewline')")
|
1054
|
-
driver.confirm_messages.first.
|
1053
|
+
expect(driver.confirm_messages.first).to eq "Hello\nnewline"
|
1055
1054
|
end
|
1056
1055
|
|
1057
1056
|
end
|
@@ -1099,14 +1098,14 @@ describe Capybara::Webkit::Driver do
|
|
1099
1098
|
driver.accept_modal(:prompt) do
|
1100
1099
|
driver.find_xpath("//input").first.click
|
1101
1100
|
end
|
1102
|
-
driver.console_messages.first[:message].
|
1101
|
+
expect(driver.console_messages.first[:message]).to eq "hello John Smith"
|
1103
1102
|
end
|
1104
1103
|
|
1105
1104
|
it 'accepts any prompt modal with the provided response' do
|
1106
1105
|
driver.accept_modal(:prompt, with: 'Capy') do
|
1107
1106
|
driver.find_xpath("//input").first.click
|
1108
1107
|
end
|
1109
|
-
driver.console_messages.first[:message].
|
1108
|
+
expect(driver.console_messages.first[:message]).to eq "hello Capy"
|
1110
1109
|
end
|
1111
1110
|
|
1112
1111
|
it 'raises an error when accepting a prompt modal that does not match' do
|
@@ -1121,14 +1120,14 @@ describe Capybara::Webkit::Driver do
|
|
1121
1120
|
driver.dismiss_modal(:prompt) do
|
1122
1121
|
driver.find_xpath("//input").first.click
|
1123
1122
|
end
|
1124
|
-
driver.console_messages.first[:message].
|
1123
|
+
expect(driver.console_messages.first[:message]).to eq "goodbye"
|
1125
1124
|
end
|
1126
1125
|
|
1127
1126
|
it 'dismisses a prompt modal that does not match' do
|
1128
1127
|
begin
|
1129
1128
|
driver.accept_modal(:prompt, text: 'Your age?') do
|
1130
1129
|
driver.find_xpath("//input").first.click
|
1131
|
-
driver.console_messages.first[:message].
|
1130
|
+
expect(driver.console_messages.first[:message]).to eq "goodbye"
|
1132
1131
|
end
|
1133
1132
|
rescue Capybara::ModalNotFound
|
1134
1133
|
end
|
@@ -1147,7 +1146,7 @@ describe Capybara::Webkit::Driver do
|
|
1147
1146
|
prompt_message = driver.accept_modal(:prompt) do
|
1148
1147
|
driver.find_css("input[name=test_async]").first.click
|
1149
1148
|
end
|
1150
|
-
prompt_message.
|
1149
|
+
expect(prompt_message).to eq "Your name?"
|
1151
1150
|
end
|
1152
1151
|
|
1153
1152
|
it 'allows the nesting of dismiss and accept' do
|
@@ -1156,7 +1155,7 @@ describe Capybara::Webkit::Driver do
|
|
1156
1155
|
driver.find_css("input[name=test_complex]").first.click
|
1157
1156
|
end
|
1158
1157
|
end
|
1159
|
-
driver.console_messages.first[:message].
|
1158
|
+
expect(driver.console_messages.first[:message]).to eq "goodbye"
|
1160
1159
|
end
|
1161
1160
|
|
1162
1161
|
it 'raises an error when an unexpected modal is displayed' do
|
@@ -1171,7 +1170,7 @@ describe Capybara::Webkit::Driver do
|
|
1171
1170
|
begin
|
1172
1171
|
driver.accept_modal(:confirm) do
|
1173
1172
|
driver.find_xpath("//input").first.click
|
1174
|
-
driver.console_messages.first[:message].
|
1173
|
+
expect(driver.console_messages.first[:message]).to eq "goodbye"
|
1175
1174
|
end
|
1176
1175
|
rescue Capybara::ModalNotFound
|
1177
1176
|
end
|
@@ -1179,48 +1178,48 @@ describe Capybara::Webkit::Driver do
|
|
1179
1178
|
|
1180
1179
|
it "should default to dismiss the prompt" do
|
1181
1180
|
driver.find_xpath("//input").first.click
|
1182
|
-
driver.console_messages.first[:message].
|
1181
|
+
expect(driver.console_messages.first[:message]).to eq "goodbye"
|
1183
1182
|
end
|
1184
1183
|
|
1185
1184
|
it "can accept the prompt without providing text" do
|
1186
1185
|
driver.accept_js_prompts!
|
1187
1186
|
driver.find_xpath("//input").first.click
|
1188
|
-
driver.console_messages.first[:message].
|
1187
|
+
expect(driver.console_messages.first[:message]).to eq "hello John Smith"
|
1189
1188
|
end
|
1190
1189
|
|
1191
1190
|
it "can accept the prompt with input" do
|
1192
1191
|
driver.js_prompt_input = "Capy"
|
1193
1192
|
driver.accept_js_prompts!
|
1194
1193
|
driver.find_xpath("//input").first.click
|
1195
|
-
driver.console_messages.first[:message].
|
1194
|
+
expect(driver.console_messages.first[:message]).to eq "hello Capy"
|
1196
1195
|
end
|
1197
1196
|
|
1198
1197
|
it "can return to dismiss the prompt after accepting prompts" do
|
1199
1198
|
driver.accept_js_prompts!
|
1200
1199
|
driver.dismiss_js_prompts!
|
1201
1200
|
driver.find_xpath("//input").first.click
|
1202
|
-
driver.console_messages.first[:message].
|
1201
|
+
expect(driver.console_messages.first[:message]).to eq "goodbye"
|
1203
1202
|
end
|
1204
1203
|
|
1205
1204
|
it "should let me remove the prompt input text" do
|
1206
1205
|
driver.js_prompt_input = "Capy"
|
1207
1206
|
driver.accept_js_prompts!
|
1208
1207
|
driver.find_xpath("//input").first.click
|
1209
|
-
driver.console_messages.first[:message].
|
1208
|
+
expect(driver.console_messages.first[:message]).to eq "hello Capy"
|
1210
1209
|
driver.js_prompt_input = nil
|
1211
1210
|
driver.find_xpath("//input").first.click
|
1212
|
-
driver.console_messages.last[:message].
|
1211
|
+
expect(driver.console_messages.last[:message]).to eq "hello John Smith"
|
1213
1212
|
end
|
1214
1213
|
|
1215
1214
|
it "should collect the javascript prompt dialog contents" do
|
1216
1215
|
driver.find_xpath("//input").first.click
|
1217
|
-
driver.prompt_messages.first.
|
1216
|
+
expect(driver.prompt_messages.first).to eq "Your name?"
|
1218
1217
|
end
|
1219
1218
|
|
1220
1219
|
it "empties the array when reset" do
|
1221
1220
|
driver.find_xpath("//input").first.click
|
1222
1221
|
driver.reset!
|
1223
|
-
driver.prompt_messages.
|
1222
|
+
expect(driver.prompt_messages).to be_empty
|
1224
1223
|
end
|
1225
1224
|
|
1226
1225
|
it "returns the prompt action to dismiss on reset" do
|
@@ -1228,12 +1227,12 @@ describe Capybara::Webkit::Driver do
|
|
1228
1227
|
driver.reset!
|
1229
1228
|
visit("/")
|
1230
1229
|
driver.find_xpath("//input").first.click
|
1231
|
-
driver.console_messages.first[:message].
|
1230
|
+
expect(driver.console_messages.first[:message]).to eq "goodbye"
|
1232
1231
|
end
|
1233
1232
|
|
1234
1233
|
it "supports multi-line prompt messages" do
|
1235
1234
|
driver.execute_script("prompt('Hello\\nnewline')")
|
1236
|
-
driver.prompt_messages.first.
|
1235
|
+
expect(driver.prompt_messages.first).to eq "Hello\nnewline"
|
1237
1236
|
end
|
1238
1237
|
|
1239
1238
|
end
|
@@ -1281,66 +1280,66 @@ describe Capybara::Webkit::Driver do
|
|
1281
1280
|
before { visit("/") }
|
1282
1281
|
|
1283
1282
|
it "returns a textarea's value" do
|
1284
|
-
driver.find_xpath("//textarea").first.value.
|
1283
|
+
expect(driver.find_xpath("//textarea").first.value).to eq "what a wonderful area for text"
|
1285
1284
|
end
|
1286
1285
|
|
1287
1286
|
it "returns a text input's value" do
|
1288
|
-
driver.find_xpath("//input").first.value.
|
1287
|
+
expect(driver.find_xpath("//input").first.value).to eq "bar"
|
1289
1288
|
end
|
1290
1289
|
|
1291
1290
|
it "returns a select's value" do
|
1292
|
-
driver.find_xpath("//select").first.value.
|
1291
|
+
expect(driver.find_xpath("//select").first.value).to eq "Capybara"
|
1293
1292
|
end
|
1294
1293
|
|
1295
1294
|
it "sets an input's value" do
|
1296
1295
|
input = driver.find_xpath("//input").first
|
1297
1296
|
input.set("newvalue")
|
1298
|
-
input.value.
|
1297
|
+
expect(input.value).to eq "newvalue"
|
1299
1298
|
end
|
1300
1299
|
|
1301
1300
|
it "sets an input's value greater than the max length" do
|
1302
1301
|
input = driver.find_xpath("//input[@name='maxlength_foo']").first
|
1303
1302
|
input.set("allegories (poems)")
|
1304
|
-
input.value.
|
1303
|
+
expect(input.value).to eq "allegories"
|
1305
1304
|
end
|
1306
1305
|
|
1307
1306
|
it "sets an input's value equal to the max length" do
|
1308
1307
|
input = driver.find_xpath("//input[@name='maxlength_foo']").first
|
1309
1308
|
input.set("allegories")
|
1310
|
-
input.value.
|
1309
|
+
expect(input.value).to eq "allegories"
|
1311
1310
|
end
|
1312
1311
|
|
1313
1312
|
it "sets an input's value less than the max length" do
|
1314
1313
|
input = driver.find_xpath("//input[@name='maxlength_foo']").first
|
1315
1314
|
input.set("poems")
|
1316
|
-
input.value.
|
1315
|
+
expect(input.value).to eq "poems"
|
1317
1316
|
end
|
1318
1317
|
|
1319
1318
|
it "sets an input's nil value" do
|
1320
1319
|
input = driver.find_xpath("//input").first
|
1321
1320
|
input.set(nil)
|
1322
|
-
input.value.
|
1321
|
+
expect(input.value).to eq ""
|
1323
1322
|
end
|
1324
1323
|
|
1325
1324
|
it "sets a select's value" do
|
1326
1325
|
select = driver.find_xpath("//select").first
|
1327
1326
|
select.set("Monkey")
|
1328
|
-
select.value.
|
1327
|
+
expect(select.value).to eq "Monkey"
|
1329
1328
|
end
|
1330
1329
|
|
1331
1330
|
it "sets a textarea's value" do
|
1332
1331
|
textarea = driver.find_xpath("//textarea").first
|
1333
1332
|
textarea.set("newvalue")
|
1334
|
-
textarea.value.
|
1333
|
+
expect(textarea.value).to eq "newvalue"
|
1335
1334
|
end
|
1336
1335
|
|
1337
1336
|
context "#send_keys" do
|
1338
1337
|
it "should support :backspace" do
|
1339
1338
|
input = driver.find_xpath("//input").first
|
1340
1339
|
input.set("dog")
|
1341
|
-
input.value.
|
1340
|
+
expect(input.value).to eq "dog"
|
1342
1341
|
input.send_keys(*[:backspace])
|
1343
|
-
input.value.
|
1342
|
+
expect(input.value).to eq "do"
|
1344
1343
|
end
|
1345
1344
|
end
|
1346
1345
|
|
@@ -1357,52 +1356,52 @@ describe Capybara::Webkit::Driver do
|
|
1357
1356
|
|
1358
1357
|
context "a select element's selection has been changed" do
|
1359
1358
|
before do
|
1360
|
-
animal_select.value.
|
1359
|
+
expect(animal_select.value).to eq "Capybara"
|
1361
1360
|
monkey_option.select_option
|
1362
1361
|
end
|
1363
1362
|
|
1364
1363
|
it "returns the new selection" do
|
1365
|
-
animal_select.value.
|
1364
|
+
expect(animal_select.value).to eq "Monkey"
|
1366
1365
|
end
|
1367
1366
|
|
1368
1367
|
it "does not modify the selected attribute of a new selection" do
|
1369
|
-
monkey_option['selected'].
|
1368
|
+
expect(monkey_option['selected']).to be_nil
|
1370
1369
|
end
|
1371
1370
|
|
1372
1371
|
it "returns the old value when a reset button is clicked" do
|
1373
1372
|
reset_button.click
|
1374
1373
|
|
1375
|
-
animal_select.value.
|
1374
|
+
expect(animal_select.value).to eq "Capybara"
|
1376
1375
|
end
|
1377
1376
|
end
|
1378
1377
|
|
1379
1378
|
context "a multi-select element's option has been unselected" do
|
1380
1379
|
before do
|
1381
|
-
toppings_select.value.
|
1380
|
+
expect(toppings_select.value).to include("Apple", "Banana", "Cherry")
|
1382
1381
|
|
1383
1382
|
apple_option.unselect_option
|
1384
1383
|
end
|
1385
1384
|
|
1386
1385
|
it "does not return the deselected option" do
|
1387
|
-
toppings_select.value.
|
1386
|
+
expect(toppings_select.value).not_to include("Apple")
|
1388
1387
|
end
|
1389
1388
|
|
1390
1389
|
it "returns the deselected option when a reset button is clicked" do
|
1391
1390
|
reset_button.click
|
1392
1391
|
|
1393
|
-
toppings_select.value.
|
1392
|
+
expect(toppings_select.value).to include("Apple", "Banana", "Cherry")
|
1394
1393
|
end
|
1395
1394
|
end
|
1396
1395
|
|
1397
1396
|
context "a multi-select (with empty multiple attribute) element's option has been unselected" do
|
1398
1397
|
before do
|
1399
|
-
guitars_select.value.
|
1398
|
+
expect(guitars_select.value).to include("Fender", "Gibson")
|
1400
1399
|
|
1401
1400
|
fender_option.unselect_option
|
1402
1401
|
end
|
1403
1402
|
|
1404
1403
|
it "does not return the deselected option" do
|
1405
|
-
guitars_select.value.
|
1404
|
+
expect(guitars_select.value).not_to include("Fender")
|
1406
1405
|
end
|
1407
1406
|
end
|
1408
1407
|
|
@@ -1411,73 +1410,73 @@ describe Capybara::Webkit::Driver do
|
|
1411
1410
|
banana_option.unselect_option
|
1412
1411
|
cherry_option.unselect_option
|
1413
1412
|
|
1414
|
-
toppings_select.value.
|
1413
|
+
expect(toppings_select.value).to eq []
|
1415
1414
|
|
1416
1415
|
apple_option.select_option
|
1417
1416
|
banana_option.select_option
|
1418
1417
|
cherry_option.select_option
|
1419
1418
|
|
1420
|
-
toppings_select.value.
|
1419
|
+
expect(toppings_select.value).to include("Apple", "Banana", "Cherry")
|
1421
1420
|
end
|
1422
1421
|
|
1423
1422
|
let(:checked_box) { driver.find_xpath("//input[@name='checkedbox']").first }
|
1424
1423
|
let(:unchecked_box) { driver.find_xpath("//input[@name='uncheckedbox']").first }
|
1425
1424
|
|
1426
1425
|
it "knows a checked box is checked" do
|
1427
|
-
checked_box['checked'].
|
1426
|
+
expect(checked_box['checked']).to be true
|
1428
1427
|
end
|
1429
1428
|
|
1430
1429
|
it "knows a checked box is checked using checked?" do
|
1431
|
-
checked_box.
|
1430
|
+
expect(checked_box).to be_checked
|
1432
1431
|
end
|
1433
1432
|
|
1434
1433
|
it "knows an unchecked box is unchecked" do
|
1435
|
-
unchecked_box['checked'].
|
1434
|
+
expect(unchecked_box['checked']).not_to be_truthy
|
1436
1435
|
end
|
1437
1436
|
|
1438
1437
|
it "knows an unchecked box is unchecked using checked?" do
|
1439
|
-
unchecked_box.
|
1438
|
+
expect(unchecked_box).not_to be_checked
|
1440
1439
|
end
|
1441
1440
|
|
1442
1441
|
it "checks an unchecked box" do
|
1443
1442
|
unchecked_box.set(true)
|
1444
|
-
unchecked_box.
|
1443
|
+
expect(unchecked_box).to be_checked
|
1445
1444
|
end
|
1446
1445
|
|
1447
1446
|
it "unchecks a checked box" do
|
1448
1447
|
checked_box.set(false)
|
1449
|
-
checked_box.
|
1448
|
+
expect(checked_box).not_to be_checked
|
1450
1449
|
end
|
1451
1450
|
|
1452
1451
|
it "leaves a checked box checked" do
|
1453
1452
|
checked_box.set(true)
|
1454
|
-
checked_box.
|
1453
|
+
expect(checked_box).to be_checked
|
1455
1454
|
end
|
1456
1455
|
|
1457
1456
|
it "leaves an unchecked box unchecked" do
|
1458
1457
|
unchecked_box.set(false)
|
1459
|
-
unchecked_box.
|
1458
|
+
expect(unchecked_box).not_to be_checked
|
1460
1459
|
end
|
1461
1460
|
|
1462
1461
|
let(:enabled_input) { driver.find_xpath("//input[@name='foo']").first }
|
1463
1462
|
let(:disabled_input) { driver.find_xpath("//input[@id='disabled_input']").first }
|
1464
1463
|
|
1465
1464
|
it "knows a disabled input is disabled" do
|
1466
|
-
disabled_input['disabled'].
|
1465
|
+
expect(disabled_input['disabled']).to be true
|
1467
1466
|
end
|
1468
1467
|
|
1469
1468
|
it "knows a not disabled input is not disabled" do
|
1470
|
-
enabled_input['disabled'].
|
1469
|
+
expect(enabled_input['disabled']).not_to be_truthy
|
1471
1470
|
end
|
1472
1471
|
|
1473
1472
|
it "does not modify a readonly input" do
|
1474
1473
|
readonly_input = driver.find_css("#readonly_input").first
|
1475
1474
|
readonly_input.set('enabled')
|
1476
|
-
readonly_input.value.
|
1475
|
+
expect(readonly_input.value).to eq 'readonly'
|
1477
1476
|
end
|
1478
1477
|
|
1479
1478
|
it "should see enabled options in disabled select as disabled" do
|
1480
|
-
driver.find_css("#select-option-disabled").first.
|
1479
|
+
expect(driver.find_css("#select-option-disabled").first).to be_disabled
|
1481
1480
|
end
|
1482
1481
|
end
|
1483
1482
|
|
@@ -1516,18 +1515,18 @@ describe Capybara::Webkit::Driver do
|
|
1516
1515
|
|
1517
1516
|
it "triggers mouse events" do
|
1518
1517
|
watch.click
|
1519
|
-
fired_events.
|
1518
|
+
expect(fired_events).to eq %w(mousedown mouseup click)
|
1520
1519
|
end
|
1521
1520
|
|
1522
1521
|
it "triggers double click" do
|
1523
1522
|
# check event order at http://www.quirksmode.org/dom/events/click.html
|
1524
1523
|
watch.double_click
|
1525
|
-
fired_events.
|
1524
|
+
expect(fired_events).to eq %w(mousedown mouseup click mousedown mouseup click dblclick)
|
1526
1525
|
end
|
1527
1526
|
|
1528
1527
|
it "triggers right click" do
|
1529
1528
|
watch.right_click
|
1530
|
-
fired_events.
|
1529
|
+
expect(fired_events).to eq %w(mousedown contextmenu mouseup)
|
1531
1530
|
end
|
1532
1531
|
end
|
1533
1532
|
|
@@ -1591,29 +1590,29 @@ describe Capybara::Webkit::Driver do
|
|
1591
1590
|
it "triggers text input events on inputs of type #{field_type}" do
|
1592
1591
|
driver.find_xpath("//input[@type='#{field_type}']").first.set(newtext)
|
1593
1592
|
driver.find_xpath("//body").first.click
|
1594
|
-
driver.find_xpath("//li").map(&:visible_text).
|
1593
|
+
expect(driver.find_xpath("//li").map(&:visible_text)).to eq textevents
|
1595
1594
|
end
|
1596
1595
|
end
|
1597
1596
|
|
1598
1597
|
it "triggers events for cleared inputs" do
|
1599
1598
|
driver.find_xpath("//input[@type='text']").first.set('')
|
1600
1599
|
driver.find_xpath("//body").first.click
|
1601
|
-
driver.find_xpath("//li").map(&:visible_text).
|
1600
|
+
expect(driver.find_xpath("//li").map(&:visible_text)).to include('change')
|
1602
1601
|
end
|
1603
1602
|
|
1604
1603
|
it "triggers textarea input events" do
|
1605
1604
|
driver.find_xpath("//textarea").first.set(newtext)
|
1606
|
-
driver.find_xpath("//li").map(&:visible_text).
|
1605
|
+
expect(driver.find_xpath("//li").map(&:visible_text)).to eq keyevents
|
1607
1606
|
end
|
1608
1607
|
|
1609
1608
|
it "triggers radio input events" do
|
1610
1609
|
driver.find_xpath("//input[@type='radio']").first.set(true)
|
1611
|
-
driver.find_xpath("//li").map(&:visible_text).
|
1610
|
+
expect(driver.find_xpath("//li").map(&:visible_text)).to eq %w(mousedown focus mouseup change click)
|
1612
1611
|
end
|
1613
1612
|
|
1614
1613
|
it "triggers checkbox events" do
|
1615
1614
|
driver.find_xpath("//input[@type='checkbox']").first.set(true)
|
1616
|
-
driver.find_xpath("//li").map(&:visible_text).
|
1615
|
+
expect(driver.find_xpath("//li").map(&:visible_text)).to eq %w(mousedown focus mouseup change click)
|
1617
1616
|
end
|
1618
1617
|
end
|
1619
1618
|
|
@@ -1674,16 +1673,16 @@ describe Capybara::Webkit::Driver do
|
|
1674
1673
|
before { visit("/") }
|
1675
1674
|
|
1676
1675
|
it "hovers an element" do
|
1677
|
-
driver.find_css("#hover").first.visible_text.
|
1676
|
+
expect(driver.find_css("#hover").first.visible_text).not_to match /Text that only shows on hover/
|
1678
1677
|
driver.find_css("#hover span").first.hover
|
1679
|
-
driver.find_css("#hover").first.visible_text.
|
1678
|
+
expect(driver.find_css("#hover").first.visible_text).to match /Text that only shows on hover/
|
1680
1679
|
end
|
1681
1680
|
|
1682
1681
|
it "hovers an svg element" do
|
1683
1682
|
# visible_text does not work for SVG elements. It returns all the text.
|
1684
|
-
driver.find_css("text").first.
|
1683
|
+
expect(driver.find_css("text").first).not_to be_visible
|
1685
1684
|
driver.find_css("#circle_hover").first.hover
|
1686
|
-
driver.find_css("text").first.
|
1685
|
+
expect(driver.find_css("text").first).to be_visible
|
1687
1686
|
end
|
1688
1687
|
|
1689
1688
|
it "hovers an element off the screen" do
|
@@ -1693,33 +1692,33 @@ describe Capybara::Webkit::Driver do
|
|
1693
1692
|
element.style.position = 'absolute';
|
1694
1693
|
element.style.left = '200px';
|
1695
1694
|
JS
|
1696
|
-
driver.find_css("#hover").first.visible_text.
|
1695
|
+
expect(driver.find_css("#hover").first.visible_text).not_to match /Text that only shows on hover/
|
1697
1696
|
driver.find_css("#hover span").first.hover
|
1698
|
-
driver.find_css("#hover").first.visible_text.
|
1697
|
+
expect(driver.find_css("#hover").first.visible_text).to match /Text that only shows on hover/
|
1699
1698
|
end
|
1700
1699
|
|
1701
1700
|
it "clicks an element" do
|
1702
1701
|
driver.find_xpath("//a").first.click
|
1703
|
-
driver.current_url
|
1702
|
+
expect(driver.current_url).to match %r{/next$}
|
1704
1703
|
end
|
1705
1704
|
|
1706
1705
|
it "fires a mouse event" do
|
1707
1706
|
driver.find_xpath("//*[@id='mouseup']").first.trigger("mouseup")
|
1708
|
-
driver.find_xpath("//*[@class='triggered']").
|
1707
|
+
expect(driver.find_xpath("//*[@class='triggered']")).not_to be_empty
|
1709
1708
|
end
|
1710
1709
|
|
1711
1710
|
it "fires a non-mouse event" do
|
1712
1711
|
driver.find_xpath("//*[@id='change']").first.trigger("change")
|
1713
|
-
driver.find_xpath("//*[@class='triggered']").
|
1712
|
+
expect(driver.find_xpath("//*[@class='triggered']")).not_to be_empty
|
1714
1713
|
end
|
1715
1714
|
|
1716
1715
|
it "fires a change on select" do
|
1717
1716
|
select = driver.find_xpath("//select").first
|
1718
|
-
select.value.
|
1717
|
+
expect(select.value).to eq "1"
|
1719
1718
|
option = driver.find_xpath("//option[@id='option-2']").first
|
1720
1719
|
option.select_option
|
1721
|
-
select.value.
|
1722
|
-
driver.find_xpath("//select[@class='triggered']").
|
1720
|
+
expect(select.value).to eq "2"
|
1721
|
+
expect(driver.find_xpath("//select[@class='triggered']")).not_to be_empty
|
1723
1722
|
end
|
1724
1723
|
|
1725
1724
|
it "fires drag events" do
|
@@ -1728,7 +1727,7 @@ describe Capybara::Webkit::Driver do
|
|
1728
1727
|
|
1729
1728
|
draggable.drag_to(container)
|
1730
1729
|
|
1731
|
-
driver.find_xpath("//*[@class='triggered']").size.
|
1730
|
+
expect(driver.find_xpath("//*[@class='triggered']").size).to eq 1
|
1732
1731
|
end
|
1733
1732
|
end
|
1734
1733
|
|
@@ -1748,12 +1747,12 @@ describe Capybara::Webkit::Driver do
|
|
1748
1747
|
|
1749
1748
|
it "evaluates nested xpath expressions" do
|
1750
1749
|
parent = driver.find_xpath("//*[@id='parent']").first
|
1751
|
-
parent.find_xpath("./*[@class='find']").map(&:visible_text).
|
1750
|
+
expect(parent.find_xpath("./*[@class='find']").map(&:visible_text)).to eq %w(Expected)
|
1752
1751
|
end
|
1753
1752
|
|
1754
1753
|
it "finds elements by CSS" do
|
1755
1754
|
parent = driver.find_css("#parent").first
|
1756
|
-
parent.find_css(".find").first.visible_text.
|
1755
|
+
expect(parent.find_css(".find").first.visible_text).to eq "Expected"
|
1757
1756
|
end
|
1758
1757
|
end
|
1759
1758
|
|
@@ -1773,7 +1772,7 @@ describe Capybara::Webkit::Driver do
|
|
1773
1772
|
end
|
1774
1773
|
visit("/", driver)
|
1775
1774
|
driver.find_xpath("//a").first.click
|
1776
|
-
result.
|
1775
|
+
expect(result).to eq "finished"
|
1777
1776
|
end
|
1778
1777
|
end
|
1779
1778
|
|
@@ -1801,8 +1800,7 @@ describe Capybara::Webkit::Driver do
|
|
1801
1800
|
driver.find_xpath("//input").first.click
|
1802
1801
|
wait_for_error_to_complete
|
1803
1802
|
driver.find_xpath("//body")
|
1804
|
-
}.
|
1805
|
-
to raise_error(Capybara::Webkit::InvalidResponseError, %r{/error})
|
1803
|
+
}.to raise_error(Capybara::Webkit::InvalidResponseError, %r{/error})
|
1806
1804
|
end
|
1807
1805
|
|
1808
1806
|
def wait_for_error_to_complete
|
@@ -1835,7 +1833,7 @@ describe Capybara::Webkit::Driver do
|
|
1835
1833
|
driver.find_xpath("//input").first.click
|
1836
1834
|
expect { driver.find_xpath("//p") }.to raise_error(Capybara::Webkit::InvalidResponseError)
|
1837
1835
|
visit("/")
|
1838
|
-
driver.find_xpath("//p").first.visible_text.
|
1836
|
+
expect(driver.find_xpath("//p").first.visible_text).to eq "hello"
|
1839
1837
|
end
|
1840
1838
|
end
|
1841
1839
|
|
@@ -1861,7 +1859,7 @@ describe Capybara::Webkit::Driver do
|
|
1861
1859
|
before { visit("/") }
|
1862
1860
|
|
1863
1861
|
it "doesn't crash from alerts" do
|
1864
|
-
driver.find_xpath("//p").first.visible_text.
|
1862
|
+
expect(driver.find_xpath("//p").first.visible_text).to eq "success"
|
1865
1863
|
end
|
1866
1864
|
end
|
1867
1865
|
|
@@ -1891,31 +1889,31 @@ describe Capybara::Webkit::Driver do
|
|
1891
1889
|
end
|
1892
1890
|
|
1893
1891
|
it "can set user_agent" do
|
1894
|
-
driver.find_xpath('id("user-agent")').first.visible_text.
|
1895
|
-
driver.evaluate_script('navigator.userAgent').
|
1892
|
+
expect(driver.find_xpath('id("user-agent")').first.visible_text).to eq 'capybara-webkit/custom-user-agent'
|
1893
|
+
expect(driver.evaluate_script('navigator.userAgent')).to eq 'capybara-webkit/custom-user-agent'
|
1896
1894
|
end
|
1897
1895
|
|
1898
1896
|
it "keep user_agent in next page" do
|
1899
1897
|
driver.find_xpath("//a").first.click
|
1900
|
-
driver.find_xpath('id("user-agent")').first.visible_text.
|
1901
|
-
driver.evaluate_script('navigator.userAgent').
|
1898
|
+
expect(driver.find_xpath('id("user-agent")').first.visible_text).to eq 'capybara-webkit/custom-user-agent'
|
1899
|
+
expect(driver.evaluate_script('navigator.userAgent')).to eq 'capybara-webkit/custom-user-agent'
|
1902
1900
|
end
|
1903
1901
|
|
1904
1902
|
it "can set custom header" do
|
1905
|
-
driver.find_xpath('id("x-capybara-webkit-header")').first.visible_text.
|
1903
|
+
expect(driver.find_xpath('id("x-capybara-webkit-header")').first.visible_text).to eq 'x-capybara-webkit-header'
|
1906
1904
|
end
|
1907
1905
|
|
1908
1906
|
it "can set Accept header" do
|
1909
|
-
driver.find_xpath('id("accept")').first.visible_text.
|
1907
|
+
expect(driver.find_xpath('id("accept")').first.visible_text).to eq 'text/html'
|
1910
1908
|
end
|
1911
1909
|
|
1912
1910
|
it "can reset all custom header" do
|
1913
1911
|
driver.reset!
|
1914
1912
|
visit('/')
|
1915
|
-
driver.find_xpath('id("user-agent")').first.visible_text.
|
1916
|
-
driver.evaluate_script('navigator.userAgent').
|
1917
|
-
driver.find_xpath('id("x-capybara-webkit-header")').first.visible_text.
|
1918
|
-
driver.find_xpath('id("accept")').first.visible_text.
|
1913
|
+
expect(driver.find_xpath('id("user-agent")').first.visible_text).not_to eq 'capybara-webkit/custom-user-agent'
|
1914
|
+
expect(driver.evaluate_script('navigator.userAgent')).not_to eq 'capybara-webkit/custom-user-agent'
|
1915
|
+
expect(driver.find_xpath('id("x-capybara-webkit-header")').first.visible_text).to be_empty
|
1916
|
+
expect(driver.find_xpath('id("accept")').first.visible_text).not_to eq 'text/html'
|
1919
1917
|
end
|
1920
1918
|
end
|
1921
1919
|
|
@@ -1935,21 +1933,18 @@ describe Capybara::Webkit::Driver do
|
|
1935
1933
|
make_the_server_go_away
|
1936
1934
|
expect {
|
1937
1935
|
driver.find_xpath("//body")
|
1938
|
-
}.
|
1939
|
-
to raise_error(Capybara::Webkit::NoResponseError, %r{response})
|
1936
|
+
}.to raise_error(Capybara::Webkit::NoResponseError, %r{response})
|
1940
1937
|
make_the_server_come_back
|
1941
1938
|
end
|
1942
1939
|
|
1943
1940
|
def make_the_server_come_back
|
1944
|
-
connection.
|
1945
|
-
connection.unstub(:puts)
|
1946
|
-
connection.unstub(:print)
|
1941
|
+
[:gets, :puts, :print].each { |msg| allow(connection).to receive(msg).and_call_original }
|
1947
1942
|
end
|
1948
1943
|
|
1949
1944
|
def make_the_server_go_away
|
1950
|
-
connection.
|
1951
|
-
connection.
|
1952
|
-
connection.
|
1945
|
+
allow(connection).to receive(:gets).and_return(nil)
|
1946
|
+
allow(connection).to receive(:puts).and_return(nil)
|
1947
|
+
allow(connection).to receive(:print).and_return(nil)
|
1953
1948
|
end
|
1954
1949
|
end
|
1955
1950
|
|
@@ -1981,15 +1976,15 @@ describe Capybara::Webkit::Driver do
|
|
1981
1976
|
end
|
1982
1977
|
|
1983
1978
|
it "ignores custom fonts" do
|
1984
|
-
font_family.
|
1979
|
+
expect(font_family).to eq "Arial"
|
1985
1980
|
end
|
1986
1981
|
|
1987
1982
|
it "ignores custom fonts before an element" do
|
1988
|
-
font_family.
|
1983
|
+
expect(font_family).to eq "Arial"
|
1989
1984
|
end
|
1990
1985
|
|
1991
1986
|
it "ignores custom fonts after an element" do
|
1992
|
-
font_family.
|
1987
|
+
expect(font_family).to eq "Arial"
|
1993
1988
|
end
|
1994
1989
|
end
|
1995
1990
|
|
@@ -2014,27 +2009,27 @@ describe Capybara::Webkit::Driver do
|
|
2014
2009
|
end
|
2015
2010
|
|
2016
2011
|
it "remembers the cookie on second visit" do
|
2017
|
-
echoed_cookie.
|
2012
|
+
expect(echoed_cookie).to eq ""
|
2018
2013
|
visit "/"
|
2019
|
-
echoed_cookie.
|
2014
|
+
expect(echoed_cookie).to eq "abc"
|
2020
2015
|
end
|
2021
2016
|
|
2022
2017
|
it "uses a custom cookie" do
|
2023
2018
|
driver.set_cookie 'cookie=abc; domain=127.0.0.1; path=/'
|
2024
2019
|
visit "/"
|
2025
|
-
echoed_cookie.
|
2020
|
+
expect(echoed_cookie).to eq "abc"
|
2026
2021
|
end
|
2027
2022
|
|
2028
2023
|
it "clears cookies" do
|
2029
2024
|
driver.clear_cookies
|
2030
2025
|
visit "/"
|
2031
|
-
echoed_cookie.
|
2026
|
+
expect(echoed_cookie).to eq ""
|
2032
2027
|
end
|
2033
2028
|
|
2034
2029
|
it "allows reading cookies" do
|
2035
|
-
driver.cookies["cookie"].
|
2036
|
-
driver.cookies.find("cookie").path.
|
2037
|
-
driver.cookies.find("cookie").domain.
|
2030
|
+
expect(driver.cookies["cookie"]).to eq "abc"
|
2031
|
+
expect(driver.cookies.find("cookie").path).to eq "/"
|
2032
|
+
expect(driver.cookies.find("cookie").domain).to include "127.0.0.1"
|
2038
2033
|
end
|
2039
2034
|
end
|
2040
2035
|
|
@@ -2063,7 +2058,7 @@ describe Capybara::Webkit::Driver do
|
|
2063
2058
|
it "allows removed nodes when reloading is disabled" do
|
2064
2059
|
node = driver.find_xpath("//p[@id='removeMe']").first
|
2065
2060
|
driver.evaluate_script("document.getElementById('parent').innerHTML = 'Magic'")
|
2066
|
-
node.visible_text.
|
2061
|
+
expect(node.visible_text).to eq 'Hello'
|
2067
2062
|
end
|
2068
2063
|
end
|
2069
2064
|
|
@@ -2124,8 +2119,8 @@ describe Capybara::Webkit::Driver do
|
|
2124
2119
|
|
2125
2120
|
cases.each do |xpath, path|
|
2126
2121
|
nodes = driver.find_xpath(xpath)
|
2127
|
-
nodes.size.
|
2128
|
-
nodes[0].path.
|
2122
|
+
expect(nodes.size).to eq 1
|
2123
|
+
expect(nodes[0].path).to eq path
|
2129
2124
|
end
|
2130
2125
|
end
|
2131
2126
|
end
|
@@ -2149,7 +2144,7 @@ describe Capybara::Webkit::Driver do
|
|
2149
2144
|
before { visit("/") }
|
2150
2145
|
|
2151
2146
|
it "handles overflow hidden" do
|
2152
|
-
driver.find_xpath("//div[@id='overflow']").first.visible_text.
|
2147
|
+
expect(driver.find_xpath("//div[@id='overflow']").first.visible_text).to eq "Overflow"
|
2153
2148
|
end
|
2154
2149
|
end
|
2155
2150
|
|
@@ -2175,7 +2170,7 @@ describe Capybara::Webkit::Driver do
|
|
2175
2170
|
it "loads a page without error" do
|
2176
2171
|
10.times do
|
2177
2172
|
visit("/redirect")
|
2178
|
-
driver.find_xpath("//p").first.visible_text.
|
2173
|
+
expect(driver.find_xpath("//p").first.visible_text).to eq "finished"
|
2179
2174
|
end
|
2180
2175
|
end
|
2181
2176
|
end
|
@@ -2204,17 +2199,17 @@ describe Capybara::Webkit::Driver do
|
|
2204
2199
|
before { visit("/") }
|
2205
2200
|
|
2206
2201
|
it "displays the message on subsequent page loads" do
|
2207
|
-
driver.find_xpath("//span[contains(.,'localStorage is enabled')]").
|
2202
|
+
expect(driver.find_xpath("//span[contains(.,'localStorage is enabled')]")).to be_empty
|
2208
2203
|
visit "/"
|
2209
|
-
driver.find_xpath("//span[contains(.,'localStorage is enabled')]").
|
2204
|
+
expect(driver.find_xpath("//span[contains(.,'localStorage is enabled')]")).not_to be_empty
|
2210
2205
|
end
|
2211
2206
|
|
2212
2207
|
it "clears the message after a driver reset!" do
|
2213
2208
|
visit "/"
|
2214
|
-
driver.find_xpath("//span[contains(.,'localStorage is enabled')]").
|
2209
|
+
expect(driver.find_xpath("//span[contains(.,'localStorage is enabled')]")).not_to be_empty
|
2215
2210
|
driver.reset!
|
2216
2211
|
visit "/"
|
2217
|
-
driver.find_xpath("//span[contains(.,'localStorage is enabled')]").
|
2212
|
+
expect(driver.find_xpath("//span[contains(.,'localStorage is enabled')]")).to be_empty
|
2218
2213
|
end
|
2219
2214
|
end
|
2220
2215
|
|
@@ -2297,20 +2292,20 @@ CACHE MANIFEST
|
|
2297
2292
|
before { visit("/f8742c39-8bef-4196-b1c3-80f8a3d65f3e") }
|
2298
2293
|
|
2299
2294
|
it "has proper state available" do
|
2300
|
-
driver.find_xpath("//*[@id='state']").first.visible_text.
|
2295
|
+
expect(driver.find_xpath("//*[@id='state']").first.visible_text).to eq '0'
|
2301
2296
|
sleep 1
|
2302
|
-
@visited.
|
2303
|
-
driver.find_xpath("//*[@id='finished']").first.visible_text.
|
2297
|
+
expect(@visited).to eq(['complex', 'manifest', 'simple']), 'files were not downloaded in expected order'
|
2298
|
+
expect(driver.find_xpath("//*[@id='finished']").first.visible_text).to eq 'cached'
|
2304
2299
|
end
|
2305
2300
|
|
2306
2301
|
it "is cleared on driver reset!" do
|
2307
2302
|
sleep 1
|
2308
|
-
@visited.
|
2303
|
+
expect(@visited).to eq(['complex', 'manifest', 'simple']), 'files were not downloaded in expected order'
|
2309
2304
|
driver.reset!
|
2310
2305
|
@visited.clear
|
2311
2306
|
visit '/4aaffa31-f42d-403e-a19e-6b248d608087'
|
2312
2307
|
sleep 1
|
2313
|
-
@visited.
|
2308
|
+
expect(@visited).to eq(['simple', 'manifest', 'simple']), 'simple action was used from cache instead of server'
|
2314
2309
|
end
|
2315
2310
|
end
|
2316
2311
|
|
@@ -2341,7 +2336,7 @@ CACHE MANIFEST
|
|
2341
2336
|
|
2342
2337
|
it "submits a form without clicking" do
|
2343
2338
|
driver.find_xpath("//form")[0].submit
|
2344
|
-
driver.html.
|
2339
|
+
expect(driver.html).to include "Congrats"
|
2345
2340
|
end
|
2346
2341
|
end
|
2347
2342
|
|
@@ -2396,59 +2391,59 @@ CACHE MANIFEST
|
|
2396
2391
|
before { visit("/") }
|
2397
2392
|
|
2398
2393
|
it "returns the charCode for the keypressed" do
|
2399
|
-
charCode_for("a").
|
2400
|
-
charCode_for("A").
|
2401
|
-
charCode_for("\r").
|
2402
|
-
charCode_for(",").
|
2403
|
-
charCode_for("<").
|
2404
|
-
charCode_for("0").
|
2394
|
+
expect(charCode_for("a")).to eq "97"
|
2395
|
+
expect(charCode_for("A")).to eq "65"
|
2396
|
+
expect(charCode_for("\r")).to eq "13"
|
2397
|
+
expect(charCode_for(",")).to eq "44"
|
2398
|
+
expect(charCode_for("<")).to eq "60"
|
2399
|
+
expect(charCode_for("0")).to eq "48"
|
2405
2400
|
end
|
2406
2401
|
|
2407
2402
|
it "returns the keyCode for the keypressed" do
|
2408
|
-
keyCode_for("a").
|
2409
|
-
keyCode_for("A").
|
2410
|
-
keyCode_for("\r").
|
2411
|
-
keyCode_for(",").
|
2412
|
-
keyCode_for("<").
|
2413
|
-
keyCode_for("0").
|
2403
|
+
expect(keyCode_for("a")).to eq "97"
|
2404
|
+
expect(keyCode_for("A")).to eq "65"
|
2405
|
+
expect(keyCode_for("\r")).to eq "13"
|
2406
|
+
expect(keyCode_for(",")).to eq "44"
|
2407
|
+
expect(keyCode_for("<")).to eq "60"
|
2408
|
+
expect(keyCode_for("0")).to eq "48"
|
2414
2409
|
end
|
2415
2410
|
|
2416
2411
|
it "returns the which for the keypressed" do
|
2417
|
-
which_for("a").
|
2418
|
-
which_for("A").
|
2419
|
-
which_for("\r").
|
2420
|
-
which_for(",").
|
2421
|
-
which_for("<").
|
2422
|
-
which_for("0").
|
2412
|
+
expect(which_for("a")).to eq "97"
|
2413
|
+
expect(which_for("A")).to eq "65"
|
2414
|
+
expect(which_for("\r")).to eq "13"
|
2415
|
+
expect(which_for(",")).to eq "44"
|
2416
|
+
expect(which_for("<")).to eq "60"
|
2417
|
+
expect(which_for("0")).to eq "48"
|
2423
2418
|
end
|
2424
2419
|
end
|
2425
2420
|
|
2426
2421
|
shared_examples "a keyupdown app" do
|
2427
2422
|
it "returns a 0 charCode for the event" do
|
2428
|
-
charCode_for("a").
|
2429
|
-
charCode_for("A").
|
2430
|
-
charCode_for("\b").
|
2431
|
-
charCode_for(",").
|
2432
|
-
charCode_for("<").
|
2433
|
-
charCode_for("0").
|
2423
|
+
expect(charCode_for("a")).to eq "0"
|
2424
|
+
expect(charCode_for("A")).to eq "0"
|
2425
|
+
expect(charCode_for("\b")).to eq "0"
|
2426
|
+
expect(charCode_for(",")).to eq "0"
|
2427
|
+
expect(charCode_for("<")).to eq "0"
|
2428
|
+
expect(charCode_for("0")).to eq "0"
|
2434
2429
|
end
|
2435
2430
|
|
2436
2431
|
it "returns the keyCode for the event" do
|
2437
|
-
keyCode_for("a").
|
2438
|
-
keyCode_for("A").
|
2439
|
-
keyCode_for("\b").
|
2440
|
-
keyCode_for(",").
|
2441
|
-
keyCode_for("<").
|
2442
|
-
|
2432
|
+
expect(keyCode_for("a")).to eq "65"
|
2433
|
+
expect(keyCode_for("A")).to eq "65"
|
2434
|
+
expect(keyCode_for("\b")).to eq "8"
|
2435
|
+
expect(keyCode_for(",")).to eq "188"
|
2436
|
+
expect(keyCode_for("<")).to eq "188"
|
2437
|
+
expect( keyCode_for("0")).to eq "48"
|
2443
2438
|
end
|
2444
2439
|
|
2445
2440
|
it "returns the which for the event" do
|
2446
|
-
which_for("a").
|
2447
|
-
which_for("A").
|
2448
|
-
which_for("\b").
|
2449
|
-
which_for(",").
|
2450
|
-
which_for("<").
|
2451
|
-
which_for("0").
|
2441
|
+
expect(which_for("a")).to eq "65"
|
2442
|
+
expect(which_for("A")).to eq "65"
|
2443
|
+
expect(which_for("\b")).to eq "8"
|
2444
|
+
expect(which_for(",")).to eq "188"
|
2445
|
+
expect(which_for("<")).to eq "188"
|
2446
|
+
expect(which_for("0")).to eq "48"
|
2452
2447
|
end
|
2453
2448
|
end
|
2454
2449
|
|
@@ -2490,20 +2485,20 @@ CACHE MANIFEST
|
|
2490
2485
|
it "has the expected text in the new window" do
|
2491
2486
|
visit("/new_window")
|
2492
2487
|
driver.within_window(driver.window_handles.last) do
|
2493
|
-
driver.find_xpath("//p").first.visible_text.
|
2488
|
+
expect(driver.find_xpath("//p").first.visible_text).to eq "finished"
|
2494
2489
|
end
|
2495
2490
|
end
|
2496
2491
|
|
2497
2492
|
it "can switch to another window" do
|
2498
2493
|
visit("/new_window")
|
2499
2494
|
driver.switch_to_window(driver.window_handles.last)
|
2500
|
-
driver.find_xpath("//p").first.visible_text.
|
2495
|
+
expect(driver.find_xpath("//p").first.visible_text).to eq "finished"
|
2501
2496
|
end
|
2502
2497
|
|
2503
2498
|
it "knows the current window handle" do
|
2504
2499
|
visit("/new_window")
|
2505
2500
|
driver.within_window(driver.window_handles.last) do
|
2506
|
-
driver.current_window_handle.
|
2501
|
+
expect(driver.current_window_handle).to eq driver.window_handles.last
|
2507
2502
|
end
|
2508
2503
|
end
|
2509
2504
|
|
@@ -2513,27 +2508,27 @@ CACHE MANIFEST
|
|
2513
2508
|
driver.switch_to_window(driver.window_handles.last)
|
2514
2509
|
driver.close_window(driver.current_window_handle)
|
2515
2510
|
|
2516
|
-
driver.current_window_handle.
|
2511
|
+
expect(driver.current_window_handle).to eq(original_handle)
|
2517
2512
|
end
|
2518
2513
|
|
2519
2514
|
it "can close an unfocused window" do
|
2520
2515
|
visit("/new_window")
|
2521
2516
|
driver.close_window(driver.window_handles.last)
|
2522
|
-
driver.window_handles.size.
|
2517
|
+
expect(driver.window_handles.size).to eq(1)
|
2523
2518
|
end
|
2524
2519
|
|
2525
2520
|
it "can close the last window" do
|
2526
2521
|
visit("/new_window")
|
2527
2522
|
handles = driver.window_handles
|
2528
2523
|
handles.each { |handle| driver.close_window(handle) }
|
2529
|
-
driver.html.
|
2530
|
-
handles.
|
2524
|
+
expect(driver.html).to be_empty
|
2525
|
+
expect(handles).not_to include(driver.current_window_handle)
|
2531
2526
|
end
|
2532
2527
|
|
2533
2528
|
it "waits for the new window to load" do
|
2534
2529
|
visit("/new_window?sleep=1")
|
2535
2530
|
driver.within_window(driver.window_handles.last) do
|
2536
|
-
driver.find_xpath("//p").first.visible_text.
|
2531
|
+
expect(driver.find_xpath("//p").first.visible_text).to eq "finished"
|
2537
2532
|
end
|
2538
2533
|
end
|
2539
2534
|
|
@@ -2541,60 +2536,59 @@ CACHE MANIFEST
|
|
2541
2536
|
visit("/new_window?sleep=2")
|
2542
2537
|
driver.execute_script("setTimeout(function() { window.location = 'about:blank' }, 1000)")
|
2543
2538
|
driver.within_window(driver.window_handles.last) do
|
2544
|
-
driver.find_xpath("//p").first.visible_text.
|
2539
|
+
expect(driver.find_xpath("//p").first.visible_text).to eq "finished"
|
2545
2540
|
end
|
2546
2541
|
end
|
2547
2542
|
|
2548
2543
|
it "switches back to the original window" do
|
2549
2544
|
visit("/new_window")
|
2550
2545
|
driver.within_window(driver.window_handles.last) { }
|
2551
|
-
driver.find_xpath("//p").first.visible_text.
|
2546
|
+
expect(driver.find_xpath("//p").first.visible_text).to eq "bananas"
|
2552
2547
|
end
|
2553
2548
|
|
2554
2549
|
it "supports finding a window by name" do
|
2555
2550
|
visit("/new_window")
|
2556
2551
|
driver.within_window('myWindow') do
|
2557
|
-
driver.find_xpath("//p").first.visible_text.
|
2552
|
+
expect(driver.find_xpath("//p").first.visible_text).to eq "finished"
|
2558
2553
|
end
|
2559
2554
|
end
|
2560
2555
|
|
2561
2556
|
it "supports finding a window by title" do
|
2562
2557
|
visit("/new_window?sleep=5")
|
2563
2558
|
driver.within_window('My New Window') do
|
2564
|
-
driver.find_xpath("//p").first.visible_text.
|
2559
|
+
expect(driver.find_xpath("//p").first.visible_text).to eq "finished"
|
2565
2560
|
end
|
2566
2561
|
end
|
2567
2562
|
|
2568
2563
|
it "supports finding a window by url" do
|
2569
2564
|
visit("/new_window?test")
|
2570
2565
|
driver.within_window(driver_url(driver, "/?test")) do
|
2571
|
-
driver.find_xpath("//p").first.visible_text.
|
2566
|
+
expect(driver.find_xpath("//p").first.visible_text).to eq "finished"
|
2572
2567
|
end
|
2573
2568
|
end
|
2574
2569
|
|
2575
2570
|
it "raises an error if the window is not found" do
|
2576
|
-
expect { driver.within_window('myWindowDoesNotExist') }.
|
2577
|
-
to raise_error(Capybara::Webkit::NoSuchWindowError)
|
2571
|
+
expect { driver.within_window('myWindowDoesNotExist') }.to raise_error(Capybara::Webkit::NoSuchWindowError)
|
2578
2572
|
end
|
2579
2573
|
|
2580
2574
|
it "has a number of window handles equal to the number of open windows" do
|
2581
|
-
driver.window_handles.size.
|
2575
|
+
expect(driver.window_handles.size).to eq 1
|
2582
2576
|
visit("/new_window")
|
2583
|
-
driver.window_handles.size.
|
2577
|
+
expect(driver.window_handles.size).to eq 2
|
2584
2578
|
end
|
2585
2579
|
|
2586
2580
|
it "removes windows when closed via JavaScript" do
|
2587
2581
|
visit("/new_window")
|
2588
2582
|
driver.execute_script('console.log(window.document.title); window.close()')
|
2589
2583
|
sleep 2
|
2590
|
-
driver.window_handles.size.
|
2584
|
+
expect(driver.window_handles.size).to eq 1
|
2591
2585
|
end
|
2592
2586
|
|
2593
2587
|
it "closes new windows on reset" do
|
2594
2588
|
visit("/new_window")
|
2595
2589
|
last_handle = driver.window_handles.last
|
2596
2590
|
driver.reset!
|
2597
|
-
driver.window_handles.
|
2591
|
+
expect(driver.window_handles).not_to include(last_handle)
|
2598
2592
|
end
|
2599
2593
|
|
2600
2594
|
it "leaves the old window focused when opening a new window" do
|
@@ -2602,15 +2596,15 @@ CACHE MANIFEST
|
|
2602
2596
|
current_window = driver.current_window_handle
|
2603
2597
|
driver.open_new_window
|
2604
2598
|
|
2605
|
-
driver.current_window_handle.
|
2606
|
-
driver.window_handles.size.
|
2599
|
+
expect(driver.current_window_handle).to eq current_window
|
2600
|
+
expect(driver.window_handles.size).to eq 3
|
2607
2601
|
end
|
2608
2602
|
|
2609
2603
|
it "opens blank windows" do
|
2610
2604
|
visit("/new_window")
|
2611
2605
|
driver.open_new_window
|
2612
2606
|
driver.switch_to_window(driver.window_handles.last)
|
2613
|
-
driver.html.
|
2607
|
+
expect(driver.html).to be_empty
|
2614
2608
|
end
|
2615
2609
|
end
|
2616
2610
|
|
@@ -2633,7 +2627,7 @@ CACHE MANIFEST
|
|
2633
2627
|
end
|
2634
2628
|
|
2635
2629
|
visit("/new_window", driver)
|
2636
|
-
driver.cookies['session_id'].
|
2630
|
+
expect(driver.cookies['session_id']).to eq session_id
|
2637
2631
|
end
|
2638
2632
|
|
2639
2633
|
context "timers app" do
|
@@ -2708,27 +2702,27 @@ CACHE MANIFEST
|
|
2708
2702
|
it "can authenticate a request" do
|
2709
2703
|
driver.authenticate('user', 'password')
|
2710
2704
|
visit("/")
|
2711
|
-
driver.html.
|
2705
|
+
expect(driver.html).to include("Basic "+Base64.encode64("user:password").strip)
|
2712
2706
|
end
|
2713
2707
|
|
2714
2708
|
it "returns 401 for incorrectly authenticated request" do
|
2715
2709
|
driver.authenticate('user1', 'password1')
|
2716
|
-
|
2717
|
-
driver.status_code.
|
2710
|
+
expect { visit("/") }.not_to raise_error
|
2711
|
+
expect(driver.status_code).to eq 401
|
2718
2712
|
end
|
2719
2713
|
|
2720
2714
|
it "returns 401 for unauthenticated request" do
|
2721
|
-
|
2722
|
-
driver.status_code.
|
2715
|
+
expect { visit("/") }.not_to raise_error
|
2716
|
+
expect(driver.status_code).to eq 401
|
2723
2717
|
end
|
2724
2718
|
|
2725
2719
|
it "can be reset with subsequent authenticate call", skip_on_qt4: true do
|
2726
2720
|
driver.authenticate('user', 'password')
|
2727
2721
|
visit("/")
|
2728
|
-
driver.html.
|
2722
|
+
expect(driver.html).to include("Basic "+Base64.encode64("user:password").strip)
|
2729
2723
|
driver.authenticate('user1', 'password1')
|
2730
|
-
|
2731
|
-
driver.status_code.
|
2724
|
+
expect{ visit("/") }.not_to raise_error
|
2725
|
+
expect(driver.status_code).to eq 401
|
2732
2726
|
end
|
2733
2727
|
end
|
2734
2728
|
|
@@ -2779,40 +2773,40 @@ CACHE MANIFEST
|
|
2779
2773
|
it "should not fetch urls blocked by host" do
|
2780
2774
|
visit("/")
|
2781
2775
|
driver.within_frame('frame1') do
|
2782
|
-
driver.find_xpath("//body").first.visible_text.
|
2776
|
+
expect(driver.find_xpath("//body").first.visible_text).to be_empty
|
2783
2777
|
end
|
2784
2778
|
end
|
2785
2779
|
|
2786
2780
|
it "should not fetch urls blocked by path" do
|
2787
2781
|
visit('/')
|
2788
2782
|
driver.within_frame('frame2') do
|
2789
|
-
driver.find_xpath("//body").first.visible_text.
|
2783
|
+
expect(driver.find_xpath("//body").first.visible_text).to be_empty
|
2790
2784
|
end
|
2791
2785
|
end
|
2792
2786
|
|
2793
2787
|
it "should not fetch blocked scripts" do
|
2794
2788
|
visit("/")
|
2795
|
-
driver.html.
|
2789
|
+
expect(driver.html).not_to include("Script Run")
|
2796
2790
|
end
|
2797
2791
|
|
2798
2792
|
it "should fetch unblocked urls" do
|
2799
2793
|
visit('/')
|
2800
2794
|
driver.within_frame('frame3') do
|
2801
|
-
driver.find_xpath("//p").first.visible_text.
|
2795
|
+
expect(driver.find_xpath("//p").first.visible_text).to eq "Inner"
|
2802
2796
|
end
|
2803
2797
|
end
|
2804
2798
|
|
2805
2799
|
it "should not fetch urls blocked by wildcard match" do
|
2806
2800
|
visit('/')
|
2807
2801
|
driver.within_frame('frame4') do
|
2808
|
-
driver.find("//body").first.text.
|
2802
|
+
expect(driver.find("//body").first.text).to be_empty
|
2809
2803
|
end
|
2810
2804
|
end
|
2811
2805
|
|
2812
2806
|
it "returns a status code for blocked urls" do
|
2813
2807
|
visit("/")
|
2814
2808
|
driver.within_frame('frame1') do
|
2815
|
-
driver.status_code.
|
2809
|
+
expect(driver.status_code).to eq 200
|
2816
2810
|
end
|
2817
2811
|
end
|
2818
2812
|
end
|
@@ -2937,46 +2931,46 @@ CACHE MANIFEST
|
|
2937
2931
|
|
2938
2932
|
it "should not raise a timeout error when zero" do
|
2939
2933
|
configure { |config| config.timeout = 0 }
|
2940
|
-
|
2934
|
+
expect{ visit("/") }.not_to raise_error
|
2941
2935
|
end
|
2942
2936
|
|
2943
2937
|
it "should raise a timeout error" do
|
2944
2938
|
configure { |config| config.timeout = 1 }
|
2945
|
-
|
2939
|
+
expect{ visit("/") }.to raise_error(Timeout::Error, "Request timed out after 1 second(s)")
|
2946
2940
|
end
|
2947
2941
|
|
2948
2942
|
it "should not raise an error when the timeout is high enough" do
|
2949
2943
|
configure { |config| config.timeout = 10 }
|
2950
|
-
|
2944
|
+
expect { visit("/") }.not_to raise_error
|
2951
2945
|
end
|
2952
2946
|
|
2953
2947
|
it "should set the timeout for each request" do
|
2954
2948
|
configure { |config| config.timeout = 10 }
|
2955
|
-
|
2949
|
+
expect{ visit("/") }.not_to raise_error
|
2956
2950
|
driver.timeout = 1
|
2957
|
-
|
2951
|
+
expect{ visit("/") }.to raise_error(Timeout::Error)
|
2958
2952
|
end
|
2959
2953
|
|
2960
2954
|
it "should set the timeout for each request" do
|
2961
2955
|
configure { |config| config.timeout = 1 }
|
2962
|
-
|
2956
|
+
expect { visit("/") }.to raise_error(Timeout::Error)
|
2963
2957
|
driver.reset!
|
2964
2958
|
driver.timeout = 10
|
2965
|
-
|
2959
|
+
expect{ visit("/") }.not_to raise_error
|
2966
2960
|
end
|
2967
2961
|
|
2968
2962
|
it "should raise a timeout on a slow form" do
|
2969
2963
|
configure { |config| config.timeout = 3 }
|
2970
2964
|
visit("/")
|
2971
|
-
driver.status_code.
|
2965
|
+
expect(driver.status_code).to eq 200
|
2972
2966
|
driver.timeout = 1
|
2973
2967
|
driver.find_xpath("//input").first.click
|
2974
|
-
|
2968
|
+
expect { driver.status_code }.to raise_error(Timeout::Error)
|
2975
2969
|
end
|
2976
2970
|
|
2977
2971
|
it "get timeout" do
|
2978
2972
|
configure { |config| config.timeout = 10 }
|
2979
|
-
driver.browser.timeout.
|
2973
|
+
expect(driver.browser.timeout).to eq 10
|
2980
2974
|
end
|
2981
2975
|
end
|
2982
2976
|
|
@@ -2989,13 +2983,13 @@ CACHE MANIFEST
|
|
2989
2983
|
it "logs nothing in normal mode" do
|
2990
2984
|
configure { |config| config.debug = false }
|
2991
2985
|
visit("/")
|
2992
|
-
stderr.
|
2986
|
+
expect(stderr).not_to include logging_message
|
2993
2987
|
end
|
2994
2988
|
|
2995
2989
|
it "logs its commands in debug mode" do
|
2996
2990
|
configure { |config| config.debug = true }
|
2997
2991
|
visit("/")
|
2998
|
-
stderr.
|
2992
|
+
expect(stderr).to include logging_message
|
2999
2993
|
end
|
3000
2994
|
|
3001
2995
|
let(:logging_message) { 'Wrote response true' }
|
@@ -3036,7 +3030,7 @@ CACHE MANIFEST
|
|
3036
3030
|
it 'should not hang the server' do
|
3037
3031
|
visit('/')
|
3038
3032
|
driver.find_xpath('//input').first.click
|
3039
|
-
driver.console_messages.first[:message].
|
3033
|
+
expect(driver.console_messages.first[:message]).to eq "hello"
|
3040
3034
|
end
|
3041
3035
|
end
|
3042
3036
|
|
@@ -3055,7 +3049,7 @@ CACHE MANIFEST
|
|
3055
3049
|
it 'returns an xpath for the current node' do
|
3056
3050
|
visit('/')
|
3057
3051
|
path = driver.find_xpath('//span').first.path
|
3058
|
-
driver.find_xpath(path).first.text.
|
3052
|
+
expect(driver.find_xpath(path).first.text).to eq 'hello'
|
3059
3053
|
end
|
3060
3054
|
end
|
3061
3055
|
|
@@ -3106,11 +3100,11 @@ CACHE MANIFEST
|
|
3106
3100
|
|
3107
3101
|
it "includes Capybara, capybara-webkit, Qt, and WebKit versions" do
|
3108
3102
|
result = driver.version
|
3109
|
-
result.
|
3110
|
-
result.
|
3111
|
-
result.
|
3112
|
-
result.
|
3113
|
-
result.
|
3103
|
+
expect(result).to include("Capybara: #{Capybara::VERSION}")
|
3104
|
+
expect(result).to include("capybara-webkit: #{Capybara::Driver::Webkit::VERSION}")
|
3105
|
+
expect(result).to match /Qt: \d+\.\d+\.\d+/
|
3106
|
+
expect(result).to match /WebKit: \d+\.\d+/
|
3107
|
+
expect(result).to match /QtWebKit: \d+\.\d+/
|
3114
3108
|
end
|
3115
3109
|
end
|
3116
3110
|
|
@@ -3132,13 +3126,13 @@ CACHE MANIFEST
|
|
3132
3126
|
|
3133
3127
|
it "can navigate in history" do
|
3134
3128
|
visit("/first")
|
3135
|
-
driver.find_xpath("//p").first.text.
|
3129
|
+
expect(driver.find_xpath("//p").first.text).to eq('first')
|
3136
3130
|
driver.find_xpath("//a").first.click
|
3137
|
-
driver.find_xpath("//p").first.text.
|
3131
|
+
expect(driver.find_xpath("//p").first.text).to eq('navigated')
|
3138
3132
|
driver.go_back
|
3139
|
-
driver.find_xpath("//p").first.text.
|
3133
|
+
expect(driver.find_xpath("//p").first.text).to eq('first')
|
3140
3134
|
driver.go_forward
|
3141
|
-
driver.find_xpath("//p").first.text.
|
3135
|
+
expect(driver.find_xpath("//p").first.text).to eq('navigated')
|
3142
3136
|
end
|
3143
3137
|
end
|
3144
3138
|
|
@@ -3197,8 +3191,8 @@ CACHE MANIFEST
|
|
3197
3191
|
visit "/"
|
3198
3192
|
sleep 0.5
|
3199
3193
|
driver.reset!
|
3200
|
-
stderr.
|
3201
|
-
stderr.
|
3194
|
+
expect(stderr).to abort_request_to("/async?2")
|
3195
|
+
expect(stderr).not_to abort_request_to("/async?1")
|
3202
3196
|
end
|
3203
3197
|
|
3204
3198
|
def abort_request_to(path)
|
@@ -3264,13 +3258,13 @@ CACHE MANIFEST
|
|
3264
3258
|
|
3265
3259
|
context "with default settings" do
|
3266
3260
|
it "doesn't accept a self-signed certificate" do
|
3267
|
-
|
3261
|
+
expect { driver.visit "https://#{@host}:#{@port}/" }.to raise_error(Capybara::Webkit::InvalidResponseError)
|
3268
3262
|
end
|
3269
3263
|
|
3270
3264
|
it "doesn't accept a self-signed certificate in a new window" do
|
3271
3265
|
driver.execute_script("window.open('about:blank')")
|
3272
3266
|
driver.switch_to_window(driver.window_handles.last)
|
3273
|
-
|
3267
|
+
expect { driver.visit "https://#{@host}:#{@port}/" }.to raise_error(Capybara::Webkit::InvalidResponseError)
|
3274
3268
|
end
|
3275
3269
|
end
|
3276
3270
|
|
@@ -3331,13 +3325,13 @@ CACHE MANIFEST
|
|
3331
3325
|
|
3332
3326
|
it "should load images by default" do
|
3333
3327
|
visit("/")
|
3334
|
-
requests.
|
3328
|
+
expect(requests).to match_array %w(image bgimage)
|
3335
3329
|
end
|
3336
3330
|
|
3337
3331
|
it "should not load images when disabled" do
|
3338
3332
|
configure(&:skip_image_loading)
|
3339
3333
|
visit("/")
|
3340
|
-
requests.
|
3334
|
+
expect(requests).to eq []
|
3341
3335
|
end
|
3342
3336
|
|
3343
3337
|
let(:requests) do
|
@@ -3394,7 +3388,7 @@ CACHE MANIFEST
|
|
3394
3388
|
fork_connection
|
3395
3389
|
|
3396
3390
|
driver.visit @url
|
3397
|
-
@proxy_requests.size.
|
3391
|
+
expect(@proxy_requests.size).to eq 2
|
3398
3392
|
@request = @proxy_requests[-1]
|
3399
3393
|
end
|
3400
3394
|
|
@@ -3408,43 +3402,88 @@ CACHE MANIFEST
|
|
3408
3402
|
end
|
3409
3403
|
|
3410
3404
|
it "uses the HTTP proxy correctly" do
|
3411
|
-
@request[0].
|
3412
|
-
@request.find { |header|
|
3413
|
-
header =~ /^Host:\s+example.org$/i }.should_not be nil
|
3405
|
+
expect(@request[0]).to match(/^GET\s+http:\/\/example.org\/\s+HTTP/i)
|
3406
|
+
expect(@request.find { |header| header =~ /^Host:\s+example.org$/i }).not_to be nil
|
3414
3407
|
end
|
3415
3408
|
|
3416
3409
|
it "sends correct proxy authentication" do
|
3417
3410
|
auth_header = @request.find { |header|
|
3418
3411
|
header =~ /^Proxy-Authorization:\s+/i }
|
3419
|
-
auth_header.
|
3412
|
+
expect(auth_header).not_to be nil
|
3420
3413
|
|
3421
3414
|
user, pass = Base64.decode64(auth_header.split(/\s+/)[-1]).split(":")
|
3422
|
-
user.
|
3423
|
-
pass.
|
3415
|
+
expect(user).to eq @user
|
3416
|
+
expect(pass).to eq @pass
|
3424
3417
|
end
|
3425
3418
|
|
3426
3419
|
it "uses the proxy's response" do
|
3427
|
-
driver.html.
|
3420
|
+
expect(driver.html).to include "D'oh!"
|
3428
3421
|
end
|
3429
3422
|
|
3430
3423
|
it "uses original URL" do
|
3431
|
-
driver.current_url.
|
3424
|
+
expect(driver.current_url).to eq @url
|
3432
3425
|
end
|
3433
3426
|
|
3434
3427
|
it "uses URLs changed by javascript" do
|
3435
3428
|
driver.execute_script %{window.history.pushState("", "", "/blah")}
|
3436
|
-
driver.current_url.
|
3429
|
+
expect(driver.current_url).to eq "http://example.org/blah"
|
3437
3430
|
end
|
3438
3431
|
|
3439
3432
|
it "is possible to disable proxy again" do
|
3440
3433
|
@proxy_requests.clear
|
3441
3434
|
driver.browser.clear_proxy
|
3442
3435
|
driver.visit "http://#{@host}:#{@port}/"
|
3443
|
-
@proxy_requests.size.
|
3436
|
+
expect(@proxy_requests.size).to eq 0
|
3444
3437
|
end
|
3445
3438
|
end
|
3446
3439
|
|
3447
3440
|
def driver_url(driver, path)
|
3448
3441
|
URI.parse(driver.current_url).merge(path).to_s
|
3449
3442
|
end
|
3443
|
+
|
3444
|
+
context "page with JavaScript errors" do
|
3445
|
+
let(:driver) do
|
3446
|
+
driver_for_app do
|
3447
|
+
get "/" do
|
3448
|
+
<<-HTML
|
3449
|
+
<!DOCTYPE html>
|
3450
|
+
<html>
|
3451
|
+
<body>
|
3452
|
+
<script type="text/javascript">
|
3453
|
+
undefinedFunc();
|
3454
|
+
</script>
|
3455
|
+
</body>
|
3456
|
+
</html>
|
3457
|
+
HTML
|
3458
|
+
end
|
3459
|
+
end
|
3460
|
+
end
|
3461
|
+
|
3462
|
+
it "raises errors as an exception, when configured" do
|
3463
|
+
configure do |config|
|
3464
|
+
config.raise_javascript_errors = true
|
3465
|
+
end
|
3466
|
+
|
3467
|
+
expected_error = Capybara::Webkit::JavaScriptError
|
3468
|
+
expected_message = "ReferenceError: Can't find variable: undefinedFunc"
|
3469
|
+
|
3470
|
+
expect { visit("/") }.to raise_error(expected_error) do |error|
|
3471
|
+
expect(error.javascript_errors.first[:message]).to eq expected_message
|
3472
|
+
end
|
3473
|
+
expect { driver.find_css("h1") }.to raise_error(expected_error)
|
3474
|
+
end
|
3475
|
+
|
3476
|
+
it "does not raise an exception when fetching the error messages" do
|
3477
|
+
configure do |config|
|
3478
|
+
config.raise_javascript_errors = true
|
3479
|
+
end
|
3480
|
+
|
3481
|
+
expect { driver.error_messages }.to_not raise_error
|
3482
|
+
end
|
3483
|
+
|
3484
|
+
it "does not raise errors as an exception by default" do
|
3485
|
+
expect { visit("/") }.to_not raise_error
|
3486
|
+
expect(driver.error_messages).to_not be_empty
|
3487
|
+
end
|
3488
|
+
end
|
3450
3489
|
end
|