Skip to content

v1.23.0

Choose a tag to compare

@yury-s yury-s released this 30 Jun 21:54
· 1 commit to release-1.23 since this release
a127bfe

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:

mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="open --save-har=example.har --save-har-glob='**/api/**' https://example.com"

Alternatively, you can record HAR programmatically:

BrowserContext context = browser.newContext(new Browser.NewContextOptions()
    .setRecordHarPath(Paths.get("example.har"))
    .setRecordHarUrlFilter("**/api/**"));

// ... Perform actions ...

// Close context to ensure HAR is saved to disk.
context.close();

Use the new methods page.routeFromHAR() or browserContext.routeFromHAR() to serve matching responses from the HAR file:

context.routeFromHAR(Paths.get("example.har"));

Read more in our documentation.

Advanced Routing

You can now use route.fallback() to defer routing to other handlers.

Consider the following example:

// Remove a header from all requests.
page.route("**/*", route -> {
  Map<String, String> headers = new HashMap<>(route.request().headers());
  headers.remove("X-Secret");
  route.resume(new Route.ResumeOptions().setHeaders(headers));
});

// Abort all images.
page.route("**/*", route -> {
  if ("image".equals(route.request().resourceType()))
    route.abort();
  else
    route.fallback();
});

Note that the new methods page.routeFromHAR() and browserContext.routeFromHAR()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 serviceWorkers:
    BrowserContext context = browser.newContext(new Browser.NewContextOptions()
        .setServiceWorkers(ServiceWorkerPolicy.BLOCK));
  • Using .zip path for recordHar context option automatically zips the resulting HAR:
    BrowserContext context = browser.newContext(new Browser.NewContextOptions()
        .setRecordHarPath(Paths.get("example.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:
    BrowserContext context = browser.newContext(new Browser.NewContextOptions()
        .setRecordHarPath(Paths.get("example.har.zip"))
        .setRecordHarMode(HarMode.MINIMAL));
  • Playwright now runs on Ubuntu 22 amd64 and Ubuntu 22 arm64.