Best Python code snippet using playwright-python
test_browsercontext.py
Source:test_browsercontext.py
...70 assert browser.contexts == []71async def test_page_event_should_propagate_default_viewport_to_the_page(browser, utils):72 context = await browser.new_context(viewport={"width": 456, "height": 789})73 page = await context.new_page()74 await utils.verify_viewport(page, 456, 789)75 await context.close()76async def test_page_event_should_respect_device_scale_factor(browser):77 context = await browser.new_context(device_scale_factor=3)78 page = await context.new_page()79 assert await page.evaluate("window.devicePixelRatio") == 380 await context.close()81async def test_page_event_should_not_allow_device_scale_factor_with_null_viewport(82 browser,83):84 with pytest.raises(Error) as exc_info:85 await browser.new_context(no_viewport=True, device_scale_factor=1)86 assert (87 exc_info.value.message88 == '"deviceScaleFactor" option is not supported with null "viewport"'...
test_defaultbrowsercontext.py
Source:test_defaultbrowsercontext.py
...127 else:128 assert cookies == []129async def test_should_support_viewport_option(launch_persistent, utils):130 (page, context) = await launch_persistent(viewport={"width": 456, "height": 789})131 await utils.verify_viewport(page, 456, 789)132 page2 = await context.new_page()133 await utils.verify_viewport(page2, 456, 789)134async def test_should_support_device_scale_factor_option(launch_persistent, utils):135 (page, context) = await launch_persistent(device_scale_factor=3)136 assert await page.evaluate("window.devicePixelRatio") == 3137async def test_should_support_user_agent_option(launch_persistent, server):138 (page, context) = await launch_persistent(user_agent="foobar")139 assert await page.evaluate("() => navigator.userAgent") == "foobar"140 [request, _] = await asyncio.gather(141 server.wait_for_request("/empty.html"),142 page.goto(server.EMPTY_PAGE),143 )144 assert request.getHeader("user-agent") == "foobar"145async def test_should_support_bypass_csp_option(launch_persistent, server):146 (page, context) = await launch_persistent(bypass_csp=True)147 await page.goto(server.PREFIX + "/csp.html")...
utils.py
Source:utils.py
...50 )51 for child in sorted_frames:52 result = result + utils.dump_frames(child, " " + indentation)53 return result54 def verify_viewport(self, page: Page, width: int, height: int):55 assert cast(ViewportSize, page.viewport_size)["width"] == width56 assert cast(ViewportSize, page.viewport_size)["height"] == height57 assert page.evaluate("window.innerWidth") == width58 assert page.evaluate("window.innerHeight") == height59 def register_selector_engine(self, selectors: Selectors, *args, **kwargs) -> None:60 try:61 selectors.register(*args, **kwargs)62 except Error as exc:63 if "has been already registered" not in exc.message:64 raise exc...
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!!