Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8c317d8
[build] allow tests tagged exclusive-if-local to run on rbe
titusfortner Mar 22, 2025
bb29c66
merge trunk
aguspe Apr 2, 2025
5b6a0ce
Merge branch 'trunk' of github.com:aguspe/selenium into trunk
aguspe Apr 22, 2025
c9cb77c
Merge branch 'trunk' of github.com:aguspe/selenium into trunk
aguspe Apr 30, 2025
ac9a80e
Merge branch 'trunk' of github.com:aguspe/selenium into trunk
aguspe May 18, 2025
aef922a
Merge branch 'trunk' of github.com:aguspe/selenium into trunk
aguspe May 24, 2025
8dc6cfc
Merge branch 'trunk' of github.com:aguspe/selenium into trunk
aguspe Jun 7, 2025
16dc0d3
Merge branch 'trunk' of github.com:aguspe/selenium into trunk
aguspe Jun 13, 2025
85fdc1c
Merge branch 'trunk' of github.com:aguspe/selenium into trunk
aguspe Jul 14, 2025
72bf4ec
Merge branch 'trunk' of github.com:aguspe/selenium into trunk
aguspe Aug 2, 2025
81f2331
Merge branch 'trunk' of github.com:aguspe/selenium into trunk
aguspe Aug 9, 2025
d03e95b
Merge branch 'trunk' of github.com:aguspe/selenium into trunk
aguspe Aug 19, 2025
0cc0626
Merge branch 'trunk' of github.com:aguspe/selenium into trunk
aguspe Sep 9, 2025
efa60a2
Merge branch 'trunk' of github.com:aguspe/selenium into trunk
aguspe Sep 29, 2025
7de5a08
Merge branch 'trunk' of github.com:aguspe/selenium into trunk
aguspe Sep 30, 2025
629be32
Merge branch 'trunk' of github.com:aguspe/selenium into trunk
aguspe Oct 15, 2025
92be65e
Remove nil values for network requests
aguspe Oct 15, 2025
72445fc
Update intercept request and response and improve headers and cookies
aguspe Oct 16, 2025
247863b
Merge branch 'trunk' into rb_fix_network_issue
diemol Oct 17, 2025
ea1f4f0
request cookie and header setters now take hashes
titusfortner Oct 18, 2025
0f186b9
put the unit tests back
titusfortner Oct 18, 2025
396d55a
All tests fixed
aguspe Oct 18, 2025
0b6d365
Merge remote-tracking branch 'origin/rb_fix_network_issue' into rb_fi…
aguspe Oct 18, 2025
91d1666
Merge branch 'trunk' into rb_fix_network_issue
aguspe Oct 18, 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
21 changes: 12 additions & 9 deletions rb/lib/selenium/webdriver/bidi/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,16 @@ def cancel_auth(request_id)
end

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

@bidi.send_cmd('network.continueRequest', **args)
end

def fail_request(request_id)
Expand All @@ -101,27 +102,29 @@ def fail_request(request_id)
end

def continue_response(**args)
@bidi.send_cmd(
'network.continueResponse',
args = {
request: args[:id],
cookies: args[:cookies],
credentials: args[:credentials],
headers: args[:headers],
reasonPhrase: args[:reason],
statusCode: args[:status]
)
}.compact

@bidi.send_cmd('network.continueResponse', **args)
end

def provide_response(**args)
@bidi.send_cmd(
'network.provideResponse',
args = {
request: args[:id],
body: args[:body],
cookies: args[:cookies],
headers: args[:headers],
reasonPhrase: args[:reason],
statusCode: args[:status]
)
}.compact

@bidi.send_cmd('network.provideResponse', **args)
end

def set_cache_behavior(behavior, *contexts)
Expand Down
13 changes: 5 additions & 8 deletions rb/lib/selenium/webdriver/bidi/network/cookies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,13 @@ module Selenium
module WebDriver
class BiDi
class Cookies < Hash
def initialize(cookies = {})
super()
merge!(cookies)
end

def as_json
self[:name] = self[:name].to_s
self[:value] = {type: 'string', value: self[:value].to_s}
map do |name, val|
self[:name] = name.to_s
self[:value] = {type: 'string', value: val.to_s}

[compact]
[compact]
end
end
end
end # BiDi
Expand Down
20 changes: 16 additions & 4 deletions rb/lib/selenium/webdriver/bidi/network/intercepted_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,18 @@ def initialize(network, request)
@method = nil
@url = nil
@body = nil
@headers = nil
@cookies = nil
end

def continue
cookies = @cookies&.as_json
headers = @headers&.as_json
network.continue_request(
id: id,
body: body,
cookies: cookies.as_json,
headers: headers.as_json,
cookies: cookies,
headers: headers,
method: method,
url: url
)
Expand All @@ -56,13 +60,21 @@ def body=(value)
}
end

def headers
@headers ||= Headers.new
def headers=(headers = {})
@headers = Headers.new(headers)
end

def headers(headers = {})
@headers ||= Headers.new(headers)
end

def cookies(cookies = {})
@cookies ||= Cookies.new(cookies)
end

def cookies=(cookies = {})
@cookies = Cookies.new(cookies)
end
end
end # BiDi
end # WebDriver
Expand Down
26 changes: 20 additions & 6 deletions rb/lib/selenium/webdriver/bidi/network/intercepted_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,30 @@ def initialize(network, request)
@reason = nil
@status = nil
@body = nil
@headers = nil
@cookies = nil
end

def continue
cookies = @cookies&.as_json
headers = @headers&.as_json
network.continue_response(
id: id,
cookies: cookies.as_json,
headers: headers.as_json,
cookies: cookies,
headers: headers,
credentials: credentials.as_json,
reason: reason,
status: status
)
end

def provide_response
cookies = @cookies&.as_json
headers = @headers&.as_json
network.provide_response(
id: id,
cookies: cookies.as_json,
headers: headers.as_json,
cookies: cookies,
headers: headers,
body: body,
reason: reason,
status: status
Expand All @@ -61,14 +67,22 @@ def credentials(username: nil, password: nil)
@credentials ||= Credentials.new(username: username, password: password)
end

def headers
@headers ||= Headers.new
def headers(headers = {})
@headers ||= Headers.new(headers)
end

def headers=(*headers)
@headers = Headers.new(headers)
end

def cookies(cookies = {})
@cookies ||= Cookies.new(cookies)
end

def cookies=(cookies = {})
@cookies ||= Cookies.new(cookies)
end

def body=(value)
@body = {
type: 'string',
Expand Down
2 changes: 1 addition & 1 deletion rb/sig/lib/selenium/webdriver/bidi/network.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module Selenium

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

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

def provide_response: -> Hash[nil, nil]

Expand Down
2 changes: 1 addition & 1 deletion rb/sig/lib/selenium/webdriver/bidi/network/cookies.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Selenium
module WebDriver
class BiDi
class Cookies
def initialize: (Hash[Symbol, String | Integer | bool] cookies) -> void
def initialize: (Hash[Symbol, String | Integer | bool]? cookies) -> void

def as_json: () -> Array[Hash[Symbol, untyped]]
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ module Selenium
module WebDriver
class BiDi
class InterceptedRequest < InterceptedItem
@method: String
@method: String?

@url: String
@url: String?

@body: Hash[untyped, untyped]
@body: Hash[untyped, untyped]?

@headers: Hash[untyped, untyped]
@headers: Hash[untyped, untyped]?

@cookies: Hash[untyped, untyped]
@cookies: Hash[untyped, untyped]?

attr_accessor method: String

Expand All @@ -22,13 +22,17 @@ module Selenium

def continue: () -> Hash[nil, nil]

def cookies=: -> Hash[nil, nil]

def fail: () -> Hash[nil, nil]

def body=: (Hash[untyped, untyped] value) -> Hash[untyped, untyped]

def headers: () -> Hash[untyped, untyped]

def cookies: () -> Hash[untyped, untyped]

def headers=: -> Hash[untyped, untyped]
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Selenium
@body: untyped
@cookies: Hash[Symbol, String | Integer]?

@reason: String
@reason: String?

@credentials: untyped

Expand All @@ -24,10 +24,14 @@ module Selenium

def cookies:(?Hash[Symbol, String | Integer]? set_cookie_headers) -> untyped

def cookies=: -> Hash[Symbol, String | Integer]

def credentials: (?username: untyped?, ?password: untyped?) -> untyped

def headers: () -> untyped

def headers=: -> Hash[untyped, untyped]

def provide_response: -> untyped

def set_cookie_headers: (?untyped? set_cookie_headers) -> untyped
Expand Down
104 changes: 104 additions & 0 deletions rb/spec/unit/selenium/webdriver/bidi/intercepted_request_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# 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.

require File.expand_path('../spec_helper', __dir__)
require File.expand_path('../../../../../lib/selenium/webdriver/bidi/network/cookies', __dir__)
require File.expand_path('../../../../../lib/selenium/webdriver/bidi/network/headers', __dir__)
require File.expand_path('../../../../../lib/selenium/webdriver/bidi/network/intercepted_request', __dir__)

module Selenium
module WebDriver
class BiDi
describe InterceptedRequest do
let(:mock_network) { instance_double(Network) }
let(:mock_request) { {'request' => 'req-123'} }
let(:request_id) { 'req-123' }
let(:intercepted_request) { described_class.new(mock_network, mock_request) }
let(:mock_headers) { [{name: 'Auth', value: 'token'}] }
let(:mock_cookies) { [{name: 'session', value: {type: 'string', value: '123'}}] }

describe '#continue' do
before do
allow(mock_network).to receive(:continue_request)
end

it 'sends only the mandatory ID when no optional fields are set' do
expected_payload = {id: request_id, body: nil, cookies: nil, headers: nil, method: nil, url: nil}
intercepted_request.continue

expect(mock_network).to have_received(:continue_request).with(expected_payload)
end

it 'sends headers payload when headers are explicitly set' do
intercepted_request.headers = mock_headers

expected_payload = {
id: request_id,
body: nil,
cookies: nil,
headers: Headers.new(mock_headers).as_json,
method: nil,
url: nil
}

intercepted_request.continue

expect(mock_network).to have_received(:continue_request).with(expected_payload)
end

it 'sends cookies payload when cookies are explicitly set' do
intercepted_request.cookies = mock_cookies

expected_payload = {
id: request_id,
body: nil,
cookies: Cookies.new(mock_cookies).as_json,
headers: nil,
method: nil,
url: nil
}

intercepted_request.continue

expect(mock_network).to have_received(:continue_request).with(expected_payload)
end

it 'sends full custom payload when all fields are set' do
intercepted_request.headers = mock_headers
intercepted_request.cookies = mock_cookies
intercepted_request.method = 'POST'

expected_payload = {
id: request_id,
body: nil,
cookies: Cookies.new(mock_cookies).as_json,
headers: Headers.new(mock_headers).as_json,
method: 'POST',
url: nil
}

intercepted_request.continue

expect(mock_network).to have_received(:continue_request).with(expected_payload)
end
end
end
end
end
end
Loading