[py] Add expect_* context managers for BiDi events#17667
Open
AutomatedTester wants to merge 1 commit into
Open
[py] Add expect_* context managers for BiDi events#17667AutomatedTester wants to merge 1 commit into
AutomatedTester wants to merge 1 commit into
Conversation
Adds a Subscription primitive to the BiDi event manager that registers
its event handler at creation time, so an event fired by an action
inside the with block cannot be missed:
with driver.network.expect_response("**/api/**") as response_info:
driver.find_element(By.ID, "load").click()
response = response_info.value
New high-level methods generated via the enhancements manifest:
- network.expect_request / network.expect_response (URL glob or
predicate filtering, observational Request/Response wrappers)
- script.expect_console_message (predicate over ConsoleMessage)
- browsing_context.expect_user_prompt (typed prompt params)
- browsing_context.expect_download, correlating downloadWillBegin and
downloadEnd by navigation id into a new Download object with path(),
save_as() and failure()
The event manager gains a raw=True option so expect_* handlers receive
the full wire-level params instead of the generated dataclasses that
drop fields like request/response.
Includes 25 unit tests and 6 browser-based integration tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds high-level
expect_*context managers for BiDi events to the Python bindings, giving users a race-free way to wait for an event triggered by an action.A new
Subscriptionprimitive registers its event handler at creation time — so an event fired by an action inside thewithblock cannot be missed:New high-level methods (generated via the enhancements manifest)
network.expect_request/network.expect_response— URL glob or predicate filtering, with observationalRequest/Responsewrappersscript.expect_console_message— predicate overConsoleMessagebrowsing_context.expect_user_prompt— typed prompt paramsbrowsing_context.expect_download— correlatesdownloadWillBeginanddownloadEndby navigation id into a newDownloadobject withpath(),save_as()andfailure()The event manager gains a
raw=Trueoption soexpect_*handlers receive the full wire-level params instead of the generated dataclasses, which drop fields likerequest/response.Testing
Cross-binding impact
This is a Python-only ergonomic layer over existing BiDi primitives; no wire-level behavior changes. Parity work for other bindings (Java/Ruby/JS/.NET) is a possible follow-up.