capybara-webkit 0.14.2 → 1.0.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.
- data/.gitignore +2 -0
- data/.travis.yml +21 -0
- data/Appraisals +4 -4
- data/CONTRIBUTING.md +14 -3
- data/Gemfile +1 -1
- data/Gemfile.lock +27 -19
- data/NEWS.md +15 -0
- data/README.md +126 -76
- data/Vagrantfile +7 -0
- data/capybara-webkit.gemspec +3 -0
- data/gemfiles/2.0.gemfile +7 -0
- data/gemfiles/2.0.gemfile.lock +72 -0
- data/gemfiles/2.1.gemfile +7 -0
- data/gemfiles/2.1.gemfile.lock +71 -0
- data/lib/capybara/webkit/browser.rb +22 -22
- data/lib/capybara/webkit/connection.rb +9 -6
- data/lib/capybara/webkit/driver.rb +22 -6
- data/lib/capybara/webkit/errors.rb +25 -0
- data/lib/capybara/webkit/node.rb +36 -10
- data/lib/capybara/webkit/version.rb +1 -1
- data/spec/browser_spec.rb +16 -1
- data/spec/capybara_webkit_builder_spec.rb +9 -3
- data/spec/connection_spec.rb +19 -3
- data/spec/driver_spec.rb +324 -144
- data/spec/errors_spec.rb +11 -0
- data/spec/integration/session_spec.rb +244 -0
- data/spec/selenium_compatibility_spec.rb +3 -1
- data/spec/spec_helper.rb +1 -9
- data/src/Authenticate.cpp +3 -2
- data/src/ClearCookies.cpp +1 -1
- data/src/ClearPromptText.cpp +1 -1
- data/src/Command.cpp +8 -4
- data/src/Command.h +7 -4
- data/src/CommandFactory.cpp +4 -2
- data/src/CommandParser.cpp +1 -1
- data/src/Connection.cpp +4 -4
- data/src/ConsoleMessages.cpp +1 -1
- data/src/CurrentUrl.cpp +2 -2
- data/src/EnableLogging.cpp +1 -1
- data/src/ErrorMessage.cpp +26 -0
- data/src/ErrorMessage.h +21 -0
- data/src/Evaluate.cpp +1 -1
- data/src/Execute.cpp +3 -2
- data/src/FindCss.cpp +13 -0
- data/src/FindCss.h +11 -0
- data/src/FindXpath.cpp +13 -0
- data/src/FindXpath.h +11 -0
- data/src/FrameFocus.cpp +4 -3
- data/src/GetCookies.cpp +1 -1
- data/src/GetTimeout.cpp +1 -1
- data/src/GetWindowHandle.cpp +1 -1
- data/src/GetWindowHandles.cpp +1 -1
- data/src/Header.cpp +2 -2
- data/src/Headers.cpp +1 -6
- data/src/IgnoreSslErrors.cpp +1 -1
- data/src/InvocationResult.cpp +29 -0
- data/src/InvocationResult.h +16 -0
- data/src/JavascriptAlertMessages.cpp +1 -1
- data/src/JavascriptCommand.cpp +15 -0
- data/src/JavascriptCommand.h +20 -0
- data/src/JavascriptConfirmMessages.cpp +1 -1
- data/src/JavascriptInvocation.cpp +128 -1
- data/src/JavascriptInvocation.h +22 -1
- data/src/JavascriptPromptMessages.cpp +1 -1
- data/src/NetworkAccessManager.cpp +8 -16
- data/src/NetworkAccessManager.h +5 -11
- data/src/NetworkReplyProxy.cpp +91 -0
- data/src/NetworkReplyProxy.h +65 -0
- data/src/Node.cpp +4 -4
- data/src/Node.h +2 -2
- data/src/NullCommand.cpp +2 -1
- data/src/PageLoadingCommand.cpp +2 -1
- data/src/Render.cpp +1 -1
- data/src/Reset.cpp +1 -1
- data/src/ResizeWindow.cpp +1 -1
- data/src/Response.cpp +7 -0
- data/src/Response.h +8 -3
- data/src/SetConfirmAction.cpp +1 -1
- data/src/SetCookie.cpp +2 -2
- data/src/SetPromptAction.cpp +1 -1
- data/src/SetPromptText.cpp +1 -1
- data/src/SetProxy.cpp +2 -2
- data/src/SetSkipImageLoading.cpp +1 -1
- data/src/SetTimeout.cpp +3 -2
- data/src/SetUrlBlacklist.cpp +2 -2
- data/src/Status.cpp +1 -1
- data/src/TimeoutCommand.cpp +4 -2
- data/src/Title.cpp +11 -0
- data/src/Title.h +9 -0
- data/src/Version.cpp +13 -0
- data/src/Version.h +10 -0
- data/src/Visit.cpp +1 -1
- data/src/WebPage.cpp +49 -27
- data/src/WebPage.h +14 -7
- data/src/WebPageManager.cpp +10 -1
- data/src/WebPageManager.h +4 -1
- data/src/WindowFocus.cpp +3 -2
- data/src/body.cpp +3 -6
- data/src/capybara.js +103 -101
- data/src/find_command.h +4 -2
- data/src/main.cpp +1 -1
- data/src/stable.h +39 -0
- data/src/webkit_server.pro +26 -6
- data/vagrant_setup.sh +58 -0
- metadata +51 -78
- data/gemfiles/1.0.gemfile +0 -7
- data/gemfiles/1.0.gemfile.lock +0 -70
- data/gemfiles/1.1.gemfile +0 -7
- data/gemfiles/1.1.gemfile.lock +0 -70
- data/src/Find.cpp +0 -20
- data/src/Find.h +0 -11
data/spec/browser_spec.rb
CHANGED
@@ -7,7 +7,8 @@ require 'base64'
|
|
7
7
|
|
8
8
|
describe Capybara::Webkit::Browser do
|
9
9
|
|
10
|
-
let(:
|
10
|
+
let(:connection) { Capybara::Webkit::Connection.new }
|
11
|
+
let(:browser) { Capybara::Webkit::Browser.new(connection) }
|
11
12
|
let(:browser_ignore_ssl_err) do
|
12
13
|
Capybara::Webkit::Browser.new(Capybara::Webkit::Connection.new).tap do |browser|
|
13
14
|
browser.ignore_ssl_errors
|
@@ -258,4 +259,18 @@ describe Capybara::Webkit::Browser do
|
|
258
259
|
|
259
260
|
expect { browser.visit("/") }.not_to raise_error(/empty response/)
|
260
261
|
end
|
262
|
+
|
263
|
+
describe '#command' do
|
264
|
+
context 'non-ok response' do
|
265
|
+
it 'raises an error of given class' do
|
266
|
+
error_json = '{"class": "ClickFailed"}'
|
267
|
+
|
268
|
+
connection.should_receive(:gets).ordered.and_return 'error'
|
269
|
+
connection.should_receive(:gets).ordered.and_return error_json.bytesize
|
270
|
+
connection.stub read: error_json
|
271
|
+
|
272
|
+
expect { browser.command 'blah', 'meh' }.to raise_error(Capybara::Webkit::ClickFailed)
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
261
276
|
end
|
@@ -23,15 +23,21 @@ describe CapybaraWebkitBuilder do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it "defaults the #make_bin" do
|
26
|
-
|
26
|
+
with_env_vars("MAKE_BIN" => nil) do
|
27
|
+
builder.make_bin.should == 'make'
|
28
|
+
end
|
27
29
|
end
|
28
30
|
|
29
31
|
it "defaults the #qmake_bin" do
|
30
|
-
|
32
|
+
with_env_vars("QMAKE" => nil) do
|
33
|
+
builder.qmake_bin.should == 'qmake'
|
34
|
+
end
|
31
35
|
end
|
32
36
|
|
33
37
|
it "defaults #spec to the #os_specs" do
|
34
|
-
|
38
|
+
with_env_vars("SPEC" => nil) do
|
39
|
+
builder.spec.should == builder.os_spec
|
40
|
+
end
|
35
41
|
end
|
36
42
|
end
|
37
43
|
|
data/spec/connection_spec.rb
CHANGED
@@ -18,9 +18,9 @@ describe Capybara::Webkit::Connection do
|
|
18
18
|
response.should include("Hey there")
|
19
19
|
end
|
20
20
|
|
21
|
-
it 'forwards
|
21
|
+
it 'forwards stderr to the given IO object' do
|
22
22
|
io = StringIO.new
|
23
|
-
redirected_connection = Capybara::Webkit::Connection.new(:
|
23
|
+
redirected_connection = Capybara::Webkit::Connection.new(:stderr => io)
|
24
24
|
script = 'console.log("hello world")'
|
25
25
|
redirected_connection.puts "EnableLogging"
|
26
26
|
redirected_connection.puts 0
|
@@ -29,7 +29,23 @@ describe Capybara::Webkit::Connection do
|
|
29
29
|
redirected_connection.puts script.to_s.bytesize
|
30
30
|
redirected_connection.print script
|
31
31
|
sleep(0.5)
|
32
|
-
io.string.should
|
32
|
+
io.string.should =~ /hello world $/
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'does not forward stderr to nil' do
|
36
|
+
IO.should_not_receive(:copy_stream)
|
37
|
+
Capybara::Webkit::Connection.new(:stderr => nil)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'prints a deprecation warning if the stdout option is used' do
|
41
|
+
Capybara::Webkit::Connection.any_instance.should_receive(:warn)
|
42
|
+
Capybara::Webkit::Connection.new(:stdout => nil)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'does not forward stdout to nil if the stdout option is used' do
|
46
|
+
Capybara::Webkit::Connection.any_instance.stub(:warn)
|
47
|
+
IO.should_not_receive(:copy_stream)
|
48
|
+
Capybara::Webkit::Connection.new(:stdout => nil)
|
33
49
|
end
|
34
50
|
|
35
51
|
it "returns the server port" do
|
data/spec/driver_spec.rb
CHANGED
@@ -41,6 +41,7 @@ describe Capybara::Webkit::Driver do
|
|
41
41
|
<<-HTML
|
42
42
|
<html>
|
43
43
|
<head>
|
44
|
+
<title>Title</title>
|
44
45
|
<style type="text/css">
|
45
46
|
#display_none { display: none }
|
46
47
|
</style>
|
@@ -62,13 +63,21 @@ describe Capybara::Webkit::Driver do
|
|
62
63
|
|
63
64
|
it "finds frames by index" do
|
64
65
|
driver.within_frame(0) do
|
65
|
-
driver.
|
66
|
+
driver.find_xpath("//*[contains(., 'goodbye')]").should_not be_empty
|
66
67
|
end
|
67
68
|
end
|
68
69
|
|
69
70
|
it "finds frames by id" do
|
70
71
|
driver.within_frame("f") do
|
71
|
-
driver.
|
72
|
+
driver.find_xpath("//*[contains(., 'goodbye')]").should_not be_empty
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it "finds frames by element" do
|
77
|
+
frame = driver.find_xpath('//iframe').first
|
78
|
+
element = double(Capybara::Node::Base, base: frame)
|
79
|
+
driver.within_frame(element) do
|
80
|
+
driver.find_xpath("//*[contains(., 'goodbye')]").should_not be_empty
|
72
81
|
end
|
73
82
|
end
|
74
83
|
|
@@ -84,22 +93,22 @@ describe Capybara::Webkit::Driver do
|
|
84
93
|
|
85
94
|
it "returns an attribute's value" do
|
86
95
|
driver.within_frame("f") do
|
87
|
-
driver.
|
96
|
+
driver.find_xpath("//p").first["id"].should == "farewell"
|
88
97
|
end
|
89
98
|
end
|
90
99
|
|
91
100
|
it "returns an attribute's innerHTML" do
|
92
|
-
driver.
|
101
|
+
driver.find_xpath('//body').first.inner_html.should =~ %r{<iframe.*</iframe>.*<script.*</script>.*}m
|
93
102
|
end
|
94
103
|
|
95
104
|
it "receive an attribute's innerHTML" do
|
96
|
-
driver.
|
97
|
-
driver.
|
105
|
+
driver.find_xpath('//body').first.inner_html = 'foobar'
|
106
|
+
driver.find_xpath("//body[contains(., 'foobar')]").should_not be_empty
|
98
107
|
end
|
99
108
|
|
100
109
|
it "returns a node's text" do
|
101
110
|
driver.within_frame("f") do
|
102
|
-
driver.
|
111
|
+
driver.find_xpath("//p").first.visible_text.should == "goodbye"
|
103
112
|
end
|
104
113
|
end
|
105
114
|
|
@@ -119,7 +128,7 @@ describe Capybara::Webkit::Driver do
|
|
119
128
|
it "executes Javascript" do
|
120
129
|
driver.within_frame("f") do
|
121
130
|
driver.execute_script(%<document.getElementById('farewell').innerHTML = 'yo'>)
|
122
|
-
driver.
|
131
|
+
driver.find_xpath("//p[contains(., 'yo')]").should_not be_empty
|
123
132
|
end
|
124
133
|
end
|
125
134
|
|
@@ -142,6 +151,12 @@ describe Capybara::Webkit::Driver do
|
|
142
151
|
driver.status_code.should == 200
|
143
152
|
end
|
144
153
|
end
|
154
|
+
|
155
|
+
it "returns the document title" do
|
156
|
+
driver.within_frame("f") do
|
157
|
+
driver.title.should == "Title"
|
158
|
+
end
|
159
|
+
end
|
145
160
|
end
|
146
161
|
|
147
162
|
context "error iframe app" do
|
@@ -207,8 +222,8 @@ describe Capybara::Webkit::Driver do
|
|
207
222
|
|
208
223
|
it "should redirect without content type" do
|
209
224
|
visit("/form")
|
210
|
-
driver.
|
211
|
-
driver.
|
225
|
+
driver.find_xpath("//input").first.click
|
226
|
+
driver.find_xpath("//p").first.visible_text.should == ""
|
212
227
|
end
|
213
228
|
|
214
229
|
it "returns the current URL when changed by pushState after a redirect" do
|
@@ -286,11 +301,30 @@ describe Capybara::Webkit::Driver do
|
|
286
301
|
end
|
287
302
|
end
|
288
303
|
|
304
|
+
context "binary content app" do
|
305
|
+
let(:driver) do
|
306
|
+
driver_for_app do
|
307
|
+
get '/' do
|
308
|
+
headers 'Content-Type' => 'application/octet-stream'
|
309
|
+
"Hello\xFF\xFF\xFF\xFFWorld"
|
310
|
+
end
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
before { visit("/") }
|
315
|
+
|
316
|
+
it "should return the binary content" do
|
317
|
+
src = driver.html.force_encoding('binary')
|
318
|
+
src.should == "Hello\xFF\xFF\xFF\xFFWorld".force_encoding('binary')
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
289
322
|
context "hello app" do
|
290
323
|
let(:driver) do
|
291
324
|
driver_for_html(<<-HTML)
|
292
325
|
<html>
|
293
326
|
<head>
|
327
|
+
<title>Title</title>
|
294
328
|
<style type="text/css">
|
295
329
|
#display_none { display: none }
|
296
330
|
#visibility_hidden { visibility: hidden }
|
@@ -304,6 +338,9 @@ describe Capybara::Webkit::Driver do
|
|
304
338
|
<div id="visibility_hidden">
|
305
339
|
<div id="invisible_with_visibility">Can't see me too</div>
|
306
340
|
</div>
|
341
|
+
<div id="hidden-text">
|
342
|
+
Some of this text is <em style="display:none">hidden!</em>
|
343
|
+
</div>
|
307
344
|
<input type="text" disabled="disabled"/>
|
308
345
|
<input id="checktest" type="checkbox" checked="checked"/>
|
309
346
|
<script type="text/javascript">
|
@@ -318,18 +355,18 @@ describe Capybara::Webkit::Driver do
|
|
318
355
|
|
319
356
|
it "handles anchor tags" do
|
320
357
|
visit("#test")
|
321
|
-
driver.
|
358
|
+
driver.find_xpath("//*[contains(., 'hello')]").should_not be_empty
|
322
359
|
visit("#test")
|
323
|
-
driver.
|
360
|
+
driver.find_xpath("//*[contains(., 'hello')]").should_not be_empty
|
324
361
|
end
|
325
362
|
|
326
363
|
it "finds content after loading a URL" do
|
327
|
-
driver.
|
364
|
+
driver.find_xpath("//*[contains(., 'hello')]").should_not be_empty
|
328
365
|
end
|
329
366
|
|
330
367
|
it "has an empty page after reseting" do
|
331
368
|
driver.reset!
|
332
|
-
driver.
|
369
|
+
driver.find_xpath("//*[contains(., 'hello')]").should be_empty
|
333
370
|
end
|
334
371
|
|
335
372
|
it "has a blank location after reseting" do
|
@@ -338,24 +375,33 @@ describe Capybara::Webkit::Driver do
|
|
338
375
|
end
|
339
376
|
|
340
377
|
it "raises an error for an invalid xpath query" do
|
341
|
-
expect { driver.
|
378
|
+
expect { driver.find_xpath("totally invalid salad") }.
|
379
|
+
to raise_error(Capybara::Webkit::InvalidResponseError, /xpath/i)
|
380
|
+
end
|
381
|
+
|
382
|
+
it "raises an error for an invalid xpath query within an element" do
|
383
|
+
expect { driver.find_xpath("//body").first.find_xpath("totally invalid salad") }.
|
342
384
|
to raise_error(Capybara::Webkit::InvalidResponseError, /xpath/i)
|
343
385
|
end
|
344
386
|
|
345
387
|
it "returns an attribute's value" do
|
346
|
-
driver.
|
388
|
+
driver.find_xpath("//p").first["id"].should == "greeting"
|
347
389
|
end
|
348
390
|
|
349
391
|
it "parses xpath with quotes" do
|
350
|
-
driver.
|
392
|
+
driver.find_xpath('//*[contains(., "hello")]').should_not be_empty
|
351
393
|
end
|
352
394
|
|
353
|
-
it "returns a node's text" do
|
354
|
-
driver.
|
395
|
+
it "returns a node's visible text" do
|
396
|
+
driver.find_xpath("//*[@id='hidden-text']").first.visible_text.should == "Some of this text is"
|
355
397
|
end
|
356
398
|
|
357
399
|
it "normalizes a node's text" do
|
358
|
-
driver.
|
400
|
+
driver.find_xpath("//div[contains(@class, 'normalize')]").first.visible_text.should == "Spaces not normalized"
|
401
|
+
end
|
402
|
+
|
403
|
+
it "returns all of a node's text" do
|
404
|
+
driver.find_xpath("//*[@id='hidden-text']").first.all_text.should == "Some of this text is hidden!"
|
359
405
|
end
|
360
406
|
|
361
407
|
it "returns the current URL" do
|
@@ -440,7 +486,7 @@ describe Capybara::Webkit::Driver do
|
|
440
486
|
|
441
487
|
it "executes Javascript" do
|
442
488
|
driver.execute_script(%<document.getElementById('greeting').innerHTML = 'yo'>)
|
443
|
-
driver.
|
489
|
+
driver.find_xpath("//p[contains(., 'yo')]").should_not be_empty
|
444
490
|
end
|
445
491
|
|
446
492
|
it "raises an error for failing Javascript" do
|
@@ -454,21 +500,49 @@ describe Capybara::Webkit::Driver do
|
|
454
500
|
end
|
455
501
|
|
456
502
|
it "returns a node's tag name" do
|
457
|
-
driver.
|
503
|
+
driver.find_xpath("//p").first.tag_name.should == "p"
|
458
504
|
end
|
459
505
|
|
460
506
|
it "reads disabled property" do
|
461
|
-
driver.
|
507
|
+
driver.find_xpath("//input").first.should be_disabled
|
462
508
|
end
|
463
509
|
|
464
510
|
it "reads checked property" do
|
465
|
-
driver.
|
511
|
+
driver.find_xpath("//input[@id='checktest']").first.should be_checked
|
466
512
|
end
|
467
513
|
|
468
514
|
it "finds visible elements" do
|
469
|
-
driver.
|
470
|
-
driver.
|
471
|
-
driver.
|
515
|
+
driver.find_xpath("//p").first.should be_visible
|
516
|
+
driver.find_xpath("//*[@id='invisible']").first.should_not be_visible
|
517
|
+
driver.find_xpath("//*[@id='invisible_with_visibility']").first.should_not be_visible
|
518
|
+
end
|
519
|
+
|
520
|
+
it "returns the document title" do
|
521
|
+
driver.title.should == "Title"
|
522
|
+
end
|
523
|
+
|
524
|
+
it "finds elements by CSS" do
|
525
|
+
driver.find_css("p").first.visible_text.should == "hello"
|
526
|
+
end
|
527
|
+
end
|
528
|
+
|
529
|
+
context "svg app" do
|
530
|
+
let(:driver) do
|
531
|
+
driver_for_html(<<-HTML)
|
532
|
+
<html>
|
533
|
+
<body>
|
534
|
+
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" height="100">
|
535
|
+
<text x="10" y="25" fill="navy" font-size="15" id="navy_text">In the navy!</text>
|
536
|
+
</svg>
|
537
|
+
</body>
|
538
|
+
</html>
|
539
|
+
HTML
|
540
|
+
end
|
541
|
+
|
542
|
+
before { visit("/") }
|
543
|
+
|
544
|
+
it "should handle text for svg elements" do
|
545
|
+
driver.find_xpath("//*[@id='navy_text']").first.visible_text.should == "In the navy!"
|
472
546
|
end
|
473
547
|
end
|
474
548
|
|
@@ -498,7 +572,7 @@ describe Capybara::Webkit::Driver do
|
|
498
572
|
url = driver_url(driver, "/")
|
499
573
|
message = driver.console_messages.first
|
500
574
|
message.should include :source => url, :message => "hello"
|
501
|
-
|
575
|
+
[6, 7].should include message[:line_number]
|
502
576
|
driver.console_messages.length.should eq 5
|
503
577
|
end
|
504
578
|
|
@@ -580,30 +654,30 @@ describe Capybara::Webkit::Driver do
|
|
580
654
|
before { visit("/") }
|
581
655
|
|
582
656
|
it "should default to accept the confirm" do
|
583
|
-
driver.
|
657
|
+
driver.find_xpath("//input").first.click
|
584
658
|
driver.console_messages.first[:message].should == "hello"
|
585
659
|
end
|
586
660
|
|
587
661
|
it "can dismiss the confirm" do
|
588
662
|
driver.dismiss_js_confirms!
|
589
|
-
driver.
|
663
|
+
driver.find_xpath("//input").first.click
|
590
664
|
driver.console_messages.first[:message].should == "goodbye"
|
591
665
|
end
|
592
666
|
|
593
667
|
it "can accept the confirm explicitly" do
|
594
668
|
driver.dismiss_js_confirms!
|
595
669
|
driver.accept_js_confirms!
|
596
|
-
driver.
|
670
|
+
driver.find_xpath("//input").first.click
|
597
671
|
driver.console_messages.first[:message].should == "hello"
|
598
672
|
end
|
599
673
|
|
600
674
|
it "should collect the javsacript confirm dialog contents" do
|
601
|
-
driver.
|
675
|
+
driver.find_xpath("//input").first.click
|
602
676
|
driver.confirm_messages.first.should == "Yes?"
|
603
677
|
end
|
604
678
|
|
605
679
|
it "empties the array when reset" do
|
606
|
-
driver.
|
680
|
+
driver.find_xpath("//input").first.click
|
607
681
|
driver.reset!
|
608
682
|
driver.confirm_messages.should be_empty
|
609
683
|
end
|
@@ -612,7 +686,7 @@ describe Capybara::Webkit::Driver do
|
|
612
686
|
driver.dismiss_js_confirms!
|
613
687
|
driver.reset!
|
614
688
|
visit("/")
|
615
|
-
driver.
|
689
|
+
driver.find_xpath("//input").first.click
|
616
690
|
driver.console_messages.first[:message].should == "hello"
|
617
691
|
end
|
618
692
|
|
@@ -648,47 +722,47 @@ describe Capybara::Webkit::Driver do
|
|
648
722
|
before { visit("/") }
|
649
723
|
|
650
724
|
it "should default to dismiss the prompt" do
|
651
|
-
driver.
|
725
|
+
driver.find_xpath("//input").first.click
|
652
726
|
driver.console_messages.first[:message].should == "goodbye"
|
653
727
|
end
|
654
728
|
|
655
729
|
it "can accept the prompt without providing text" do
|
656
730
|
driver.accept_js_prompts!
|
657
|
-
driver.
|
731
|
+
driver.find_xpath("//input").first.click
|
658
732
|
driver.console_messages.first[:message].should == "hello John Smith"
|
659
733
|
end
|
660
734
|
|
661
735
|
it "can accept the prompt with input" do
|
662
736
|
driver.js_prompt_input = "Capy"
|
663
737
|
driver.accept_js_prompts!
|
664
|
-
driver.
|
738
|
+
driver.find_xpath("//input").first.click
|
665
739
|
driver.console_messages.first[:message].should == "hello Capy"
|
666
740
|
end
|
667
741
|
|
668
742
|
it "can return to dismiss the prompt after accepting prompts" do
|
669
743
|
driver.accept_js_prompts!
|
670
744
|
driver.dismiss_js_prompts!
|
671
|
-
driver.
|
745
|
+
driver.find_xpath("//input").first.click
|
672
746
|
driver.console_messages.first[:message].should == "goodbye"
|
673
747
|
end
|
674
748
|
|
675
749
|
it "should let me remove the prompt input text" do
|
676
750
|
driver.js_prompt_input = "Capy"
|
677
751
|
driver.accept_js_prompts!
|
678
|
-
driver.
|
752
|
+
driver.find_xpath("//input").first.click
|
679
753
|
driver.console_messages.first[:message].should == "hello Capy"
|
680
754
|
driver.js_prompt_input = nil
|
681
|
-
driver.
|
755
|
+
driver.find_xpath("//input").first.click
|
682
756
|
driver.console_messages.last[:message].should == "hello John Smith"
|
683
757
|
end
|
684
758
|
|
685
759
|
it "should collect the javsacript prompt dialog contents" do
|
686
|
-
driver.
|
760
|
+
driver.find_xpath("//input").first.click
|
687
761
|
driver.prompt_messages.first.should == "Your name?"
|
688
762
|
end
|
689
763
|
|
690
764
|
it "empties the array when reset" do
|
691
|
-
driver.
|
765
|
+
driver.find_xpath("//input").first.click
|
692
766
|
driver.reset!
|
693
767
|
driver.prompt_messages.should be_empty
|
694
768
|
end
|
@@ -697,7 +771,7 @@ describe Capybara::Webkit::Driver do
|
|
697
771
|
driver.accept_js_prompts!
|
698
772
|
driver.reset!
|
699
773
|
visit("/")
|
700
|
-
driver.
|
774
|
+
driver.find_xpath("//input").first.click
|
701
775
|
driver.console_messages.first[:message].should == "goodbye"
|
702
776
|
end
|
703
777
|
|
@@ -717,12 +791,16 @@ describe Capybara::Webkit::Driver do
|
|
717
791
|
<input type="text" name="foo" value="bar"/>
|
718
792
|
<input type="text" name="maxlength_foo" value="bar" maxlength="10"/>
|
719
793
|
<input type="text" id="disabled_input" disabled="disabled"/>
|
794
|
+
<input type="text" id="readonly_input" readonly="readonly" value="readonly"/>
|
720
795
|
<input type="checkbox" name="checkedbox" value="1" checked="checked"/>
|
721
796
|
<input type="checkbox" name="uncheckedbox" value="2"/>
|
722
797
|
<select name="animal">
|
723
798
|
<option id="select-option-monkey">Monkey</option>
|
724
799
|
<option id="select-option-capybara" selected="selected">Capybara</option>
|
725
800
|
</select>
|
801
|
+
<select name="disabled" disabled="disabled">
|
802
|
+
<option id="select-option-disabled">Disabled</option>
|
803
|
+
</select>
|
726
804
|
<select name="toppings" multiple="multiple">
|
727
805
|
<optgroup label="Mediocre Toppings">
|
728
806
|
<option selected="selected" id="topping-apple">Apple</option>
|
@@ -747,69 +825,69 @@ describe Capybara::Webkit::Driver do
|
|
747
825
|
before { visit("/") }
|
748
826
|
|
749
827
|
it "returns a textarea's value" do
|
750
|
-
driver.
|
828
|
+
driver.find_xpath("//textarea").first.value.should == "what a wonderful area for text"
|
751
829
|
end
|
752
830
|
|
753
831
|
it "returns a text input's value" do
|
754
|
-
driver.
|
832
|
+
driver.find_xpath("//input").first.value.should == "bar"
|
755
833
|
end
|
756
834
|
|
757
835
|
it "returns a select's value" do
|
758
|
-
driver.
|
836
|
+
driver.find_xpath("//select").first.value.should == "Capybara"
|
759
837
|
end
|
760
838
|
|
761
839
|
it "sets an input's value" do
|
762
|
-
input = driver.
|
840
|
+
input = driver.find_xpath("//input").first
|
763
841
|
input.set("newvalue")
|
764
842
|
input.value.should == "newvalue"
|
765
843
|
end
|
766
844
|
|
767
845
|
it "sets an input's value greater than the max length" do
|
768
|
-
input = driver.
|
846
|
+
input = driver.find_xpath("//input[@name='maxlength_foo']").first
|
769
847
|
input.set("allegories (poems)")
|
770
848
|
input.value.should == "allegories"
|
771
849
|
end
|
772
850
|
|
773
851
|
it "sets an input's value equal to the max length" do
|
774
|
-
input = driver.
|
852
|
+
input = driver.find_xpath("//input[@name='maxlength_foo']").first
|
775
853
|
input.set("allegories")
|
776
854
|
input.value.should == "allegories"
|
777
855
|
end
|
778
856
|
|
779
857
|
it "sets an input's value less than the max length" do
|
780
|
-
input = driver.
|
858
|
+
input = driver.find_xpath("//input[@name='maxlength_foo']").first
|
781
859
|
input.set("poems")
|
782
860
|
input.value.should == "poems"
|
783
861
|
end
|
784
862
|
|
785
863
|
it "sets an input's nil value" do
|
786
|
-
input = driver.
|
864
|
+
input = driver.find_xpath("//input").first
|
787
865
|
input.set(nil)
|
788
866
|
input.value.should == ""
|
789
867
|
end
|
790
868
|
|
791
869
|
it "sets a select's value" do
|
792
|
-
select = driver.
|
870
|
+
select = driver.find_xpath("//select").first
|
793
871
|
select.set("Monkey")
|
794
872
|
select.value.should == "Monkey"
|
795
873
|
end
|
796
874
|
|
797
875
|
it "sets a textarea's value" do
|
798
|
-
textarea = driver.
|
876
|
+
textarea = driver.find_xpath("//textarea").first
|
799
877
|
textarea.set("newvalue")
|
800
878
|
textarea.value.should == "newvalue"
|
801
879
|
end
|
802
880
|
|
803
|
-
let(:monkey_option) { driver.
|
804
|
-
let(:capybara_option) { driver.
|
805
|
-
let(:animal_select) { driver.
|
806
|
-
let(:apple_option) { driver.
|
807
|
-
let(:banana_option) { driver.
|
808
|
-
let(:cherry_option) { driver.
|
809
|
-
let(:toppings_select) { driver.
|
810
|
-
let(:guitars_select) { driver.
|
811
|
-
let(:fender_option) { driver.
|
812
|
-
let(:reset_button) { driver.
|
881
|
+
let(:monkey_option) { driver.find_xpath("//option[@id='select-option-monkey']").first }
|
882
|
+
let(:capybara_option) { driver.find_xpath("//option[@id='select-option-capybara']").first }
|
883
|
+
let(:animal_select) { driver.find_xpath("//select[@name='animal']").first }
|
884
|
+
let(:apple_option) { driver.find_xpath("//option[@id='topping-apple']").first }
|
885
|
+
let(:banana_option) { driver.find_xpath("//option[@id='topping-banana']").first }
|
886
|
+
let(:cherry_option) { driver.find_xpath("//option[@id='topping-cherry']").first }
|
887
|
+
let(:toppings_select) { driver.find_xpath("//select[@name='toppings']").first }
|
888
|
+
let(:guitars_select) { driver.find_xpath("//select[@name='guitars']").first }
|
889
|
+
let(:fender_option) { driver.find_xpath("//option[@id='fender']").first }
|
890
|
+
let(:reset_button) { driver.find_xpath("//button[@type='reset']").first }
|
813
891
|
|
814
892
|
context "a select element's selection has been changed" do
|
815
893
|
before do
|
@@ -876,8 +954,8 @@ describe Capybara::Webkit::Driver do
|
|
876
954
|
toppings_select.value.should include("Apple", "Banana", "Cherry")
|
877
955
|
end
|
878
956
|
|
879
|
-
let(:checked_box) { driver.
|
880
|
-
let(:unchecked_box) { driver.
|
957
|
+
let(:checked_box) { driver.find_xpath("//input[@name='checkedbox']").first }
|
958
|
+
let(:unchecked_box) { driver.find_xpath("//input[@name='uncheckedbox']").first }
|
881
959
|
|
882
960
|
it "knows a checked box is checked" do
|
883
961
|
checked_box['checked'].should be_true
|
@@ -915,8 +993,8 @@ describe Capybara::Webkit::Driver do
|
|
915
993
|
unchecked_box.should_not be_checked
|
916
994
|
end
|
917
995
|
|
918
|
-
let(:enabled_input) { driver.
|
919
|
-
let(:disabled_input) { driver.
|
996
|
+
let(:enabled_input) { driver.find_xpath("//input[@name='foo']").first }
|
997
|
+
let(:disabled_input) { driver.find_xpath("//input[@id='disabled_input']").first }
|
920
998
|
|
921
999
|
it "knows a disabled input is disabled" do
|
922
1000
|
disabled_input['disabled'].should be_true
|
@@ -925,6 +1003,16 @@ describe Capybara::Webkit::Driver do
|
|
925
1003
|
it "knows a not disabled input is not disabled" do
|
926
1004
|
enabled_input['disabled'].should_not be_true
|
927
1005
|
end
|
1006
|
+
|
1007
|
+
it "does not modify a readonly input" do
|
1008
|
+
readonly_input = driver.find_css("#readonly_input").first
|
1009
|
+
readonly_input.set('enabled')
|
1010
|
+
readonly_input.value.should == 'readonly'
|
1011
|
+
end
|
1012
|
+
|
1013
|
+
it "should see enabled options in disabled select as disabled" do
|
1014
|
+
driver.find_css("#select-option-disabled").first.should be_disabled
|
1015
|
+
end
|
928
1016
|
end
|
929
1017
|
|
930
1018
|
context "dom events" do
|
@@ -947,6 +1035,8 @@ describe Capybara::Webkit::Driver do
|
|
947
1035
|
element.addEventListener("mousedown", recordEvent);
|
948
1036
|
element.addEventListener("mouseup", recordEvent);
|
949
1037
|
element.addEventListener("click", recordEvent);
|
1038
|
+
element.addEventListener("dblclick", recordEvent);
|
1039
|
+
element.addEventListener("contextmenu", recordEvent);
|
950
1040
|
}
|
951
1041
|
</script>
|
952
1042
|
</body></html>
|
@@ -955,9 +1045,23 @@ describe Capybara::Webkit::Driver do
|
|
955
1045
|
|
956
1046
|
before { visit("/") }
|
957
1047
|
|
1048
|
+
let(:watch) { driver.find_xpath("//a").first }
|
1049
|
+
let(:fired_events) { driver.find_xpath("//li").map(&:visible_text) }
|
1050
|
+
|
958
1051
|
it "triggers mouse events" do
|
959
|
-
|
960
|
-
|
1052
|
+
watch.click
|
1053
|
+
fired_events.should == %w(mousedown mouseup click)
|
1054
|
+
end
|
1055
|
+
|
1056
|
+
it "triggers double click" do
|
1057
|
+
# check event order at http://www.quirksmode.org/dom/events/click.html
|
1058
|
+
watch.double_click
|
1059
|
+
fired_events.should == %w(mousedown mouseup click mousedown mouseup click dblclick)
|
1060
|
+
end
|
1061
|
+
|
1062
|
+
it "triggers right click" do
|
1063
|
+
watch.right_click
|
1064
|
+
fired_events.should == %w(mousedown contextmenu mouseup)
|
961
1065
|
end
|
962
1066
|
end
|
963
1067
|
|
@@ -1011,40 +1115,53 @@ describe Capybara::Webkit::Driver do
|
|
1011
1115
|
|
1012
1116
|
let(:keyevents) do
|
1013
1117
|
(%w{focus} +
|
1014
|
-
newtext.length.times.collect { %w{keydown keypress keyup
|
1015
|
-
|
1118
|
+
newtext.length.times.collect { %w{keydown keypress input keyup} }
|
1119
|
+
).flatten
|
1016
1120
|
end
|
1017
1121
|
|
1018
1122
|
%w(email number password search tel text url).each do | field_type |
|
1019
1123
|
it "triggers text input events on inputs of type #{field_type}" do
|
1020
|
-
driver.
|
1021
|
-
driver.
|
1124
|
+
driver.find_xpath("//input[@type='#{field_type}']").first.set(newtext)
|
1125
|
+
driver.find_xpath("//li").map(&:visible_text).should == keyevents
|
1022
1126
|
end
|
1023
1127
|
end
|
1024
1128
|
|
1025
1129
|
it "triggers textarea input events" do
|
1026
|
-
driver.
|
1027
|
-
driver.
|
1130
|
+
driver.find_xpath("//textarea").first.set(newtext)
|
1131
|
+
driver.find_xpath("//li").map(&:visible_text).should == keyevents
|
1028
1132
|
end
|
1029
1133
|
|
1030
1134
|
it "triggers radio input events" do
|
1031
|
-
driver.
|
1032
|
-
driver.
|
1135
|
+
driver.find_xpath("//input[@type='radio']").first.set(true)
|
1136
|
+
driver.find_xpath("//li").map(&:visible_text).should == %w(mousedown focus mouseup change click)
|
1033
1137
|
end
|
1034
1138
|
|
1035
1139
|
it "triggers checkbox events" do
|
1036
|
-
driver.
|
1037
|
-
driver.
|
1140
|
+
driver.find_xpath("//input[@type='checkbox']").first.set(true)
|
1141
|
+
driver.find_xpath("//li").map(&:visible_text).should == %w(mousedown focus mouseup change click)
|
1038
1142
|
end
|
1039
1143
|
end
|
1040
1144
|
|
1041
1145
|
context "mouse app" do
|
1042
1146
|
let(:driver) do
|
1043
1147
|
driver_for_html(<<-HTML)
|
1044
|
-
<html
|
1148
|
+
<html>
|
1149
|
+
<head>
|
1150
|
+
<style type="text/css">
|
1151
|
+
#hover { max-width: 30em; }
|
1152
|
+
#hover span { line-height: 1.5; }
|
1153
|
+
#hover span:hover + .hidden { display: block; }
|
1154
|
+
.hidden { display: none; }
|
1155
|
+
</style>
|
1156
|
+
</head>
|
1157
|
+
<body>
|
1045
1158
|
<div id="change">Change me</div>
|
1046
1159
|
<div id="mouseup">Push me</div>
|
1047
1160
|
<div id="mousedown">Release me</div>
|
1161
|
+
<div id="hover">
|
1162
|
+
<span>This really long paragraph has a lot of text and will wrap. This sentence ensures that we have four lines of text.</span>
|
1163
|
+
<div class="hidden">Text that only shows on hover.</div>
|
1164
|
+
</div>
|
1048
1165
|
<form action="/" method="GET">
|
1049
1166
|
<select id="change_select" name="change_select">
|
1050
1167
|
<option value="1" id="option-1" selected="selected">one</option>
|
@@ -1076,37 +1193,55 @@ describe Capybara::Webkit::Driver do
|
|
1076
1193
|
|
1077
1194
|
before { visit("/") }
|
1078
1195
|
|
1196
|
+
it "hovers an element" do
|
1197
|
+
driver.find_css("#hover").first.visible_text.should_not =~ /Text that only shows on hover/
|
1198
|
+
driver.find_css("#hover span").first.hover
|
1199
|
+
driver.find_css("#hover").first.visible_text.should =~ /Text that only shows on hover/
|
1200
|
+
end
|
1201
|
+
|
1202
|
+
it "hovers an element off the screen" do
|
1203
|
+
driver.resize_window(200, 200)
|
1204
|
+
driver.evaluate_script(<<-JS)
|
1205
|
+
var element = document.getElementById('hover');
|
1206
|
+
element.style.position = 'absolute';
|
1207
|
+
element.style.left = '200px';
|
1208
|
+
JS
|
1209
|
+
driver.find_css("#hover").first.visible_text.should_not =~ /Text that only shows on hover/
|
1210
|
+
driver.find_css("#hover span").first.hover
|
1211
|
+
driver.find_css("#hover").first.visible_text.should =~ /Text that only shows on hover/
|
1212
|
+
end
|
1213
|
+
|
1079
1214
|
it "clicks an element" do
|
1080
|
-
driver.
|
1215
|
+
driver.find_xpath("//a").first.click
|
1081
1216
|
driver.current_url =~ %r{/next$}
|
1082
1217
|
end
|
1083
1218
|
|
1084
1219
|
it "fires a mouse event" do
|
1085
|
-
driver.
|
1086
|
-
driver.
|
1220
|
+
driver.find_xpath("//*[@id='mouseup']").first.trigger("mouseup")
|
1221
|
+
driver.find_xpath("//*[@class='triggered']").should_not be_empty
|
1087
1222
|
end
|
1088
1223
|
|
1089
1224
|
it "fires a non-mouse event" do
|
1090
|
-
driver.
|
1091
|
-
driver.
|
1225
|
+
driver.find_xpath("//*[@id='change']").first.trigger("change")
|
1226
|
+
driver.find_xpath("//*[@class='triggered']").should_not be_empty
|
1092
1227
|
end
|
1093
1228
|
|
1094
1229
|
it "fires a change on select" do
|
1095
|
-
select = driver.
|
1230
|
+
select = driver.find_xpath("//select").first
|
1096
1231
|
select.value.should == "1"
|
1097
|
-
option = driver.
|
1232
|
+
option = driver.find_xpath("//option[@id='option-2']").first
|
1098
1233
|
option.select_option
|
1099
1234
|
select.value.should == "2"
|
1100
|
-
driver.
|
1235
|
+
driver.find_xpath("//select[@class='triggered']").should_not be_empty
|
1101
1236
|
end
|
1102
1237
|
|
1103
1238
|
it "fires drag events" do
|
1104
|
-
draggable = driver.
|
1105
|
-
container = driver.
|
1239
|
+
draggable = driver.find_xpath("//*[@id='mousedown']").first
|
1240
|
+
container = driver.find_xpath("//*[@id='mouseup']").first
|
1106
1241
|
|
1107
1242
|
draggable.drag_to(container)
|
1108
1243
|
|
1109
|
-
driver.
|
1244
|
+
driver.find_xpath("//*[@class='triggered']").size.should == 1
|
1110
1245
|
end
|
1111
1246
|
end
|
1112
1247
|
|
@@ -1125,8 +1260,13 @@ describe Capybara::Webkit::Driver do
|
|
1125
1260
|
before { visit("/") }
|
1126
1261
|
|
1127
1262
|
it "evaluates nested xpath expressions" do
|
1128
|
-
parent = driver.
|
1129
|
-
parent.
|
1263
|
+
parent = driver.find_xpath("//*[@id='parent']").first
|
1264
|
+
parent.find_xpath("./*[@class='find']").map(&:visible_text).should == %w(Expected)
|
1265
|
+
end
|
1266
|
+
|
1267
|
+
it "finds elements by CSS" do
|
1268
|
+
parent = driver.find_css("#parent").first
|
1269
|
+
parent.find_css(".find").first.visible_text.should == "Expected"
|
1130
1270
|
end
|
1131
1271
|
end
|
1132
1272
|
|
@@ -1145,7 +1285,7 @@ describe Capybara::Webkit::Driver do
|
|
1145
1285
|
end
|
1146
1286
|
end
|
1147
1287
|
visit("/", driver)
|
1148
|
-
driver.
|
1288
|
+
driver.find_xpath("//a").first.click
|
1149
1289
|
result.should == "finished"
|
1150
1290
|
end
|
1151
1291
|
end
|
@@ -1171,9 +1311,9 @@ describe Capybara::Webkit::Driver do
|
|
1171
1311
|
|
1172
1312
|
it "raises a webkit error for the requested url" do
|
1173
1313
|
expect {
|
1174
|
-
driver.
|
1314
|
+
driver.find_xpath("//input").first.click
|
1175
1315
|
wait_for_error_to_complete
|
1176
|
-
driver.
|
1316
|
+
driver.find_xpath("//body")
|
1177
1317
|
}.
|
1178
1318
|
to raise_error(Capybara::Webkit::InvalidResponseError, %r{/error})
|
1179
1319
|
end
|
@@ -1205,10 +1345,10 @@ describe Capybara::Webkit::Driver do
|
|
1205
1345
|
before { visit("/") }
|
1206
1346
|
|
1207
1347
|
it "raises a webkit error and then continues" do
|
1208
|
-
driver.
|
1209
|
-
expect { driver.
|
1348
|
+
driver.find_xpath("//input").first.click
|
1349
|
+
expect { driver.find_xpath("//p") }.to raise_error(Capybara::Webkit::InvalidResponseError)
|
1210
1350
|
visit("/")
|
1211
|
-
driver.
|
1351
|
+
driver.find_xpath("//p").first.visible_text.should == "hello"
|
1212
1352
|
end
|
1213
1353
|
end
|
1214
1354
|
|
@@ -1234,7 +1374,7 @@ describe Capybara::Webkit::Driver do
|
|
1234
1374
|
before { visit("/") }
|
1235
1375
|
|
1236
1376
|
it "doesn't crash from alerts" do
|
1237
|
-
driver.
|
1377
|
+
driver.find_xpath("//p").first.visible_text.should == "success"
|
1238
1378
|
end
|
1239
1379
|
end
|
1240
1380
|
|
@@ -1264,31 +1404,31 @@ describe Capybara::Webkit::Driver do
|
|
1264
1404
|
end
|
1265
1405
|
|
1266
1406
|
it "can set user_agent" do
|
1267
|
-
driver.
|
1407
|
+
driver.find_xpath('id("user-agent")').first.visible_text.should == 'capybara-webkit/custom-user-agent'
|
1268
1408
|
driver.evaluate_script('navigator.userAgent').should == 'capybara-webkit/custom-user-agent'
|
1269
1409
|
end
|
1270
1410
|
|
1271
1411
|
it "keep user_agent in next page" do
|
1272
|
-
driver.
|
1273
|
-
driver.
|
1412
|
+
driver.find_xpath("//a").first.click
|
1413
|
+
driver.find_xpath('id("user-agent")').first.visible_text.should == 'capybara-webkit/custom-user-agent'
|
1274
1414
|
driver.evaluate_script('navigator.userAgent').should == 'capybara-webkit/custom-user-agent'
|
1275
1415
|
end
|
1276
1416
|
|
1277
1417
|
it "can set custom header" do
|
1278
|
-
driver.
|
1418
|
+
driver.find_xpath('id("x-capybara-webkit-header")').first.visible_text.should == 'x-capybara-webkit-header'
|
1279
1419
|
end
|
1280
1420
|
|
1281
1421
|
it "can set Accept header" do
|
1282
|
-
driver.
|
1422
|
+
driver.find_xpath('id("accept")').first.visible_text.should == 'text/html'
|
1283
1423
|
end
|
1284
1424
|
|
1285
1425
|
it "can reset all custom header" do
|
1286
1426
|
driver.reset!
|
1287
1427
|
visit('/')
|
1288
|
-
driver.
|
1428
|
+
driver.find_xpath('id("user-agent")').first.visible_text.should_not == 'capybara-webkit/custom-user-agent'
|
1289
1429
|
driver.evaluate_script('navigator.userAgent').should_not == 'capybara-webkit/custom-user-agent'
|
1290
|
-
driver.
|
1291
|
-
driver.
|
1430
|
+
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 == 'text/html'
|
1292
1432
|
end
|
1293
1433
|
end
|
1294
1434
|
|
@@ -1306,7 +1446,7 @@ describe Capybara::Webkit::Driver do
|
|
1306
1446
|
it "raises a webkit error for the requested url" do
|
1307
1447
|
make_the_server_go_away
|
1308
1448
|
expect {
|
1309
|
-
driver.
|
1449
|
+
driver.find_xpath("//body")
|
1310
1450
|
}.
|
1311
1451
|
to raise_error(Capybara::Webkit::NoResponseError, %r{response})
|
1312
1452
|
make_the_server_come_back
|
@@ -1382,7 +1522,7 @@ describe Capybara::Webkit::Driver do
|
|
1382
1522
|
before { visit("/") }
|
1383
1523
|
|
1384
1524
|
def echoed_cookie
|
1385
|
-
driver.
|
1525
|
+
driver.find_xpath('id("cookie")').first.visible_text
|
1386
1526
|
end
|
1387
1527
|
|
1388
1528
|
it "remembers the cookie on second visit" do
|
@@ -1442,9 +1582,9 @@ describe Capybara::Webkit::Driver do
|
|
1442
1582
|
end
|
1443
1583
|
|
1444
1584
|
it "allows removed nodes when reloading is disabled" do
|
1445
|
-
node = driver.
|
1585
|
+
node = driver.find_xpath("//p[@id='removeMe']").first
|
1446
1586
|
driver.evaluate_script("document.getElementById('parent').innerHTML = 'Magic'")
|
1447
|
-
node.
|
1587
|
+
node.visible_text.should == 'Hello'
|
1448
1588
|
end
|
1449
1589
|
end
|
1450
1590
|
|
@@ -1504,7 +1644,7 @@ describe Capybara::Webkit::Driver do
|
|
1504
1644
|
}
|
1505
1645
|
|
1506
1646
|
cases.each do |xpath, path|
|
1507
|
-
nodes = driver.
|
1647
|
+
nodes = driver.find_xpath(xpath)
|
1508
1648
|
nodes.size.should == 1
|
1509
1649
|
nodes[0].path.should == path
|
1510
1650
|
end
|
@@ -1530,7 +1670,7 @@ describe Capybara::Webkit::Driver do
|
|
1530
1670
|
before { visit("/") }
|
1531
1671
|
|
1532
1672
|
it "handles overflow hidden" do
|
1533
|
-
driver.
|
1673
|
+
driver.find_xpath("//div[@id='overflow']").first.visible_text.should == "Overflow"
|
1534
1674
|
end
|
1535
1675
|
end
|
1536
1676
|
|
@@ -1556,7 +1696,7 @@ describe Capybara::Webkit::Driver do
|
|
1556
1696
|
it "loads a page without error" do
|
1557
1697
|
10.times do
|
1558
1698
|
visit("/redirect")
|
1559
|
-
driver.
|
1699
|
+
driver.find_xpath("//p").first.visible_text.should == "finished"
|
1560
1700
|
end
|
1561
1701
|
end
|
1562
1702
|
end
|
@@ -1585,9 +1725,17 @@ describe Capybara::Webkit::Driver do
|
|
1585
1725
|
before { visit("/") }
|
1586
1726
|
|
1587
1727
|
it "displays the message on subsequent page loads" do
|
1588
|
-
driver.
|
1728
|
+
driver.find_xpath("//span[contains(.,'localStorage is enabled')]").should be_empty
|
1589
1729
|
visit "/"
|
1590
|
-
driver.
|
1730
|
+
driver.find_xpath("//span[contains(.,'localStorage is enabled')]").should_not be_empty
|
1731
|
+
end
|
1732
|
+
|
1733
|
+
it "clears the message after a driver reset!" do
|
1734
|
+
visit "/"
|
1735
|
+
driver.find_xpath("//span[contains(.,'localStorage is enabled')]").should_not be_empty
|
1736
|
+
driver.reset!
|
1737
|
+
visit "/"
|
1738
|
+
driver.find_xpath("//span[contains(.,'localStorage is enabled')]").should be_empty
|
1591
1739
|
end
|
1592
1740
|
end
|
1593
1741
|
|
@@ -1617,7 +1765,7 @@ describe Capybara::Webkit::Driver do
|
|
1617
1765
|
before { visit("/") }
|
1618
1766
|
|
1619
1767
|
it "submits a form without clicking" do
|
1620
|
-
driver.
|
1768
|
+
driver.find_xpath("//form")[0].submit
|
1621
1769
|
driver.html.should include "Congrats"
|
1622
1770
|
end
|
1623
1771
|
end
|
@@ -1653,18 +1801,18 @@ describe Capybara::Webkit::Driver do
|
|
1653
1801
|
end
|
1654
1802
|
|
1655
1803
|
def charCode_for(character)
|
1656
|
-
driver.
|
1657
|
-
driver.
|
1804
|
+
driver.find_xpath("//input")[0].set(character)
|
1805
|
+
driver.find_xpath("//div[@id='charcode_value']")[0].visible_text
|
1658
1806
|
end
|
1659
1807
|
|
1660
1808
|
def keyCode_for(character)
|
1661
|
-
driver.
|
1662
|
-
driver.
|
1809
|
+
driver.find_xpath("//input")[0].set(character)
|
1810
|
+
driver.find_xpath("//div[@id='keycode_value']")[0].visible_text
|
1663
1811
|
end
|
1664
1812
|
|
1665
1813
|
def which_for(character)
|
1666
|
-
driver.
|
1667
|
-
driver.
|
1814
|
+
driver.find_xpath("//input")[0].set(character)
|
1815
|
+
driver.find_xpath("//div[@id='which_value']")[0].visible_text
|
1668
1816
|
end
|
1669
1817
|
|
1670
1818
|
context "keypress app" do
|
@@ -1704,7 +1852,7 @@ describe Capybara::Webkit::Driver do
|
|
1704
1852
|
it "returns a 0 charCode for the event" do
|
1705
1853
|
charCode_for("a").should == "0"
|
1706
1854
|
charCode_for("A").should == "0"
|
1707
|
-
charCode_for("\
|
1855
|
+
charCode_for("\b").should == "0"
|
1708
1856
|
charCode_for(",").should == "0"
|
1709
1857
|
charCode_for("<").should == "0"
|
1710
1858
|
charCode_for("0").should == "0"
|
@@ -1713,7 +1861,7 @@ describe Capybara::Webkit::Driver do
|
|
1713
1861
|
it "returns the keyCode for the event" do
|
1714
1862
|
keyCode_for("a").should == "65"
|
1715
1863
|
keyCode_for("A").should == "65"
|
1716
|
-
keyCode_for("\
|
1864
|
+
keyCode_for("\b").should == "8"
|
1717
1865
|
keyCode_for(",").should == "188"
|
1718
1866
|
keyCode_for("<").should == "188"
|
1719
1867
|
keyCode_for("0").should == "48"
|
@@ -1722,7 +1870,7 @@ describe Capybara::Webkit::Driver do
|
|
1722
1870
|
it "returns the which for the event" do
|
1723
1871
|
which_for("a").should == "65"
|
1724
1872
|
which_for("A").should == "65"
|
1725
|
-
which_for("\
|
1873
|
+
which_for("\b").should == "8"
|
1726
1874
|
which_for(",").should == "188"
|
1727
1875
|
which_for("<").should == "188"
|
1728
1876
|
which_for("0").should == "48"
|
@@ -1767,14 +1915,14 @@ describe Capybara::Webkit::Driver do
|
|
1767
1915
|
it "has the expected text in the new window" do
|
1768
1916
|
visit("/new_window")
|
1769
1917
|
driver.within_window(driver.window_handles.last) do
|
1770
|
-
driver.
|
1918
|
+
driver.find_xpath("//p").first.visible_text.should == "finished"
|
1771
1919
|
end
|
1772
1920
|
end
|
1773
1921
|
|
1774
1922
|
it "waits for the new window to load" do
|
1775
1923
|
visit("/new_window?sleep=1")
|
1776
1924
|
driver.within_window(driver.window_handles.last) do
|
1777
|
-
driver.
|
1925
|
+
driver.find_xpath("//p").first.visible_text.should == "finished"
|
1778
1926
|
end
|
1779
1927
|
end
|
1780
1928
|
|
@@ -1782,34 +1930,34 @@ describe Capybara::Webkit::Driver do
|
|
1782
1930
|
visit("/new_window?sleep=2")
|
1783
1931
|
driver.execute_script("setTimeout(function() { window.location = 'about:blank' }, 1000)")
|
1784
1932
|
driver.within_window(driver.window_handles.last) do
|
1785
|
-
driver.
|
1933
|
+
driver.find_xpath("//p").first.visible_text.should == "finished"
|
1786
1934
|
end
|
1787
1935
|
end
|
1788
1936
|
|
1789
1937
|
it "switches back to the original window" do
|
1790
1938
|
visit("/new_window")
|
1791
1939
|
driver.within_window(driver.window_handles.last) { }
|
1792
|
-
driver.
|
1940
|
+
driver.find_xpath("//p").first.visible_text.should == "bananas"
|
1793
1941
|
end
|
1794
1942
|
|
1795
1943
|
it "supports finding a window by name" do
|
1796
1944
|
visit("/new_window")
|
1797
1945
|
driver.within_window('myWindow') do
|
1798
|
-
driver.
|
1946
|
+
driver.find_xpath("//p").first.visible_text.should == "finished"
|
1799
1947
|
end
|
1800
1948
|
end
|
1801
1949
|
|
1802
1950
|
it "supports finding a window by title" do
|
1803
1951
|
visit("/new_window?sleep=5")
|
1804
1952
|
driver.within_window('My New Window') do
|
1805
|
-
driver.
|
1953
|
+
driver.find_xpath("//p").first.visible_text.should == "finished"
|
1806
1954
|
end
|
1807
1955
|
end
|
1808
1956
|
|
1809
1957
|
it "supports finding a window by url" do
|
1810
1958
|
visit("/new_window?test")
|
1811
1959
|
driver.within_window(driver_url(driver, "/?test")) do
|
1812
|
-
driver.
|
1960
|
+
driver.find_xpath("//p").first.visible_text.should == "finished"
|
1813
1961
|
end
|
1814
1962
|
end
|
1815
1963
|
|
@@ -1893,7 +2041,7 @@ describe Capybara::Webkit::Driver do
|
|
1893
2041
|
expect do
|
1894
2042
|
visit("/outer")
|
1895
2043
|
sleep 1
|
1896
|
-
driver.
|
2044
|
+
driver.find_xpath("//body")
|
1897
2045
|
end.to raise_error(Capybara::Webkit::InvalidResponseError)
|
1898
2046
|
end
|
1899
2047
|
end
|
@@ -1910,9 +2058,19 @@ describe Capybara::Webkit::Driver do
|
|
1910
2058
|
"401 Unauthorized."
|
1911
2059
|
end
|
1912
2060
|
end
|
2061
|
+
|
2062
|
+
get "/reset" do
|
2063
|
+
headers "WWW-Authenticate" => 'Basic realm="Secure Area"'
|
2064
|
+
status 401
|
2065
|
+
"401 Unauthorized."
|
2066
|
+
end
|
1913
2067
|
end
|
1914
2068
|
end
|
1915
2069
|
|
2070
|
+
before do
|
2071
|
+
visit('/reset')
|
2072
|
+
end
|
2073
|
+
|
1916
2074
|
it "can authenticate a request" do
|
1917
2075
|
driver.browser.authenticate('user', 'password')
|
1918
2076
|
visit("/")
|
@@ -1976,14 +2134,14 @@ describe Capybara::Webkit::Driver do
|
|
1976
2134
|
it "should not fetch urls blocked by host" do
|
1977
2135
|
visit("/")
|
1978
2136
|
driver.within_frame('frame1') do
|
1979
|
-
driver.
|
2137
|
+
driver.find_xpath("//body").first.visible_text.should be_empty
|
1980
2138
|
end
|
1981
2139
|
end
|
1982
2140
|
|
1983
2141
|
it "should not fetch urls blocked by path" do
|
1984
2142
|
visit('/')
|
1985
2143
|
driver.within_frame('frame2') do
|
1986
|
-
driver.
|
2144
|
+
driver.find_xpath("//body").first.visible_text.should be_empty
|
1987
2145
|
end
|
1988
2146
|
end
|
1989
2147
|
|
@@ -1995,7 +2153,7 @@ describe Capybara::Webkit::Driver do
|
|
1995
2153
|
it "should fetch unblocked urls" do
|
1996
2154
|
visit('/')
|
1997
2155
|
driver.within_frame('frame3') do
|
1998
|
-
driver.
|
2156
|
+
driver.find_xpath("//p").first.visible_text.should == "Inner"
|
1999
2157
|
end
|
2000
2158
|
end
|
2001
2159
|
|
@@ -2039,7 +2197,7 @@ describe Capybara::Webkit::Driver do
|
|
2039
2197
|
|
2040
2198
|
it "should raise a timeout error" do
|
2041
2199
|
driver.browser.timeout = 1
|
2042
|
-
lambda { visit("/") }.should raise_error(Timeout::Error, "Request timed out after 1 second")
|
2200
|
+
lambda { visit("/") }.should raise_error(Timeout::Error, "Request timed out after 1 second(s)")
|
2043
2201
|
end
|
2044
2202
|
|
2045
2203
|
it "should not raise an error when the timeout is high enough" do
|
@@ -2067,7 +2225,7 @@ describe Capybara::Webkit::Driver do
|
|
2067
2225
|
visit("/")
|
2068
2226
|
driver.status_code.should == 200
|
2069
2227
|
driver.browser.timeout = 1
|
2070
|
-
driver.
|
2228
|
+
driver.find_xpath("//input").first.click
|
2071
2229
|
lambda { driver.status_code }.should raise_error(Timeout::Error)
|
2072
2230
|
end
|
2073
2231
|
|
@@ -2082,17 +2240,19 @@ describe Capybara::Webkit::Driver do
|
|
2082
2240
|
describe "logger app" do
|
2083
2241
|
it "logs nothing before turning on the logger" do
|
2084
2242
|
visit("/")
|
2085
|
-
log.
|
2243
|
+
log.should_not include logging_message
|
2086
2244
|
end
|
2087
2245
|
|
2088
2246
|
it "logs its commands after turning on the logger" do
|
2089
2247
|
driver.enable_logging
|
2090
2248
|
visit("/")
|
2091
|
-
log.
|
2249
|
+
log.should include logging_message
|
2092
2250
|
end
|
2093
2251
|
|
2252
|
+
let(:logging_message) { 'Wrote response true' }
|
2253
|
+
|
2094
2254
|
let(:driver) do
|
2095
|
-
connection = Capybara::Webkit::Connection.new(:
|
2255
|
+
connection = Capybara::Webkit::Connection.new(:stderr => output)
|
2096
2256
|
browser = Capybara::Webkit::Browser.new(connection)
|
2097
2257
|
Capybara::Webkit::Driver.new(AppRunner.app, :browser => browser)
|
2098
2258
|
end
|
@@ -2122,6 +2282,7 @@ describe Capybara::Webkit::Driver do
|
|
2122
2282
|
xhr.setRequestHeader('Content-Type', 'text/plain');
|
2123
2283
|
xhr.send('hello');
|
2124
2284
|
console.log(xhr.response);
|
2285
|
+
return false;
|
2125
2286
|
}
|
2126
2287
|
</script>
|
2127
2288
|
</body>
|
@@ -2137,11 +2298,30 @@ describe Capybara::Webkit::Driver do
|
|
2137
2298
|
|
2138
2299
|
it 'should not hang the server' do
|
2139
2300
|
visit('/')
|
2140
|
-
driver.
|
2301
|
+
driver.find_xpath('//input').first.click
|
2141
2302
|
driver.console_messages.first[:message].should == "hello"
|
2142
2303
|
end
|
2143
2304
|
end
|
2144
2305
|
|
2306
|
+
context "version" do
|
2307
|
+
let(:driver) do
|
2308
|
+
driver_for_html(<<-HTML)
|
2309
|
+
<html><body></body></html>
|
2310
|
+
HTML
|
2311
|
+
end
|
2312
|
+
|
2313
|
+
before { visit("/") }
|
2314
|
+
|
2315
|
+
it "includes Capybara, capybara-webkit, Qt, and WebKit versions" do
|
2316
|
+
result = driver.version
|
2317
|
+
result.should include("Capybara: #{Capybara::VERSION}")
|
2318
|
+
result.should include("capybara-webkit: #{Capybara::Driver::Webkit::VERSION}")
|
2319
|
+
result.should =~ /Qt: \d+\.\d+\.\d+/
|
2320
|
+
result.should =~ /WebKit: \d+\.\d+/
|
2321
|
+
result.should =~ /QtWebKit: \d+\.\d+/
|
2322
|
+
end
|
2323
|
+
end
|
2324
|
+
|
2145
2325
|
def driver_url(driver, path)
|
2146
2326
|
URI.parse(driver.current_url).merge(path).to_s
|
2147
2327
|
end
|