Playwright (playwrightais v1.32.1-rc) View Source

Playwright launches and manages with Playwright browser-server instances.

An example of using Playwright to drive automation:

Example

alias Playwright.API.{Browser, Page, Response}

{:ok, browser}  = Playwright.launch(:chromium)
{:ok, page}     = Browser.new_page(browser)
{:ok, response} = Page.goto(browser, "http://example.com")

assert Response.ok(response)

Browser.close(browser)

Link to this section Summary

Types

The web client type used for launch and connect functions.

Options for launch and connect functions.

t()

%Playwright{}

Functions

Optional callback implementation for Playwright.ChannelOwner.init/2.

Link to this section Types

Specs

client() :: :chromium | :firefox | :webkit

The web client type used for launch and connect functions.

Specs

options() :: Playwright.Config.launch_options()

Options for launch and connect functions.

Specs

t() :: %Playwright{
  chromium: term(),
  firefox: term(),
  guid: term(),
  initializer: term(),
  listeners: term(),
  parent: term(),
  session: term(),
  type: term(),
  webkit: term()
}

%Playwright{}

Link to this section Functions

Link to this function

init(owner, initializer)

View Source

Specs

init(
  struct(),
  map()
) :: {atom(), struct()}

Optional callback implementation for Playwright.ChannelOwner.init/2.

If implemented, the callback will receive:

  1. The newly created "channel owner" struct.
  2. The :initializer received from the Playwright browser server.

The implementation has the option of "patching" the struct as stored in the catalog, and/or binding event handlers.

Example

def init(%{session: session} = owner, _initializer) do
  Channel.bind(session, {:guid, owner.guid}, :close, fn event ->
    Logger.warn("Closing #{inspect(event.target)}")
  end)

  {:ok, %{owner | version: "1.2.3"}}
end

Returns

  • {:ok, struct()}

Arguments

key/nametypedescription
ownerparamstruct()The newly created channel owner (resource).
initializerparamstruct()The initializer received from with the channel owner instance was derived.
Link to this function

launch(client, options \\ %{})

View Source

Specs

launch(client(), options() | map()) :: {:ok, Playwright.Browser.t()}

Launches an instance of Playwright.Browser.

Returns

  • {:ok, Playwright.Browser.t()}

Arguments

key/nametypdescription
typeparamclient()The type of client (browser) to launch.
optionsparamoptions()Playwright.Config.launch_options()