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][BiDi] Add support for provide response command #15080

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 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
eea4a65
remove unnecessary comment
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
52fd7b0
merge latest
aguspe Jan 13, 2025
71da231
Merge branch 'trunk' into add_response_handler
aguspe Jan 14, 2025
26253b8
Merge branch 'add_response_handler' of github.com:aguspe/selenium int…
aguspe Jan 14, 2025
3557bfb
add provide response support
aguspe Jan 14, 2025
5d276c2
Correct rubocop offenses
aguspe Jan 14, 2025
313d0f6
Merge branch 'trunk' into add_support_for_provide_response_command
aguspe Jan 20, 2025
86626e0
Merge trunk
aguspe Jan 25, 2025
56dd637
Merge remote-tracking branch 'origin/add_support_for_provide_response…
aguspe Jan 25, 2025
816ba51
Remove set cookie headers
aguspe Jan 25, 2025
74a0545
Remove set cookie headers
aguspe Jan 25, 2025
6a2255d
Fix failing tests
aguspe Jan 25, 2025
6e88cfc
Merge branch 'trunk' into add_support_for_provide_response_command
aguspe Jan 30, 2025
d5e2726
Merge branch 'trunk' into add_support_for_provide_response_command
aguspe Feb 5, 2025
894883c
Add negative scenario
aguspe Feb 5, 2025
0a38fee
Merge remote-tracking branch 'origin/add_support_for_provide_response…
aguspe Feb 5, 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
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 @@ -112,6 +112,18 @@ def continue_response(**args)
)
end

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

def on(event, &)
event = EVENTS[event] if event.is_a?(Symbol)
@bidi.add_callback(event, &)
Expand Down
26 changes: 24 additions & 2 deletions rb/lib/selenium/webdriver/bidi/network/intercepted_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ module Selenium
module WebDriver
class BiDi
class InterceptedResponse < InterceptedItem
attr_accessor :reason
attr_accessor :reason, :status
attr_reader :body

def initialize(network, request)
super
@reason = nil
@status = nil
@body = nil
end

def continue
Expand All @@ -38,7 +41,19 @@ def continue
cookies: cookies.as_json,
headers: headers.as_json,
credentials: credentials.as_json,
reason: reason
reason: reason,
status: status
)
end

def provide_response
network.provide_response(
id: id,
cookies: cookies.as_json,
headers: headers.as_json,
body: body,
reason: reason,
status: status
)
end

Expand All @@ -53,6 +68,13 @@ def headers
def cookies(cookies = {})
@cookies ||= Cookies.new(cookies)
end

def body=(value)
@body = {
type: 'string',
value: value.to_json
}
end
end
end # BiDi
end # WebDriver
Expand Down
2 changes: 2 additions & 0 deletions rb/sig/lib/selenium/webdriver/bidi/network.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ module Selenium

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

def provide_response: -> Hash[nil, nil]

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

def initialize: (Hash[Symbol, String | Integer | bool] cookies) -> void

def as_json: () -> Array[Hash[Symbol, untyped]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Selenium
module WebDriver
class BiDi
class InterceptedResponse < InterceptedItem
@body: untyped
@cookies: Hash[Symbol, String | Integer]?

@reason: String
Expand All @@ -10,17 +11,26 @@ module Selenium

@headers: untyped

attr_reader body: untyped
attr_accessor reason: String

attr_accessor status: Integer?

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

def body=: -> untyped

def continue: () -> untyped

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

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

def headers: () -> untyped

def provide_response: -> untyped

def set_cookie_headers: (?untyped? set_cookie_headers) -> untyped
end
end
end
Expand Down
11 changes: 0 additions & 11 deletions rb/sig/lib/selenium/webdriver/bidi/network/set_cookie_headers.rbs

This file was deleted.

32 changes: 32 additions & 0 deletions rb/spec/integration/selenium/webdriver/bidi/network_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,38 @@ class BiDi
expect(driver.find_element(name: 'login')).to be_displayed
end
end

it 'provides 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['request']['request']
network.provide_response(
id: request_id,
status: 200,
headers: [
{
name: 'foo',
value: {
type: 'string',
value: 'bar'
}
}
],
body: {
type: 'string',
value: '<html><head><title>Hello World!</title></head><body/></html>'
}
)
end

driver.navigate.to url_for('formPage.html')
source = driver.page_source
expect(source).not_to include('There should be a form here:')
expect(source).to include('Hello World!')
end
end
end
end
end
Expand Down
16 changes: 16 additions & 0 deletions rb/spec/integration/selenium/webdriver/network_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,22 @@ module WebDriver
end
end

it 'adds a response handler that provides a response' do
reset_driver!(web_socket_url: true) do |driver|
network = described_class.new(driver)
network.add_response_handler do |response|
response.status = 200
response.headers['foo'] = 'bar'
response.body = '<html><head><title>Hello World!</title></head><body/></html>'
response.provide_response
end
driver.navigate.to url_for('formPage.html')
source = driver.page_source
expect(source).not_to include('There should be a form here:')
expect(source).to include('Hello World!')
end
end

it 'removes a response handler' do
reset_driver!(web_socket_url: true) do |driver|
network = described_class.new(driver)
Expand Down
Loading