Interface Playwright

All Superinterfaces:
AutoCloseable
All Known Implementing Classes:
PlaywrightImpl

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

 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();
     }
   }
 }
 
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static class 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    This object can be used to launch or connect to Chromium, returning instances of Browser.
    void
    Terminates this instance of Playwright, will also close all created browsers if they are still running.
    static Playwright
     
    static Playwright
    Launches new Playwright driver process and connects to it.
    This object can be used to launch or connect to Firefox, returning instances of Browser.
    Exposes API that can be used for the Web API testing.
    Selectors can be used to install custom selector engines.
    This object can be used to launch or connect to WebKit, returning instances of Browser.
  • Method Details

    • chromium

      BrowserType chromium()
      This object can be used to launch or connect to Chromium, returning instances of Browser.
      Since:
      v1.8
    • firefox

      BrowserType firefox()
      This object can be used to launch or connect to Firefox, returning instances of Browser.
      Since:
      v1.8
    • request

      APIRequest request()
      Exposes API that can be used for the Web API testing.
      Since:
      v1.16
    • selectors

      Selectors selectors()
      Selectors can be used to install custom selector engines. See extensibility for more information.
      Since:
      v1.8
    • webkit

      BrowserType webkit()
      This object can be used to launch or connect to WebKit, returning instances of Browser.
      Since:
      v1.8
    • close

      void close()
      Terminates this instance of Playwright, will also close all created browsers if they are still running.
      Specified by:
      close in interface AutoCloseable
      Since:
      v1.9
    • create

      static Playwright create(Playwright.CreateOptions options)
      Launches new Playwright driver process and connects to it. Playwright.close() should be called when the instance is no longer needed.
      
       Playwright playwright = Playwright.create();
       Browser browser = playwright.webkit().launch();
       Page page = browser.newPage();
       page.navigate("https://www.w3.org/");
       playwright.close();
       
      Since:
      v1.10
    • create

      static Playwright create()