Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
[rubycdp/ferrum#689]

### Fixed
- `Driver#reset!` and `Driver#quit` don't launch Chrome when no browser has started, so a failed launch doesn't
launch again during teardown

### Removed
- Methods deprecated in 0.20, see its Deprecated section for replacements
Expand Down
8 changes: 7 additions & 1 deletion lib/capybara/cuprite/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Driver < Capybara::Driver::Base
extend Forwardable
include Extensions

delegate %i[quit title window_handles current_window_handle close_window switch_to_window refresh] => :browser
delegate %i[title window_handles current_window_handle close_window switch_to_window refresh] => :browser
delegate %i[send_keys] => :active_element
def_delegator :browser, :url, :current_url
def_delegator :browser, :body, :html
Expand Down Expand Up @@ -133,7 +133,13 @@ def no_such_window_error
Ferrum::NoSuchPageError
end

def quit
@browser&.quit
end

def reset!
return unless @browser

browser.url_blacklist = @options[:url_blacklist]
browser.url_whitelist = @options[:url_whitelist]
browser.raise_on_unhandled_modal = @options.fetch(:raise_on_unhandled_modal, false)
Expand Down
19 changes: 19 additions & 0 deletions spec/lib/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,25 @@
ensure
driver&.quit
end

it "doesn't launch a browser when none has started" do
driver = described_class.new(nil)
allow(Capybara::Cuprite::Browser).to receive(:new).and_raise(Ferrum::ProcessTimeoutError.new(10, ""))

expect { driver.visit("about:blank") }.to raise_error(Ferrum::ProcessTimeoutError)
expect { driver.reset! }.not_to raise_error
expect(Capybara::Cuprite::Browser).to have_received(:new).once
end
end

describe "#quit" do
it "doesn't launch a browser when none has started" do
driver = described_class.new(nil)
allow(Capybara::Cuprite::Browser).to receive(:new).and_raise(Ferrum::ProcessTimeoutError.new(10, ""))

expect { driver.quit }.not_to raise_error
expect(Capybara::Cuprite::Browser).not_to have_received(:new)
end
end

describe "save_path configuration" do
Expand Down
Loading