v1.18.0
API Testing
Playwright for Python 1.18 introduces new API Testing that lets you send requests to the server directly from Python!
Now you can:
- test your server API
- prepare server side state before visiting the web application in a test
- validate server side post-conditions after running some actions in the browser
To do a request on behalf of Playwright's Page, use new page.request
API:
# Do a GET request on behalf of page
res = page.request.get("http://example.com/foo.json")
Read more in our documentation.
Web-First Assertions
Playwright for Python 1.18 introduces Web-First Assertions.
Consider the following example:
from playwright.sync_api import Page, expect
def test_status_becomes_submitted(page: Page) -> None:
# ..
page.click("#submit-button")
expect(page.locator(".status")).to_have_text("Submitted")
Playwright will be re-testing the node with the selector .status
until
fetched Node has the "Submitted"
text. It will be re-fetching the node and
checking it over and over, until the condition is met or until the timeout is
reached. You can pass this timeout as an option.
Read more in our documentation.
Locator Improvements
-
Each locator can now be optionally filtered by the text it contains:
page.locator("li", has_text="my item").locator("button").click()
Read more in locator documentation
New APIs & changes
accept_downloads
option now defaults toTrue
.sources
option to embed sources into traces.
Browser Versions
- Chromium 99.0.4812.0
- Mozilla Firefox 95.0
- WebKit 15.4
This version was also tested against the following stable channels:
- Google Chrome 97
- Microsoft Edge 97