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

Merged
merged 63 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
7ef9d83
Add response handler
aguspe Dec 14, 2024
2f2012a
Update auth handlers and improve the :on method
aguspe Dec 18, 2024
487a6e3
Merge branch 'trunk' into add_response_handler
aguspe Dec 18, 2024
28cf363
Request and response working as expected
aguspe Dec 18, 2024
314b458
Add test for continue without auth and cancel auth
aguspe Dec 18, 2024
305135e
Finish implementation
aguspe Dec 18, 2024
ff2ba0d
Correct rubocop offenses
aguspe Dec 18, 2024
0b41266
Add alias for user to do network.bidi instead of network.network
aguspe Dec 18, 2024
25c201b
Fix rust file causing formatting error
aguspe Dec 18, 2024
92ea3ef
Merge branch 'trunk' into add_response_handler
aguspe Dec 19, 2024
7e22239
Handle requests and responses in block
aguspe Dec 22, 2024
ad82e86
Merge remote-tracking branch 'origin/add_response_handler' into add_r…
aguspe Dec 22, 2024
b2cea1d
Merge branch 'trunk' into add_response_handler
pujagani Dec 23, 2024
ae80832
Add ability to pass handlers to each different intercepted element
aguspe Dec 23, 2024
b4a4fe7
Merge remote-tracking branch 'origin/add_response_handler' into add_r…
aguspe Dec 23, 2024
13a0912
Merge branch 'trunk' into add_response_handler
aguspe Dec 23, 2024
c21f643
Headers working
aguspe Jan 1, 2025
f390699
Merge branch 'trunk' into add_response_handler
aguspe Jan 1, 2025
69b5690
All tests passing and signatures simplified
aguspe Jan 1, 2025
bb1ece5
remove unnecessary changes
aguspe Jan 1, 2025
996c527
remove unnecessary changes
aguspe Jan 1, 2025
f8f3f7f
Merge remote-tracking branch 'origin/add_response_handler' into add_r…
aguspe Jan 1, 2025
f2f9e01
Added credentials and set cookie header to intercepted response
aguspe Jan 2, 2025
38d0b9a
Merge branch 'trunk' into add_response_handler
aguspe Jan 2, 2025
71f5fa6
Fix rubocop issues
aguspe Jan 2, 2025
9c23adf
Merge branch 'trunk' into add_response_handler
aguspe Jan 3, 2025
d9e0ffc
Make auth handler more user friendly
aguspe Jan 3, 2025
87dc1e6
Add filtering an url pattern support
aguspe Jan 4, 2025
9612939
Merge branch 'trunk' into add_response_handler
aguspe Jan 4, 2025
7c49b93
Fix formatting issues
aguspe Jan 4, 2025
b1e14b6
Merge remote-tracking branch 'origin/add_response_handler' into add_r…
aguspe Jan 4, 2025
3772844
Modify tests to avoid element related failures on firefox
aguspe Jan 4, 2025
0515131
Fix styling of comments
aguspe Jan 4, 2025
eb3f378
Improve types and hash consistency
aguspe Jan 5, 2025
ac43ca2
Merge branch 'trunk' into add_response_handler
aguspe Jan 6, 2025
abb697d
Merge branch 'trunk' into add_response_handler
aguspe Jan 8, 2025
edc5508
Merge branch 'trunk' into add_response_handler
aguspe Jan 10, 2025
296105e
Update all the places that use 9.4.8.0
aguspe Jan 10, 2025
51e8f84
Merge branch 'trunk' into add_response_handler
aguspe Jan 11, 2025
c7552aa
Serialize request values
aguspe Jan 11, 2025
ab0f4c2
Refactor cookies, headers and set cookie headers
aguspe Jan 11, 2025
fa0c87a
Simplify serialization
aguspe Jan 11, 2025
bbd7bcc
Add extra type support
aguspe Jan 11, 2025
acce734
Improve typing
aguspe Jan 12, 2025
2197e67
Merge branch 'trunk' into add_response_handler
aguspe Jan 12, 2025
3ac73c1
Merge branch 'trunk' into add_response_handler
aguspe Jan 12, 2025
a98eafd
Merge branch 'trunk' into add_response_handler
aguspe Jan 13, 2025
0484ee2
Merge branch 'trunk' into add_response_handler
aguspe Jan 13, 2025
7760eb3
Merge branch 'trunk' into add_response_handler
aguspe Jan 13, 2025
5596a53
Merge branch 'trunk' into add_response_handler
aguspe Jan 13, 2025
71da231
Merge branch 'trunk' into add_response_handler
aguspe Jan 14, 2025
15ef477
transform serialize to as_json
aguspe Jan 15, 2025
c35bdc2
Merge remote-tracking branch 'origin/add_response_handler' into add_r…
aguspe Jan 15, 2025
1aa8835
Merge branch 'trunk' into add_response_handler
aguspe Jan 15, 2025
75e89a9
Simplify cookies and add extra unit tests
aguspe Jan 18, 2025
e8f35c4
Merge branch 'trunk' into add_response_handler
aguspe Jan 18, 2025
ca3a0fe
Merge branch 'trunk' into add_response_handler
aguspe Jan 18, 2025
8e27704
Simplify cookies and add extra unit tests
aguspe Jan 19, 2025
0daec6d
Merge branch 'trunk' into add_response_handler
aguspe Jan 19, 2025
00dd4aa
Merge branch 'trunk' into add_response_handler
aguspe Jan 20, 2025
14853b6
Merge branch 'trunk' into add_response_handler
aguspe Jan 22, 2025
68d28e1
Merge branch 'trunk' into add_response_handler
aguspe Jan 23, 2025
fe2bf4a
Merge branch 'trunk' into add_response_handler
aguspe Jan 23, 2025
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
Next Next commit
Add response handler
  • Loading branch information
aguspe committed Dec 14, 2024
commit 7ef9d83c1b5e789f8af9881c0f0a9770c0445669
12 changes: 12 additions & 0 deletions rb/lib/selenium/webdriver/bidi/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ def continue_with_request(**args)
)
end

def continue_with_response(**args)
aguspe marked this conversation as resolved.
Show resolved Hide resolved
@bidi.send_cmd(
'network.continueWithResponse',
response: args[:response_id],
'body' => args[:body],
'cookies' => args[:cookies],
'credentials' => args[:credentials],
'headers' => args[:headers],
'status' => args[:status]
)
end

def on(event, &)
event = EVENTS[event] if event.is_a?(Symbol)
@bidi.add_callback(event, &)
Expand Down
32 changes: 22 additions & 10 deletions rb/lib/selenium/webdriver/common/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ def initialize(bridge)
@callbacks = {}
end

def remove_handler(id)
intercept = @callbacks[id]
@network.remove_intercept(intercept['intercept'])
@callbacks.delete(id)
end

def clear_handlers
@callbacks.each_key { |id| remove_handler(id) }
end

def add_authentication_handler(username, password)
intercept = @network.add_intercept(phases: [BiDi::Network::PHASES[:auth_required]])
auth_id = @network.on(:auth_required) do |event|
Expand All @@ -38,16 +48,6 @@ def add_authentication_handler(username, password)
auth_id
end

def remove_handler(id)
intercept = @callbacks[id]
@network.remove_intercept(intercept['intercept'])
@callbacks.delete(id)
end

def clear_handlers
@callbacks.each_key { |id| remove_handler(id) }
end

def add_request_handler
intercept = @network.add_intercept(phases: [BiDi::Network::PHASES[:before_request]])
request_id = @network.on(:before_request) do |event|
Expand All @@ -59,6 +59,18 @@ def add_request_handler

request_id
end

def add_response_handler
intercept = @network.add_intercept(phases: [BiDi::Network::PHASES[:response_started]])
response_id = @network.on(:response_started) do |event|
request_id = event['requestId']
@network.continue_with_response(request_id: request_id)
end

@callbacks[response_id] = intercept

response_id
end
end # Network
end # WebDriver
end # Selenium
4 changes: 3 additions & 1 deletion rb/sig/lib/selenium/webdriver/bidi/network.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ module Selenium

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

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

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

def remove_intercept: (String intercept) -> 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 @@ -13,6 +13,8 @@ module Selenium

def add_request_handler: -> Integer

def add_response_handler: -> String

def clear_handlers: -> Hash[nil, nil]

def remove_handler: (Integer id) -> nil
Expand Down
15 changes: 14 additions & 1 deletion rb/spec/integration/selenium/webdriver/bidi/network_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
# specific language governing permissions and limitations
# under the License.


require_relative '../spec_helper'

module Selenium
Expand Down Expand Up @@ -70,6 +69,20 @@ class BiDi
expect(driver.find_element(name: 'login')).to be_displayed
end
end

it 'continues with response' do
reset_driver!(web_socket_url: true) do |driver|
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']
network.continue_with_response(request_id: request_id)
end

driver.navigate.to url_for('formPage.html')
expect(driver.find_element(name: 'login')).to be_displayed
end
end
end
end
end
Expand Down
27 changes: 27 additions & 0 deletions rb/spec/integration/selenium/webdriver/network_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,33 @@ module WebDriver
expect(network.callbacks.count).to be 0
end
end

it 'adds a response handler' do
reset_driver!(web_socket_url: true) do |driver|
network = described_class.new(driver)
network.add_response_handler
expect(network.callbacks.count).to be 1
end
end

it 'removes a response handler' do
reset_driver!(web_socket_url: true) do |driver|
network = described_class.new(driver)
id = network.add_response_handler
network.remove_handler(id)
expect(network.callbacks.count).to be 0
end
end

it 'clears all response handlers' do
reset_driver!(web_socket_url: true) do |driver|
network = described_class.new(driver)
network.add_response_handler
network.add_response_handler
network.clear_handlers
expect(network.callbacks.count).to be 0
end
end
end
end
end
Loading