2020-12-14 23:23:00 -08:00
2020-09-25 11:15:33 -07:00
2020-09-25 11:15:33 -07:00
2020-09-25 11:15:33 -07:00
2020-09-25 11:15:33 -07:00
2020-12-14 23:23:00 -08:00
2020-12-14 21:28:25 -08:00
2020-09-25 11:15:33 -07:00

🎭 Playwright for Java

maven version Join Slack

The project is in early development phase, the APIs match those in typescript version of Playwright but are subject to change.

Usage

Add Maven dependency

To run Playwright simply add 2 modules to your Maven project:

<dependency>
  <groupId>com.microsoft.playwright</groupId>
  <artifactId>playwright</artifactId>
  <version>0.162.2</version>
</dependency>
<dependency>
  <groupId>com.microsoft.playwright</groupId>
  <artifactId>driver-bundle</artifactId>
  <version>0.162.2</version>
</dependency>

Examples

Page screenshot

This code snippet navigates to whatsmyuseragent.org 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) throws Exception {
    Playwright playwright = Playwright.create();
    List<BrowserType> browserTypes = Arrays.asList(
        playwright.chromium(),
        playwright.webkit(),
        playwright.firefox()
    );
    for (BrowserType browserType : browserTypes) {
      Browser browser = browserType.launch(
          new BrowserType.LaunchOptions().withHeadless(false));
      BrowserContext context = browser.newContext(
          new Browser.NewContextOptions().withViewport(800, 600));
      Page page = context.newPage();
      page.navigate("http://whatsmyuseragent.org/");
      page.screenshot(new Page.ScreenshotOptions().withPath(Paths.get("screenshot-" + browserType.name() + ".png")));
      browser.close();
    }
    playwright.close();
  }
}

Notes

Follow the instructions to build the project from source and install driver.

Original Playwright documentation. We are converting it to javadoc.

Description
Java version of the Playwright testing and automation library
Readme Apache-2.0 9.2 MiB
Languages
Java 98.2%
HTML 1.3%
Shell 0.4%
CSS 0.1%