-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[py] BiDi Network implementation of Intercepts and Auth in Python #14592
base: trunk
Are you sure you want to change the base?
[py] BiDi Network implementation of Intercepts and Auth in Python #14592
Conversation
PR Reviewer Guide 🔍(Review updated until commit 01f6aaf)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to 01f6aaf
Previous suggestions✅ Suggestions up to commit 14bf971
|
Thought I might need it, but didn't
was adding this to BUILD.bazel for easy testing:
so i could run |
Think it's ready now... @AutomatedTester could you give it a look? |
Persistent review updated to latest commit 01f6aaf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a Python expert but I ended up being the person who drafted the initial BiDi implementation. I tried to avoid using the async/await
pattern because I assumed that it can't be used in a sync code that the majority of Python clients of the library do. Is there any reason to use the pattern in this PR?
It has pros and cons, but I think you're right that it isn't needed and could be more trouble than it's worth. I'll remove it for the time being and if we decide later it's an easy shift. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add some high-level API examples and tests per an original issue?
- driver.network.add_request_handler(...)
- driver.network.add_response_handler(...)
This would allow us to surface the API usage and make sure it works nicely via lambdas.
Could you provide a bit more guidance here? What would those two tests entail that isn't already being covered? the tests I added are an expanded version of the .spec from the ruby implementation |
I think the current tests expose the low-level API that users are not supposed to call. The high-level API unfortunately is not implemented in any bindings so there is no example to follow. However, the proposal is to allow the add_request_handler to accept a matcher (e.g. URL filter for what requests should be handled) and a callback that received the request to handle. This callable is responsible for continuing/failing the request optionally allowing to mutate it (e.g. add headers). def handle_request(request):
request.headers["X-FOO"] = "bar"
request.continue()
driver.network.add_request_handler('https://google.com', handle_request) This is roughly what we had considered to be a user-facing API. |
Interesting. I think I understood - what do you think about this most recent push? |
tests passing locally
|
Much closer to what we are aiming for! Let's add some abstractions (Request/Response) objects, move continuation there, and write more tests. I've left more detailed comments in the PR review. |
@p0deje Is this closer? |
Not quite, we need to make Request/Response be passed to the callbacks instead of plain |
Hmm... Seems I misunderstood. Let me see if I got it now:
it should create a request/response object, then perform the callback on that object instead of on the event itself.
|
@p0deje I did some updates based on my comment above. If I still haven't quite understood, I can just revert the commits lol |
User description
Add implementations for BiDi Network's Auth and Interception to Python
Description
Added network.py
Added bidi_network_tests.py
updated command.py
Motivation and Context
Issue #13993
Types of changes
Checklist
PR Type
Enhancement, Tests
Description
Network
class to handle network events and requests, supporting BiDi protocol operations.Network
class into the WebDriver, allowing network interception and authentication handling.Changes walkthrough 📝
network.py
Implement Network class for BiDi protocol support
py/selenium/webdriver/common/bidi/network.py
Network
class for handling network events andrequests.
command.py
Add network command constants for BiDi operations
py/selenium/webdriver/remote/command.py
remote_connection.py
Map network commands to HTTP endpoints
py/selenium/webdriver/remote/remote_connection.py
webdriver.py
Integrate Network class into WebDriver
py/selenium/webdriver/remote/webdriver.py
Network
class into WebDriver for BiDi support.bidi_network_tests.py
Add tests for BiDi network functionalities
py/test/selenium/webdriver/common/bidi_network_tests.py