mirror of
https://github.com/thoughtbot/capybara-webkit
synced 2023-03-27 23:22:28 -04:00
Attempt to handle crashes
* Restart server process after a command crashes the process * Inform the user where they can get help
This commit is contained in:
parent
9fabb9b73d
commit
8820275188
4 changed files with 42 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
|||
require 'json'
|
||||
require "json"
|
||||
require "capybara/webkit/errors"
|
||||
|
||||
module Capybara::Webkit
|
||||
class Browser
|
||||
|
@ -209,6 +210,17 @@ module Capybara::Webkit
|
|||
end
|
||||
check
|
||||
read_response
|
||||
rescue SystemCallError => exception
|
||||
@connection.restart
|
||||
raise(Capybara::Webkit::CrashError, <<-MESSAGE.strip)
|
||||
The webkit_server process crashed!
|
||||
|
||||
#{exception.message}
|
||||
|
||||
This is a bug in capybara-webkit. For help with this crash, please visit:
|
||||
|
||||
https://github.com/thoughtbot/capybara-webkit/wiki/Reporting-Crashes
|
||||
MESSAGE
|
||||
end
|
||||
|
||||
def evaluate_script(script)
|
||||
|
|
|
@ -61,6 +61,12 @@ module Capybara::Webkit
|
|||
response
|
||||
end
|
||||
|
||||
def restart
|
||||
@socket = nil
|
||||
start_server
|
||||
connect
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def start_server
|
||||
|
|
|
@ -23,6 +23,9 @@ module Capybara::Webkit
|
|||
class ModalNotFound < StandardError
|
||||
end
|
||||
|
||||
class CrashError < StandardError
|
||||
end
|
||||
|
||||
class JsonError
|
||||
def initialize(response)
|
||||
error = JSON.parse response
|
||||
|
|
|
@ -3092,6 +3092,26 @@ CACHE MANIFEST
|
|||
end
|
||||
end
|
||||
|
||||
context "when the driver process crashes" do
|
||||
let(:driver) do
|
||||
driver_for_app browser do
|
||||
get "/" do
|
||||
"<html><body>Relaunched</body></html>"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
let(:browser) { Capybara::Webkit::Browser.new(connection) }
|
||||
let(:connection) { Capybara::Webkit::Connection.new }
|
||||
|
||||
it "reports and relaunches on reset" do
|
||||
Process.kill "KILL", connection.pid
|
||||
expect { driver.reset! }.to raise_error(Capybara::Webkit::CrashError)
|
||||
visit "/"
|
||||
expect(driver.html).to include("Relaunched")
|
||||
end
|
||||
end
|
||||
|
||||
def driver_url(driver, path)
|
||||
URI.parse(driver.current_url).merge(path).to_s
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue