async def test_page_events_request_should_report_requests_and_responses_handled_by_service_worker( page: Page, server): await page.goto(server.PREFIX + "/serviceworkers/fetchdummy/sw.html") await page.evaluate("() => window.activationPromise") [request, sw_response ] = await asyncio.gather(page.waitForEvent("request"), page.evaluate('() => fetchDummy("foo")')) assert sw_response == "responseFromServiceWorker:foo" assert request.url == server.PREFIX + "/serviceworkers/fetchdummy/foo" response = await request.response assert response.url == server.PREFIX + "/serviceworkers/fetchdummy/foo" assert await response.text() == "responseFromServiceWorker:foo"
async def test_console_should_work(page: Page, server): messages: List[ConsoleMessage] = [] page.once("console", lambda m: messages.append(m)) await asyncio.gather( page.evaluate('() => console.log("hello", 5, {foo: "bar"})'), page.waitForEvent("console"), ) assert len(messages) == 1 message = messages[0] assert message.text == "hello 5 JSHandle@object" assert str(message) == "hello 5 JSHandle@object" assert message.type == "log" assert await message.args[0].jsonValue() == "hello" assert await message.args[1].jsonValue() == 5 assert await message.args[2].jsonValue() == {"foo": "bar"}