跳到正文
本页尚未翻译成中文,以下为英文原文。 查看英文版

Playwright ​

Added in: v1.8

Playwright module provides a method to launch a browser instance. The following is a typical example of using Playwright to drive automation:

java
import com.microsoft.playwright.*;

public class Example {
  public static void main(String[] args) {
    try (Playwright playwright = Playwright.create()) {
      BrowserType chromium = playwright.chromium();
      Browser browser = chromium.launch();
      Page page = browser.newPage();
      page.navigate("http://example.com");
      // other actions...
      browser.close();
    }
  }
}

Methods ​

playwright.close() ​

Added in: v1.9

Terminates this instance of Playwright, will also close all created browsers if they are still running.

playwright.create() ​

Added in: v1.10

Launches new Playwright driver process and connects to it. playwright.close() should be called when the instance is no longer needed.

java
Playwright playwright = Playwright.create();
Browser browser = playwright.webkit().launch();
Page page = browser.newPage();
page.navigate("https://www.w3.org/");
playwright.close();

Arguments

  • options Object (optional)

    • env Object<string, string> (optional) Added in: v1.13

      Additional environment variables that will be passed to the driver process. By default driver process inherits environment variables of the Playwright process.

Returns

  • Playwright

Properties ​

playwright.chromium() ​

Added in: v1.8

This object can be used to launch or connect to Chromium, returning instances of Browser.

Type

  • BrowserType

playwright.firefox() ​

Added in: v1.8

This object can be used to launch or connect to Firefox, returning instances of Browser.

Type

  • BrowserType

playwright.request() ​

Added in: v1.16

Exposes API that can be used for the Web API testing.

Type

  • APIRequest

playwright.selectors() ​

Added in: v1.8

Selectors can be used to install custom selector engines. See extensibility for more information.

Type

  • Selectors

playwright.webkit() ​

Added in: v1.8

This object can be used to launch or connect to WebKit, returning instances of Browser.

Type

  • BrowserType

基于 Apache 2.0 许可证发布。