capybara-webkit 1.0.0 → 1.1.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 +7 -0
- data/.gitignore +1 -0
- data/.travis.yml +2 -3
- data/Gemfile.lock +25 -27
- data/NEWS.md +12 -0
- data/README.md +1 -1
- data/Rakefile +9 -5
- data/capybara-webkit.gemspec +2 -1
- data/gemfiles/2.0.gemfile.lock +7 -7
- data/gemfiles/2.1.gemfile.lock +5 -5
- data/lib/capybara/webkit/connection.rb +1 -0
- data/lib/capybara/webkit/cookie_jar.rb +1 -1
- data/lib/capybara/webkit/node.rb +1 -5
- data/lib/capybara/webkit/version.rb +1 -1
- data/lib/capybara_webkit_builder.rb +2 -2
- data/spec/browser_spec.rb +18 -18
- data/spec/connection_spec.rb +4 -4
- data/spec/cookie_jar_spec.rb +9 -9
- data/spec/driver_rendering_spec.rb +9 -9
- data/spec/driver_spec.rb +242 -181
- data/spec/integration/session_spec.rb +86 -15
- data/spec/support/app_runner.rb +6 -0
- data/src/FindCss.cpp +1 -1
- data/src/FindXpath.cpp +1 -1
- data/src/IgnoreDebugOutput.cpp +36 -0
- data/src/IgnoreDebugOutput.h +1 -0
- data/src/InvocationResult.cpp +2 -0
- data/src/JavascriptInvocation.cpp +25 -18
- data/src/JavascriptInvocation.h +5 -2
- data/src/NetworkAccessManager.cpp +10 -0
- data/src/NetworkAccessManager.h +2 -0
- data/src/Node.cpp +2 -1
- data/src/Visit.cpp +1 -1
- data/src/WebPage.cpp +22 -4
- data/src/WebPage.h +5 -2
- data/src/WebPageManager.cpp +4 -3
- data/src/capybara.js +107 -52
- data/src/main.cpp +2 -1
- data/src/pointer.png +0 -0
- data/src/webkit_server.pro +9 -2
- data/src/webkit_server.qrc +1 -0
- data/test/testignoredebugoutput.cpp +45 -0
- data/test/testwebkitserver.pro +5 -0
- data/webkit_server.pro +3 -1
- metadata +86 -42
data/spec/cookie_jar_spec.rb
CHANGED
|
@@ -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.should
|
|
20
|
+
subject.find("cookie1", "www.facebook.com").domain.should 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.should
|
|
25
|
-
subject.find("cookie1", "www.facebook.com").value.should
|
|
26
|
-
subject.find("cookie2", "sub1.example.org").value.should
|
|
24
|
+
subject.find("cookie1", "example.org").value.should eq "1"
|
|
25
|
+
subject.find("cookie1", "www.facebook.com").value.should eq "3"
|
|
26
|
+
subject.find("cookie2", "sub1.example.org").value.should 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").should
|
|
30
|
+
subject.find("cookie2", "www.example.org").should eq nil
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
it "respects path precedence rules" do
|
|
34
|
-
subject.find("cookie1", "www.example.org").value.should
|
|
35
|
-
subject.find("cookie1", "www.example.org", "/dir1/123").value.should
|
|
34
|
+
subject.find("cookie1", "www.example.org").value.should eq "1"
|
|
35
|
+
subject.find("cookie1", "www.example.org", "/dir1/123").value.should 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"].should
|
|
41
|
+
subject["cookie1", "example.org"].should eq "1"
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
it "returns nil if no cookie is found" do
|
|
45
|
-
subject["notexisting"].should
|
|
45
|
+
subject["notexisting"].should eq nil
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
48
|
end
|
|
@@ -34,7 +34,7 @@ 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].should
|
|
37
|
+
@image[:format].should eq "PNG"
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
it "width default to 1000px (with 15px less for the scrollbar)" do
|
|
@@ -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].should
|
|
54
|
+
@image[:width].should eq 500
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
it "height should match the height given" do
|
|
58
|
-
@image[:height].should
|
|
58
|
+
@image[:height].should 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').should
|
|
63
|
-
driver.evaluate_script('window.innerHeight').should
|
|
62
|
+
driver.evaluate_script('window.innerWidth').should eq 1680
|
|
63
|
+
driver.evaluate_script('window.innerHeight').should eq 1050
|
|
64
64
|
end
|
|
65
65
|
end
|
|
66
66
|
|
|
@@ -76,8 +76,8 @@ describe Capybara::Webkit::Driver, "rendering an image" do
|
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
it "should restore viewport dimensions after rendering" do
|
|
79
|
-
driver.evaluate_script('window.innerWidth').should
|
|
80
|
-
driver.evaluate_script('window.innerHeight').should
|
|
79
|
+
driver.evaluate_script('window.innerWidth').should eq 1680
|
|
80
|
+
driver.evaluate_script('window.innerHeight').should 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').should
|
|
90
|
-
driver.evaluate_script('window.innerHeight').should
|
|
89
|
+
driver.evaluate_script('window.innerWidth').should eq 800
|
|
90
|
+
driver.evaluate_script('window.innerHeight').should eq 600
|
|
91
91
|
end
|
|
92
92
|
end
|
|
93
93
|
end
|
data/spec/driver_spec.rb
CHANGED
|
@@ -93,7 +93,7 @@ describe Capybara::Webkit::Driver do
|
|
|
93
93
|
|
|
94
94
|
it "returns an attribute's value" do
|
|
95
95
|
driver.within_frame("f") do
|
|
96
|
-
driver.find_xpath("//p").first["id"].should
|
|
96
|
+
driver.find_xpath("//p").first["id"].should eq "farewell"
|
|
97
97
|
end
|
|
98
98
|
end
|
|
99
99
|
|
|
@@ -108,20 +108,20 @@ describe Capybara::Webkit::Driver do
|
|
|
108
108
|
|
|
109
109
|
it "returns a node's text" do
|
|
110
110
|
driver.within_frame("f") do
|
|
111
|
-
driver.find_xpath("//p").first.visible_text.should
|
|
111
|
+
driver.find_xpath("//p").first.visible_text.should eq "goodbye"
|
|
112
112
|
end
|
|
113
113
|
end
|
|
114
114
|
|
|
115
115
|
it "returns the current URL" do
|
|
116
116
|
driver.within_frame("f") do
|
|
117
|
-
driver.current_url.should
|
|
117
|
+
driver.current_url.should eq driver_url(driver, "/iframe")
|
|
118
118
|
end
|
|
119
119
|
end
|
|
120
120
|
|
|
121
121
|
it "evaluates Javascript" do
|
|
122
122
|
driver.within_frame("f") do
|
|
123
123
|
result = driver.evaluate_script(%<document.getElementById('farewell').innerText>)
|
|
124
|
-
result.should
|
|
124
|
+
result.should eq "goodbye"
|
|
125
125
|
end
|
|
126
126
|
end
|
|
127
127
|
|
|
@@ -137,24 +137,24 @@ describe Capybara::Webkit::Driver do
|
|
|
137
137
|
|
|
138
138
|
driver.within_frame("f") {}
|
|
139
139
|
|
|
140
|
-
driver.current_url.should
|
|
140
|
+
driver.current_url.should eq original_url
|
|
141
141
|
end
|
|
142
142
|
|
|
143
143
|
it "returns the headers for the page" do
|
|
144
144
|
driver.within_frame("f") do
|
|
145
|
-
driver.response_headers['X-Redirected'].should
|
|
145
|
+
driver.response_headers['X-Redirected'].should eq "true"
|
|
146
146
|
end
|
|
147
147
|
end
|
|
148
148
|
|
|
149
149
|
it "returns the status code for the page" do
|
|
150
150
|
driver.within_frame("f") do
|
|
151
|
-
driver.status_code.should
|
|
151
|
+
driver.status_code.should eq 200
|
|
152
152
|
end
|
|
153
153
|
end
|
|
154
154
|
|
|
155
155
|
it "returns the document title" do
|
|
156
156
|
driver.within_frame("f") do
|
|
157
|
-
driver.title.should
|
|
157
|
+
driver.title.should eq "Title"
|
|
158
158
|
end
|
|
159
159
|
end
|
|
160
160
|
end
|
|
@@ -223,35 +223,35 @@ describe Capybara::Webkit::Driver do
|
|
|
223
223
|
it "should redirect without content type" do
|
|
224
224
|
visit("/form")
|
|
225
225
|
driver.find_xpath("//input").first.click
|
|
226
|
-
driver.find_xpath("//p").first.visible_text.should
|
|
226
|
+
driver.find_xpath("//p").first.visible_text.should eq ""
|
|
227
227
|
end
|
|
228
228
|
|
|
229
229
|
it "returns the current URL when changed by pushState after a redirect" do
|
|
230
230
|
visit("/redirect-me")
|
|
231
|
-
driver.current_url.should
|
|
231
|
+
driver.current_url.should eq driver_url(driver, "/target")
|
|
232
232
|
driver.execute_script("window.history.pushState({}, '', '/pushed-after-redirect')")
|
|
233
|
-
driver.current_url.should
|
|
233
|
+
driver.current_url.should eq driver_url(driver, "/pushed-after-redirect")
|
|
234
234
|
end
|
|
235
235
|
|
|
236
236
|
it "returns the current URL when changed by replaceState after a redirect" do
|
|
237
237
|
visit("/redirect-me")
|
|
238
|
-
driver.current_url.should
|
|
238
|
+
driver.current_url.should eq driver_url(driver, "/target")
|
|
239
239
|
driver.execute_script("window.history.replaceState({}, '', '/replaced-after-redirect')")
|
|
240
|
-
driver.current_url.should
|
|
240
|
+
driver.current_url.should eq driver_url(driver, "/replaced-after-redirect")
|
|
241
241
|
end
|
|
242
242
|
|
|
243
243
|
it "should make headers available through response_headers" do
|
|
244
244
|
visit('/redirect-me')
|
|
245
|
-
driver.response_headers['X-Redirected'].should
|
|
245
|
+
driver.response_headers['X-Redirected'].should eq "true"
|
|
246
246
|
visit('/target')
|
|
247
|
-
driver.response_headers['X-Redirected'].should
|
|
247
|
+
driver.response_headers['X-Redirected'].should eq "false"
|
|
248
248
|
end
|
|
249
249
|
|
|
250
250
|
it "should make the status code available through status_code" do
|
|
251
251
|
visit('/redirect-me')
|
|
252
|
-
driver.status_code.should
|
|
252
|
+
driver.status_code.should eq 200
|
|
253
253
|
visit('/target')
|
|
254
|
-
driver.status_code.should
|
|
254
|
+
driver.status_code.should eq 200
|
|
255
255
|
end
|
|
256
256
|
end
|
|
257
257
|
|
|
@@ -272,7 +272,7 @@ describe Capybara::Webkit::Driver do
|
|
|
272
272
|
end
|
|
273
273
|
|
|
274
274
|
it "sets the response headers with respect to the unsupported request" do
|
|
275
|
-
driver.response_headers["Content-Type"].should
|
|
275
|
+
driver.response_headers["Content-Type"].should eq "text/css"
|
|
276
276
|
end
|
|
277
277
|
|
|
278
278
|
it "does not wrap the content in HTML tags" do
|
|
@@ -315,7 +315,7 @@ describe Capybara::Webkit::Driver do
|
|
|
315
315
|
|
|
316
316
|
it "should return the binary content" do
|
|
317
317
|
src = driver.html.force_encoding('binary')
|
|
318
|
-
src.should
|
|
318
|
+
src.should eq "Hello\xFF\xFF\xFF\xFFWorld".force_encoding('binary')
|
|
319
319
|
end
|
|
320
320
|
end
|
|
321
321
|
|
|
@@ -371,7 +371,7 @@ describe Capybara::Webkit::Driver do
|
|
|
371
371
|
|
|
372
372
|
it "has a blank location after reseting" do
|
|
373
373
|
driver.reset!
|
|
374
|
-
driver.current_url.should
|
|
374
|
+
driver.current_url.should eq "about:blank"
|
|
375
375
|
end
|
|
376
376
|
|
|
377
377
|
it "raises an error for an invalid xpath query" do
|
|
@@ -385,7 +385,7 @@ describe Capybara::Webkit::Driver do
|
|
|
385
385
|
end
|
|
386
386
|
|
|
387
387
|
it "returns an attribute's value" do
|
|
388
|
-
driver.find_xpath("//p").first["id"].should
|
|
388
|
+
driver.find_xpath("//p").first["id"].should eq "greeting"
|
|
389
389
|
end
|
|
390
390
|
|
|
391
391
|
it "parses xpath with quotes" do
|
|
@@ -393,30 +393,30 @@ describe Capybara::Webkit::Driver do
|
|
|
393
393
|
end
|
|
394
394
|
|
|
395
395
|
it "returns a node's visible text" do
|
|
396
|
-
driver.find_xpath("//*[@id='hidden-text']").first.visible_text.should
|
|
396
|
+
driver.find_xpath("//*[@id='hidden-text']").first.visible_text.should eq "Some of this text is"
|
|
397
397
|
end
|
|
398
398
|
|
|
399
399
|
it "normalizes a node's text" do
|
|
400
|
-
driver.find_xpath("//div[contains(@class, 'normalize')]").first.visible_text.should
|
|
400
|
+
driver.find_xpath("//div[contains(@class, 'normalize')]").first.visible_text.should eq "Spaces not normalized"
|
|
401
401
|
end
|
|
402
402
|
|
|
403
403
|
it "returns all of a node's text" do
|
|
404
|
-
driver.find_xpath("//*[@id='hidden-text']").first.all_text.should
|
|
404
|
+
driver.find_xpath("//*[@id='hidden-text']").first.all_text.should eq "Some of this text is hidden!"
|
|
405
405
|
end
|
|
406
406
|
|
|
407
407
|
it "returns the current URL" do
|
|
408
408
|
visit "/hello/world?success=true"
|
|
409
|
-
driver.current_url.should
|
|
409
|
+
driver.current_url.should eq driver_url(driver, "/hello/world?success=true")
|
|
410
410
|
end
|
|
411
411
|
|
|
412
412
|
it "returns the current URL when changed by pushState" do
|
|
413
413
|
driver.execute_script("window.history.pushState({}, '', '/pushed')")
|
|
414
|
-
driver.current_url.should
|
|
414
|
+
driver.current_url.should eq driver_url(driver, "/pushed")
|
|
415
415
|
end
|
|
416
416
|
|
|
417
417
|
it "returns the current URL when changed by replaceState" do
|
|
418
418
|
driver.execute_script("window.history.replaceState({}, '', '/replaced')")
|
|
419
|
-
driver.current_url.should
|
|
419
|
+
driver.current_url.should eq driver_url(driver, "/replaced")
|
|
420
420
|
end
|
|
421
421
|
|
|
422
422
|
it "does not double-encode URLs" do
|
|
@@ -424,6 +424,12 @@ describe Capybara::Webkit::Driver do
|
|
|
424
424
|
driver.current_url.should =~ /success=\%25true/
|
|
425
425
|
end
|
|
426
426
|
|
|
427
|
+
it "returns the current URL with encoded characters" do
|
|
428
|
+
visit("/hello/world?success[value]=true")
|
|
429
|
+
current_url = Rack::Utils.unescape(driver.current_url)
|
|
430
|
+
current_url.should include('success[value]=true')
|
|
431
|
+
end
|
|
432
|
+
|
|
427
433
|
it "visits a page with an anchor" do
|
|
428
434
|
visit("/hello#display_none")
|
|
429
435
|
driver.current_url.should =~ /hello#display_none/
|
|
@@ -431,37 +437,37 @@ describe Capybara::Webkit::Driver do
|
|
|
431
437
|
|
|
432
438
|
it "evaluates Javascript and returns a string" do
|
|
433
439
|
result = driver.evaluate_script(%<document.getElementById('greeting').innerText>)
|
|
434
|
-
result.should
|
|
440
|
+
result.should eq "hello"
|
|
435
441
|
end
|
|
436
442
|
|
|
437
443
|
it "evaluates Javascript and returns an array" do
|
|
438
444
|
result = driver.evaluate_script(%<["hello", "world"]>)
|
|
439
|
-
result.should
|
|
445
|
+
result.should eq %w(hello world)
|
|
440
446
|
end
|
|
441
447
|
|
|
442
448
|
it "evaluates Javascript and returns an int" do
|
|
443
449
|
result = driver.evaluate_script(%<123>)
|
|
444
|
-
result.should
|
|
450
|
+
result.should eq 123
|
|
445
451
|
end
|
|
446
452
|
|
|
447
453
|
it "evaluates Javascript and returns a float" do
|
|
448
454
|
result = driver.evaluate_script(%<1.5>)
|
|
449
|
-
result.should
|
|
455
|
+
result.should eq 1.5
|
|
450
456
|
end
|
|
451
457
|
|
|
452
458
|
it "evaluates Javascript and returns null" do
|
|
453
459
|
result = driver.evaluate_script(%<(function () {})()>)
|
|
454
|
-
result.should
|
|
460
|
+
result.should eq nil
|
|
455
461
|
end
|
|
456
462
|
|
|
457
463
|
it "evaluates Infinity and returns null" do
|
|
458
464
|
result = driver.evaluate_script(%<Infinity>)
|
|
459
|
-
result.should
|
|
465
|
+
result.should eq nil
|
|
460
466
|
end
|
|
461
467
|
|
|
462
468
|
it "evaluates Javascript and returns an object" do
|
|
463
469
|
result = driver.evaluate_script(%<({ 'one' : 1 })>)
|
|
464
|
-
result.should
|
|
470
|
+
result.should eq 'one' => 1
|
|
465
471
|
end
|
|
466
472
|
|
|
467
473
|
it "evaluates Javascript and returns true" do
|
|
@@ -481,7 +487,7 @@ describe Capybara::Webkit::Driver do
|
|
|
481
487
|
|
|
482
488
|
it "evaluates Javascript with multiple lines" do
|
|
483
489
|
result = driver.evaluate_script("[1,\n2]")
|
|
484
|
-
result.should
|
|
490
|
+
result.should eq [1, 2]
|
|
485
491
|
end
|
|
486
492
|
|
|
487
493
|
it "executes Javascript" do
|
|
@@ -500,7 +506,7 @@ describe Capybara::Webkit::Driver do
|
|
|
500
506
|
end
|
|
501
507
|
|
|
502
508
|
it "returns a node's tag name" do
|
|
503
|
-
driver.find_xpath("//p").first.tag_name.should
|
|
509
|
+
driver.find_xpath("//p").first.tag_name.should eq "p"
|
|
504
510
|
end
|
|
505
511
|
|
|
506
512
|
it "reads disabled property" do
|
|
@@ -518,11 +524,11 @@ describe Capybara::Webkit::Driver do
|
|
|
518
524
|
end
|
|
519
525
|
|
|
520
526
|
it "returns the document title" do
|
|
521
|
-
driver.title.should
|
|
527
|
+
driver.title.should eq "Title"
|
|
522
528
|
end
|
|
523
529
|
|
|
524
530
|
it "finds elements by CSS" do
|
|
525
|
-
driver.find_css("p").first.visible_text.should
|
|
531
|
+
driver.find_css("p").first.visible_text.should eq "hello"
|
|
526
532
|
end
|
|
527
533
|
end
|
|
528
534
|
|
|
@@ -542,7 +548,7 @@ describe Capybara::Webkit::Driver do
|
|
|
542
548
|
before { visit("/") }
|
|
543
549
|
|
|
544
550
|
it "should handle text for svg elements" do
|
|
545
|
-
driver.find_xpath("//*[@id='navy_text']").first.visible_text.should
|
|
551
|
+
driver.find_xpath("//*[@id='navy_text']").first.visible_text.should eq "In the navy!"
|
|
546
552
|
end
|
|
547
553
|
end
|
|
548
554
|
|
|
@@ -582,7 +588,7 @@ describe Capybara::Webkit::Driver do
|
|
|
582
588
|
|
|
583
589
|
it "supports multi-line console messages" do
|
|
584
590
|
message = driver.console_messages[2]
|
|
585
|
-
message[:message].should
|
|
591
|
+
message[:message].should eq "hello\nnewline"
|
|
586
592
|
end
|
|
587
593
|
|
|
588
594
|
it "empties the array when reset" do
|
|
@@ -592,13 +598,13 @@ describe Capybara::Webkit::Driver do
|
|
|
592
598
|
|
|
593
599
|
it "supports console messages from an unknown source" do
|
|
594
600
|
driver.execute_script("console.log('hello')")
|
|
595
|
-
driver.console_messages.last[:message].should
|
|
601
|
+
driver.console_messages.last[:message].should eq 'hello'
|
|
596
602
|
driver.console_messages.last[:source].should be_nil
|
|
597
603
|
driver.console_messages.last[:line_number].should be_nil
|
|
598
604
|
end
|
|
599
605
|
|
|
600
606
|
it "escapes unicode console messages" do
|
|
601
|
-
driver.console_messages[3][:message].should
|
|
607
|
+
driver.console_messages[3][:message].should eq '𝄞'
|
|
602
608
|
end
|
|
603
609
|
end
|
|
604
610
|
|
|
@@ -621,7 +627,7 @@ describe Capybara::Webkit::Driver do
|
|
|
621
627
|
before { visit("/") }
|
|
622
628
|
|
|
623
629
|
it "should let me read my alert messages" do
|
|
624
|
-
driver.alert_messages.first.should
|
|
630
|
+
driver.alert_messages.first.should eq "Alert Text\nGoes Here"
|
|
625
631
|
end
|
|
626
632
|
|
|
627
633
|
it "empties the array when reset" do
|
|
@@ -655,25 +661,25 @@ describe Capybara::Webkit::Driver do
|
|
|
655
661
|
|
|
656
662
|
it "should default to accept the confirm" do
|
|
657
663
|
driver.find_xpath("//input").first.click
|
|
658
|
-
driver.console_messages.first[:message].should
|
|
664
|
+
driver.console_messages.first[:message].should eq "hello"
|
|
659
665
|
end
|
|
660
666
|
|
|
661
667
|
it "can dismiss the confirm" do
|
|
662
668
|
driver.dismiss_js_confirms!
|
|
663
669
|
driver.find_xpath("//input").first.click
|
|
664
|
-
driver.console_messages.first[:message].should
|
|
670
|
+
driver.console_messages.first[:message].should eq "goodbye"
|
|
665
671
|
end
|
|
666
672
|
|
|
667
673
|
it "can accept the confirm explicitly" do
|
|
668
674
|
driver.dismiss_js_confirms!
|
|
669
675
|
driver.accept_js_confirms!
|
|
670
676
|
driver.find_xpath("//input").first.click
|
|
671
|
-
driver.console_messages.first[:message].should
|
|
677
|
+
driver.console_messages.first[:message].should eq "hello"
|
|
672
678
|
end
|
|
673
679
|
|
|
674
|
-
it "should collect the
|
|
680
|
+
it "should collect the javascript confirm dialog contents" do
|
|
675
681
|
driver.find_xpath("//input").first.click
|
|
676
|
-
driver.confirm_messages.first.should
|
|
682
|
+
driver.confirm_messages.first.should eq "Yes?"
|
|
677
683
|
end
|
|
678
684
|
|
|
679
685
|
it "empties the array when reset" do
|
|
@@ -687,12 +693,12 @@ describe Capybara::Webkit::Driver do
|
|
|
687
693
|
driver.reset!
|
|
688
694
|
visit("/")
|
|
689
695
|
driver.find_xpath("//input").first.click
|
|
690
|
-
driver.console_messages.first[:message].should
|
|
696
|
+
driver.console_messages.first[:message].should eq "hello"
|
|
691
697
|
end
|
|
692
698
|
|
|
693
699
|
it "supports multi-line confirmation messages" do
|
|
694
700
|
driver.execute_script("confirm('Hello\\nnewline')")
|
|
695
|
-
driver.confirm_messages.first.should
|
|
701
|
+
driver.confirm_messages.first.should eq "Hello\nnewline"
|
|
696
702
|
end
|
|
697
703
|
|
|
698
704
|
end
|
|
@@ -723,42 +729,42 @@ describe Capybara::Webkit::Driver do
|
|
|
723
729
|
|
|
724
730
|
it "should default to dismiss the prompt" do
|
|
725
731
|
driver.find_xpath("//input").first.click
|
|
726
|
-
driver.console_messages.first[:message].should
|
|
732
|
+
driver.console_messages.first[:message].should eq "goodbye"
|
|
727
733
|
end
|
|
728
734
|
|
|
729
735
|
it "can accept the prompt without providing text" do
|
|
730
736
|
driver.accept_js_prompts!
|
|
731
737
|
driver.find_xpath("//input").first.click
|
|
732
|
-
driver.console_messages.first[:message].should
|
|
738
|
+
driver.console_messages.first[:message].should eq "hello John Smith"
|
|
733
739
|
end
|
|
734
740
|
|
|
735
741
|
it "can accept the prompt with input" do
|
|
736
742
|
driver.js_prompt_input = "Capy"
|
|
737
743
|
driver.accept_js_prompts!
|
|
738
744
|
driver.find_xpath("//input").first.click
|
|
739
|
-
driver.console_messages.first[:message].should
|
|
745
|
+
driver.console_messages.first[:message].should eq "hello Capy"
|
|
740
746
|
end
|
|
741
747
|
|
|
742
748
|
it "can return to dismiss the prompt after accepting prompts" do
|
|
743
749
|
driver.accept_js_prompts!
|
|
744
750
|
driver.dismiss_js_prompts!
|
|
745
751
|
driver.find_xpath("//input").first.click
|
|
746
|
-
driver.console_messages.first[:message].should
|
|
752
|
+
driver.console_messages.first[:message].should eq "goodbye"
|
|
747
753
|
end
|
|
748
754
|
|
|
749
755
|
it "should let me remove the prompt input text" do
|
|
750
756
|
driver.js_prompt_input = "Capy"
|
|
751
757
|
driver.accept_js_prompts!
|
|
752
758
|
driver.find_xpath("//input").first.click
|
|
753
|
-
driver.console_messages.first[:message].should
|
|
759
|
+
driver.console_messages.first[:message].should eq "hello Capy"
|
|
754
760
|
driver.js_prompt_input = nil
|
|
755
761
|
driver.find_xpath("//input").first.click
|
|
756
|
-
driver.console_messages.last[:message].should
|
|
762
|
+
driver.console_messages.last[:message].should eq "hello John Smith"
|
|
757
763
|
end
|
|
758
764
|
|
|
759
|
-
it "should collect the
|
|
765
|
+
it "should collect the javascript prompt dialog contents" do
|
|
760
766
|
driver.find_xpath("//input").first.click
|
|
761
|
-
driver.prompt_messages.first.should
|
|
767
|
+
driver.prompt_messages.first.should eq "Your name?"
|
|
762
768
|
end
|
|
763
769
|
|
|
764
770
|
it "empties the array when reset" do
|
|
@@ -772,12 +778,12 @@ describe Capybara::Webkit::Driver do
|
|
|
772
778
|
driver.reset!
|
|
773
779
|
visit("/")
|
|
774
780
|
driver.find_xpath("//input").first.click
|
|
775
|
-
driver.console_messages.first[:message].should
|
|
781
|
+
driver.console_messages.first[:message].should eq "goodbye"
|
|
776
782
|
end
|
|
777
783
|
|
|
778
784
|
it "supports multi-line prompt messages" do
|
|
779
785
|
driver.execute_script("prompt('Hello\\nnewline')")
|
|
780
|
-
driver.prompt_messages.first.should
|
|
786
|
+
driver.prompt_messages.first.should eq "Hello\nnewline"
|
|
781
787
|
end
|
|
782
788
|
|
|
783
789
|
end
|
|
@@ -825,57 +831,57 @@ describe Capybara::Webkit::Driver do
|
|
|
825
831
|
before { visit("/") }
|
|
826
832
|
|
|
827
833
|
it "returns a textarea's value" do
|
|
828
|
-
driver.find_xpath("//textarea").first.value.should
|
|
834
|
+
driver.find_xpath("//textarea").first.value.should eq "what a wonderful area for text"
|
|
829
835
|
end
|
|
830
836
|
|
|
831
837
|
it "returns a text input's value" do
|
|
832
|
-
driver.find_xpath("//input").first.value.should
|
|
838
|
+
driver.find_xpath("//input").first.value.should eq "bar"
|
|
833
839
|
end
|
|
834
840
|
|
|
835
841
|
it "returns a select's value" do
|
|
836
|
-
driver.find_xpath("//select").first.value.should
|
|
842
|
+
driver.find_xpath("//select").first.value.should eq "Capybara"
|
|
837
843
|
end
|
|
838
844
|
|
|
839
845
|
it "sets an input's value" do
|
|
840
846
|
input = driver.find_xpath("//input").first
|
|
841
847
|
input.set("newvalue")
|
|
842
|
-
input.value.should
|
|
848
|
+
input.value.should eq "newvalue"
|
|
843
849
|
end
|
|
844
850
|
|
|
845
851
|
it "sets an input's value greater than the max length" do
|
|
846
852
|
input = driver.find_xpath("//input[@name='maxlength_foo']").first
|
|
847
853
|
input.set("allegories (poems)")
|
|
848
|
-
input.value.should
|
|
854
|
+
input.value.should eq "allegories"
|
|
849
855
|
end
|
|
850
856
|
|
|
851
857
|
it "sets an input's value equal to the max length" do
|
|
852
858
|
input = driver.find_xpath("//input[@name='maxlength_foo']").first
|
|
853
859
|
input.set("allegories")
|
|
854
|
-
input.value.should
|
|
860
|
+
input.value.should eq "allegories"
|
|
855
861
|
end
|
|
856
862
|
|
|
857
863
|
it "sets an input's value less than the max length" do
|
|
858
864
|
input = driver.find_xpath("//input[@name='maxlength_foo']").first
|
|
859
865
|
input.set("poems")
|
|
860
|
-
input.value.should
|
|
866
|
+
input.value.should eq "poems"
|
|
861
867
|
end
|
|
862
868
|
|
|
863
869
|
it "sets an input's nil value" do
|
|
864
870
|
input = driver.find_xpath("//input").first
|
|
865
871
|
input.set(nil)
|
|
866
|
-
input.value.should
|
|
872
|
+
input.value.should eq ""
|
|
867
873
|
end
|
|
868
874
|
|
|
869
875
|
it "sets a select's value" do
|
|
870
876
|
select = driver.find_xpath("//select").first
|
|
871
877
|
select.set("Monkey")
|
|
872
|
-
select.value.should
|
|
878
|
+
select.value.should eq "Monkey"
|
|
873
879
|
end
|
|
874
880
|
|
|
875
881
|
it "sets a textarea's value" do
|
|
876
882
|
textarea = driver.find_xpath("//textarea").first
|
|
877
883
|
textarea.set("newvalue")
|
|
878
|
-
textarea.value.should
|
|
884
|
+
textarea.value.should eq "newvalue"
|
|
879
885
|
end
|
|
880
886
|
|
|
881
887
|
let(:monkey_option) { driver.find_xpath("//option[@id='select-option-monkey']").first }
|
|
@@ -891,12 +897,12 @@ describe Capybara::Webkit::Driver do
|
|
|
891
897
|
|
|
892
898
|
context "a select element's selection has been changed" do
|
|
893
899
|
before do
|
|
894
|
-
animal_select.value.should
|
|
900
|
+
animal_select.value.should eq "Capybara"
|
|
895
901
|
monkey_option.select_option
|
|
896
902
|
end
|
|
897
903
|
|
|
898
904
|
it "returns the new selection" do
|
|
899
|
-
animal_select.value.should
|
|
905
|
+
animal_select.value.should eq "Monkey"
|
|
900
906
|
end
|
|
901
907
|
|
|
902
908
|
it "does not modify the selected attribute of a new selection" do
|
|
@@ -906,7 +912,7 @@ describe Capybara::Webkit::Driver do
|
|
|
906
912
|
it "returns the old value when a reset button is clicked" do
|
|
907
913
|
reset_button.click
|
|
908
914
|
|
|
909
|
-
animal_select.value.should
|
|
915
|
+
animal_select.value.should eq "Capybara"
|
|
910
916
|
end
|
|
911
917
|
end
|
|
912
918
|
|
|
@@ -945,7 +951,7 @@ describe Capybara::Webkit::Driver do
|
|
|
945
951
|
banana_option.unselect_option
|
|
946
952
|
cherry_option.unselect_option
|
|
947
953
|
|
|
948
|
-
toppings_select.value.should
|
|
954
|
+
toppings_select.value.should eq []
|
|
949
955
|
|
|
950
956
|
apple_option.select_option
|
|
951
957
|
banana_option.select_option
|
|
@@ -1007,7 +1013,7 @@ describe Capybara::Webkit::Driver do
|
|
|
1007
1013
|
it "does not modify a readonly input" do
|
|
1008
1014
|
readonly_input = driver.find_css("#readonly_input").first
|
|
1009
1015
|
readonly_input.set('enabled')
|
|
1010
|
-
readonly_input.value.should
|
|
1016
|
+
readonly_input.value.should eq 'readonly'
|
|
1011
1017
|
end
|
|
1012
1018
|
|
|
1013
1019
|
it "should see enabled options in disabled select as disabled" do
|
|
@@ -1050,18 +1056,18 @@ describe Capybara::Webkit::Driver do
|
|
|
1050
1056
|
|
|
1051
1057
|
it "triggers mouse events" do
|
|
1052
1058
|
watch.click
|
|
1053
|
-
fired_events.should
|
|
1059
|
+
fired_events.should eq %w(mousedown mouseup click)
|
|
1054
1060
|
end
|
|
1055
1061
|
|
|
1056
1062
|
it "triggers double click" do
|
|
1057
1063
|
# check event order at http://www.quirksmode.org/dom/events/click.html
|
|
1058
1064
|
watch.double_click
|
|
1059
|
-
fired_events.should
|
|
1065
|
+
fired_events.should eq %w(mousedown mouseup click mousedown mouseup click dblclick)
|
|
1060
1066
|
end
|
|
1061
1067
|
|
|
1062
1068
|
it "triggers right click" do
|
|
1063
1069
|
watch.right_click
|
|
1064
|
-
fired_events.should
|
|
1070
|
+
fired_events.should eq %w(mousedown contextmenu mouseup)
|
|
1065
1071
|
end
|
|
1066
1072
|
end
|
|
1067
1073
|
|
|
@@ -1122,23 +1128,23 @@ describe Capybara::Webkit::Driver do
|
|
|
1122
1128
|
%w(email number password search tel text url).each do | field_type |
|
|
1123
1129
|
it "triggers text input events on inputs of type #{field_type}" do
|
|
1124
1130
|
driver.find_xpath("//input[@type='#{field_type}']").first.set(newtext)
|
|
1125
|
-
driver.find_xpath("//li").map(&:visible_text).should
|
|
1131
|
+
driver.find_xpath("//li").map(&:visible_text).should eq keyevents
|
|
1126
1132
|
end
|
|
1127
1133
|
end
|
|
1128
1134
|
|
|
1129
1135
|
it "triggers textarea input events" do
|
|
1130
1136
|
driver.find_xpath("//textarea").first.set(newtext)
|
|
1131
|
-
driver.find_xpath("//li").map(&:visible_text).should
|
|
1137
|
+
driver.find_xpath("//li").map(&:visible_text).should eq keyevents
|
|
1132
1138
|
end
|
|
1133
1139
|
|
|
1134
1140
|
it "triggers radio input events" do
|
|
1135
1141
|
driver.find_xpath("//input[@type='radio']").first.set(true)
|
|
1136
|
-
driver.find_xpath("//li").map(&:visible_text).should
|
|
1142
|
+
driver.find_xpath("//li").map(&:visible_text).should eq %w(mousedown focus mouseup change click)
|
|
1137
1143
|
end
|
|
1138
1144
|
|
|
1139
1145
|
it "triggers checkbox events" do
|
|
1140
1146
|
driver.find_xpath("//input[@type='checkbox']").first.set(true)
|
|
1141
|
-
driver.find_xpath("//li").map(&:visible_text).should
|
|
1147
|
+
driver.find_xpath("//li").map(&:visible_text).should eq %w(mousedown focus mouseup change click)
|
|
1142
1148
|
end
|
|
1143
1149
|
end
|
|
1144
1150
|
|
|
@@ -1228,10 +1234,10 @@ describe Capybara::Webkit::Driver do
|
|
|
1228
1234
|
|
|
1229
1235
|
it "fires a change on select" do
|
|
1230
1236
|
select = driver.find_xpath("//select").first
|
|
1231
|
-
select.value.should
|
|
1237
|
+
select.value.should eq "1"
|
|
1232
1238
|
option = driver.find_xpath("//option[@id='option-2']").first
|
|
1233
1239
|
option.select_option
|
|
1234
|
-
select.value.should
|
|
1240
|
+
select.value.should eq "2"
|
|
1235
1241
|
driver.find_xpath("//select[@class='triggered']").should_not be_empty
|
|
1236
1242
|
end
|
|
1237
1243
|
|
|
@@ -1241,7 +1247,7 @@ describe Capybara::Webkit::Driver do
|
|
|
1241
1247
|
|
|
1242
1248
|
draggable.drag_to(container)
|
|
1243
1249
|
|
|
1244
|
-
driver.find_xpath("//*[@class='triggered']").size.should
|
|
1250
|
+
driver.find_xpath("//*[@class='triggered']").size.should eq 1
|
|
1245
1251
|
end
|
|
1246
1252
|
end
|
|
1247
1253
|
|
|
@@ -1261,12 +1267,12 @@ describe Capybara::Webkit::Driver do
|
|
|
1261
1267
|
|
|
1262
1268
|
it "evaluates nested xpath expressions" do
|
|
1263
1269
|
parent = driver.find_xpath("//*[@id='parent']").first
|
|
1264
|
-
parent.find_xpath("./*[@class='find']").map(&:visible_text).should
|
|
1270
|
+
parent.find_xpath("./*[@class='find']").map(&:visible_text).should eq %w(Expected)
|
|
1265
1271
|
end
|
|
1266
1272
|
|
|
1267
1273
|
it "finds elements by CSS" do
|
|
1268
1274
|
parent = driver.find_css("#parent").first
|
|
1269
|
-
parent.find_css(".find").first.visible_text.should
|
|
1275
|
+
parent.find_css(".find").first.visible_text.should eq "Expected"
|
|
1270
1276
|
end
|
|
1271
1277
|
end
|
|
1272
1278
|
|
|
@@ -1286,7 +1292,7 @@ describe Capybara::Webkit::Driver do
|
|
|
1286
1292
|
end
|
|
1287
1293
|
visit("/", driver)
|
|
1288
1294
|
driver.find_xpath("//a").first.click
|
|
1289
|
-
result.should
|
|
1295
|
+
result.should eq "finished"
|
|
1290
1296
|
end
|
|
1291
1297
|
end
|
|
1292
1298
|
|
|
@@ -1348,7 +1354,7 @@ describe Capybara::Webkit::Driver do
|
|
|
1348
1354
|
driver.find_xpath("//input").first.click
|
|
1349
1355
|
expect { driver.find_xpath("//p") }.to raise_error(Capybara::Webkit::InvalidResponseError)
|
|
1350
1356
|
visit("/")
|
|
1351
|
-
driver.find_xpath("//p").first.visible_text.should
|
|
1357
|
+
driver.find_xpath("//p").first.visible_text.should eq "hello"
|
|
1352
1358
|
end
|
|
1353
1359
|
end
|
|
1354
1360
|
|
|
@@ -1374,7 +1380,7 @@ describe Capybara::Webkit::Driver do
|
|
|
1374
1380
|
before { visit("/") }
|
|
1375
1381
|
|
|
1376
1382
|
it "doesn't crash from alerts" do
|
|
1377
|
-
driver.find_xpath("//p").first.visible_text.should
|
|
1383
|
+
driver.find_xpath("//p").first.visible_text.should eq "success"
|
|
1378
1384
|
end
|
|
1379
1385
|
end
|
|
1380
1386
|
|
|
@@ -1404,31 +1410,31 @@ describe Capybara::Webkit::Driver do
|
|
|
1404
1410
|
end
|
|
1405
1411
|
|
|
1406
1412
|
it "can set user_agent" do
|
|
1407
|
-
driver.find_xpath('id("user-agent")').first.visible_text.should
|
|
1408
|
-
driver.evaluate_script('navigator.userAgent').should
|
|
1413
|
+
driver.find_xpath('id("user-agent")').first.visible_text.should eq 'capybara-webkit/custom-user-agent'
|
|
1414
|
+
driver.evaluate_script('navigator.userAgent').should eq 'capybara-webkit/custom-user-agent'
|
|
1409
1415
|
end
|
|
1410
1416
|
|
|
1411
1417
|
it "keep user_agent in next page" do
|
|
1412
1418
|
driver.find_xpath("//a").first.click
|
|
1413
|
-
driver.find_xpath('id("user-agent")').first.visible_text.should
|
|
1414
|
-
driver.evaluate_script('navigator.userAgent').should
|
|
1419
|
+
driver.find_xpath('id("user-agent")').first.visible_text.should eq 'capybara-webkit/custom-user-agent'
|
|
1420
|
+
driver.evaluate_script('navigator.userAgent').should eq 'capybara-webkit/custom-user-agent'
|
|
1415
1421
|
end
|
|
1416
1422
|
|
|
1417
1423
|
it "can set custom header" do
|
|
1418
|
-
driver.find_xpath('id("x-capybara-webkit-header")').first.visible_text.should
|
|
1424
|
+
driver.find_xpath('id("x-capybara-webkit-header")').first.visible_text.should eq 'x-capybara-webkit-header'
|
|
1419
1425
|
end
|
|
1420
1426
|
|
|
1421
1427
|
it "can set Accept header" do
|
|
1422
|
-
driver.find_xpath('id("accept")').first.visible_text.should
|
|
1428
|
+
driver.find_xpath('id("accept")').first.visible_text.should eq 'text/html'
|
|
1423
1429
|
end
|
|
1424
1430
|
|
|
1425
1431
|
it "can reset all custom header" do
|
|
1426
1432
|
driver.reset!
|
|
1427
1433
|
visit('/')
|
|
1428
|
-
driver.find_xpath('id("user-agent")').first.visible_text.should_not
|
|
1429
|
-
driver.evaluate_script('navigator.userAgent').should_not
|
|
1434
|
+
driver.find_xpath('id("user-agent")').first.visible_text.should_not eq 'capybara-webkit/custom-user-agent'
|
|
1435
|
+
driver.evaluate_script('navigator.userAgent').should_not eq 'capybara-webkit/custom-user-agent'
|
|
1430
1436
|
driver.find_xpath('id("x-capybara-webkit-header")').first.visible_text.should be_empty
|
|
1431
|
-
driver.find_xpath('id("accept")').first.visible_text.should_not
|
|
1437
|
+
driver.find_xpath('id("accept")').first.visible_text.should_not eq 'text/html'
|
|
1432
1438
|
end
|
|
1433
1439
|
end
|
|
1434
1440
|
|
|
@@ -1453,15 +1459,15 @@ describe Capybara::Webkit::Driver do
|
|
|
1453
1459
|
end
|
|
1454
1460
|
|
|
1455
1461
|
def make_the_server_come_back
|
|
1456
|
-
driver.browser.instance_variable_get(:@connection).unstub
|
|
1457
|
-
driver.browser.instance_variable_get(:@connection).unstub
|
|
1458
|
-
driver.browser.instance_variable_get(:@connection).unstub
|
|
1462
|
+
driver.browser.instance_variable_get(:@connection).unstub(:gets)
|
|
1463
|
+
driver.browser.instance_variable_get(:@connection).unstub(:puts)
|
|
1464
|
+
driver.browser.instance_variable_get(:@connection).unstub(:print)
|
|
1459
1465
|
end
|
|
1460
1466
|
|
|
1461
1467
|
def make_the_server_go_away
|
|
1462
|
-
driver.browser.instance_variable_get(:@connection).stub
|
|
1463
|
-
driver.browser.instance_variable_get(:@connection).stub
|
|
1464
|
-
driver.browser.instance_variable_get(:@connection).stub
|
|
1468
|
+
driver.browser.instance_variable_get(:@connection).stub(:gets).and_return(nil)
|
|
1469
|
+
driver.browser.instance_variable_get(:@connection).stub(:puts)
|
|
1470
|
+
driver.browser.instance_variable_get(:@connection).stub(:print)
|
|
1465
1471
|
end
|
|
1466
1472
|
end
|
|
1467
1473
|
|
|
@@ -1493,15 +1499,15 @@ describe Capybara::Webkit::Driver do
|
|
|
1493
1499
|
end
|
|
1494
1500
|
|
|
1495
1501
|
it "ignores custom fonts" do
|
|
1496
|
-
font_family.should
|
|
1502
|
+
font_family.should eq "Arial"
|
|
1497
1503
|
end
|
|
1498
1504
|
|
|
1499
1505
|
it "ignores custom fonts before an element" do
|
|
1500
|
-
font_family.should
|
|
1506
|
+
font_family.should eq "Arial"
|
|
1501
1507
|
end
|
|
1502
1508
|
|
|
1503
1509
|
it "ignores custom fonts after an element" do
|
|
1504
|
-
font_family.should
|
|
1510
|
+
font_family.should eq "Arial"
|
|
1505
1511
|
end
|
|
1506
1512
|
end
|
|
1507
1513
|
|
|
@@ -1526,36 +1532,36 @@ describe Capybara::Webkit::Driver do
|
|
|
1526
1532
|
end
|
|
1527
1533
|
|
|
1528
1534
|
it "remembers the cookie on second visit" do
|
|
1529
|
-
echoed_cookie.should
|
|
1535
|
+
echoed_cookie.should eq ""
|
|
1530
1536
|
visit "/"
|
|
1531
|
-
echoed_cookie.should
|
|
1537
|
+
echoed_cookie.should eq "abc"
|
|
1532
1538
|
end
|
|
1533
1539
|
|
|
1534
1540
|
it "uses a custom cookie" do
|
|
1535
1541
|
driver.browser.set_cookie 'cookie=abc; domain=127.0.0.1; path=/'
|
|
1536
1542
|
visit "/"
|
|
1537
|
-
echoed_cookie.should
|
|
1543
|
+
echoed_cookie.should eq "abc"
|
|
1538
1544
|
end
|
|
1539
1545
|
|
|
1540
1546
|
it "clears cookies" do
|
|
1541
1547
|
driver.browser.clear_cookies
|
|
1542
1548
|
visit "/"
|
|
1543
|
-
echoed_cookie.should
|
|
1549
|
+
echoed_cookie.should eq ""
|
|
1544
1550
|
end
|
|
1545
1551
|
|
|
1546
1552
|
it "allows enumeration of cookies" do
|
|
1547
1553
|
cookies = driver.browser.get_cookies
|
|
1548
1554
|
|
|
1549
|
-
cookies.size.should
|
|
1555
|
+
cookies.size.should eq 1
|
|
1550
1556
|
|
|
1551
1557
|
cookie = Hash[cookies[0].split(/\s*;\s*/).map { |x| x.split("=", 2) }]
|
|
1552
|
-
cookie["cookie"].should
|
|
1558
|
+
cookie["cookie"].should eq "abc"
|
|
1553
1559
|
cookie["domain"].should include "127.0.0.1"
|
|
1554
|
-
cookie["path"].should
|
|
1560
|
+
cookie["path"].should eq "/"
|
|
1555
1561
|
end
|
|
1556
1562
|
|
|
1557
1563
|
it "allows reading access to cookies using a nice syntax" do
|
|
1558
|
-
driver.cookies["cookie"].should
|
|
1564
|
+
driver.cookies["cookie"].should eq "abc"
|
|
1559
1565
|
end
|
|
1560
1566
|
end
|
|
1561
1567
|
|
|
@@ -1584,7 +1590,7 @@ describe Capybara::Webkit::Driver do
|
|
|
1584
1590
|
it "allows removed nodes when reloading is disabled" do
|
|
1585
1591
|
node = driver.find_xpath("//p[@id='removeMe']").first
|
|
1586
1592
|
driver.evaluate_script("document.getElementById('parent').innerHTML = 'Magic'")
|
|
1587
|
-
node.visible_text.should
|
|
1593
|
+
node.visible_text.should eq 'Hello'
|
|
1588
1594
|
end
|
|
1589
1595
|
end
|
|
1590
1596
|
|
|
@@ -1645,8 +1651,8 @@ describe Capybara::Webkit::Driver do
|
|
|
1645
1651
|
|
|
1646
1652
|
cases.each do |xpath, path|
|
|
1647
1653
|
nodes = driver.find_xpath(xpath)
|
|
1648
|
-
nodes.size.should
|
|
1649
|
-
nodes[0].path.should
|
|
1654
|
+
nodes.size.should eq 1
|
|
1655
|
+
nodes[0].path.should eq path
|
|
1650
1656
|
end
|
|
1651
1657
|
end
|
|
1652
1658
|
end
|
|
@@ -1670,7 +1676,7 @@ describe Capybara::Webkit::Driver do
|
|
|
1670
1676
|
before { visit("/") }
|
|
1671
1677
|
|
|
1672
1678
|
it "handles overflow hidden" do
|
|
1673
|
-
driver.find_xpath("//div[@id='overflow']").first.visible_text.should
|
|
1679
|
+
driver.find_xpath("//div[@id='overflow']").first.visible_text.should eq "Overflow"
|
|
1674
1680
|
end
|
|
1675
1681
|
end
|
|
1676
1682
|
|
|
@@ -1696,7 +1702,7 @@ describe Capybara::Webkit::Driver do
|
|
|
1696
1702
|
it "loads a page without error" do
|
|
1697
1703
|
10.times do
|
|
1698
1704
|
visit("/redirect")
|
|
1699
|
-
driver.find_xpath("//p").first.visible_text.should
|
|
1705
|
+
driver.find_xpath("//p").first.visible_text.should eq "finished"
|
|
1700
1706
|
end
|
|
1701
1707
|
end
|
|
1702
1708
|
end
|
|
@@ -1821,59 +1827,59 @@ describe Capybara::Webkit::Driver do
|
|
|
1821
1827
|
before { visit("/") }
|
|
1822
1828
|
|
|
1823
1829
|
it "returns the charCode for the keypressed" do
|
|
1824
|
-
charCode_for("a").should
|
|
1825
|
-
charCode_for("A").should
|
|
1826
|
-
charCode_for("\r").should
|
|
1827
|
-
charCode_for(",").should
|
|
1828
|
-
charCode_for("<").should
|
|
1829
|
-
charCode_for("0").should
|
|
1830
|
+
charCode_for("a").should eq "97"
|
|
1831
|
+
charCode_for("A").should eq "65"
|
|
1832
|
+
charCode_for("\r").should eq "13"
|
|
1833
|
+
charCode_for(",").should eq "44"
|
|
1834
|
+
charCode_for("<").should eq "60"
|
|
1835
|
+
charCode_for("0").should eq "48"
|
|
1830
1836
|
end
|
|
1831
1837
|
|
|
1832
1838
|
it "returns the keyCode for the keypressed" do
|
|
1833
|
-
keyCode_for("a").should
|
|
1834
|
-
keyCode_for("A").should
|
|
1835
|
-
keyCode_for("\r").should
|
|
1836
|
-
keyCode_for(",").should
|
|
1837
|
-
keyCode_for("<").should
|
|
1838
|
-
keyCode_for("0").should
|
|
1839
|
+
keyCode_for("a").should eq "97"
|
|
1840
|
+
keyCode_for("A").should eq "65"
|
|
1841
|
+
keyCode_for("\r").should eq "13"
|
|
1842
|
+
keyCode_for(",").should eq "44"
|
|
1843
|
+
keyCode_for("<").should eq "60"
|
|
1844
|
+
keyCode_for("0").should eq "48"
|
|
1839
1845
|
end
|
|
1840
1846
|
|
|
1841
1847
|
it "returns the which for the keypressed" do
|
|
1842
|
-
which_for("a").should
|
|
1843
|
-
which_for("A").should
|
|
1844
|
-
which_for("\r").should
|
|
1845
|
-
which_for(",").should
|
|
1846
|
-
which_for("<").should
|
|
1847
|
-
which_for("0").should
|
|
1848
|
+
which_for("a").should eq "97"
|
|
1849
|
+
which_for("A").should eq "65"
|
|
1850
|
+
which_for("\r").should eq "13"
|
|
1851
|
+
which_for(",").should eq "44"
|
|
1852
|
+
which_for("<").should eq "60"
|
|
1853
|
+
which_for("0").should eq "48"
|
|
1848
1854
|
end
|
|
1849
1855
|
end
|
|
1850
1856
|
|
|
1851
1857
|
shared_examples "a keyupdown app" do
|
|
1852
1858
|
it "returns a 0 charCode for the event" do
|
|
1853
|
-
charCode_for("a").should
|
|
1854
|
-
charCode_for("A").should
|
|
1855
|
-
charCode_for("\b").should
|
|
1856
|
-
charCode_for(",").should
|
|
1857
|
-
charCode_for("<").should
|
|
1858
|
-
charCode_for("0").should
|
|
1859
|
+
charCode_for("a").should eq "0"
|
|
1860
|
+
charCode_for("A").should eq "0"
|
|
1861
|
+
charCode_for("\b").should eq "0"
|
|
1862
|
+
charCode_for(",").should eq "0"
|
|
1863
|
+
charCode_for("<").should eq "0"
|
|
1864
|
+
charCode_for("0").should eq "0"
|
|
1859
1865
|
end
|
|
1860
1866
|
|
|
1861
1867
|
it "returns the keyCode for the event" do
|
|
1862
|
-
keyCode_for("a").should
|
|
1863
|
-
keyCode_for("A").should
|
|
1864
|
-
keyCode_for("\b").should
|
|
1865
|
-
keyCode_for(",").should
|
|
1866
|
-
keyCode_for("<").should
|
|
1867
|
-
keyCode_for("0").should
|
|
1868
|
+
keyCode_for("a").should eq "65"
|
|
1869
|
+
keyCode_for("A").should eq "65"
|
|
1870
|
+
keyCode_for("\b").should eq "8"
|
|
1871
|
+
keyCode_for(",").should eq "188"
|
|
1872
|
+
keyCode_for("<").should eq "188"
|
|
1873
|
+
keyCode_for("0").should eq "48"
|
|
1868
1874
|
end
|
|
1869
1875
|
|
|
1870
1876
|
it "returns the which for the event" do
|
|
1871
|
-
which_for("a").should
|
|
1872
|
-
which_for("A").should
|
|
1873
|
-
which_for("\b").should
|
|
1874
|
-
which_for(",").should
|
|
1875
|
-
which_for("<").should
|
|
1876
|
-
which_for("0").should
|
|
1877
|
+
which_for("a").should eq "65"
|
|
1878
|
+
which_for("A").should eq "65"
|
|
1879
|
+
which_for("\b").should eq "8"
|
|
1880
|
+
which_for(",").should eq "188"
|
|
1881
|
+
which_for("<").should eq "188"
|
|
1882
|
+
which_for("0").should eq "48"
|
|
1877
1883
|
end
|
|
1878
1884
|
end
|
|
1879
1885
|
|
|
@@ -1915,14 +1921,14 @@ describe Capybara::Webkit::Driver do
|
|
|
1915
1921
|
it "has the expected text in the new window" do
|
|
1916
1922
|
visit("/new_window")
|
|
1917
1923
|
driver.within_window(driver.window_handles.last) do
|
|
1918
|
-
driver.find_xpath("//p").first.visible_text.should
|
|
1924
|
+
driver.find_xpath("//p").first.visible_text.should eq "finished"
|
|
1919
1925
|
end
|
|
1920
1926
|
end
|
|
1921
1927
|
|
|
1922
1928
|
it "waits for the new window to load" do
|
|
1923
1929
|
visit("/new_window?sleep=1")
|
|
1924
1930
|
driver.within_window(driver.window_handles.last) do
|
|
1925
|
-
driver.find_xpath("//p").first.visible_text.should
|
|
1931
|
+
driver.find_xpath("//p").first.visible_text.should eq "finished"
|
|
1926
1932
|
end
|
|
1927
1933
|
end
|
|
1928
1934
|
|
|
@@ -1930,34 +1936,34 @@ describe Capybara::Webkit::Driver do
|
|
|
1930
1936
|
visit("/new_window?sleep=2")
|
|
1931
1937
|
driver.execute_script("setTimeout(function() { window.location = 'about:blank' }, 1000)")
|
|
1932
1938
|
driver.within_window(driver.window_handles.last) do
|
|
1933
|
-
driver.find_xpath("//p").first.visible_text.should
|
|
1939
|
+
driver.find_xpath("//p").first.visible_text.should eq "finished"
|
|
1934
1940
|
end
|
|
1935
1941
|
end
|
|
1936
1942
|
|
|
1937
1943
|
it "switches back to the original window" do
|
|
1938
1944
|
visit("/new_window")
|
|
1939
1945
|
driver.within_window(driver.window_handles.last) { }
|
|
1940
|
-
driver.find_xpath("//p").first.visible_text.should
|
|
1946
|
+
driver.find_xpath("//p").first.visible_text.should eq "bananas"
|
|
1941
1947
|
end
|
|
1942
1948
|
|
|
1943
1949
|
it "supports finding a window by name" do
|
|
1944
1950
|
visit("/new_window")
|
|
1945
1951
|
driver.within_window('myWindow') do
|
|
1946
|
-
driver.find_xpath("//p").first.visible_text.should
|
|
1952
|
+
driver.find_xpath("//p").first.visible_text.should eq "finished"
|
|
1947
1953
|
end
|
|
1948
1954
|
end
|
|
1949
1955
|
|
|
1950
1956
|
it "supports finding a window by title" do
|
|
1951
1957
|
visit("/new_window?sleep=5")
|
|
1952
1958
|
driver.within_window('My New Window') do
|
|
1953
|
-
driver.find_xpath("//p").first.visible_text.should
|
|
1959
|
+
driver.find_xpath("//p").first.visible_text.should eq "finished"
|
|
1954
1960
|
end
|
|
1955
1961
|
end
|
|
1956
1962
|
|
|
1957
1963
|
it "supports finding a window by url" do
|
|
1958
1964
|
visit("/new_window?test")
|
|
1959
1965
|
driver.within_window(driver_url(driver, "/?test")) do
|
|
1960
|
-
driver.find_xpath("//p").first.visible_text.should
|
|
1966
|
+
driver.find_xpath("//p").first.visible_text.should eq "finished"
|
|
1961
1967
|
end
|
|
1962
1968
|
end
|
|
1963
1969
|
|
|
@@ -1967,9 +1973,9 @@ describe Capybara::Webkit::Driver do
|
|
|
1967
1973
|
end
|
|
1968
1974
|
|
|
1969
1975
|
it "has a number of window handles equal to the number of open windows" do
|
|
1970
|
-
driver.window_handles.size.should
|
|
1976
|
+
driver.window_handles.size.should eq 1
|
|
1971
1977
|
visit("/new_window")
|
|
1972
|
-
driver.window_handles.size.should
|
|
1978
|
+
driver.window_handles.size.should eq 2
|
|
1973
1979
|
end
|
|
1974
1980
|
|
|
1975
1981
|
it "closes new windows on reset" do
|
|
@@ -1999,7 +2005,7 @@ describe Capybara::Webkit::Driver do
|
|
|
1999
2005
|
end
|
|
2000
2006
|
|
|
2001
2007
|
visit("/new_window", driver)
|
|
2002
|
-
driver.cookies['session_id'].should
|
|
2008
|
+
driver.cookies['session_id'].should eq session_id
|
|
2003
2009
|
end
|
|
2004
2010
|
|
|
2005
2011
|
context "timers app" do
|
|
@@ -2080,14 +2086,14 @@ describe Capybara::Webkit::Driver do
|
|
|
2080
2086
|
it "returns 401 for incorrectly authenticated request" do
|
|
2081
2087
|
driver.browser.authenticate('user1', 'password1')
|
|
2082
2088
|
driver.browser.timeout = 2
|
|
2083
|
-
lambda { visit("/") }.should_not raise_error
|
|
2084
|
-
driver.status_code.should
|
|
2089
|
+
lambda { visit("/") }.should_not raise_error
|
|
2090
|
+
driver.status_code.should eq 401
|
|
2085
2091
|
end
|
|
2086
2092
|
|
|
2087
2093
|
it "returns 401 for unauthenticated request" do
|
|
2088
2094
|
driver.browser.timeout = 2
|
|
2089
|
-
lambda { visit("/") }.should_not raise_error
|
|
2090
|
-
driver.status_code.should
|
|
2095
|
+
lambda { visit("/") }.should_not raise_error
|
|
2096
|
+
driver.status_code.should eq 401
|
|
2091
2097
|
end
|
|
2092
2098
|
end
|
|
2093
2099
|
|
|
@@ -2153,14 +2159,14 @@ describe Capybara::Webkit::Driver do
|
|
|
2153
2159
|
it "should fetch unblocked urls" do
|
|
2154
2160
|
visit('/')
|
|
2155
2161
|
driver.within_frame('frame3') do
|
|
2156
|
-
driver.find_xpath("//p").first.visible_text.should
|
|
2162
|
+
driver.find_xpath("//p").first.visible_text.should eq "Inner"
|
|
2157
2163
|
end
|
|
2158
2164
|
end
|
|
2159
2165
|
|
|
2160
2166
|
it "returns a status code for blocked urls" do
|
|
2161
2167
|
visit("/")
|
|
2162
2168
|
driver.within_frame('frame1') do
|
|
2163
|
-
driver.status_code.should
|
|
2169
|
+
driver.status_code.should eq 200
|
|
2164
2170
|
end
|
|
2165
2171
|
end
|
|
2166
2172
|
end
|
|
@@ -2192,7 +2198,7 @@ describe Capybara::Webkit::Driver do
|
|
|
2192
2198
|
|
|
2193
2199
|
it "should not raise a timeout error when zero" do
|
|
2194
2200
|
driver.browser.timeout = 0
|
|
2195
|
-
lambda { visit("/") }.should_not raise_error
|
|
2201
|
+
lambda { visit("/") }.should_not raise_error
|
|
2196
2202
|
end
|
|
2197
2203
|
|
|
2198
2204
|
it "should raise a timeout error" do
|
|
@@ -2202,12 +2208,12 @@ describe Capybara::Webkit::Driver do
|
|
|
2202
2208
|
|
|
2203
2209
|
it "should not raise an error when the timeout is high enough" do
|
|
2204
2210
|
driver.browser.timeout = 10
|
|
2205
|
-
lambda { visit("/") }.should_not raise_error
|
|
2211
|
+
lambda { visit("/") }.should_not raise_error
|
|
2206
2212
|
end
|
|
2207
2213
|
|
|
2208
2214
|
it "should set the timeout for each request" do
|
|
2209
2215
|
driver.browser.timeout = 10
|
|
2210
|
-
lambda { visit("/") }.should_not raise_error
|
|
2216
|
+
lambda { visit("/") }.should_not raise_error
|
|
2211
2217
|
driver.browser.timeout = 1
|
|
2212
2218
|
lambda { visit("/") }.should raise_error(Timeout::Error)
|
|
2213
2219
|
end
|
|
@@ -2217,13 +2223,13 @@ describe Capybara::Webkit::Driver do
|
|
|
2217
2223
|
lambda { visit("/") }.should raise_error(Timeout::Error)
|
|
2218
2224
|
driver.reset!
|
|
2219
2225
|
driver.browser.timeout = 10
|
|
2220
|
-
lambda { visit("/") }.should_not raise_error
|
|
2226
|
+
lambda { visit("/") }.should_not raise_error
|
|
2221
2227
|
end
|
|
2222
2228
|
|
|
2223
2229
|
it "should raise a timeout on a slow form" do
|
|
2224
2230
|
driver.browser.timeout = 3
|
|
2225
2231
|
visit("/")
|
|
2226
|
-
driver.status_code.should
|
|
2232
|
+
driver.status_code.should eq 200
|
|
2227
2233
|
driver.browser.timeout = 1
|
|
2228
2234
|
driver.find_xpath("//input").first.click
|
|
2229
2235
|
lambda { driver.status_code }.should raise_error(Timeout::Error)
|
|
@@ -2231,9 +2237,9 @@ describe Capybara::Webkit::Driver do
|
|
|
2231
2237
|
|
|
2232
2238
|
it "get timeout" do
|
|
2233
2239
|
driver.browser.timeout = 10
|
|
2234
|
-
driver.browser.timeout.should
|
|
2240
|
+
driver.browser.timeout.should eq 10
|
|
2235
2241
|
driver.browser.timeout = 3
|
|
2236
|
-
driver.browser.timeout.should
|
|
2242
|
+
driver.browser.timeout.should eq 3
|
|
2237
2243
|
end
|
|
2238
2244
|
end
|
|
2239
2245
|
|
|
@@ -2299,7 +2305,62 @@ describe Capybara::Webkit::Driver do
|
|
|
2299
2305
|
it 'should not hang the server' do
|
|
2300
2306
|
visit('/')
|
|
2301
2307
|
driver.find_xpath('//input').first.click
|
|
2302
|
-
driver.console_messages.first[:message].should
|
|
2308
|
+
driver.console_messages.first[:message].should eq "hello"
|
|
2309
|
+
end
|
|
2310
|
+
end
|
|
2311
|
+
|
|
2312
|
+
context 'path' do
|
|
2313
|
+
let(:driver) do
|
|
2314
|
+
driver_for_html(<<-HTML)
|
|
2315
|
+
<html>
|
|
2316
|
+
<body>
|
|
2317
|
+
<div></div>
|
|
2318
|
+
<div><div><span>hello</span></div></div>
|
|
2319
|
+
</body>
|
|
2320
|
+
</html>
|
|
2321
|
+
HTML
|
|
2322
|
+
end
|
|
2323
|
+
|
|
2324
|
+
it 'returns an xpath for the current node' do
|
|
2325
|
+
visit('/')
|
|
2326
|
+
path = driver.find_xpath('//span').first.path
|
|
2327
|
+
driver.find_xpath(path).first.text.should eq 'hello'
|
|
2328
|
+
end
|
|
2329
|
+
end
|
|
2330
|
+
|
|
2331
|
+
context 'unattached node app' do
|
|
2332
|
+
let(:driver) do
|
|
2333
|
+
driver_for_html(<<-HTML)
|
|
2334
|
+
<html><body>
|
|
2335
|
+
<p id="remove-me">Remove me</p>
|
|
2336
|
+
<a href="#" id="remove-button">remove</a>
|
|
2337
|
+
<script type="text/javascript">
|
|
2338
|
+
document.getElementById('remove-button').addEventListener('click', function() {
|
|
2339
|
+
var p = document.getElementById('remove-me');
|
|
2340
|
+
p.parentNode.removeChild(p);
|
|
2341
|
+
});
|
|
2342
|
+
</script>
|
|
2343
|
+
</body></html>
|
|
2344
|
+
HTML
|
|
2345
|
+
end
|
|
2346
|
+
|
|
2347
|
+
it 'raises NodeNotAttachedError' do
|
|
2348
|
+
visit '/'
|
|
2349
|
+
remove_me = driver.find_css('#remove-me').first
|
|
2350
|
+
expect(remove_me).not_to be_nil
|
|
2351
|
+
driver.find_css('#remove-button').first.click
|
|
2352
|
+
expect { remove_me.text }.to raise_error(Capybara::Webkit::NodeNotAttachedError)
|
|
2353
|
+
end
|
|
2354
|
+
|
|
2355
|
+
it 'raises NodeNotAttachedError if the argument node is unattached' do
|
|
2356
|
+
visit '/'
|
|
2357
|
+
remove_me = driver.find_css('#remove-me').first
|
|
2358
|
+
expect(remove_me).not_to be_nil
|
|
2359
|
+
remove_button = driver.find_css('#remove-button').first
|
|
2360
|
+
expect(remove_button).not_to be_nil
|
|
2361
|
+
remove_button.click
|
|
2362
|
+
expect { remove_button == remove_me }.to raise_error(Capybara::Webkit::NodeNotAttachedError)
|
|
2363
|
+
expect { remove_me == remove_button }.to raise_error(Capybara::Webkit::NodeNotAttachedError)
|
|
2303
2364
|
end
|
|
2304
2365
|
end
|
|
2305
2366
|
|