capybara-webkit 1.9.0 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Appraisals +4 -4
- data/NEWS.md +9 -0
- data/capybara-webkit.gemspec +1 -1
- data/gemfiles/2.6.gemfile +1 -1
- data/gemfiles/{2.4.gemfile → 2.7.gemfile} +1 -1
- data/lib/capybara/webkit.rb +8 -0
- data/lib/capybara/webkit/configuration.rb +3 -0
- data/lib/capybara/webkit/connection.rb +9 -49
- data/lib/capybara/webkit/driver.rb +3 -1
- data/lib/capybara/webkit/server.rb +72 -0
- data/lib/capybara/webkit/version.rb +1 -1
- data/spec/browser_spec.rb +2 -1
- data/spec/connection_spec.rb +7 -133
- data/spec/driver_spec.rb +18 -15
- data/spec/server_spec.rb +150 -0
- data/spec/spec_helper.rb +2 -1
- data/spec/support/app_runner.rb +24 -12
- data/spec/support/output_writer.rb +2 -5
- data/src/JsonSerializer.cpp +2 -2
- data/src/WebPageManager.cpp +9 -8
- metadata +7 -6
- data/gemfiles/2.5.gemfile +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfe45069f7c609493f80959297ea7d06b1cba3f6
|
4
|
+
data.tar.gz: 144cd7bbc569e2ba13898e82ef283c0ba7bfdcd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67ece91583df2ece012ee3ed52f31388ab07fa06216f66466c07b33dfab3b0daecbd97726ebd7376d57ff712ad201e152780edf36a4daa0635a564aaa19a2ed7
|
7
|
+
data.tar.gz: ee13cf5f47fb27b8ffc044bf4e592df638e7963647432255ec9744c016453291b3cfa72b64b4091e9cfab63ca7dd2f91e3dc249007feb9eb30018f694138f3e2
|
data/Appraisals
CHANGED
data/NEWS.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
New for 1.10.0:
|
2
|
+
|
3
|
+
* Capybara 2.7 compatibility
|
4
|
+
* Extract class for booting the server
|
5
|
+
* Move stderr option to config
|
6
|
+
* Deprecate webkit_debug driver
|
7
|
+
* Abort requests before changing settings
|
8
|
+
* Convert JavaScript DateTime objects to Ruby Date objects on evaluation
|
9
|
+
|
1
10
|
New for 1.9.0:
|
2
11
|
|
3
12
|
* Raise error for Qt version greater than 5.5
|
data/capybara-webkit.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
|
20
20
|
s.required_ruby_version = ">= 1.9.0"
|
21
21
|
|
22
|
-
s.add_runtime_dependency("capybara", ">= 2.3.0", "< 2.
|
22
|
+
s.add_runtime_dependency("capybara", ">= 2.3.0", "< 2.8.0")
|
23
23
|
s.add_runtime_dependency("json")
|
24
24
|
|
25
25
|
s.add_development_dependency("rspec", "~> 2.14.0")
|
data/gemfiles/2.6.gemfile
CHANGED
data/lib/capybara/webkit.rb
CHANGED
@@ -16,6 +16,14 @@ Capybara.register_driver :webkit do |app|
|
|
16
16
|
end
|
17
17
|
|
18
18
|
Capybara.register_driver :webkit_debug do |app|
|
19
|
+
warn "[DEPRECATION] The webkit_debug driver is deprecated. " \
|
20
|
+
"Please use Capybara::Webkit.configure instead:\n\n" \
|
21
|
+
" Capybara::Webkit.configure do |config|\n" \
|
22
|
+
" config.debug = true\n" \
|
23
|
+
" end\n\n" \
|
24
|
+
"This option is global and can be configured once" \
|
25
|
+
" (not in a `before` or `setup` block)."
|
26
|
+
|
19
27
|
Capybara::Webkit::Driver.new(
|
20
28
|
app,
|
21
29
|
Capybara::Webkit::Configuration.to_hash.merge(debug: true)
|
@@ -27,6 +27,7 @@ module Capybara
|
|
27
27
|
attr_accessor :debug
|
28
28
|
attr_writer :ignore_ssl_errors
|
29
29
|
attr_accessor :proxy
|
30
|
+
attr_accessor :stderr
|
30
31
|
attr_accessor :timeout
|
31
32
|
attr_writer :skip_image_loading
|
32
33
|
|
@@ -38,6 +39,7 @@ module Capybara
|
|
38
39
|
@ignore_ssl_errors = false
|
39
40
|
@proxy = nil
|
40
41
|
@skip_image_loading = false
|
42
|
+
@stderr = $stderr
|
41
43
|
@timeout = -1
|
42
44
|
end
|
43
45
|
|
@@ -90,6 +92,7 @@ module Capybara
|
|
90
92
|
ignore_ssl_errors: ignore_ssl_errors?,
|
91
93
|
proxy: proxy,
|
92
94
|
skip_image_loading: skip_image_loading?,
|
95
|
+
stderr: stderr,
|
93
96
|
timeout: timeout
|
94
97
|
}
|
95
98
|
end
|
@@ -1,15 +1,9 @@
|
|
1
1
|
require 'socket'
|
2
2
|
require 'timeout'
|
3
3
|
require 'thread'
|
4
|
-
require 'open3'
|
5
4
|
|
6
5
|
module Capybara::Webkit
|
7
6
|
class Connection
|
8
|
-
SERVER_PATH = File.expand_path("../../../../bin/webkit_server", __FILE__)
|
9
|
-
WEBKIT_SERVER_START_TIMEOUT = 15
|
10
|
-
|
11
|
-
attr_reader :port, :pid
|
12
|
-
|
13
7
|
def initialize(options = {})
|
14
8
|
@socket = nil
|
15
9
|
if options.has_key?(:socket_class)
|
@@ -19,15 +13,7 @@ module Capybara::Webkit
|
|
19
13
|
else
|
20
14
|
@socket_class = TCPSocket
|
21
15
|
end
|
22
|
-
|
23
|
-
@output_target = options[:stderr]
|
24
|
-
elsif options.has_key?(:stdout)
|
25
|
-
warn '[DEPRECATION] The Capybara::Webkit::Connection `stdout` option ' \
|
26
|
-
'is deprecated. Please use `stderr` instead.'
|
27
|
-
@output_target = options[:stdout]
|
28
|
-
else
|
29
|
-
@output_target = $stderr
|
30
|
-
end
|
16
|
+
@server = options[:server]
|
31
17
|
start_server
|
32
18
|
connect
|
33
19
|
end
|
@@ -67,44 +53,18 @@ module Capybara::Webkit
|
|
67
53
|
connect
|
68
54
|
end
|
69
55
|
|
70
|
-
|
71
|
-
|
72
|
-
def start_server
|
73
|
-
open_pipe
|
74
|
-
discover_port
|
75
|
-
discover_pid
|
76
|
-
forward_output_in_background_thread
|
56
|
+
def port
|
57
|
+
@server.port
|
77
58
|
end
|
78
59
|
|
79
|
-
def
|
80
|
-
@
|
60
|
+
def pid
|
61
|
+
@server.pid
|
81
62
|
end
|
82
63
|
|
83
|
-
|
84
|
-
if match = line.to_s.match(/listening on port: (\d+)/)
|
85
|
-
match[1].to_i
|
86
|
-
else
|
87
|
-
raise ConnectionError, "#{SERVER_PATH} failed to start."
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def discover_port
|
92
|
-
if IO.select([@pipe_stdout], nil, nil, WEBKIT_SERVER_START_TIMEOUT)
|
93
|
-
@port = parse_port(@pipe_stdout.first)
|
94
|
-
else
|
95
|
-
raise ConnectionError, "#{SERVER_PATH} failed to start after #{WEBKIT_SERVER_START_TIMEOUT} seconds."
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
def discover_pid
|
100
|
-
@pid = @wait_thr[:pid]
|
101
|
-
end
|
64
|
+
private
|
102
65
|
|
103
|
-
def
|
104
|
-
|
105
|
-
Thread.current.abort_on_exception = true
|
106
|
-
IO.copy_stream(@pipe_stderr, @output_target) if @output_target
|
107
|
-
end
|
66
|
+
def start_server
|
67
|
+
@server.start
|
108
68
|
end
|
109
69
|
|
110
70
|
def connect
|
@@ -116,7 +76,7 @@ module Capybara::Webkit
|
|
116
76
|
end
|
117
77
|
|
118
78
|
def attempt_connect
|
119
|
-
@socket = @socket_class.open("127.0.0.1",
|
79
|
+
@socket = @socket_class.open("127.0.0.1", port)
|
120
80
|
if defined?(Socket::TCP_NODELAY)
|
121
81
|
@socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, true)
|
122
82
|
end
|
@@ -5,12 +5,14 @@ require "capybara/webkit/connection"
|
|
5
5
|
require "capybara/webkit/browser"
|
6
6
|
require "capybara/webkit/cookie_jar"
|
7
7
|
require "capybara/webkit/errors"
|
8
|
+
require "capybara/webkit/server"
|
8
9
|
|
9
10
|
module Capybara::Webkit
|
10
11
|
class Driver < Capybara::Driver::Base
|
11
12
|
def initialize(app, options={})
|
12
13
|
@app = app
|
13
|
-
@options = options
|
14
|
+
@options = options.dup
|
15
|
+
@options[:server] ||= Server.new(options)
|
14
16
|
@browser = options[:browser] || Browser.new(Connection.new(options))
|
15
17
|
apply_options
|
16
18
|
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require "open3"
|
2
|
+
require "thread"
|
3
|
+
|
4
|
+
module Capybara
|
5
|
+
module Webkit
|
6
|
+
class Server
|
7
|
+
SERVER_PATH = File.expand_path("../../../../bin/webkit_server", __FILE__)
|
8
|
+
WEBKIT_SERVER_START_TIMEOUT = 15
|
9
|
+
|
10
|
+
attr_reader :port, :pid
|
11
|
+
|
12
|
+
def initialize(options = {})
|
13
|
+
if options.has_key?(:stderr)
|
14
|
+
@output_target = options[:stderr]
|
15
|
+
elsif options.has_key?(:stdout)
|
16
|
+
warn "[DEPRECATION] The Capybara::Webkit::Connection `stdout` " \
|
17
|
+
"option is deprecated. Please use `stderr` instead."
|
18
|
+
@output_target = options[:stdout]
|
19
|
+
else
|
20
|
+
@output_target = $stderr
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def start
|
25
|
+
open_pipe
|
26
|
+
discover_port
|
27
|
+
discover_pid
|
28
|
+
forward_output_in_background_thread
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def open_pipe
|
34
|
+
@pipe_stdin,
|
35
|
+
@pipe_stdout,
|
36
|
+
@pipe_stderr,
|
37
|
+
@wait_thr = Open3.popen3(SERVER_PATH)
|
38
|
+
end
|
39
|
+
|
40
|
+
def discover_port
|
41
|
+
if IO.select([@pipe_stdout], nil, nil, WEBKIT_SERVER_START_TIMEOUT)
|
42
|
+
@port = parse_port(@pipe_stdout.first)
|
43
|
+
else
|
44
|
+
raise(
|
45
|
+
ConnectionError,
|
46
|
+
"#{SERVER_PATH} failed to start after " \
|
47
|
+
"#{WEBKIT_SERVER_START_TIMEOUT} seconds.",
|
48
|
+
)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def parse_port(line)
|
53
|
+
if match = line.to_s.match(/listening on port: (\d+)/)
|
54
|
+
match[1].to_i
|
55
|
+
else
|
56
|
+
raise ConnectionError, "#{SERVER_PATH} failed to start."
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def discover_pid
|
61
|
+
@pid = @wait_thr[:pid]
|
62
|
+
end
|
63
|
+
|
64
|
+
def forward_output_in_background_thread
|
65
|
+
Thread.new do
|
66
|
+
Thread.current.abort_on_exception = true
|
67
|
+
IO.copy_stream(@pipe_stderr, @output_target) if @output_target
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
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(:server) { Capybara::Webkit::Server.new }
|
11
|
+
let(:connection) { Capybara::Webkit::Connection.new(server: server) }
|
11
12
|
let(:browser) { Capybara::Webkit::Browser.new(connection) }
|
12
13
|
|
13
14
|
describe "forking", skip_on_windows: true, skip_on_jruby: true do
|
data/spec/connection_spec.rb
CHANGED
@@ -2,144 +2,18 @@ require 'spec_helper'
|
|
2
2
|
require 'capybara/webkit/connection'
|
3
3
|
|
4
4
|
describe Capybara::Webkit::Connection do
|
5
|
-
it "
|
6
|
-
|
7
|
-
|
8
|
-
fork_pid = fork do
|
9
|
-
read_io.close
|
10
|
-
connection = Capybara::Webkit::Connection.new
|
11
|
-
write_io.write(connection.pid)
|
12
|
-
write_io.close
|
13
|
-
Process.wait(connection.pid)
|
14
|
-
end
|
15
|
-
|
16
|
-
write_io.close
|
17
|
-
|
18
|
-
webkit_pid = read_io.read.to_i
|
19
|
-
webkit_pid.should be > 1
|
20
|
-
read_io.close
|
21
|
-
Process.kill(9, fork_pid)
|
22
|
-
eventually { expect { Process.getpgid(webkit_pid) }.to raise_error Errno::ESRCH }
|
23
|
-
end
|
24
|
-
|
25
|
-
def eventually
|
26
|
-
polling_interval = 0.1
|
27
|
-
time_limit = Time.now + 3
|
28
|
-
loop do
|
29
|
-
begin
|
30
|
-
yield
|
31
|
-
return
|
32
|
-
rescue RSpec::Expectations::ExpectationNotMetError => error
|
33
|
-
raise error if Time.now >= time_limit
|
34
|
-
sleep polling_interval
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
it "raises an error if the server has stopped", skip_on_windows: true do
|
40
|
-
path = 'false'
|
41
|
-
stub_const("Capybara::Webkit::Connection::SERVER_PATH", path)
|
42
|
-
|
43
|
-
expect { Capybara::Webkit::Connection.new }.
|
44
|
-
to raise_error(
|
45
|
-
Capybara::Webkit::ConnectionError,
|
46
|
-
"#{path} failed to start.")
|
47
|
-
end
|
48
|
-
|
49
|
-
it "raises an error if the server is not ready", skip_on_windows: true do
|
50
|
-
server_path = 'sleep 1'
|
51
|
-
stub_const("Capybara::Webkit::Connection::SERVER_PATH", server_path)
|
52
|
-
start_timeout = 0.5
|
53
|
-
stub_const("Capybara::Webkit::Connection::WEBKIT_SERVER_START_TIMEOUT", start_timeout)
|
54
|
-
|
55
|
-
error_string =
|
56
|
-
if defined?(::JRUBY_VERSION)
|
57
|
-
"#{server_path} failed to start."
|
58
|
-
else
|
59
|
-
"#{server_path} failed to start after #{start_timeout} seconds."
|
60
|
-
end
|
61
|
-
|
62
|
-
expect { Capybara::Webkit::Connection.new }.
|
63
|
-
to raise_error(Capybara::Webkit::ConnectionError, error_string)
|
64
|
-
end
|
65
|
-
|
66
|
-
it "boots a server to talk to" do
|
67
|
-
url = "http://#{@rack_server.host}:#{@rack_server.port}/"
|
68
|
-
connection.puts "Visit"
|
69
|
-
connection.puts 1
|
70
|
-
connection.puts url.to_s.bytesize
|
71
|
-
connection.print url
|
72
|
-
connection.gets.should eq "ok\n"
|
73
|
-
connection.gets.should eq "0\n"
|
74
|
-
connection.puts "Body"
|
75
|
-
connection.puts 0
|
76
|
-
connection.gets.should eq "ok\n"
|
77
|
-
response_length = connection.gets.to_i
|
78
|
-
response = connection.read(response_length)
|
79
|
-
response.should include("Hey there")
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'forwards stderr to the given IO object' do
|
83
|
-
read_io, write_io = IO.pipe
|
84
|
-
redirected_connection = Capybara::Webkit::Connection.new(:stderr => write_io)
|
85
|
-
redirected_connection.puts "EnableLogging"
|
86
|
-
redirected_connection.puts 0
|
87
|
-
|
88
|
-
script = 'console.log("hello world")'
|
89
|
-
redirected_connection.puts "Execute"
|
90
|
-
redirected_connection.puts 1
|
91
|
-
redirected_connection.puts script.to_s.bytesize
|
92
|
-
redirected_connection.print script
|
93
|
-
|
94
|
-
expect(read_io).to include_response "\nhello world"
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'does not forward stderr to nil' do
|
98
|
-
IO.should_not_receive(:copy_stream)
|
99
|
-
Capybara::Webkit::Connection.new(:stderr => nil)
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'prints a deprecation warning if the stdout option is used' do
|
103
|
-
Capybara::Webkit::Connection.any_instance.should_receive(:warn)
|
104
|
-
Capybara::Webkit::Connection.new(:stdout => nil)
|
105
|
-
end
|
106
|
-
|
107
|
-
it 'does not forward stdout to nil if the stdout option is used' do
|
108
|
-
Capybara::Webkit::Connection.any_instance.stub(:warn)
|
109
|
-
IO.should_not_receive(:copy_stream)
|
110
|
-
Capybara::Webkit::Connection.new(:stdout => nil)
|
111
|
-
end
|
112
|
-
|
113
|
-
it "returns the server port" do
|
114
|
-
connection.port.should be_between 0x400, 0xffff
|
115
|
-
end
|
116
|
-
|
117
|
-
it 'sets appropriate options on its socket' do
|
118
|
-
socket = double('socket')
|
5
|
+
it "sets appropriate options on its socket" do
|
6
|
+
socket = double("socket")
|
7
|
+
server = double(:Server, start: nil, port: 123)
|
119
8
|
TCPSocket.stub(:open).and_return(socket)
|
120
9
|
if defined?(Socket::TCP_NODELAY)
|
121
|
-
socket.
|
10
|
+
socket.
|
11
|
+
should_receive(:setsockopt).
|
12
|
+
with(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, true)
|
122
13
|
else
|
123
14
|
socket.should_not_receive(:setsockopt)
|
124
15
|
end
|
125
|
-
Capybara::Webkit::Connection.new
|
126
|
-
end
|
127
16
|
|
128
|
-
|
129
|
-
new_connection = Capybara::Webkit::Connection.new
|
130
|
-
new_connection.port.should_not == connection.port
|
131
|
-
end
|
132
|
-
|
133
|
-
let(:connection) { Capybara::Webkit::Connection.new }
|
134
|
-
|
135
|
-
before(:all) do
|
136
|
-
@app = lambda do |env|
|
137
|
-
body = "<html><body>Hey there</body></html>"
|
138
|
-
[200,
|
139
|
-
{ 'Content-Type' => 'text/html', 'Content-Length' => body.size.to_s },
|
140
|
-
[body]]
|
141
|
-
end
|
142
|
-
@rack_server = Capybara::Server.new(@app)
|
143
|
-
@rack_server.boot
|
17
|
+
Capybara::Webkit::Connection.new(server: server)
|
144
18
|
end
|
145
19
|
end
|
data/spec/driver_spec.rb
CHANGED
@@ -479,6 +479,11 @@ describe Capybara::Webkit::Driver do
|
|
479
479
|
result.should eq nil
|
480
480
|
end
|
481
481
|
|
482
|
+
it "evaluates Javascript and returns a date" do
|
483
|
+
result = driver.evaluate_script(%<new Date("2016-04-01T00:00:00Z")>)
|
484
|
+
result.should eq "2016-04-01T00:00:00Z"
|
485
|
+
end
|
486
|
+
|
482
487
|
it "evaluates Javascript and returns an object" do
|
483
488
|
result = driver.evaluate_script(%<({ 'one' : 1 })>)
|
484
489
|
result.should eq 'one' => 1
|
@@ -1821,13 +1826,14 @@ describe Capybara::Webkit::Driver do
|
|
1821
1826
|
|
1822
1827
|
context "no response app" do
|
1823
1828
|
let(:driver) do
|
1824
|
-
driver_for_html(<<-HTML
|
1829
|
+
driver_for_html(<<-HTML)
|
1825
1830
|
<html><body>
|
1826
1831
|
<form action="/error"><input type="submit"/></form>
|
1827
1832
|
</body></html>
|
1828
1833
|
HTML
|
1829
1834
|
end
|
1830
1835
|
|
1836
|
+
let!(:connection) { fork_connection }
|
1831
1837
|
before { visit("/") }
|
1832
1838
|
|
1833
1839
|
it "raises a webkit error for the requested url" do
|
@@ -1850,9 +1856,6 @@ describe Capybara::Webkit::Driver do
|
|
1850
1856
|
connection.stub(:puts)
|
1851
1857
|
connection.stub(:print)
|
1852
1858
|
end
|
1853
|
-
|
1854
|
-
let(:browser) { Capybara::Webkit::Browser.new(connection) }
|
1855
|
-
let(:connection) { Capybara::Webkit::Connection.new }
|
1856
1859
|
end
|
1857
1860
|
|
1858
1861
|
context "custom font app" do
|
@@ -2722,7 +2725,7 @@ CACHE MANIFEST
|
|
2722
2725
|
describe "url whitelisting", skip_if_offline: true do
|
2723
2726
|
it_behaves_like "output writer" do
|
2724
2727
|
let(:driver) do
|
2725
|
-
driver_for_html(<<-HTML
|
2728
|
+
driver_for_html(<<-HTML)
|
2726
2729
|
<<-HTML
|
2727
2730
|
<html>
|
2728
2731
|
<body>
|
@@ -2885,7 +2888,7 @@ CACHE MANIFEST
|
|
2885
2888
|
describe "logger app" do
|
2886
2889
|
it_behaves_like "output writer" do
|
2887
2890
|
let(:driver) do
|
2888
|
-
driver_for_html("<html><body>Hello</body></html>"
|
2891
|
+
driver_for_html("<html><body>Hello</body></html>")
|
2889
2892
|
end
|
2890
2893
|
|
2891
2894
|
it "logs nothing in normal mode" do
|
@@ -3066,7 +3069,7 @@ CACHE MANIFEST
|
|
3066
3069
|
it_behaves_like "output writer" do
|
3067
3070
|
let(:driver) do
|
3068
3071
|
count = 0
|
3069
|
-
driver_for_app
|
3072
|
+
driver_for_app do
|
3070
3073
|
get "/" do
|
3071
3074
|
count += 1
|
3072
3075
|
<<-HTML
|
@@ -3111,17 +3114,15 @@ CACHE MANIFEST
|
|
3111
3114
|
|
3112
3115
|
context "when the driver process crashes" do
|
3113
3116
|
let(:driver) do
|
3114
|
-
driver_for_app
|
3117
|
+
driver_for_app do
|
3115
3118
|
get "/" do
|
3116
3119
|
"<html><body>Relaunched</body></html>"
|
3117
3120
|
end
|
3118
3121
|
end
|
3119
3122
|
end
|
3120
3123
|
|
3121
|
-
let(:browser) { Capybara::Webkit::Browser.new(connection) }
|
3122
|
-
let(:connection) { Capybara::Webkit::Connection.new }
|
3123
|
-
|
3124
3124
|
it "reports and relaunches on reset" do
|
3125
|
+
connection = fork_connection
|
3125
3126
|
Process.kill "KILL", connection.pid
|
3126
3127
|
expect { driver.reset! }.to raise_error(Capybara::Webkit::CrashError)
|
3127
3128
|
visit "/"
|
@@ -3157,6 +3158,8 @@ CACHE MANIFEST
|
|
3157
3158
|
conn.close
|
3158
3159
|
end
|
3159
3160
|
end
|
3161
|
+
|
3162
|
+
fork_connection
|
3160
3163
|
end
|
3161
3164
|
|
3162
3165
|
after do
|
@@ -3190,9 +3193,7 @@ CACHE MANIFEST
|
|
3190
3193
|
end
|
3191
3194
|
end
|
3192
3195
|
|
3193
|
-
let(:driver) { driver_for_html(""
|
3194
|
-
let(:browser) { Capybara::Webkit::Browser.new(connection) }
|
3195
|
-
let(:connection) { Capybara::Webkit::Connection.new }
|
3196
|
+
let(:driver) { driver_for_html("") }
|
3196
3197
|
end
|
3197
3198
|
|
3198
3199
|
context "skip image loading" do
|
@@ -3295,6 +3296,8 @@ CACHE MANIFEST
|
|
3295
3296
|
config.use_proxy host: @host, port: @port, user: @user, pass: @pass
|
3296
3297
|
end
|
3297
3298
|
|
3299
|
+
fork_connection
|
3300
|
+
|
3298
3301
|
driver.visit @url
|
3299
3302
|
@proxy_requests.size.should eq 2
|
3300
3303
|
@request = @proxy_requests[-1]
|
@@ -3306,7 +3309,7 @@ CACHE MANIFEST
|
|
3306
3309
|
end
|
3307
3310
|
|
3308
3311
|
let(:driver) do
|
3309
|
-
driver_for_html(""
|
3312
|
+
driver_for_html("")
|
3310
3313
|
end
|
3311
3314
|
|
3312
3315
|
it "uses the HTTP proxy correctly" do
|
data/spec/server_spec.rb
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "capybara/webkit/server"
|
3
|
+
|
4
|
+
describe Capybara::Webkit::Connection do
|
5
|
+
it "ensures the process ends", skip_on_windows: true, skip_on_jruby: true do
|
6
|
+
read_io, write_io = IO.pipe
|
7
|
+
|
8
|
+
fork_pid = fork do
|
9
|
+
read_io.close
|
10
|
+
server = start_server
|
11
|
+
write_io.write(server.pid)
|
12
|
+
write_io.close
|
13
|
+
Process.wait(server.pid)
|
14
|
+
end
|
15
|
+
|
16
|
+
write_io.close
|
17
|
+
|
18
|
+
webkit_pid = read_io.read.to_i
|
19
|
+
webkit_pid.should be > 1
|
20
|
+
read_io.close
|
21
|
+
Process.kill(9, fork_pid)
|
22
|
+
|
23
|
+
eventually do
|
24
|
+
expect { Process.getpgid(webkit_pid) }.to raise_error Errno::ESRCH
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it "raises an error if the server has stopped", skip_on_windows: true do
|
29
|
+
path = "false"
|
30
|
+
stub_const("Capybara::Webkit::Server::SERVER_PATH", path)
|
31
|
+
|
32
|
+
expect { start_server }.
|
33
|
+
to raise_error(
|
34
|
+
Capybara::Webkit::ConnectionError,
|
35
|
+
"#{path} failed to start.")
|
36
|
+
end
|
37
|
+
|
38
|
+
it "raises an error if the server is not ready", skip_on_windows: true do
|
39
|
+
server_path = "sleep 1"
|
40
|
+
stub_const("Capybara::Webkit::Server::SERVER_PATH", server_path)
|
41
|
+
start_timeout = 0.5
|
42
|
+
stub_const(
|
43
|
+
"Capybara::Webkit::Server::WEBKIT_SERVER_START_TIMEOUT",
|
44
|
+
start_timeout,
|
45
|
+
)
|
46
|
+
|
47
|
+
error_string =
|
48
|
+
if defined?(::JRUBY_VERSION)
|
49
|
+
"#{server_path} failed to start."
|
50
|
+
else
|
51
|
+
"#{server_path} failed to start after #{start_timeout} seconds."
|
52
|
+
end
|
53
|
+
|
54
|
+
expect { start_server }.
|
55
|
+
to raise_error(Capybara::Webkit::ConnectionError, error_string)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "boots a server to talk to" do
|
59
|
+
url = "http://#{@rack_server.host}:#{@rack_server.port}/"
|
60
|
+
server = start_server
|
61
|
+
socket = connect_to(server)
|
62
|
+
socket.puts "Visit"
|
63
|
+
socket.puts 1
|
64
|
+
socket.puts url.to_s.bytesize
|
65
|
+
socket.print url
|
66
|
+
socket.gets.should eq "ok\n"
|
67
|
+
socket.gets.should eq "0\n"
|
68
|
+
socket.puts "Body"
|
69
|
+
socket.puts 0
|
70
|
+
socket.gets.should eq "ok\n"
|
71
|
+
response_length = socket.gets.to_i
|
72
|
+
response = socket.read(response_length)
|
73
|
+
response.should include("Hey there")
|
74
|
+
end
|
75
|
+
|
76
|
+
it "forwards stderr to the given IO object" do
|
77
|
+
read_io, write_io = IO.pipe
|
78
|
+
server = start_server(stderr: write_io)
|
79
|
+
socket = connect_to(server)
|
80
|
+
socket.puts "EnableLogging"
|
81
|
+
socket.puts 0
|
82
|
+
|
83
|
+
script = "console.log('hello world')"
|
84
|
+
socket.puts "Execute"
|
85
|
+
socket.puts 1
|
86
|
+
socket.puts script.to_s.bytesize
|
87
|
+
socket.print script
|
88
|
+
|
89
|
+
expect(read_io).to include_response "\nhello world"
|
90
|
+
end
|
91
|
+
|
92
|
+
it "does not forward stderr to nil" do
|
93
|
+
IO.should_not_receive(:copy_stream)
|
94
|
+
start_server(stderr: nil)
|
95
|
+
end
|
96
|
+
|
97
|
+
it "prints a deprecation warning if the stdout option is used" do
|
98
|
+
Capybara::Webkit::Server.any_instance.should_receive(:warn)
|
99
|
+
start_server(stdout: nil)
|
100
|
+
end
|
101
|
+
|
102
|
+
it "does not forward stdout to nil if the stdout option is used" do
|
103
|
+
Capybara::Webkit::Server.any_instance.stub(:warn)
|
104
|
+
IO.should_not_receive(:copy_stream)
|
105
|
+
start_server(stdout: nil)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "returns the server port" do
|
109
|
+
start_server.port.should be_between 0x400, 0xffff
|
110
|
+
end
|
111
|
+
|
112
|
+
it "chooses a new port number for a new connection" do
|
113
|
+
start_server.port.should_not == start_server.port
|
114
|
+
end
|
115
|
+
|
116
|
+
before(:all) do
|
117
|
+
@app = lambda do |_|
|
118
|
+
body = "<html><body>Hey there</body></html>"
|
119
|
+
[
|
120
|
+
200,
|
121
|
+
{ "Content-Type" => "text/html", "Content-Length" => body.size.to_s },
|
122
|
+
[body],
|
123
|
+
]
|
124
|
+
end
|
125
|
+
@rack_server = Capybara::Server.new(@app)
|
126
|
+
@rack_server.boot
|
127
|
+
end
|
128
|
+
|
129
|
+
def start_server(options = {})
|
130
|
+
Capybara::Webkit::Server.new(options).tap(&:start)
|
131
|
+
end
|
132
|
+
|
133
|
+
def connect_to(server)
|
134
|
+
TCPSocket.open("127.0.0.1", server.port)
|
135
|
+
end
|
136
|
+
|
137
|
+
def eventually
|
138
|
+
polling_interval = 0.1
|
139
|
+
time_limit = Time.now + 3
|
140
|
+
loop do
|
141
|
+
begin
|
142
|
+
yield
|
143
|
+
return
|
144
|
+
rescue RSpec::Expectations::ExpectationNotMetError => error
|
145
|
+
raise error if Time.now >= time_limit
|
146
|
+
sleep polling_interval
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -10,7 +10,8 @@ $LOAD_PATH << File.join(PROJECT_ROOT, 'lib')
|
|
10
10
|
Dir[File.join(PROJECT_ROOT, 'spec', 'support', '**', '*.rb')].each { |file| require(file) }
|
11
11
|
|
12
12
|
require 'capybara/webkit'
|
13
|
-
$
|
13
|
+
$webkit_server = Capybara::Webkit::Server.new
|
14
|
+
$webkit_connection = Capybara::Webkit::Connection.new(server: $webkit_server)
|
14
15
|
$webkit_browser = Capybara::Webkit::Browser.new($webkit_connection)
|
15
16
|
|
16
17
|
if ENV['DEBUG']
|
data/spec/support/app_runner.rb
CHANGED
@@ -5,7 +5,7 @@ require 'sinatra/base'
|
|
5
5
|
|
6
6
|
module AppRunner
|
7
7
|
class << self
|
8
|
-
attr_accessor :app, :app_host, :configuration
|
8
|
+
attr_accessor :app, :app_host, :browser, :configuration
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.boot
|
@@ -20,6 +20,8 @@ module AppRunner
|
|
20
20
|
[200, { 'Content-Type' => 'html', 'Content-Length' => 0 }, []]
|
21
21
|
end
|
22
22
|
|
23
|
+
self.browser = $webkit_browser
|
24
|
+
|
23
25
|
self.configuration = Capybara::Webkit::Configuration.new
|
24
26
|
end
|
25
27
|
|
@@ -31,15 +33,26 @@ module AppRunner
|
|
31
33
|
yield AppRunner.configuration
|
32
34
|
end
|
33
35
|
|
34
|
-
def
|
36
|
+
def fork_connection
|
37
|
+
AppRunner.fork_connection
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.fork_connection
|
41
|
+
server = Capybara::Webkit::Server.new(options)
|
42
|
+
connection = Capybara::Webkit::Connection.new(server: server)
|
43
|
+
AppRunner.browser = Capybara::Webkit::Browser.new(connection)
|
44
|
+
connection
|
45
|
+
end
|
46
|
+
|
47
|
+
def driver_for_app(&body)
|
35
48
|
app = Class.new(ExampleApp, &body)
|
36
49
|
run_application app
|
37
|
-
build_driver
|
50
|
+
AppRunner.build_driver
|
38
51
|
end
|
39
52
|
|
40
|
-
def driver_for_html(html
|
53
|
+
def driver_for_html(html)
|
41
54
|
run_application_for_html html
|
42
|
-
build_driver
|
55
|
+
AppRunner.build_driver
|
43
56
|
end
|
44
57
|
|
45
58
|
def session_for_app(&body)
|
@@ -54,15 +67,14 @@ module AppRunner
|
|
54
67
|
}
|
55
68
|
end
|
56
69
|
|
57
|
-
|
70
|
+
def self.build_driver
|
71
|
+
Capybara::Webkit::Driver.new(app, options.merge(browser: browser))
|
72
|
+
end
|
58
73
|
|
59
|
-
def
|
60
|
-
|
61
|
-
to_hash.
|
62
|
-
merge(browser: $webkit_browser).
|
63
|
-
merge(overrides)
|
64
|
-
Capybara::Webkit::Driver.new(AppRunner.app, options)
|
74
|
+
def self.options
|
75
|
+
configuration.to_hash
|
65
76
|
end
|
77
|
+
private_class_method :options
|
66
78
|
|
67
79
|
def self.included(example_group)
|
68
80
|
example_group.class_eval do
|
@@ -1,11 +1,8 @@
|
|
1
1
|
shared_examples_for "output writer" do
|
2
2
|
before do
|
3
3
|
@read, @write = IO.pipe
|
4
|
-
|
5
|
-
|
6
|
-
let(:browser) do
|
7
|
-
connection = Capybara::Webkit::Connection.new(:stderr => @write)
|
8
|
-
Capybara::Webkit::Browser.new(connection)
|
4
|
+
configure { |config| config.stderr = @write }
|
5
|
+
fork_connection
|
9
6
|
end
|
10
7
|
|
11
8
|
let(:stderr) do
|
data/src/JsonSerializer.cpp
CHANGED
@@ -13,9 +13,9 @@ void JsonSerializer::addVariant(const QVariant &object) {
|
|
13
13
|
if (object.isValid()) {
|
14
14
|
switch(object.type()) {
|
15
15
|
case QMetaType::QString:
|
16
|
+
case QMetaType::QDateTime:
|
16
17
|
{
|
17
|
-
|
18
|
-
addString(string);
|
18
|
+
addString(object.toString());
|
19
19
|
}
|
20
20
|
break;
|
21
21
|
case QMetaType::QVariantList:
|
data/src/WebPageManager.cpp
CHANGED
@@ -145,14 +145,6 @@ void WebPageManager::setTimeout(int timeout) {
|
|
145
145
|
}
|
146
146
|
|
147
147
|
void WebPageManager::reset() {
|
148
|
-
m_timeout = -1;
|
149
|
-
m_cookieJar->clearCookies();
|
150
|
-
m_networkAccessManager->reset();
|
151
|
-
m_customHeadersRequestHandler->reset();
|
152
|
-
m_currentPage->resetLocalStorage();
|
153
|
-
m_blacklistedRequestHandler->reset();
|
154
|
-
m_unknownUrlHandler->reset();
|
155
|
-
|
156
148
|
foreach(QNetworkReply *reply, m_pendingReplies) {
|
157
149
|
logger() << "Aborting request to" << reply->url().toString();
|
158
150
|
reply->abort();
|
@@ -164,6 +156,15 @@ void WebPageManager::reset() {
|
|
164
156
|
page->deleteLater();
|
165
157
|
}
|
166
158
|
|
159
|
+
m_timeout = -1;
|
160
|
+
m_cookieJar->clearCookies();
|
161
|
+
m_networkAccessManager->reset();
|
162
|
+
m_customHeadersRequestHandler->reset();
|
163
|
+
m_currentPage->resetLocalStorage();
|
164
|
+
m_blacklistedRequestHandler->reset();
|
165
|
+
m_unknownUrlHandler->reset();
|
166
|
+
|
167
|
+
|
167
168
|
qint64 size = QWebSettings::offlineWebApplicationCacheQuota();
|
168
169
|
// No public function was found to wrap the empty() call to
|
169
170
|
// WebCore::cacheStorage().empty()
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capybara-webkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thoughtbot
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2016-
|
16
|
+
date: 2016-04-08 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: capybara
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
version: 2.3.0
|
25
25
|
- - "<"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 2.
|
27
|
+
version: 2.8.0
|
28
28
|
type: :runtime
|
29
29
|
prerelease: false
|
30
30
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
version: 2.3.0
|
35
35
|
- - "<"
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 2.
|
37
|
+
version: 2.8.0
|
38
38
|
- !ruby/object:Gem::Dependency
|
39
39
|
name: json
|
40
40
|
requirement: !ruby/object:Gem::Requirement
|
@@ -169,9 +169,8 @@ files:
|
|
169
169
|
- bin/Info.plist
|
170
170
|
- capybara-webkit.gemspec
|
171
171
|
- extconf.rb
|
172
|
-
- gemfiles/2.4.gemfile
|
173
|
-
- gemfiles/2.5.gemfile
|
174
172
|
- gemfiles/2.6.gemfile
|
173
|
+
- gemfiles/2.7.gemfile
|
175
174
|
- gemfiles/master.gemfile
|
176
175
|
- lib/capybara-webkit.rb
|
177
176
|
- lib/capybara/webkit.rb
|
@@ -183,6 +182,7 @@ files:
|
|
183
182
|
- lib/capybara/webkit/errors.rb
|
184
183
|
- lib/capybara/webkit/matchers.rb
|
185
184
|
- lib/capybara/webkit/node.rb
|
185
|
+
- lib/capybara/webkit/server.rb
|
186
186
|
- lib/capybara/webkit/version.rb
|
187
187
|
- lib/capybara_webkit_builder.rb
|
188
188
|
- spec/browser_spec.rb
|
@@ -197,6 +197,7 @@ files:
|
|
197
197
|
- spec/integration/session_spec.rb
|
198
198
|
- spec/selenium_compatibility_spec.rb
|
199
199
|
- spec/self_signed_ssl_cert.rb
|
200
|
+
- spec/server_spec.rb
|
200
201
|
- spec/spec_helper.rb
|
201
202
|
- spec/support/app_runner.rb
|
202
203
|
- spec/support/matchers/include_response.rb
|