Microsoft: Playwright for Python lets you test web apps in all major browsers
Microsoft announced Playwright, a tool that lets developers write tests in Python for web apps on Chrome, Chromium-based Edge, Apple Safari, and Mozilla Firefox.
Playwright, a Python library, allows developers to essentially control the browser with a few lines of Python code to automate cross-browser testing for Single Page Web Apps and Progressive Web Apps.
The Playwright for Python library is available in preview and is designed to help speed up the process of testing web applications on Windows, Linux, and macOS. It can also be used to emulate smartphones with different screen sizes, time zones and web permissions to test web application in mobile web browsers.
SEE: Recruitment Kit: Python Developer (TechRepublic Premium)
It provides a set of application programming interfaces (APIs) to automate browsers that use Chromium, Firefox, and WebKit browser engines. Using the Playwright API, developers can write Python code to create new browser pages, access URLs, and interact with page elements.
“With the Playwright API, you can create end-to-end tests that run on all modern web browsers. Playwright offers faster, more reliable, and better performing automation than existing testing tools,” says Arjun Attam , program manager for Playwright. .
“End-to-end automated testing has become more important than ever. Teams are shipping faster and building apps that run on a growing set of devices. This increase in speed and web targets is putting immense pressure on the testing process, and automation is critical.”
While currently Playwright only supports mobile emulation from a desktop browser, there is an open issue on Microsoft’s GitHub page for Playwright that users can vote to bring testing support to actual mobile browsers.
Playwright integrates with the pytest testing framework and can be used for testing views in Django web applications as well as using Django’s built-in testing tools.
SEE: Programming languages: Julia users most likely to switch to Python for data science
Especially for automated testing, Playwright expects the web application’s UI to be ready to handle testing actions like clicking a button, which must be there before its functionality can be tested. It can also be used to automate web application connection testing on a login form.
“Under the hood, Playwright uses an event-driven architecture that can listen for precise browser events such as DOM changes, network requests, and page navigations,” Attam notes.
Playwright also provides standard interfaces to monitor and modify network traffic for testing tasks such as managing attachments downloaded by a page and network response after a user clicks a button.