Best Python code snippet using playwright-python
test_worker.py
Source:test_worker.py
...25 == "worker function result"26 )27 await page.goto(server.EMPTY_PAGE)28 assert len(page.workers) == 029async def test_workers_should_emit_created_and_destroyed_events(page: Page):30 worker_obj = None31 async with page.expect_event("worker") as event_info:32 worker_obj = await page.evaluate_handle(33 "() => new Worker(URL.createObjectURL(new Blob(['1'], {type: 'application/javascript'})))"34 )35 worker = await event_info.value36 worker_this_obj = await worker.evaluate_handle("() => this")37 worker_destroyed_promise: Future[Worker] = asyncio.Future()38 worker.once("close", lambda w: worker_destroyed_promise.set_result(w))39 await page.evaluate("workerObj => workerObj.terminate()", worker_obj)40 assert await worker_destroyed_promise == worker41 with pytest.raises(Error) as exc:42 await worker_this_obj.get_property("self")43 assert "Most likely the worker has been closed." in exc.value.message...
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!