Skip to content
Merged
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
6 changes: 5 additions & 1 deletion lib/capybara/cuprite/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,11 @@ def dismiss_modal(type, options = {})
private

def build_remote_debug_url(path:)
"http://#{browser.process.host}:#{browser.process.port}#{path}"
uri = URI.parse(path)
uri.scheme ||= "http"
uri.host ||= browser.process.host
uri.port ||= browser.process.port
uri.to_s
end

def default_domain
Expand Down
9 changes: 9 additions & 0 deletions spec/features/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1605,6 +1605,15 @@ def create_screenshot(file, *args)

expect(@session).to have_content("test_cookie")
end

it "has a working debug_url" do
session = Capybara::Session.new(:cuprite_with_inspector, TestApp)
session.visit "/cuprite/arbitrary_path/200"

expect do
URI.parse(session.driver.debug_url)
end.not_to raise_error
end
end
end
end
15 changes: 14 additions & 1 deletion spec/lib/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
end

describe "debug_url" do
it "parses the devtools frontend url correctly" do
it "parses the devtools frontend url correctly when devtoolsFrontendUrl is relative" do
driver = described_class.new(nil, { port: 12_345 })
driver.browser # initialize browser before stubbing Net::HTTP as it also calls it
uri = instance_double(URI)
Expand All @@ -40,6 +40,19 @@

expect(driver.debug_url).to eq("http://127.0.0.1:12345/works")
end

it "parses the devtools frontend url correctly when devtoolsFrontendUrl is fully qualified" do
driver = described_class.new(nil, { port: 12_346 })
driver.browser # initialize browser before stubbing Net::HTTP as it also calls it
uri = instance_double(URI)

allow(driver).to receive(:URI).with("http://127.0.0.1:12346/json").and_return(uri)
allow(Net::HTTP).to receive(:get).with(uri).and_return(
%([{"devtoolsFrontendUrl":"https://chrome-devtools-frontend.appspot.com/serve_rev?ws=123"}])
)

expect(driver.debug_url).to eq("https://chrome-devtools-frontend.appspot.com/serve_rev?ws=123")
end
end

private
Expand Down
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
Capybara::Cuprite::Driver.new(app, options)
end

Capybara.register_driver(:cuprite_with_inspector) do |app|
Capybara::Cuprite::Driver.new(app, { inspector: true })
end

module TestSessions
Cuprite = Capybara::Session.new(:cuprite, TestApp)
end
Expand Down