Playwright

Hex.pm Version Hex Docs License GitHub Actions Workflow Status

Elixir client for Playwright. Automate Chromium, Firefox and WebKit: end-to-end tests, web scraping, agentic AI.

It is a 1:1 port of the official JavaScript client. Its API is generated from Playwright's docs, so the docs at playwright.dev apply. The driver (Node.js and playwright-core) is pinned and installed by Mix, no npm needed. This release drives Playwright 1.65.1.

For Phoenix feature tests with the Ecto sandbox, use Fluffy, which is built on this library.

Installation

def deps do
  [
    {:playwright, "~> 1.65.0-rc.2", hex: :playwright_ex}
  ]
end

The Hex package is playwright_ex, the app and modules are playwright and Playwright. hex: :playwright_ex is required: playwright on Hex is another library.

mix deps.get
mix playwright.install

Arguments are playwright install's, with no --: mix playwright.install chromium --with-deps.

Versioning

The major.minor is Playwright's and the patch is ours, as in playwright-python: 1.65.x drives Playwright 1.65, and this release pins driver 1.65.1. Our own breaking changes ship only with a Playwright minor, so depend on ~> 1.65.0.

Example

alias Playwright.{Browser, BrowserType, Expect, Locator, Page}

{:ok, _} = Playwright.Supervisor.start_link()
browser = BrowserType.launch!(Playwright.chromium(Playwright.instance()))
page = Browser.new_page!(browser)
Page.goto!(page, "https://elixir-lang.org/")
Page.get_by_role(page, :link, name: "Install") |> Locator.click!()
Expect.to_have_title!(page, ~r/Install/)
# Closes the browser and waits for the driver to exit before the VM halts.
Supervisor.stop(Playwright)

For no timeout, pass timeout: :infinity; 0 also means no timeout, unlike Elixir's convention (details).

Reading playwright.dev

The Python docs are the closest read, since the names match Python's: snake_case, keyword options, expect_popup, eval_on_selector. page.get_by_role("button").click() is Page.get_by_role(page, :button) |> Locator.click!().

Guides

Feedback of any shape and size is welcome: get in touch.

Contributing

  1. mix setup installs dependencies, the pinned Playwright driver and Chromium.
  2. mix test, or mix check for everything CI runs.
  3. Porting rules: PORTING.md; the why behind the design: docs/architecture.md.

Reviewing

Besides correctness, review a change for simplicity, consistency and scope. This applies to human and agent reviews alike.

License

Apache-2.0 (LICENSE), as the client is a port of Playwright's: see NOTICE. Each ported file starts with its upstream file's copyright header. Releases up to 0.16 were MIT.