8000 GitHub - microsoft/playwright-java at
[go: up one dir, main page]

Skip to content

microsoft/playwright-java

🎭 Playwright for Java

javadoc maven version Join Discord

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 136.0.7103.25
WebKit 18.4
Firefox 137.0

Documentation

https://playwright.dev/java/docs/intro

API Reference

https://playwright.dev/java/docs/api/class-playwright

Example

This code snippet navigates to Playwright homepage in Chromium, Firefox and WebKit, and saves 3 screenshots.

import com.microsoft.playwright.*;

import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;

public class PageScreenshot {
  public static void main(String[] args) {
    try (Playwright playwright = Playwright.create()) {
      List<BrowserType> browserTypes = Arrays.asList(
        playwright.chromium(),
        playwright.webkit(),
        playwright.firefox()
      );
      for (BrowserType browserType : browserTypes) {
        try (Browser browser = browserType.launch()) {
          BrowserContext context = browser.newContext();
          Page page = context.newPage();
          page.navigate("https://playwright.dev/");
          page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("screenshot-" + browserType.name() + ".png")));
        }
      }
    }
  }
}

Other languages

More comfortable in another programming language? Playwright is also available in

About

Java version of the Playwright testing and automation library

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Contributors 36

Languages

0