Best Python code snippet using playwright-python
test_interception.py
Source: test_interception.py
...572 server.PREFIX,573 )574 img = await page.query_selector("img")575 assert img576 assert_to_be_golden(await img.screenshot(), "mock-binary-response.png")577async def test_request_fulfill_should_allow_mocking_svg_with_charset(578 page, server, assert_to_be_golden579):580 await page.route(581 "**/*",582 lambda route: route.fulfill(583 content_type="image/svg+xml ; charset=utf-8",584 body='<svg width="50" height="50" version="1.1" xmlns="http://www.w3.org/2000/svg"><rect x="10" y="10" width="30" height="30" stroke="black" fill="transparent" stroke-width="5"/></svg>',585 ),586 )587 await page.evaluate(588 """PREFIX => {589 const img = document.createElement('img');590 img.src = PREFIX + '/does-not-exist.svg';591 document.body.appendChild(img);592 return new Promise((f, r) => { img.onload = f; img.onerror = r; });593 }""",594 server.PREFIX,595 )596 img = await page.query_selector("img")597 assert_to_be_golden(await img.screenshot(), "mock-svg.png")598async def test_request_fulfill_should_work_with_file_path(599 page: Page, server, assert_to_be_golden, assetdir600):601 await page.route(602 "**/*",603 lambda route: route.fulfill(604 content_type="shouldBeIgnored", path=assetdir / "pptr.png"605 ),606 )607 await page.evaluate(608 """PREFIX => {609 const img = document.createElement('img');610 img.src = PREFIX + '/does-not-exist.png';611 document.body.appendChild(img);612 return new Promise(fulfill => img.onload = fulfill);613 }""",614 server.PREFIX,615 )616 img = await page.query_selector("img")617 assert img618 assert_to_be_golden(await img.screenshot(), "mock-binary-response.png")619async def test_request_fulfill_should_stringify_intercepted_request_response_headers(620 page, server621):622 await page.route(623 "**/*",624 lambda route: route.fulfill(625 status=200, headers={"foo": True}, body="Yo, page!"626 ),627 )628 response = await page.goto(server.EMPTY_PAGE)629 assert response.status == 200630 headers = response.headers631 assert headers["foo"] == "True"632 assert await page.evaluate("() => document.body.textContent") == "Yo, page!"...
test_locators.py
Source: test_locators.py
...287 )288 page.goto(server.PREFIX + "/grid.html")289 page.evaluate("window.scrollBy(50, 100)")290 element = page.locator(".box:nth-of-type(3)")291 assert_to_be_golden(element.screenshot(), "screenshot-element-bounding-box.png")292def test_locators_should_return_bounding_box(page: Page, server: Server) -> None:293 page.set_viewport_size(294 {295 "width": 500,296 "height": 500,297 }298 )299 page.goto(server.PREFIX + "/grid.html")300 element = page.locator(".box:nth-of-type(13)")301 box = element.bounding_box()302 assert box == {303 "x": 100,304 "y": 50,305 "width": 50,...
test_emulation_focus.py
Source: test_emulation_focus.py
...98 screenshots = await asyncio.gather(99 page.screenshot(),100 page2.screenshot(),101 )102 assert_to_be_golden(screenshots[0], "screenshot-sanity.png")103 assert_to_be_golden(screenshots[1], "grid-cell-0.png")104async def test_should_change_focused_iframe(page, server, utils):105 await page.goto(server.EMPTY_PAGE)106 [frame1, frame2] = await asyncio.gather(107 utils.attach_frame(page, "frame1", server.PREFIX + "/input/textarea.html"),108 utils.attach_frame(page, "frame2", server.PREFIX + "/input/textarea.html"),109 )110 logger = """() => {111 self._events = [];112 const element = document.querySelector('input');113 element.onfocus = element.onblur = (e) => self._events.push(e.type);114 }"""115 await asyncio.gather(116 frame1.evaluate(logger),117 frame2.evaluate(logger),...
conftest.py
Source: conftest.py
...117 default=False,118 help="Run tests in headful mode.",119 )120@pytest.fixture(scope="session")121def assert_to_be_golden(browser_name: str):122 def compare(received_raw: bytes, golden_name: str):123 golden_file = (_dirname / f"golden-{browser_name}" / golden_name).read_bytes()124 received_image = Image.open(io.BytesIO(received_raw))125 golden_image = Image.open(io.BytesIO(golden_file))126 if golden_image.size != received_image.size:127 pytest.fail("Image size differs to golden image")128 return129 diff_pixels = pixelmatch(130 from_PIL_to_raw_data(received_image),131 from_PIL_to_raw_data(golden_image),132 golden_image.size[0],133 golden_image.size[1],134 threshold=0.2,135 )...
Playwright error connection refused in docker
playwright-python advanced setup
How to select an input according to a parent sibling label
Error when installing Microsoft Playwright
Trouble waiting for changes to complete that are triggered by Python Playwright `select_option`
Capturing and Storing Request Data Using Playwright for Python
Can Playwright be used to launch a browser instance
Trouble in Clicking on Log in Google Button of Pop Up Menu Playwright Python
Scrapy Playwright get date by clicking button
React locator example
I solved my problem. In fact my docker container (frontend) is called "app" which is also domain name of fronend application. My application is running locally on http. Chromium and geko drivers force httpS connection for some domain names one of which is "app". So i have to change name for my docker container wich contains frontend application.
Check out the latest blogs from LambdaTest on this topic:
The sky’s the limit (and even beyond that) when you want to run test automation. Technology has developed so much that you can reduce time and stay more productive than you used to 10 years ago. You needn’t put up with the limitations brought to you by Selenium if that’s your go-to automation testing tool. Instead, you can pick from various test automation frameworks and tools to write effective test cases and run them successfully.
When it comes to web automation testing, there are a number of frameworks like Selenium, Cypress, PlayWright, Puppeteer, etc., that make it to the ‘preferred list’ of frameworks. The choice of test automation framework depends on a range of parameters like type, complexity, scale, along with the framework expertise available within the team. However, it’s no surprise that Selenium is still the most preferred framework among developers and QAs.
Playwright is a framework that I’ve always heard great things about but never had a chance to pick up until earlier this year. And since then, it’s become one of my favorite test automation frameworks to use when building a new automation project. It’s easy to set up, feature-packed, and one of the fastest, most reliable frameworks I’ve worked with.
The speed at which tests are executed and the “dearth of smartness” in testing are the two major problems developers and testers encounter.
With the rapidly evolving technology due to its ever-increasing demand in today’s world, Digital Security has become a major concern for the Software Industry. There are various ways through which Digital Security can be achieved, Captcha being one of them.Captcha is easy for humans to solve but hard for “bots” and other malicious software to figure out. However, Captcha has always been tricky for the testers to automate, as many of them don’t know how to handle captcha in Selenium or using any other test automation framework.
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!!