Releases: microsoft/playwright-java
v1.49.0
Aria snapshots
New assertion assertThat(locator).matchesAriaSnapshot() verifies page structure by comparing to an expected accessibility tree, represented as YAML.
page.navigate("https://playwright.dev");
assertThat(page.locator("body")).matchesAriaSnapshot("""
- banner:
- heading /Playwright enables reliable/ [level=1]
- link "Get started"
- link "Star microsoft/playwright on GitHub"
- main:
- img "Browsers (Chromium, Firefox, WebKit)"
- heading "Any browser • Any platform • One API"
""");
You can generate this assertion with Test Generator or by calling locator.ariaSnapshot().
Learn more in the aria snapshots guide.
Tracing groups
New method tracing.group() allows you to visually group actions in the trace viewer.
// All actions between group and groupEnd
// will be shown in the trace viewer as a group.
page.context().tracing().group("Open Playwright.dev > API");
page.navigate("https://playwright.dev/");
page.getByRole(AriaRole.LINK, new Page.GetByRoleOptions().setName("API")).click();
page.context().tracing().groupEnd();
Breaking: chrome
and msedge
channels switch to new headless mode
This change affects you if you're using one of the following channels in your playwright.config.ts
:
chrome
,chrome-dev
,chrome-beta
, orchrome-canary
msedge
,msedge-dev
,msedge-beta
, ormsedge-canary
After updating to Playwright v1.49, run your test suite. If it still passes, you're good to go. If not, you will probably need to update your snapshots, and adapt some of your test code around PDF viewers and extensions. See issue #33566 for more details.
Try new Chromium headless
You can opt into the new headless mode by using 'chromium'
channel. As official Chrome documentation puts it:
New Headless on the other hand is the real Chrome browser, and is thus more authentic, reliable, and offers more features. This makes it more suitable for high-accuracy end-to-end web app testing or browser extension testing.
See issue #33566 for the list of possible breakages you could encounter and more details on Chromium headless. Please file an issue if you see any problems after opting in.
Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setChannel("chromium"));
Miscellaneous
- There will be no more updates for WebKit on Ubuntu 20.04 and Debian 11. We recommend updating your OS to a later version.
<canvas>
elements inside a snapshot now draw a preview.
Browser Versions
- Chromium 131.0.6778.33
- Mozilla Firefox 132.0
- WebKit 18.2
This version was also tested against the following stable channels:
- Google Chrome 130
- Microsoft Edge 130
v1.48.0
WebSocket routing
New methods page.routeWebSocket() and browserContext.routeWebSocket() allow to intercept, modify and mock WebSocket connections initiated in the page. Below is a simple example that mocks WebSocket communication by responding to a "request"
with a "response"
.
page.routeWebSocket("/ws", ws -> {
ws.onMessage(message -> {
if ("request".equals(message))
ws.send("response");
});
});
See WebSocketRoute for more details.
UI updates
- New "copy" buttons for annotations and test location in the HTML report.
- Route method calls like route.fulfill() are not shown in the report and trace viewer anymore. You can see which network requests were routed in the network tab instead.
- New "Copy as cURL" and "Copy as fetch" buttons for requests in the network tab.
Miscellaneous
- New method page.requestGC() may help detect memory leaks.
- Requests made by APIRequestContext now record detailed timing and security information in the HAR.
Browser Versions
- Chromium 130.0.6723.19
- Mozilla Firefox 130.0
- WebKit 18.0
This version was also tested against the following stable channels:
- Google Chrome 129
- Microsoft Edge 129
v1.47.0
Network Tab improvements
The Network tab in the trace viewer has several nice improvements:
- filtering by asset type and URL
- better display of query string parameters
- preview of font assets
Miscellaneous
- The
mcr.microsoft.com/playwright/java:v1.47.0
now serves a Playwright image based on Ubuntu 24.04 Noble.
To use the 22.02 jammy-based image, please usemcr.microsoft.com/playwright/java:v1.47.0-jammy
instead. - The
:latest
/:focal
/:jammy
tag for Playwright Docker images is no longer being published. Pin to a specific version for better stability and reproducibility. - TLS client certificates can now be passed from memory by passing
cert
andkey
as byte arrays instead of file paths. noWaitAfter
in locator.selectOption() was deprecated.- We've seen reports of WebGL in Webkit misbehaving on GitHub Actions
macos-13
. We recommend upgrading GitHub Actions tomacos-14
.
Browser Versions
- Chromium 129.0.6668.29
- Mozilla Firefox 130.0
- WebKit 18.0
This version was also tested against the following stable channels:
- Google Chrome 128
- Microsoft Edge 128
v1.46.0
TLS Client Certificates
Playwright now allows to supply client-side certificates, so that server can verify them, as specified by TLS Client Authentication.
You can provide client certificates as a parameter of browser.newContext() and apiRequest.newContext(). The following snippet sets up a client certificate for https://example.com
:
BrowserContext context = browser.newContext(new Browser.NewContextOptions()
.setClientCertificates(asList(new ClientCertificate("https://example.com")
.setCertPath(Paths.get("client-certificates/cert.pem"))
.setKeyPath(Paths.get("client-certificates/key.pem")))));
Trace Viewer Updates
- Content of text attachments is now rendered inline in the attachments pane.
- New setting to show/hide routing actions like route.resume().
- Request method and status are shown in the network details tab.
- New button to copy source file location to clipboard.
- Metadata pane now displays the
baseURL
.
Miscellaneous
- New
maxRetries
option in apiRequestContext.fetch() which retries on theECONNRESET
network error.
Browser Versions
- Chromium 128.0.6613.18
- Mozilla Firefox 128.0
- WebKit 18.0
This version was also tested against the following stable channels:
- Google Chrome 127
- Microsoft Edge 127
v1.45.1
Highlights
#1617 - [Bug]: Traceviewer not reporting all actions
microsoft/playwright#31764 - [Bug]: some actions do not appear in the trace file
Browser Versions
- Chromium 127.0.6533.5
- Mozilla Firefox 127.0
- WebKit 17.4
This version was also tested against the following stable channels:
- Google Chrome 126
- Microsoft Edge 126
v1.45.0
Clock
Utilizing the new Clock API allows to manipulate and control time within tests to verify time-related behavior. This API covers many common scenarios, including:
- testing with predefined time;
- keeping consistent time and timers;
- monitoring inactivity;
- ticking through time manually.
// Initialize clock with some time before the test time and let the page load
// naturally. `Date.now` will progress as the timers fire.
page.clock().install(new Clock.InstallOptions().setTime("2024-02-02T08:00:00"));
page.navigate("http://localhost:3333");
Locator locator = page.getByTestId("current-time");
// Pretend that the user closed the laptop lid and opened it again at 10am.
// Pause the time once reached that point.
page.clock().pauseAt("2024-02-02T10:00:00");
// Assert the page state.
assertThat(locator).hasText("2/2/2024, 10:00:00 AM");
// Close the laptop lid again and open it at 10:30am.
page.clock().fastForward("30:00");
assertThat(locator).hasText("2/2/2024, 10:30:00 AM");
See the clock guide for more details.
Miscellaneous
-
Method locator.setInputFiles() now supports uploading a directory for
<input type=file webkitdirectory>
elements.page.getByLabel("Upload directory").setInputFiles(Paths.get("mydir"));
-
Multiple methods like locator.click() or locator.press() now support a
ControlOrMeta
modifier key. This key maps toMeta
on macOS and maps toControl
on Windows and Linux.// Press the common keyboard shortcut Control+S or Meta+S to trigger a "Save" operation. page.keyboard.press("ControlOrMeta+S");
-
New property
httpCredentials.send
in apiRequest.newContext() that allows to either always send theAuthorization
header or only send it in response to401 Unauthorized
. -
Playwright now supports Chromium, Firefox and WebKit on Ubuntu 24.04.
-
v1.45 is the last release to receive WebKit update for macOS 12 Monterey. Please update macOS to keep using the latest WebKit.
Browser Versions
- Chromium 127.0.6533.5
- Mozilla Firefox 127.0
- WebKit 17.4
This version was also tested against the following stable channels:
- Google Chrome 126
- Microsoft Edge 126
v1.44.0
New APIs
Accessibility assertions
-
assertThat(locator).toHaveAccessibleName() checks if the element has the specified accessible name:
Locator locator = page.getByRole(AriaRole.BUTTON); assertThat(locator).hasAccessibleName("Submit");
-
assertThat(locator).toHaveAccessibleDescription() checks if the element has the specified accessible description:
Locator locator = page.getByRole(AriaRole.BUTTON); assertThat(locator).hasAccessibleDescription("Upload a photo");
-
assertThat(locator).toHaveRole() checks if the element has the specified ARIA role:
Locator locator = page.getByTestId("save-button"); assertThat(locator).hasRole(AriaRole.BUTTON);
Locator handler
- After executing the handler added with page.addLocatorHandler(), Playwright will now wait until the overlay that triggered the handler is not visible anymore. You can opt-out of this behavior with the new
setNoWaitAfter
option. - You can use new
setTimes
option in page.addLocatorHandler() to specify maximum number of times the handler should be run. - The handler in page.addLocatorHandler() now accepts the locator as argument.
- New page.removeLocatorHandler() method for removing previously added locator handlers.
Locator locator = page.getByText("This interstitial covers the button");
page.addLocatorHandler(locator, overlay -> {
overlay.locator("#close").click();
}, new Page.AddLocatorHandlerOptions().setTimes(3).setNoWaitAfter(true));
// Run your tests that can be interrupted by the overlay.
// ...
page.removeLocatorHandler(locator);
Miscellaneous options
-
New method formData.append() allows to specify repeating fields with the same name in
setMultipart
option inRequestOptions
:FormData formData = FormData.create(); formData.append("file", new FilePayload("f1.js", "text/javascript", "var x = 2024;".getBytes(StandardCharsets.UTF_8))); formData.append("file", new FilePayload("f2.txt", "text/plain", "hello".getBytes(StandardCharsets.UTF_8))); APIResponse response = context.request().post("https://example.com/uploadFile", RequestOptions.create().setMultipart(formData));
-
expect(page).toHaveURL(url)
now supportssetIgnoreCase
option.
Browser Versions
- Chromium 125.0.6422.14
- Mozilla Firefox 125.0.1
- WebKit 17.4
This version was also tested against the following stable channels:
- Google Chrome 124
- Microsoft Edge 124
v1.43.0
New APIs
-
Method browserContext.clearCookies([options]) now supports filters to remove only some cookies.
// Clear all cookies. context.clearCookies(); // New: clear cookies with a particular name. context.clearCookies(new BrowserContext.ClearCookiesOptions().setName("session-id")); // New: clear cookies for a particular domain. context.clearCookies(new BrowserContext.ClearCookiesOptions().setDomain("my-origin.com"));
-
New method locator.contentFrame() converts a Locator object to a FrameLocator. This can be useful when you have a Locator object obtained somewhere, and later on would like to interact with the content inside the frame.
Locator locator = page.locator("iframe[name='embedded']"); // ... FrameLocator frameLocator = locator.contentFrame(); frameLocator.getByRole(AriaRole.BUTTON).click();
-
New method frameLocator.owner() converts a FrameLocator object to a Locator. This can be useful when you have a FrameLocator object obtained somewhere, and later on would like to interact with the
iframe
element.FrameLocator frameLocator = page.frameLocator("iframe[name='embedded']"); // ... Locator locator = frameLocator.owner(); assertThat(locator).isVisible();
Browser Versions
- Chromium 124.0.6367.8
- Mozilla Firefox 124.0
- WebKit 17.4
This version was also tested against the following stable channels:
- Google Chrome 123
- Microsoft Edge 123
v1.42.0
JUnit integration
Warning
This feature is experimental, we are actively looking for the feedback based on your scenarios.
Add new @UsePlaywright
annotation to your test classes to start using Playwright
fixtures for Page, BrowserContext, Browser, APIRequestContext and Playwright in the
test methods.
package org.example;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.junit.UsePlaywright;
import org.junit.jupiter.api.Test;
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
@UsePlaywright
public class TestExample {
void shouldNavigateToInstallationGuide(Page page) {
page.navigate("https://playwright.dev/java/");
page.getByRole(AriaRole.LINK, new Page.GetByRoleOptions().setName("Docs")).click();
assertThat(page.getByRole(AriaRole.HEADING, new Page.GetByRoleOptions().setName("Installation"))).isVisible();
}
@Test
void shouldCheckTheBox(Page page) {
page.setContent("<input id='checkbox' type='checkbox'></input>");
page.locator("input").check();
assertEquals(true, page.evaluate("window['checkbox'].checked"));
}
@Test
void shouldSearchWiki(Page page) {
page.navigate("https://www.wikipedia.org/");
page.locator("input[name=\"search\"]").click();
page.locator("input[name=\"search\"]").fill("playwright");
page.locator("input[name=\"search\"]").press("Enter");
assertThat(page).hasURL("https://en.wikipedia.org/wiki/Playwright");
}
}
In the example above, all three test methods use the same Browser. Each test
uses its own BrowserContext and Page.
Custom options
Implement your own OptionsFactory
to initialize the fixtures with custom configuration.
import com.microsoft.playwright.junit.Options;
import com.microsoft.playwright.junit.OptionsFactory;
import com.microsoft.playwright.junit.UsePlaywright;
@UsePlaywright(MyTest.CustomOptions.class)
public class MyTest {
public static class CustomOptions implements OptionsFactory {
@Override
public Options getOptions() {
return new Options()
.setHeadless(false)
.setContextOption(new Browser.NewContextOptions()
.setBaseURL("https://github.com"))
.setApiRequestOptions(new APIRequest.NewContextOptions()
.setBaseURL("https://playwright.dev"));
}
}
@Test
public void testWithCustomOptions(Page page, APIRequestContext request) {
page.navigate("/");
assertThat(page).hasURL(Pattern.compile("github"));
APIResponse response = request.get("/");
assertTrue(response.text().contains("Playwright"));
}
}
Learn more about the fixtures in our JUnit guide.
New Locator Handler
New method page.addLocatorHandler(locator, handler, handler, handler) registers a callback that will be invoked when specified element becomes visible and may block Playwright actions. The callback can get rid of the overlay. Here is an example that closes a cookie dialog when it appears.
// Setup the handler.
page.addLocatorHandler(
page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Hej! You are in control of your cookies.")),
() - > {
page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Accept all")).click();
});
// Write the test as usual.
page.navigate("https://www.ikea.com/");
page.getByRole(AriaRole.LINK, new Page.GetByRoleOptions().setName("Collection of blue and white")).click();
assertThat(page.getByRole(AriaRole.HEADING, new Page.GetByRoleOptions().setName("Light and easy"))).isVisible();
New APIs
- page.pdf() accepts two new options
tagged
andoutline
.
Announcements
⚠️ Ubuntu 18 is not supported anymore.
Browser Versions
- Chromium 123.0.6312.4
- Mozilla Firefox 123.0
- WebKit 17.4
This version was also tested against the following stable channels:
- Google Chrome 122
- Microsoft Edge 123
v1.41.2
Highlights
microsoft/playwright#29123 - [REGRESSION] route.continue: Protocol error (Fetch.continueRequest): Invalid InterceptionId.
#1468 - [BUG] File Upload leads to "Exactly one of payloads, localPaths and streams must be provided"
Browser Versions
- Chromium 121.0.6167.57
- Mozilla Firefox 121.0
- WebKit 17.4
This version was also tested against the following stable channels:
- Google Chrome 120
- Microsoft Edge 120