Microsoft has announced Playwright, a tool that lets developers write tests in Python for web applications across 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 accelerate the process of testing web applications across Windows, Linux and macOS. It can also be used to emulate smartphones with different screen sizes, timezones, and web permissions to test a web app in mobile web browsers.
SEE: Hiring Kit: Python developer (TechRepublic Premium)
It provides a set of application programming interfaces (APIs) to automate browsers that use the Chromium, Firefox and WebKit browser engines. Using the Playwright API, developers can write Python code to create new browser pages, navigate to URLs and interact with elements on a page.
“With the Playwright API, you can author end-to-end tests that run on all modern web browsers. Playwright delivers automation that is faster, more reliable and more capable than existing testing tools,” says Arjun Attam, a program manager for Playwright.
“Automated end-to-end tests have become more important than ever before. Teams are shipping faster and building apps that run on a growing set of devices. This increase in velocity and web targets puts immense pressure on the testing process, and automation is critical.”
While presently Playwright only supports mobile emulation from a desktop browser, there is an open issue on Microsoft’s GitHub page for Playwright that users can upvote to bring support for testing on actual mobile browsers.
Playwright integrates with the pytest testing framework and can be used to test views in Django web apps as well as use Django’s built-in testing tools.
Importantly for automated testing, Playwright waits for the web app’s UI to be ready to handle testing actions like clicking a button, which needs to be there before its functionality can be tested. It can also be used to automate tests for logging in to a web app on a login form.
“Under the hood, Playwright uses an event-driven architecture that can listen to precise browser events like DOM changes, network requests and page navigations,” notes Attam.
Playwright also provides standard interfaces to monitor and modify network traffic for testing tasks like handling attachments downloaded by a page and a network response after a user clicks a button.