2011-07-08 09:17:38 -04:00
|
|
|
require 'spec_helper'
|
2011-09-28 16:41:13 -04:00
|
|
|
require 'self_signed_ssl_cert'
|
2011-08-15 12:17:14 -04:00
|
|
|
require 'stringio'
|
2012-07-08 15:17:08 -04:00
|
|
|
require 'capybara/webkit/driver'
|
2011-09-24 17:55:18 -04:00
|
|
|
require 'socket'
|
|
|
|
require 'base64'
|
2011-07-06 08:30:52 -04:00
|
|
|
|
2012-07-08 15:17:08 -04:00
|
|
|
describe Capybara::Webkit::Browser do
|
2011-07-06 08:30:52 -04:00
|
|
|
|
2016-04-05 17:18:14 -04:00
|
|
|
let(:server) { Capybara::Webkit::Server.new }
|
|
|
|
let(:connection) { Capybara::Webkit::Connection.new(server: server) }
|
2013-05-21 07:58:46 -04:00
|
|
|
let(:browser) { Capybara::Webkit::Browser.new(connection) }
|
2012-03-29 21:38:34 -04:00
|
|
|
|
2014-01-28 19:17:16 -05:00
|
|
|
describe "forking", skip_on_windows: true, skip_on_jruby: true do
|
2011-10-14 15:49:07 -04:00
|
|
|
it "only shuts down the server from the main process" do
|
|
|
|
browser.reset!
|
|
|
|
pid = fork {}
|
|
|
|
Process.wait(pid)
|
|
|
|
expect { browser.reset! }.not_to raise_error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-05-04 16:00:21 -04:00
|
|
|
it "doesn't try to read an empty response" do
|
2017-02-03 14:20:27 -05:00
|
|
|
connection = double("connection", puts: nil, print: nil)
|
|
|
|
allow(connection).to receive(:gets).and_return("ok\n", "0\n")
|
|
|
|
allow(connection).to receive(:read).and_raise(StandardError.new("tried to read empty response"))
|
2012-05-04 16:00:21 -04:00
|
|
|
|
2012-07-08 15:17:08 -04:00
|
|
|
browser = Capybara::Webkit::Browser.new(connection)
|
2012-05-04 16:00:21 -04:00
|
|
|
|
2013-08-11 10:38:42 -04:00
|
|
|
expect { browser.visit("/") }.not_to raise_error
|
2012-05-04 16:00:21 -04:00
|
|
|
end
|
2013-05-21 07:58:46 -04:00
|
|
|
|
|
|
|
describe '#command' do
|
|
|
|
context 'non-ok response' do
|
|
|
|
it 'raises an error of given class' do
|
|
|
|
error_json = '{"class": "ClickFailed"}'
|
|
|
|
|
2017-02-03 14:20:27 -05:00
|
|
|
expect(connection).to receive(:gets).ordered.and_return 'error'
|
|
|
|
expect(connection).to receive(:gets).ordered.and_return error_json.bytesize
|
|
|
|
allow(connection).to receive(:read).and_return(error_json)
|
2013-05-21 07:58:46 -04:00
|
|
|
|
|
|
|
expect { browser.command 'blah', 'meh' }.to raise_error(Capybara::Webkit::ClickFailed)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-03-17 10:54:36 -04:00
|
|
|
|
|
|
|
describe "#reset!" do
|
|
|
|
it "resets to the default state" do
|
|
|
|
connection = double("connection", puts: nil, print: nil)
|
|
|
|
allow(connection).to receive(:gets).and_return("ok\n", "{}\n")
|
|
|
|
|
|
|
|
browser = Capybara::Webkit::Browser.new(connection)
|
|
|
|
browser.set_raise_javascript_errors(true)
|
|
|
|
|
|
|
|
expect(browser.raise_javascript_errors?).to be true
|
|
|
|
|
|
|
|
browser.reset!
|
|
|
|
|
|
|
|
expect(browser.raise_javascript_errors?).to be false
|
|
|
|
end
|
|
|
|
end
|
2011-07-06 08:30:52 -04:00
|
|
|
end
|