v1.23.0
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
- New method
assertThat(locator).hasValues()that asserts all selected values of<select multiple>element. - Methods
assertThat(locator).containsText()andassertThat(locator).hasText()now acceptignoreCaseoption.
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
.zippath forrecordHarcontext 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.