Skip to content
Merged
Changes from all commits
Commits
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
20 changes: 11 additions & 9 deletions tests/sync/test_browsercontext_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,23 +172,25 @@ def test_dialog_event_should_work_with_inline_script_tag(
) -> None:
def handle_route(request: TestServerRequest) -> None:
request.setHeader("content-type", "text/html")
request.write(b"""<script>window.result = prompt('hey?')</script>""")
request.write(b"<script>window.result = prompt('hey?')</script>")
request.finish()

server.set_route("/popup.html", handle_route)
page.goto(server.EMPTY_PAGE)
page.set_content("<a href='popup.html' target=_blank>Click me</a>")

def handle_dialog(dialog: Dialog) -> None:
assert dialog.message == "hey?"
assert dialog.page == popup
dialog.accept("hello")
with (
page.context.expect_event("dialog") as dialog_info,
page.expect_popup() as popup_info,
):
page.click("a")

page.context.on("dialog", handle_dialog)
dialog: Dialog = dialog_info.value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

today I learned about python's with - what a neat syntax!

popup: Page = popup_info.value

with page.expect_popup() as popup_info:
page.click("a")
popup = popup_info.value
assert dialog.message == "hey?"
assert dialog.page == popup
dialog.accept("hello")
assert popup.evaluate("window.result") == "hello"


Expand Down
Loading