Skip to content

v1.23.0

Compare
Choose a tag to compare
@rwoll rwoll released this 30 Jun 23:51
0f0c735

Highlights

Network Replay

Now you can record network traffic into a HAR file and re-use this traffic in your tests.

To record network into HAR file:

npx playwright open --save-har=github.har.zip https://github.com/microsoft

Alternatively, you can record HAR programmatically:

context = browser.new_context(record_har_path="github.har.zip")
# ... do stuff ...
context.close()

Use the new methods method: Page.route_from_har or method: BrowserContext.route_from_har to serve matching responses from the HAR file:

context.route_from_har("github.har.zip")

Read more in our documentation.

Advanced Routing

You can now use method: Route.fallback to defer routing to other handlers.

Consider the following example:

# Remove a header from all requests
def remove_header_handler(route: Route) -> None:
    headers = route.request.all_headers()
    if "if-none-match" in headers:
        del headers["if-none-match"]
    route.fallback(headers=headers)

page.route("**/*", remove_header_handler)

# Abort all images
def abort_images_handler(route: Route) -> None:
    if route.request.resource_type == "image":
        route.abort()
    else:
        route.fallback()

page.route("**/*", abort_images_handler)

Note that the new methods method: Page.route_from_har or method: BrowserContext.route_from_har also participate in routing and could be deferred to.

Web-First Assertions Update

Miscellaneous

  • If there's a service worker that's in your way, you can now easily disable it with a new context option service_workers:

    context = browser.new_context(service_workers="block")
    page = context.new_page()
  • Using .zip path for recordHar context option automatically zips the resulting HAR:

    context = browser.new_context(record_har_path="github.har.zip")
  • If you intend to edit HAR by hand, consider using the "minimal" HAR recording mode
    that only records information that is essential for replaying:

    context = browser.new_context(record_har_mode="minimal", record_har_path="har.har")
  • Playwright now runs on Ubuntu 22 amd64 and Ubuntu 22 arm64.