PlaywrightTest.Case (playwright v0.1.17-preview-1) View Source

Use PlaywrightTest.Case in an ExUnit test module to start a Playwright server and put it into the test context.

Examples

defmodule Example.PageTest do
  use PlaywrightTest.Case

  describe "features w/ default context" do
    test "goes to a page", %{page: page} do
      text =
        page
        |> Playwright.Page.goto("https://playwright.dev")
        |> Playwright.Page.text_content(".navbar__title")

      assert text == "Playwright"
    end
  end
end

defmodule Example.BrowserTest do
  use PlaywrightTest.Case

  describe "features w/out `page` context" do
    @tag exclude: [:page]
    test "goes to a page", %{browser: browser} do
      page =
        browser
        |> Playwright.Browser.new_page()

      text =
        page
        |> Playwright.Page.goto("https://playwright.dev")
        |> Playwright.Page.text_content(".navbar__title")

      assert text == "Playwright"

      # must close test-created `page`
      Playwright.Page.close(page)
    end
  end
end