Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rb] Add Bidi Network Response Handler #14900

Open
wants to merge 16 commits into
base: trunk
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Request and response working as expected
  • Loading branch information
aguspe committed Dec 18, 2024
commit 28cf3635408b1db6923fec5fb915f1551d110fd3
25 changes: 25 additions & 0 deletions rb/lib/selenium/webdriver/bidi/network.rb
Original file line number Diff line number Diff line change
@@ -76,6 +76,31 @@ def cancel_auth(request_id)
)
end

def continue_with_request(**args)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we rename the method too?

response = @bidi.send_cmd(
'network.continueRequest',
request: args[:request_id],
'body' => args[:body],
'cookies' => args[:cookies],
'headers' => args[:headers],
'method' => args[:method],
'url' => args[:url]
)
response.inspect
end

def continue_with_response(**args)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

@bidi.send_cmd(
'network.continueResponse',
request: args[:request_id],
'body' => args[:body],
'cookies' => args[:cookies],
'credentials' => args[:credentials],
'headers' => args[:headers],
'status' => args[:status]
)
end

def on(event, &block)
event = EVENTS[event] if event.is_a?(Symbol)
@bidi.add_callback(event, &block)
4 changes: 4 additions & 0 deletions rb/sig/lib/selenium/webdriver/bidi/network.rbs
Original file line number Diff line number Diff line change
@@ -12,6 +12,10 @@ module Selenium

def add_intercept: (?phases: Array[String], ?contexts: BrowsingContext?, ?url_patterns: untyped?) -> Hash[String, String]

def cancel_auth: -> untyped

def continue_with_auth_no_credentials: -> untyped

def continue_with_request: (**untyped args) -> untyped

def continue_with_response: (**untyped args) -> untyped
2 changes: 2 additions & 0 deletions rb/sig/lib/selenium/webdriver/common/network.rbs
Original file line number Diff line number Diff line change
@@ -7,6 +7,8 @@ module Selenium

attr_reader callbacks: Hash[String, String]

attr_reader network: untyped

def initialize: (Remote::Bridge bridge) -> void

def add_authentication_handler: (String username, String password) -> String
8 changes: 2 additions & 6 deletions rb/spec/integration/selenium/webdriver/bidi/network_spec.rb
Original file line number Diff line number Diff line change
@@ -57,20 +57,16 @@ class BiDi
end
end


it 'continues with request' do
reset_driver!(web_socket_url: true) do |driver|
network = described_class.new(driver.bidi)
network.add_intercept(phases: [described_class::PHASES[:before_request]])
network.on(:before_request) do |event|
request_id = event['requestId']
pp 'cheese'
request_id = event['request']['request']
network.continue_with_request(request_id: request_id)
end

sleep 2
driver.navigate.to url_for('formPage.html')
sleep 2
expect(driver.find_element(name: 'login')).to be_displayed
end
end
@@ -80,7 +76,7 @@ class BiDi
network = described_class.new(driver.bidi)
network.add_intercept(phases: [described_class::PHASES[:response_started]])
network.on(:response_started) do |event|
request_id = event['requestId']
request_id = event['request']['request']
network.continue_with_response(request_id: request_id)
end