v1.18.0
API Testing
Playwright for Java 1.18 introduces new API Testing that lets you send requests to the server directly from Java!
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
APIResponse res = page.request().get("http://example.com/foo.json");Read more about it in our API testing guide.
Web-First Assertions
Playwright for Java 1.18 introduces Web-First Assertions.
Consider the following example:
...
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
public class TestExample {
...
@Test
void statusBecomesSubmitted() {
...
page.click("#submit-button");
assertThat(page.locator(".status")).hasText("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
Locator.dragTo()- Each locator can now be optionally filtered by the text it contains:
Read more in locator documentation
page.locator("li", new Page.LocatorOptions().setHasText("my item")) .locator("button").click();
Tracing Improvements
Tracing now can embed Java sources to recorded
traces, using new setSources option.
New APIs & changes
acceptDownloadsoption now defaults totrue.
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
