Skip to content

[py] Add expect_* context managers for BiDi events#17667

Open
AutomatedTester wants to merge 1 commit into
trunkfrom
worktree-py-bidi-expect-events
Open

[py] Add expect_* context managers for BiDi events#17667
AutomatedTester wants to merge 1 commit into
trunkfrom
worktree-py-bidi-expect-events

Conversation

@AutomatedTester

Copy link
Copy Markdown
Member

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 Subscription primitive 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, with observational Request/Response wrappers
  • script.expect_console_message — predicate over ConsoleMessage
  • browsing_context.expect_user_prompt — typed prompt params
  • browsing_context.expect_download — correlates 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, which drop fields like request/response.

Testing

  • 25 unit tests
  • 6 browser-based integration tests

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.

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.
@selenium-ci selenium-ci added the C-py Python Bindings label Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-py Python Bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants