PlaywrightEx.Playwright (PlaywrightEx v0.17.0-rc.5)

Copy Markdown View Source

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

# Or Playwright.firefox/1 or Playwright.webkit/1.
browser = BrowserType.launch!(Playwright.chromium(playwright))
page = Browser.new_page!(browser)
Page.goto!(page, "http://example.com")
# other actions...
Browser.close!(browser)

Since Playwright 1.8.

The examples alias the modules they use (alias PlaywrightEx.{Locator, Page}).

Summary

Types

t()

A Playwright handle. Compare handles with ==, their fields are internal.

Functions

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

Returns a dictionary of devices to be used with PlaywrightEx.Browser.new_context/2 or PlaywrightEx.Browser.new_page/2.

Playwright methods might fail if they are unable to fulfill a request. For example, PlaywrightEx.Locator.wait_for/2 might fail if the selector doesn't match any nodes during the given timeframe.

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. See extensibility for more information.

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

Types

t()

@type t() :: %PlaywrightEx.Playwright{
  conn: term(),
  guid: term(),
  initializer: term(),
  table: term(),
  type: term()
}

A Playwright handle. Compare handles with ==, their fields are internal.

Functions

chromium(playwright)

@spec chromium(t()) :: PlaywrightEx.BrowserType.t()

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

Since Playwright 1.8.

devices(playwright)

@spec devices(t()) :: %{
  optional(String.t()) => PlaywrightEx.Browser.new_context_options()
}

Returns a dictionary of devices to be used with PlaywrightEx.Browser.new_context/2 or PlaywrightEx.Browser.new_page/2.

iphone = Playwright.devices(playwright)["iPhone 6"]

browser = BrowserType.launch!(Playwright.webkit(playwright))
context = Browser.new_context!(browser, iphone)
page = BrowserContext.new_page!(context)
Page.goto!(page, "http://example.com")
# other actions...
Browser.close!(browser)

In Elixir, a descriptor has the snake_case keys of the options (user_agent:), as in the Python client: Browser.new_context(browser, devices["iPhone 6"]).

Since Playwright 1.8.

errors(playwright)

@spec errors(t()) :: %{TimeoutError: PlaywrightEx.TimeoutError}

Playwright methods might fail if they are unable to fulfill a request. For example, PlaywrightEx.Locator.wait_for/2 might fail if the selector doesn't match any nodes during the given timeframe.

For certain types of errors Playwright uses specific error classes. These classes are available via PlaywrightEx.Playwright.errors/1.

An example of handling a timeout error:

try do
  Page.locator(page, ".foo") |> Locator.wait_for!()
rescue
  _ in PlaywrightEx.TimeoutError ->
    # Do something if this is a timeout.
    nil
end

Since Playwright 1.8.

firefox(playwright)

@spec firefox(t()) :: PlaywrightEx.BrowserType.t()

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

Since Playwright 1.8.

request(playwright)

@spec request(t()) :: PlaywrightEx.APIRequest.t()

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

Since Playwright 1.16.

selectors(playwright)

@spec selectors(t()) :: PlaywrightEx.Selectors.t()

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

Since Playwright 1.8.

webkit(playwright)

@spec webkit(t()) :: PlaywrightEx.BrowserType.t()

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

Since Playwright 1.8.