🎭 Playwright for Java
Playwright is a Java library to automate Chromium, Firefox and WebKit with a single API. Playwright is built to enable cross-browser web automation that is ever-green, capable, reliable and fast.
| Linux | macOS | Windows | |
|---|---|---|---|
| Chromium 151.0.7922.34 | ✅ | ✅ | ✅ |
| WebKit 26.5 | ✅ | ✅ | ✅ |
| Firefox 153.0 | ✅ | ✅ | ✅ |
https://playwright.dev/java/docs/intro
https://playwright.dev/java/docs/api/class-playwright
This code snippet navigates to Playwright homepage in Chromium, Firefox and WebKit, and saves 3 screenshots.
importcom.microsoft.playwright.*;
importjava.nio.file.Paths;
importjava.util.Arrays;
importjava.util.List;
publicclassPageScreenshot {
publicstaticvoidmain(String[] args) {
try (Playwrightplaywright = Playwright.create()) {
List<BrowserType> browserTypes = Arrays.asList(
playwright.chromium(),
playwright.webkit(),
playwright.firefox()
);
for (BrowserTypebrowserType : browserTypes) {
try (Browserbrowser = browserType.launch()) {
BrowserContextcontext = browser.newContext();
Pagepage = context.newPage();
page.navigate("https://playwright.dev/");
page.screenshot(newPage.ScreenshotOptions().setPath(Paths.get("screenshot-" + browserType.name() + ".png")));
}
}
}
}
}More comfortable in another programming language? Playwright is also available in