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
Prev Previous commit
Next Next commit
Improve types and hash consistency
  • Loading branch information
aguspe committed Jan 5, 2025
commit eb3f378aef1d5ecacf6fc843358bcd0b4a2b524b
40 changes: 20 additions & 20 deletions rb/lib/selenium/webdriver/bidi/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,41 +55,41 @@ def remove_intercept(intercept)
def continue_with_auth(request_id, username, password)
@bidi.send_cmd(
'network.continueWithAuth',
'request' => request_id,
'action' => 'provideCredentials',
'credentials' => {
'type' => 'password',
'username' => username,
'password' => password
request: request_id,
action: 'provideCredentials',
credentials: {
type: 'password',
username: username,
password: password
}
)
end

def continue_without_auth(request_id)
@bidi.send_cmd(
'network.continueWithAuth',
'request' => request_id,
'action' => 'default'
request: request_id,
action: 'default'
)
end

def cancel_auth(request_id)
@bidi.send_cmd(
'network.continueWithAuth',
'request' => request_id,
'action' => 'cancel'
request: request_id,
action: 'cancel'
)
end

def continue_request(**args)
@bidi.send_cmd(
'network.continueRequest',
request: args[:id],
'body' => args[:body],
'cookies' => args[:cookies],
'headers' => args[:headers],
'method' => args[:method],
'url' => args[:url]
body: args[:body],
cookies: args[:cookies],
headers: args[:headers],
method: args[:method],
url: args[:url]
)
end

Expand All @@ -104,11 +104,11 @@ def continue_response(**args)
@bidi.send_cmd(
'network.continueResponse',
request: args[:id],
'cookies' => args[:cookies],
'credentials' => args[:credentials],
'headers' => args[:headers],
'reasonPhrase' => args[:reason],
'statusCode' => args[:status]
cookies: args[:cookies],
credentials: args[:credentials],
headers: args[:headers],
reasonPhrase: args[:reason],
statusCode: args[:status]
)
end

Expand Down
32 changes: 16 additions & 16 deletions rb/lib/selenium/webdriver/bidi/network/cookies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,32 @@ class BiDi
module Cookies
def add_cookie(name, value)
cookies.push(
'name' => name,
'value' => {
'type' => 'string',
'value' => value
name: name,
value: {
type: 'string',
value: value
}
)
end

def remove_cookie(name)
cookies.delete_if { |cookie| cookie['name'] == name }
cookies.delete_if { |cookie| cookie[:name] == name }
end

def set_cookie_header(**args)
cookies.push(
'name' => args[:name],
'value' => {
'type' => 'string',
'value' => 'input'
name: args[:name],
value: {
type: 'string',
value: 'input'
},
'domain' => args[:domain],
'httpOnly' => args[:http_only],
'expiry' => args[:expiry],
'maxAge' => args[:max_age],
'path' => args[:path],
'sameSite' => args[:same_site],
'secure' => args[:secure]
domain: args[:domain],
httpOnly: args[:http_only],
expiry: args[:expiry],
maxAge: args[:max_age],
path: args[:path],
sameSite: args[:same_site],
secure: args[:secure]
)
end
end
Expand Down
10 changes: 5 additions & 5 deletions rb/lib/selenium/webdriver/bidi/network/headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ class BiDi
module Headers
def add_header(name, value)
headers.push(
'name' => name,
'value' => {
'type' => 'string',
'value' => value
name: name,
value: {
type: 'string',
value: value
}
)
end

def remove_header(name)
headers.delete_if { |header| header['name'] == name }
headers.delete_if { |header| header[:name] == name }
end
end
end # BiDi
Expand Down
4 changes: 2 additions & 2 deletions rb/lib/selenium/webdriver/bidi/network/intercepted_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def fail

def body=(value)
@body = {
'type' => 'string',
'value' => value.to_json
type: 'string',
value: value.to_json
}
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ def continue

def add_credentials(username, password)
@credentials = {
'type' => 'password',
'username' => username,
'password' => password
type: 'password',
username: username,
password: password
}
end
end
Expand Down
18 changes: 9 additions & 9 deletions rb/sig/lib/selenium/webdriver/bidi/network.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ module Selenium

def initialize: (BiDi bidi) -> void

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

def cancel_auth: -> untyped
def cancel_auth: -> Hash[nil, nil]

def continue_request: -> untyped
def continue_request: -> Hash[nil, nil]

def continue_response: -> untyped
def continue_response: -> Hash[nil, nil]

def continue_without_auth: -> untyped
def continue_without_auth: -> Hash[nil, nil]

def fail_request: -> untyped
def fail_request: -> Hash[nil, nil]

def remove_intercept: (String intercept) -> untyped
def remove_intercept: (String intercept) -> Hash[nil, nil]

def continue_with_auth: (String request_id, String username, String password) -> untyped
def continue_with_auth: (String request_id, String username, String password) -> Hash[nil, nil]

def on: (Symbol event) { (?) -> untyped } -> untyped
def on: (Symbol event) { (?) -> untyped } -> Hash[nil, nil]
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions rb/sig/lib/selenium/webdriver/bidi/network/cookies.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ module Selenium
module WebDriver
class BiDi
module Cookies
def add_cookie: (untyped name, untyped value) -> untyped
def add_cookie: (String name, String value) -> Array[Hash[Symbol, String]]

def remove_cookie: (untyped name) -> untyped
def remove_cookie: (String name) -> Array[Hash[Symbol, String]]

def set_cookie_header: (**untyped args) -> untyped
def set_cookie_header: (**Hash[Symbol, String | bool | Numeric] args) -> Array[Hash[Symbol, String | bool | Numeric]]
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions rb/sig/lib/selenium/webdriver/bidi/network/headers.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ module Selenium
module WebDriver
class BiDi
module Headers
def add_header: (untyped name, untyped value) -> untyped
def add_header: (String name, String value) -> Array[Hash[Symbol, String]]

def remove_header: (untyped name) -> untyped
def remove_header: (String name) -> Array[Hash[Symbol, String]]
end
end
end
Expand Down
21 changes: 21 additions & 0 deletions rb/sig/lib/selenium/webdriver/bidi/network/intercepted_item.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Selenium
module WebDriver
class BiDi
class InterceptedItem
@network: untyped

@request: untyped

@id: untyped

attr_reader network: untyped

attr_reader request: untyped

def initialize: (untyped network, untyped request) -> void

def id: () -> untyped
end
end
end
end
39 changes: 39 additions & 0 deletions rb/sig/lib/selenium/webdriver/bidi/network/intercepted_request.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module Selenium
module WebDriver
class BiDi
class InterceptedRequest < InterceptedItem
@body: untyped

@cookies: untyped

@headers: untyped

@method: untyped

@url: untyped

include Cookies

include Headers

attr_accessor cookies: untyped

attr_accessor headers: untyped

attr_accessor method: untyped

attr_accessor url: untyped

attr_reader body: untyped

def initialize: (untyped network, untyped request) -> void

def continue: () -> untyped

def fail: () -> untyped

def body=: (untyped value) -> untyped
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module Selenium
module WebDriver
class BiDi
class InterceptedResponse < InterceptedItem
@cookies: untyped

@headers: untyped

@credentials: untyped

@reason: untyped

include Cookies

include Headers

attr_accessor cookies: untyped

attr_accessor headers: untyped

attr_accessor reason: untyped

attr_reader credentials: untyped

def initialize: (untyped network, untyped request) -> void

def continue: () -> untyped

def add_credentials: (untyped username, untyped password) -> untyped
end
end
end
end
6 changes: 3 additions & 3 deletions rb/sig/lib/selenium/webdriver/bidi/network/url_pattern.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ module Selenium
module WebDriver
class BiDi
module UrlPattern
def self?.format_pattern: (untyped url_patterns, untyped pattern_type) -> untyped
def self?.format_pattern: (Array[String] | String url_patterns, Symbol pattern_type) -> Array[Hash[Symbol, String]]

def self?.to_url_pattern: (*untyped url_patterns) -> untyped
def self?.to_url_pattern: (*String url_patterns) -> Array[Hash[Symbol, String]]

def self?.to_url_string_pattern: (*untyped url_patterns) -> untyped
def self?.to_url_string_pattern: (*String url_patterns) -> Array[Hash[Symbol, String]]
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion rb/sig/lib/selenium/webdriver/bidi/session.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Selenium

def status: () -> untyped

def subscribe: (untyped events, ?untyped? browsing_contexts) -> untyped
def subscribe: (untyped events, ?untyped? browsing_contexts) -> Hash[nil, nil]

def unsubscribe: (untyped events, ?untyped? browsing_contexts) -> untyped
end
Expand Down
18 changes: 9 additions & 9 deletions rb/sig/lib/selenium/webdriver/common/network.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@ module Selenium

attr_reader callbacks: Hash[String, String]

attr_reader network: untyped
attr_reader network: BiDi::Network

def initialize: (Remote::Bridge bridge) -> void
alias bidi network

def add_authentication_handler: (String username, String password) -> String
def initialize: (Remote::Bridge bridge) -> void

def add_request_handler: -> Integer
def remove_handler: (Numeric id) -> untyped

def add_response_handler: -> String
def clear_handlers: () -> untyped

alias bidi network
def add_authentication_handler: (?String? username, ?String? password, *String filter, ?pattern_type: Symbol?) { (?) -> untyped } -> untyped

def clear_handlers: -> Hash[nil, nil]
def add_request_handler: (*String filter, ?pattern_type: Symbol?) -> Hash[String, String]

def remove_handler: (Integer id) -> nil
def add_response_handler: (*String filter, ?pattern_type: Symbol?) -> Hash[String, String]

private

def add_handler: -> untyped
def add_handler: (Symbol event_type, String phase, BiDi::InterceptedItem intercept_type, Array[String] filter, ?pattern_type: Symbol?) { (untyped) -> untyped } -> untyped
end
end
end
Loading