Skip to content

Commit

Permalink
Request and response working as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
aguspe committed Dec 18, 2024
1 parent 487a6e3 commit 28cf363
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
25 changes: 25 additions & 0 deletions rb/lib/selenium/webdriver/bidi/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,31 @@ def cancel_auth(request_id)
)
end

def continue_with_request(**args)
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)
@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)
Expand Down
4 changes: 4 additions & 0 deletions rb/sig/lib/selenium/webdriver/bidi/network.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions rb/sig/lib/selenium/webdriver/common/network.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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
Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 28cf363

Please sign in to comment.