MCPcopy Index your code
hub / github.com/microsoft/playwright-python / test_should_emit_close_events

Function test_should_emit_close_events

tests/async/test_websocket.py:40–56  ·  view source on GitHub ↗
(page: Page, server: Server)

Source from the content-addressed store, hash-verified

38
39
40async def test_should_emit_close_events(page: Page, server: Server) -> None:
41 await page.goto(server.EMPTY_PAGE)
42 close_future: asyncio.Future[None] = asyncio.Future()
43 async with page.expect_websocket() as ws_info:
44 await page.evaluate(
45 """port => {
46 const ws = new WebSocket('ws://localhost:' + port + '/ws');
47 ws.addEventListener('open', data => ws.close());
48 }""",
49 server.PORT,
50 )
51 ws = await ws_info.value
52 ws.on("close", lambda ws: close_future.set_result(None))
53 assert ws.url == f"ws://localhost:{server.PORT}/ws"
54 assert repr(ws) == f"<WebSocket url={ws.url!r}>"
55 await close_future
56 assert ws.is_closed()
57
58
59async def test_should_emit_frame_events(page: Page, server: Server) -> None:

Callers

nothing calls this directly

Calls 5

gotoMethod · 0.45
expect_websocketMethod · 0.45
evaluateMethod · 0.45
onMethod · 0.45
is_closedMethod · 0.45

Tested by

no test coverage detected