Best Python code snippet using playwright-python
test_proxy.py
Source:test_proxy.py
...17async def test_should_throw_for_bad_server_value(browser_factory):18 with pytest.raises(Error) as exc_info:19 await browser_factory(proxy={"server": 123})20 assert "proxy.server: expected string, got number" in exc_info.value.message21async def test_should_use_proxy(browser_factory, server):22 server.set_route(23 "/target.html",24 lambda r: (25 r.write(b"<html><title>Served by the proxy</title></html>"),26 r.finish(),27 ),28 )29 browser = await browser_factory(proxy={"server": f"localhost:{server.PORT}"})30 page = await browser.new_page()31 await page.goto("http://non-existent.com/target.html")32 assert await page.title() == "Served by the proxy"33async def test_should_use_proxy_for_second_page(browser_factory, server):34 server.set_route(35 "/target.html",...
test_browsercontext_proxy.py
Source:test_browsercontext_proxy.py
...17async def browser(browser_factory):18 browser = await browser_factory(proxy={"server": "dummy"})19 yield browser20 await browser.close()21async def test_should_use_proxy(context_factory, server):22 server.set_route(23 "/target.html",24 lambda r: (25 r.write(b"<html><title>Served by the proxy</title></html>"),26 r.finish(),27 ),28 )29 context = await context_factory(proxy={"server": f"localhost:{server.PORT}"})30 page = await context.new_page()31 await page.goto("http://non-existent.com/target.html")32 assert await page.title() == "Served by the proxy"33async def test_should_use_proxy_for_second_page(context_factory, server):34 server.set_route(35 "/target.html",...
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!!