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 support for provide response command #15080

Open
wants to merge 56 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 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
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
4 changes: 4 additions & 0 deletions rb/lib/selenium/webdriver/bidi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class BiDi
autoload :BrowsingContext, 'selenium/webdriver/bidi/browsing_context'
autoload :Struct, 'selenium/webdriver/bidi/struct'
autoload :Network, 'selenium/webdriver/bidi/network'
autoload :InterceptedRequest, 'selenium/webdriver/bidi/network/intercepted_request'
autoload :InterceptedResponse, 'selenium/webdriver/bidi/network/intercepted_response'
autoload :InterceptedAuth, 'selenium/webdriver/bidi/network/intercepted_auth'
autoload :InterceptedItem, 'selenium/webdriver/bidi/network/intercepted_item'

def initialize(url:)
@ws = WebSocketConnection.new(url: url)
Expand Down
85 changes: 69 additions & 16 deletions rb/lib/selenium/webdriver/bidi/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
require_relative 'network/url_pattern'

module Selenium
module WebDriver
Expand All @@ -39,8 +40,12 @@ def initialize(bidi)
@bidi = bidi
end

def add_intercept(phases: [], contexts: nil, url_patterns: nil)
@bidi.send_cmd('network.addIntercept', phases: phases, contexts: contexts, urlPatterns: url_patterns)
def add_intercept(phases: [], contexts: nil, url_patterns: nil, pattern_type: :string)
url_patterns = url_patterns && pattern_type ? UrlPattern.format_pattern(url_patterns, pattern_type) : nil
@bidi.send_cmd('network.addIntercept',
phases: phases,
contexts: contexts,
urlPatterns: url_patterns)
end

def remove_intercept(intercept)
Expand All @@ -50,31 +55,79 @@ 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_with_request(**args)
def continue_without_auth(request_id)
@bidi.send_cmd(
'network.continueWithRequest',
request: args[:request_id],
'body' => args[:body],
'cookies' => args[:cookies],
'headers' => args[:headers],
'method' => args[:method],
'url' => args[:url]
'network.continueWithAuth',
request: request_id,
action: 'default'
)
end

def cancel_auth(request_id)
@bidi.send_cmd(
'network.continueWithAuth',
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]
)
end

def fail_request(request_id)
@bidi.send_cmd(
'network.failRequest',
request: request_id
)
end

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]
)
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, &)
@bidi.session.subscribe(event)
end
end # Network
end # BiDi
Expand Down
43 changes: 43 additions & 0 deletions rb/lib/selenium/webdriver/bidi/network/cookies.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 Cookies < Hash
def initialize(cookies = {})
super()
merge!(cookies)
end

def serialize
map do |name, value|
{
name: name.to_s,
value: {
type: 'string',
value: value.to_s
}
}
end
end
end
end # BiDi
end # WebDriver
end # Selenium
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
38 changes: 38 additions & 0 deletions rb/lib/selenium/webdriver/bidi/network/headers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# 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 Headers < Hash
def serialize
map do |name, val|
{
name: name.to_s,
value: {
type: 'string',
value: val.to_s
}
}
end
end
end
end # BiDi
end # WebDriver
end # Selenium
38 changes: 38 additions & 0 deletions rb/lib/selenium/webdriver/bidi/network/intercepted_auth.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# 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 InterceptedAuth < InterceptedItem
def authenticate(username, password)
network.continue_with_auth(id, username, password)
end

def skip
network.continue_without_auth(id)
end

def cancel
network.cancel_auth(id)
end
end
end # BiDi
end # WebDriver
end # Selenium
37 changes: 37 additions & 0 deletions rb/lib/selenium/webdriver/bidi/network/intercepted_item.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 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 InterceptedItem
attr_reader :network, :request

def initialize(network, request)
@network = network
@request = request
end

def id
@id ||= @request['request']
end
end
end # BiDi
end # WebDriver
end # Selenium
Loading
Loading