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
Serialize request values
  • Loading branch information
aguspe committed Jan 11, 2025
commit c7552aa6546681ed58c35c7fb33ac7417502952f
61 changes: 35 additions & 26 deletions rb/lib/selenium/webdriver/bidi/network/cookies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,45 @@
module Selenium
module WebDriver
class BiDi
module Cookies
class Cookies
def initialize
@cookies = {}
end

def all
@cookies
end

def add_cookie(name, value)
cookies.push(
name: name,
value: {
type: 'string',
value: value
}
)
@cookies[name] = value
end

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

def set_cookie_header(**args)
cookies.push(
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]
)
@cookies.delete(name)
end

def []=(key, value)
add_cookie(key, value)
end

def [](key)
@cookies[key]
end

def delete(key)
remove_cookie(key)
end

def serialize
aguspe marked this conversation as resolved.
Show resolved Hide resolved
@cookies.map do |name, value|
{
name: name.to_s,
value: {
type: 'string',
value: value.to_s
}
}
end
end
end
end # BiDi
Expand Down
43 changes: 43 additions & 0 deletions rb/lib/selenium/webdriver/bidi/network/credentials.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

module Selenium
module WebDriver
class BiDi
class Credentials
attr_accessor :username, :password

def initialize(username: nil, password: nil)
@username = username
@password = password
end

def serialize
return nil unless username && password

{
type: 'password',
username: username,
password: password
}
end
end
end # BiDi
end # WebDriver
end # Selenium
44 changes: 35 additions & 9 deletions rb/lib/selenium/webdriver/bidi/network/headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,45 @@
module Selenium
module WebDriver
class BiDi
module Headers
class Headers
def initialize
@headers = {}
end

def all
@headers
end

def add_header(name, value)
headers.push(
name: name,
value: {
type: 'string',
value: value
}
)
@headers[name] = value
end

def remove_header(name)
headers.delete_if { |header| header[:name] == name }
@headers.delete(name)
end

def []=(key, value)
add_header(key, value)
end

def [](key)
@headers[key]
end

def delete(key)
remove_header(key)
end

def serialize
@headers.map do |name, val|
{
name: name.to_s,
value: {
type: 'string',
value: val.to_s
}
}
end
end
end
end # BiDi
Expand Down
27 changes: 19 additions & 8 deletions rb/lib/selenium/webdriver/bidi/network/intercepted_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,26 @@ module Selenium
module WebDriver
class BiDi
class InterceptedRequest < InterceptedItem
include Cookies
include Headers

attr_accessor :cookies, :headers, :method, :url
attr_accessor :method, :url
attr_reader :body

def initialize(network, request)
super
@body = nil
@cookies = []
@headers = []
# We now rely on the modules above to initialize @headers and @cookies as Hashes
@method = nil
@url = nil
@body = nil
end

def continue
network.continue_request(id:, body:, cookies:, headers:, method:, url:)
network.continue_request(
id: id,
body: body,
cookies: cookies.serialize,
headers: headers.serialize,
method: method,
url: url
)
end

def fail
Expand All @@ -53,6 +56,14 @@ def body=(value)
value: value.to_json
}
end

def headers
@headers ||= Headers.new
end

def cookies
@cookies ||= Cookies.new
end
end
end # BiDi
end # WebDriver
Expand Down
36 changes: 20 additions & 16 deletions rb/lib/selenium/webdriver/bidi/network/intercepted_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,41 @@
# specific language governing permissions and limitations
# under the License.

require_relative 'cookies'
require_relative 'credentials'
require_relative 'headers'
require_relative 'set_cookie_headers'

module Selenium
module WebDriver
class BiDi
class InterceptedResponse < InterceptedItem
include Cookies
include Headers

attr_accessor :cookies, :headers, :reason
attr_reader :credentials
attr_accessor :reason

def initialize(network, request)
super
@cookies = []
@headers = []
@credentials = nil
@reason = nil
end

def continue
network.continue_response(id:, cookies:, headers:, credentials:, reason:)
network.continue_response(
id: id,
cookies: set_cookie_headers.serialize,
headers: headers.serialize,
credentials: credentials.serialize,
reason: reason
)
end

def credentials(username: nil, password: nil)
@credentials ||= Credentials.new(username: username, password: password)
end

def headers
@headers ||= Headers.new
end

def add_credentials(username, password)
@credentials = {
type: 'password',
username: username,
password: password
}
def set_cookie_headers(set_cookie_headers = nil)
@set_cookie_headers ||= SetCookieHeaders.new(set_cookie_headers)
end
end
end # BiDi
Expand Down
94 changes: 94 additions & 0 deletions rb/lib/selenium/webdriver/bidi/network/set_cookie_headers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# frozen_string_literal: true

# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

module Selenium
module WebDriver
class BiDi
class SetCookieHeaders
def initialize(set_cookie_headers)
@set_cookie_headers = set_cookie_headers
end

def all
@set_cookie_headers
end

def add_set_cookie_header(name, value)
@set_cookie_headers[name] = {value: value}
end

def remove_set_cookie_header(name)
@set_cookie_headers.delete(name)
end

def set_cookie_header(**args)
set_cookie_header = args[:name]

set_cookie_header_data = {
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]
}

@set_cookie_headers[set_cookie_header] = set_cookie_header_data
end

def []=(key, value)
add_set_cookie_header(key, value)
end

def [](key)
@set_cookie_headers[key]
end

def delete(key)
remove_set_cookie_header(key)
end

def serialize
return [] unless @set_cookie_headers

@set_cookie_headers.map do |name, data|
data = {value: data} unless data.is_a?(Hash)

{
name: name.to_s,
value: {
type: 'string',
value: data[:value].to_s
},
domain: data[:domain],
httpOnly: data[:httpOnly],
expiry: data[:expiry],
maxAge: data[:maxAge],
path: data[:path],
sameSite: data[:sameSite],
secure: data[:secure]
}.compact
end
end
end
end # BiDi
end # WebDriver
end # Selenium
Loading
Loading