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

Copy Markdown View Source

Web-first assertions: the methods of LocatorAssertions, PageAssertions and APIResponseAssertions, as functions of their receiver.

expect(locator).toHaveText(expected) is to_have_text(locator, expected), expect(locator).not.toHaveText(expected) is not_to_have_text(locator, expected) or locator |> not_() |> to_have_text(expected). They retry until the expectation is met or the timeout (5 seconds by default, see Configuration below) passes, then return :ok or {:error, %PlaywrightEx.ExpectError{}} whose matcherResult mirrors JS; the bang forms raise the PlaywrightEx.ExpectError (Testing with ExUnit shows how to wrap it in an ExUnit.AssertionError).

The LocatorAssertions class provides assertion methods that can be used to make assertions about the Locator state in the tests.

test "status becomes submitted", %{page: page} do
  # ...
  Page.get_by_role(page, :button) |> Locator.click!()
  Page.locator(page, ".status") |> Expect.to_have_text!("Submitted")
end

Configuration

The expect part of upstream's playwright.config.ts, read when a matcher runs (so an Application.put_env/3 in test_helper.exs applies too):

config :playwright_ex, :expect, timeout: 10_000, update_snapshots: :missing

The keys (other keys raise ArgumentError, at application start for the config files):

  • :timeout - Default timeout of the matchers in milliseconds, 0 or :infinity for no timeout. Defaults to 5000. A timeout: option of a matcher wins.
  • :update_snapshots - When to_have_screenshot and to_match_aria_snapshot write snapshots: :all, :changed, :missing, :none or :default (the default: write missing ones). A screenshot, or an aria snapshot with path:, is written to its path. An inline aria snapshot can't be written into the test source without a test runner, so where upstream suggests a rebaseline (an empty snapshot, or any under :all or a mismatch under :changed) the matcher fails with the new snapshot in its message.
  • :ignore_snapshots - Skip the snapshot matchers. Defaults to false.
  • :to_have_screenshot, :to_match_aria_snapshot - Defaults for their options, maps with the JS keys (%{maxDiffPixels: 10}, %{children: "equal"}), as upstream's config.

Since Playwright 1.17.

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

Summary

Types

Options of not_to_be_empty/2, see its docs.

Options of not_to_have_css/4, see its docs.

Options of not_to_have_id/3, see its docs.

Options of not_to_have_url/3, see its docs.

t()

A negated receiver of any matcher.

A negated receiver (not_/1): expect(actual).not in JS.

Options of to_be_attached/2, see its docs.

Options of to_be_checked/2, see its docs.

Options of to_be_disabled/2, see its docs.

Options of to_be_editable/2, see its docs.

Options of to_be_empty/2, see its docs.

Options of to_be_enabled/2, see its docs.

Options of to_be_focused/2, see its docs.

Options of to_be_hidden/2, see its docs.

Options of to_be_visible/2, see its docs.

Options of to_contain_text/3, see its docs.

Options of to_have_class/3, see its docs.

Options of to_have_count/3, see its docs.

Options of to_have_css/4, see its docs.

Options of to_have_id/3, see its docs.

Options of to_have_role/3, see its docs.

Options of to_have_text/3, see its docs.

Options of to_have_title/3, see its docs.

Options of to_have_url/3, see its docs.

Options of to_have_value/3, see its docs.

Options of to_have_values/3, see its docs.

Functions

Makes the assertion check for the opposite condition.

The opposite of to_be_attached/2: expect(x).not.toBeAttached(...) in JS.

The opposite of to_be_checked/2: expect(x).not.toBeChecked(...) in JS.

The opposite of to_be_disabled/2: expect(x).not.toBeDisabled(...) in JS.

The opposite of to_be_editable/2: expect(x).not.toBeEditable(...) in JS.

The opposite of to_be_empty/2: expect(x).not.toBeEmpty(...) in JS.

Like not_to_be_empty/2, but raises PlaywrightEx.ExpectError when the expectation is not met.

The opposite of to_be_enabled/2: expect(x).not.toBeEnabled(...) in JS.

The opposite of to_be_focused/2: expect(x).not.toBeFocused(...) in JS.

The opposite of to_be_hidden/2: expect(x).not.toBeHidden(...) in JS.

The opposite of to_be_in_viewport/2: expect(x).not.toBeInViewport(...) in JS.

The opposite of to_be_ok/1: expect(x).not.toBeOK(...) in JS.

Like not_to_be_ok/1, but raises PlaywrightEx.ExpectError when the expectation is not met.

The opposite of to_be_visible/2: expect(x).not.toBeVisible(...) in JS.

The opposite of to_contain_class/3: expect(x).not.toContainClass(...) in JS.

The opposite of to_contain_text/3: expect(x).not.toContainText(...) in JS.

The opposite of to_have_accessible_description/3: expect(x).not.toHaveAccessibleDescription(...) in JS.

The opposite of to_have_accessible_error_message/3: expect(x).not.toHaveAccessibleErrorMessage(...) in JS.

The opposite of to_have_accessible_name/3: expect(x).not.toHaveAccessibleName(...) in JS.

The opposite of to_have_attribute/4: expect(x).not.toHaveAttribute(...) in JS.

The opposite of to_have_class/3: expect(x).not.toHaveClass(...) in JS.

The opposite of to_have_count/3: expect(x).not.toHaveCount(...) in JS.

The opposite of to_have_css/4: expect(x).not.toHaveCSS(...) in JS.

The opposite of to_have_id/3: expect(x).not.toHaveId(...) in JS.

The opposite of to_have_js_property/4: expect(x).not.toHaveJSProperty(...) in JS.

The opposite of to_have_role/3: expect(x).not.toHaveRole(...) in JS.

The opposite of to_have_screenshot/2: expect(x).not.toHaveScreenshot(...) in JS.

The opposite of to_have_text/3: expect(x).not.toHaveText(...) in JS.

The opposite of to_have_title/3: expect(x).not.toHaveTitle(...) in JS.

The opposite of to_have_url/3: expect(x).not.toHaveURL(...) in JS.

The opposite of to_have_value/3: expect(x).not.toHaveValue(...) in JS.

The opposite of to_have_values/3: expect(x).not.toHaveValues(...) in JS.

The opposite of to_match_aria_snapshot/3: expect(x).not.toMatchAriaSnapshot(...) in JS.

Ensures that Locator points to an element that is connected to a Document or a ShadowRoot.

Like to_be_attached/2, but raises PlaywrightEx.ExpectError when the expectation is not met.

Ensures the Locator points to a checked input.

Like to_be_checked/2, but raises PlaywrightEx.ExpectError when the expectation is not met.

Ensures the Locator points to a disabled element. Element is disabled if it has "disabled" attribute or is disabled via 'aria-disabled'. Note that only native control elements such as HTML button, input, select, textarea, option, optgroup can be disabled by setting "disabled" attribute. "disabled" attribute on other elements is ignored by the browser.

Like to_be_disabled/2, but raises PlaywrightEx.ExpectError when the expectation is not met.

Ensures the Locator points to an editable element.

Like to_be_editable/2, but raises PlaywrightEx.ExpectError when the expectation is not met.

Ensures the Locator points to an empty editable element or to a DOM node that has no text.

Like to_be_empty/2, but raises PlaywrightEx.ExpectError when the expectation is not met.

Ensures the Locator points to an enabled element.

Like to_be_enabled/2, but raises PlaywrightEx.ExpectError when the expectation is not met.

Ensures the Locator points to a focused DOM node.

Like to_be_focused/2, but raises PlaywrightEx.ExpectError when the expectation is not met.

Ensures that Locator either does not resolve to any DOM node, or resolves to a non-visible one.

Like to_be_hidden/2, but raises PlaywrightEx.ExpectError when the expectation is not met.

Ensures the Locator points to an element that intersects viewport, according to the intersection observer API.

Ensures the response status code is within 200..299 range.

Like to_be_ok/1, but raises PlaywrightEx.ExpectError when the expectation is not met.

Ensures that Locator points to an attached and visible DOM node.

Like to_be_visible/2, but raises PlaywrightEx.ExpectError when the expectation is not met.

Ensures the Locator points to an element with given CSS classes. All classes from the asserted value, separated by spaces, must be present in the Element.classList in any order.

Ensures the Locator points to an element that contains the given text. All nested elements will be considered when computing the text content of the element. You can use regular expressions for the value as well.

Ensures the Locator points to an element with a given accessible name.

Ensures the Locator points to an element with given attribute.

Ensures the Locator points to an element with given CSS classes. When a string is provided, it must fully match the element's class attribute. To match individual classes use PlaywrightEx.Expect.to_contain_class/3.

Ensures the Locator resolves to an exact number of DOM nodes.

Ensures the Locator resolves to an element with the given computed CSS style.

Ensures the Locator points to an element with the given DOM Node ID.

Like to_have_id/3, but raises PlaywrightEx.ExpectError when the expectation is not met.

Ensures the Locator points to an element with given JavaScript property. Note that this property can be of a primitive type as well as a plain serializable JavaScript object.

Ensures the Locator points to an element with a given ARIA role.

Like to_have_role/3, but raises PlaywrightEx.ExpectError when the expectation is not met.

This function will wait until two consecutive locator screenshots yield the same result, and then compare the last screenshot with the expectation.

Ensures the Locator points to an element with the given text. All nested elements will be considered when computing the text content of the element. You can use regular expressions for the value as well.

Ensures the page has the given title.

Ensures the page is navigated to the given URL.

Like to_have_url/3, but raises PlaywrightEx.ExpectError when the expectation is not met.

Ensures the Locator points to an element with the given input value. You can use regular expressions for the value as well.

Ensures the Locator points to multi-select/combobox (i.e. a select with the multiple attribute) and the specified values are selected.

Types

not_to_be_attached_options()

@type not_to_be_attached_options() ::
  [
    attached: boolean(),
    signal: PlaywrightEx.AbortSignal.t(),
    timeout: number() | :infinity
  ]
  | %{
      optional(:attached) => boolean(),
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of not_to_be_attached/2, see its docs.

not_to_be_checked_options()

@type not_to_be_checked_options() ::
  [
    checked: boolean(),
    indeterminate: boolean(),
    signal: PlaywrightEx.AbortSignal.t(),
    timeout: number() | :infinity
  ]
  | %{
      optional(:checked) => boolean(),
      optional(:indeterminate) => boolean(),
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of not_to_be_checked/2, see its docs.

not_to_be_disabled_options()

@type not_to_be_disabled_options() ::
  [signal: PlaywrightEx.AbortSignal.t(), timeout: number() | :infinity]
  | %{
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of not_to_be_disabled/2, see its docs.

not_to_be_editable_options()

@type not_to_be_editable_options() ::
  [
    editable: boolean(),
    signal: PlaywrightEx.AbortSignal.t(),
    timeout: number() | :infinity
  ]
  | %{
      optional(:editable) => boolean(),
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of not_to_be_editable/2, see its docs.

not_to_be_empty_options()

@type not_to_be_empty_options() ::
  [signal: PlaywrightEx.AbortSignal.t(), timeout: number() | :infinity]
  | %{
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of not_to_be_empty/2, see its docs.

not_to_be_enabled_options()

@type not_to_be_enabled_options() ::
  [
    enabled: boolean(),
    signal: PlaywrightEx.AbortSignal.t(),
    timeout: number() | :infinity
  ]
  | %{
      optional(:enabled) => boolean(),
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of not_to_be_enabled/2, see its docs.

not_to_be_focused_options()

@type not_to_be_focused_options() ::
  [signal: PlaywrightEx.AbortSignal.t(), timeout: number() | :infinity]
  | %{
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of not_to_be_focused/2, see its docs.

not_to_be_hidden_options()

@type not_to_be_hidden_options() ::
  [signal: PlaywrightEx.AbortSignal.t(), timeout: number() | :infinity]
  | %{
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of not_to_be_hidden/2, see its docs.

not_to_be_in_viewport_options()

@type not_to_be_in_viewport_options() ::
  [
    ratio: number(),
    signal: PlaywrightEx.AbortSignal.t(),
    timeout: number() | :infinity
  ]
  | %{
      optional(:ratio) => number(),
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of not_to_be_in_viewport/2, see its docs.

not_to_be_visible_options()

@type not_to_be_visible_options() ::
  [
    signal: PlaywrightEx.AbortSignal.t(),
    timeout: number() | :infinity,
    visible: boolean()
  ]
  | %{
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity,
      optional(:visible) => boolean()
    }

Options of not_to_be_visible/2, see its docs.

not_to_contain_class_options()

@type not_to_contain_class_options() ::
  [signal: PlaywrightEx.AbortSignal.t(), timeout: number() | :infinity]
  | %{
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of not_to_contain_class/3, see its docs.

not_to_contain_text_options()

@type not_to_contain_text_options() ::
  [
    ignore_case: boolean(),
    signal: PlaywrightEx.AbortSignal.t(),
    timeout: number() | :infinity,
    use_inner_text: boolean()
  ]
  | %{
      optional(:ignore_case) => boolean(),
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity,
      optional(:use_inner_text) => boolean()
    }

Options of not_to_contain_text/3, see its docs.

not_to_have_accessible_description_options()

@type not_to_have_accessible_description_options() ::
  [
    ignore_case: boolean(),
    signal: PlaywrightEx.AbortSignal.t(),
    timeout: number() | :infinity
  ]
  | %{
      optional(:ignore_case) => boolean(),
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of not_to_have_accessible_description/3, see its docs.

not_to_have_accessible_error_message_options()

@type not_to_have_accessible_error_message_options() ::
  [
    ignore_case: boolean(),
    signal: PlaywrightEx.AbortSignal.t(),
    timeout: number() | :infinity
  ]
  | %{
      optional(:ignore_case) => boolean(),
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of not_to_have_accessible_error_message/3, see its docs.

not_to_have_accessible_name_options()

@type not_to_have_accessible_name_options() ::
  [
    ignore_case: boolean(),
    signal: PlaywrightEx.AbortSignal.t(),
    timeout: number() | :infinity
  ]
  | %{
      optional(:ignore_case) => boolean(),
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of not_to_have_accessible_name/3, see its docs.

not_to_have_attribute_options()

@type not_to_have_attribute_options() ::
  [
    ignore_case: boolean(),
    signal: PlaywrightEx.AbortSignal.t(),
    timeout: number() | :infinity
  ]
  | %{
      optional(:ignore_case) => boolean(),
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of not_to_have_attribute/4, see its docs.

not_to_have_class_options()

@type not_to_have_class_options() ::
  [signal: PlaywrightEx.AbortSignal.t(), timeout: number() | :infinity]
  | %{
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of not_to_have_class/3, see its docs.

not_to_have_count_options()

@type not_to_have_count_options() ::
  [signal: PlaywrightEx.AbortSignal.t(), timeout: number() | :infinity]
  | %{
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of not_to_have_count/3, see its docs.

not_to_have_css_options()

@type not_to_have_css_options() ::
  [
    pseudo: :before | :after,
    signal: PlaywrightEx.AbortSignal.t(),
    timeout: number() | :infinity
  ]
  | %{
      optional(:pseudo) => :before | :after,
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of not_to_have_css/4, see its docs.

not_to_have_id_options()

@type not_to_have_id_options() ::
  [signal: PlaywrightEx.AbortSignal.t(), timeout: number() | :infinity]
  | %{
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of not_to_have_id/3, see its docs.

not_to_have_js_property_options()

@type not_to_have_js_property_options() ::
  [signal: PlaywrightEx.AbortSignal.t(), timeout: number() | :infinity]
  | %{
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of not_to_have_js_property/4, see its docs.

not_to_have_role_options()

@type not_to_have_role_options() ::
  [signal: PlaywrightEx.AbortSignal.t(), timeout: number() | :infinity]
  | %{
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of not_to_have_role/3, see its docs.

not_to_have_screenshot_options()

@type not_to_have_screenshot_options() ::
  [
    path: String.t(),
    animations: :disabled | :allow,
    caret: :hide | :initial,
    mask: [PlaywrightEx.Locator.t()],
    mask_color: String.t(),
    max_diff_pixel_ratio: number(),
    max_diff_pixels: integer(),
    omit_background: boolean(),
    scale: :css | :device,
    signal: PlaywrightEx.AbortSignal.t(),
    style_path: String.t() | [String.t()],
    threshold: number(),
    timeout: number() | :infinity,
    clip: %{x: number(), y: number(), width: number(), height: number()},
    full_page: boolean()
  ]
  | %{
      optional(:path) => String.t(),
      optional(:animations) => :disabled | :allow,
      optional(:caret) => :hide | :initial,
      optional(:mask) => [PlaywrightEx.Locator.t()],
      optional(:mask_color) => String.t(),
      optional(:max_diff_pixel_ratio) => number(),
      optional(:max_diff_pixels) => integer(),
      optional(:omit_background) => boolean(),
      optional(:scale) => :css | :device,
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:style_path) => String.t() | [String.t()],
      optional(:threshold) => number(),
      optional(:timeout) => number() | :infinity,
      optional(:clip) => %{
        x: number(),
        y: number(),
        width: number(),
        height: number()
      },
      optional(:full_page) => boolean()
    }

Options of not_to_have_screenshot/2, see its docs.

not_to_have_text_options()

@type not_to_have_text_options() ::
  [
    ignore_case: boolean(),
    signal: PlaywrightEx.AbortSignal.t(),
    timeout: number() | :infinity,
    use_inner_text: boolean()
  ]
  | %{
      optional(:ignore_case) => boolean(),
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity,
      optional(:use_inner_text) => boolean()
    }

Options of not_to_have_text/3, see its docs.

not_to_have_title_options()

@type not_to_have_title_options() ::
  [signal: PlaywrightEx.AbortSignal.t(), timeout: number() | :infinity]
  | %{
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of not_to_have_title/3, see its docs.

not_to_have_url_options()

@type not_to_have_url_options() ::
  [
    ignore_case: boolean(),
    signal: PlaywrightEx.AbortSignal.t(),
    timeout: number() | :infinity
  ]
  | %{
      optional(:ignore_case) => boolean(),
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of not_to_have_url/3, see its docs.

not_to_have_value_options()

@type not_to_have_value_options() ::
  [signal: PlaywrightEx.AbortSignal.t(), timeout: number() | :infinity]
  | %{
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of not_to_have_value/3, see its docs.

not_to_have_values_options()

@type not_to_have_values_options() ::
  [signal: PlaywrightEx.AbortSignal.t(), timeout: number() | :infinity]
  | %{
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of not_to_have_values/3, see its docs.

not_to_match_aria_snapshot_options()

@type not_to_match_aria_snapshot_options() ::
  [
    path: String.t(),
    signal: PlaywrightEx.AbortSignal.t(),
    timeout: number() | :infinity
  ]
  | %{
      optional(:path) => String.t(),
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of not_to_match_aria_snapshot/3, see its docs.

t()

A negated receiver of any matcher.

t(actual)

@type t(actual) :: %PlaywrightEx.Expect{actual: actual, isNot: true}

A negated receiver (not_/1): expect(actual).not in JS.

to_be_attached_options()

@type to_be_attached_options() ::
  [
    attached: boolean(),
    signal: PlaywrightEx.AbortSignal.t(),
    timeout: number() | :infinity
  ]
  | %{
      optional(:attached) => boolean(),
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of to_be_attached/2, see its docs.

to_be_checked_options()

@type to_be_checked_options() ::
  [
    checked: boolean(),
    indeterminate: boolean(),
    signal: PlaywrightEx.AbortSignal.t(),
    timeout: number() | :infinity
  ]
  | %{
      optional(:checked) => boolean(),
      optional(:indeterminate) => boolean(),
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of to_be_checked/2, see its docs.

to_be_disabled_options()

@type to_be_disabled_options() ::
  [signal: PlaywrightEx.AbortSignal.t(), timeout: number() | :infinity]
  | %{
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of to_be_disabled/2, see its docs.

to_be_editable_options()

@type to_be_editable_options() ::
  [
    editable: boolean(),
    signal: PlaywrightEx.AbortSignal.t(),
    timeout: number() | :infinity
  ]
  | %{
      optional(:editable) => boolean(),
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of to_be_editable/2, see its docs.

to_be_empty_options()

@type to_be_empty_options() ::
  [signal: PlaywrightEx.AbortSignal.t(), timeout: number() | :infinity]
  | %{
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of to_be_empty/2, see its docs.

to_be_enabled_options()

@type to_be_enabled_options() ::
  [
    enabled: boolean(),
    signal: PlaywrightEx.AbortSignal.t(),
    timeout: number() | :infinity
  ]
  | %{
      optional(:enabled) => boolean(),
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of to_be_enabled/2, see its docs.

to_be_focused_options()

@type to_be_focused_options() ::
  [signal: PlaywrightEx.AbortSignal.t(), timeout: number() | :infinity]
  | %{
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of to_be_focused/2, see its docs.

to_be_hidden_options()

@type to_be_hidden_options() ::
  [signal: PlaywrightEx.AbortSignal.t(), timeout: number() | :infinity]
  | %{
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of to_be_hidden/2, see its docs.

to_be_in_viewport_options()

@type to_be_in_viewport_options() ::
  [
    ratio: number(),
    signal: PlaywrightEx.AbortSignal.t(),
    timeout: number() | :infinity
  ]
  | %{
      optional(:ratio) => number(),
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of to_be_in_viewport/2, see its docs.

to_be_visible_options()

@type to_be_visible_options() ::
  [
    signal: PlaywrightEx.AbortSignal.t(),
    timeout: number() | :infinity,
    visible: boolean()
  ]
  | %{
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity,
      optional(:visible) => boolean()
    }

Options of to_be_visible/2, see its docs.

to_contain_class_options()

@type to_contain_class_options() ::
  [signal: PlaywrightEx.AbortSignal.t(), timeout: number() | :infinity]
  | %{
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of to_contain_class/3, see its docs.

to_contain_text_options()

@type to_contain_text_options() ::
  [
    ignore_case: boolean(),
    signal: PlaywrightEx.AbortSignal.t(),
    timeout: number() | :infinity,
    use_inner_text: boolean()
  ]
  | %{
      optional(:ignore_case) => boolean(),
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity,
      optional(:use_inner_text) => boolean()
    }

Options of to_contain_text/3, see its docs.

to_have_accessible_description_options()

@type to_have_accessible_description_options() ::
  [
    ignore_case: boolean(),
    signal: PlaywrightEx.AbortSignal.t(),
    timeout: number() | :infinity
  ]
  | %{
      optional(:ignore_case) => boolean(),
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of to_have_accessible_description/3, see its docs.

to_have_accessible_error_message_options()

@type to_have_accessible_error_message_options() ::
  [
    ignore_case: boolean(),
    signal: PlaywrightEx.AbortSignal.t(),
    timeout: number() | :infinity
  ]
  | %{
      optional(:ignore_case) => boolean(),
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of to_have_accessible_error_message/3, see its docs.

to_have_accessible_name_options()

@type to_have_accessible_name_options() ::
  [
    ignore_case: boolean(),
    signal: PlaywrightEx.AbortSignal.t(),
    timeout: number() | :infinity
  ]
  | %{
      optional(:ignore_case) => boolean(),
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of to_have_accessible_name/3, see its docs.

to_have_attribute_options()

@type to_have_attribute_options() ::
  [
    ignore_case: boolean(),
    signal: PlaywrightEx.AbortSignal.t(),
    timeout: number() | :infinity
  ]
  | %{
      optional(:ignore_case) => boolean(),
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of to_have_attribute/4, see its docs.

to_have_class_options()

@type to_have_class_options() ::
  [signal: PlaywrightEx.AbortSignal.t(), timeout: number() | :infinity]
  | %{
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of to_have_class/3, see its docs.

to_have_count_options()

@type to_have_count_options() ::
  [signal: PlaywrightEx.AbortSignal.t(), timeout: number() | :infinity]
  | %{
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of to_have_count/3, see its docs.

to_have_css_options()

@type to_have_css_options() ::
  [
    pseudo: :before | :after,
    signal: PlaywrightEx.AbortSignal.t(),
    timeout: number() | :infinity
  ]
  | %{
      optional(:pseudo) => :before | :after,
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of to_have_css/4, see its docs.

to_have_id_options()

@type to_have_id_options() ::
  [signal: PlaywrightEx.AbortSignal.t(), timeout: number() | :infinity]
  | %{
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of to_have_id/3, see its docs.

to_have_js_property_options()

@type to_have_js_property_options() ::
  [signal: PlaywrightEx.AbortSignal.t(), timeout: number() | :infinity]
  | %{
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of to_have_js_property/4, see its docs.

to_have_role_options()

@type to_have_role_options() ::
  [signal: PlaywrightEx.AbortSignal.t(), timeout: number() | :infinity]
  | %{
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of to_have_role/3, see its docs.

to_have_screenshot_options()

@type to_have_screenshot_options() ::
  [
    path: String.t(),
    animations: :disabled | :allow,
    caret: :hide | :initial,
    mask: [PlaywrightEx.Locator.t()],
    mask_color: String.t(),
    max_diff_pixel_ratio: number(),
    max_diff_pixels: integer(),
    omit_background: boolean(),
    scale: :css | :device,
    signal: PlaywrightEx.AbortSignal.t(),
    style_path: String.t() | [String.t()],
    threshold: number(),
    timeout: number() | :infinity,
    clip: %{x: number(), y: number(), width: number(), height: number()},
    full_page: boolean()
  ]
  | %{
      optional(:path) => String.t(),
      optional(:animations) => :disabled | :allow,
      optional(:caret) => :hide | :initial,
      optional(:mask) => [PlaywrightEx.Locator.t()],
      optional(:mask_color) => String.t(),
      optional(:max_diff_pixel_ratio) => number(),
      optional(:max_diff_pixels) => integer(),
      optional(:omit_background) => boolean(),
      optional(:scale) => :css | :device,
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:style_path) => String.t() | [String.t()],
      optional(:threshold) => number(),
      optional(:timeout) => number() | :infinity,
      optional(:clip) => %{
        x: number(),
        y: number(),
        width: number(),
        height: number()
      },
      optional(:full_page) => boolean()
    }

Options of to_have_screenshot/2, see its docs.

to_have_text_options()

@type to_have_text_options() ::
  [
    ignore_case: boolean(),
    signal: PlaywrightEx.AbortSignal.t(),
    timeout: number() | :infinity,
    use_inner_text: boolean()
  ]
  | %{
      optional(:ignore_case) => boolean(),
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity,
      optional(:use_inner_text) => boolean()
    }

Options of to_have_text/3, see its docs.

to_have_title_options()

@type to_have_title_options() ::
  [signal: PlaywrightEx.AbortSignal.t(), timeout: number() | :infinity]
  | %{
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of to_have_title/3, see its docs.

to_have_url_options()

@type to_have_url_options() ::
  [
    ignore_case: boolean(),
    signal: PlaywrightEx.AbortSignal.t(),
    timeout: number() | :infinity
  ]
  | %{
      optional(:ignore_case) => boolean(),
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of to_have_url/3, see its docs.

to_have_value_options()

@type to_have_value_options() ::
  [signal: PlaywrightEx.AbortSignal.t(), timeout: number() | :infinity]
  | %{
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of to_have_value/3, see its docs.

to_have_values_options()

@type to_have_values_options() ::
  [signal: PlaywrightEx.AbortSignal.t(), timeout: number() | :infinity]
  | %{
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of to_have_values/3, see its docs.

to_match_aria_snapshot_options()

@type to_match_aria_snapshot_options() ::
  [
    path: String.t(),
    signal: PlaywrightEx.AbortSignal.t(),
    timeout: number() | :infinity
  ]
  | %{
      optional(:path) => String.t(),
      optional(:signal) => PlaywrightEx.AbortSignal.t(),
      optional(:timeout) => number() | :infinity
    }

Options of to_match_aria_snapshot/3, see its docs.

Functions

not_(actual)

@spec not_(actual) :: t(actual)
when actual:
       PlaywrightEx.Locator.t()
       | PlaywrightEx.Page.t()
       | PlaywrightEx.APIResponse.t()

Makes the assertion check for the opposite condition.

Usage

For example, this code tests that the Locator doesn't contain text "error":

locator |> Expect.not_() |> Expect.to_contain_text!("error")

In Elixir, not_/1 wraps the receiver, which every matcher takes too: locator |> Expect.not_() |> Expect.to_contain_text("error") is Expect.not_to_contain_text(locator, "error"). As JS has no expect(x).not.not, a negated receiver is not negated again: not_/1 and the not_to_* matchers raise ArgumentError for one.

Since Playwright 1.20.

not_to_be_attached(locator, options \\ [])

@spec not_to_be_attached(PlaywrightEx.Locator.t(), not_to_be_attached_options()) ::
  :ok | {:error, PlaywrightEx.error()}

The opposite of to_be_attached/2: expect(x).not.toBeAttached(...) in JS.

Since Playwright 1.33.

Options

  • :attached (boolean/0)

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

not_to_be_attached!(locator, options \\ [])

@spec not_to_be_attached!(PlaywrightEx.Locator.t(), not_to_be_attached_options()) ::
  :ok

Like not_to_be_attached/2, but raises PlaywrightEx.ExpectError when the expectation is not met.

not_to_be_checked(locator, options \\ [])

@spec not_to_be_checked(PlaywrightEx.Locator.t(), not_to_be_checked_options()) ::
  :ok | {:error, PlaywrightEx.error()}

The opposite of to_be_checked/2: expect(x).not.toBeChecked(...) in JS.

Since Playwright 1.20.

Options

  • :checked (boolean/0) - Provides state to assert for. Asserts for input to be checked by default. This option can't be used when :indeterminate is set to true.

  • :indeterminate (boolean/0) - Since Playwright 1.50. Asserts that the element is in the indeterminate (mixed) state. Only supported for checkboxes and radio buttons. This option can't be true when :checked is provided.

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

not_to_be_checked!(locator, options \\ [])

@spec not_to_be_checked!(PlaywrightEx.Locator.t(), not_to_be_checked_options()) :: :ok

Like not_to_be_checked/2, but raises PlaywrightEx.ExpectError when the expectation is not met.

not_to_be_disabled(locator, options \\ [])

@spec not_to_be_disabled(PlaywrightEx.Locator.t(), not_to_be_disabled_options()) ::
  :ok | {:error, PlaywrightEx.error()}

The opposite of to_be_disabled/2: expect(x).not.toBeDisabled(...) in JS.

Since Playwright 1.20.

Options

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

not_to_be_disabled!(locator, options \\ [])

@spec not_to_be_disabled!(PlaywrightEx.Locator.t(), not_to_be_disabled_options()) ::
  :ok

Like not_to_be_disabled/2, but raises PlaywrightEx.ExpectError when the expectation is not met.

not_to_be_editable(locator, options \\ [])

@spec not_to_be_editable(PlaywrightEx.Locator.t(), not_to_be_editable_options()) ::
  :ok | {:error, PlaywrightEx.error()}

The opposite of to_be_editable/2: expect(x).not.toBeEditable(...) in JS.

Since Playwright 1.20.

Options

  • :editable (boolean/0) - Since Playwright 1.26.

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

not_to_be_editable!(locator, options \\ [])

@spec not_to_be_editable!(PlaywrightEx.Locator.t(), not_to_be_editable_options()) ::
  :ok

Like not_to_be_editable/2, but raises PlaywrightEx.ExpectError when the expectation is not met.

not_to_be_empty(locator, options \\ [])

@spec not_to_be_empty(PlaywrightEx.Locator.t(), not_to_be_empty_options()) ::
  :ok | {:error, PlaywrightEx.error()}

The opposite of to_be_empty/2: expect(x).not.toBeEmpty(...) in JS.

Since Playwright 1.20.

Options

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

not_to_be_empty!(locator, options \\ [])

@spec not_to_be_empty!(PlaywrightEx.Locator.t(), not_to_be_empty_options()) :: :ok

Like not_to_be_empty/2, but raises PlaywrightEx.ExpectError when the expectation is not met.

not_to_be_enabled(locator, options \\ [])

@spec not_to_be_enabled(PlaywrightEx.Locator.t(), not_to_be_enabled_options()) ::
  :ok | {:error, PlaywrightEx.error()}

The opposite of to_be_enabled/2: expect(x).not.toBeEnabled(...) in JS.

Since Playwright 1.20.

Options

  • :enabled (boolean/0) - Since Playwright 1.26.

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

not_to_be_enabled!(locator, options \\ [])

@spec not_to_be_enabled!(PlaywrightEx.Locator.t(), not_to_be_enabled_options()) :: :ok

Like not_to_be_enabled/2, but raises PlaywrightEx.ExpectError when the expectation is not met.

not_to_be_focused(locator, options \\ [])

@spec not_to_be_focused(PlaywrightEx.Locator.t(), not_to_be_focused_options()) ::
  :ok | {:error, PlaywrightEx.error()}

The opposite of to_be_focused/2: expect(x).not.toBeFocused(...) in JS.

Since Playwright 1.20.

Options

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

not_to_be_focused!(locator, options \\ [])

@spec not_to_be_focused!(PlaywrightEx.Locator.t(), not_to_be_focused_options()) :: :ok

Like not_to_be_focused/2, but raises PlaywrightEx.ExpectError when the expectation is not met.

not_to_be_hidden(locator, options \\ [])

@spec not_to_be_hidden(PlaywrightEx.Locator.t(), not_to_be_hidden_options()) ::
  :ok | {:error, PlaywrightEx.error()}

The opposite of to_be_hidden/2: expect(x).not.toBeHidden(...) in JS.

Since Playwright 1.20.

Options

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

not_to_be_hidden!(locator, options \\ [])

@spec not_to_be_hidden!(PlaywrightEx.Locator.t(), not_to_be_hidden_options()) :: :ok

Like not_to_be_hidden/2, but raises PlaywrightEx.ExpectError when the expectation is not met.

not_to_be_in_viewport(locator, options \\ [])

@spec not_to_be_in_viewport(PlaywrightEx.Locator.t(), not_to_be_in_viewport_options()) ::
  :ok | {:error, PlaywrightEx.error()}

The opposite of to_be_in_viewport/2: expect(x).not.toBeInViewport(...) in JS.

Since Playwright 1.31.

Options

  • :ratio (number/0) - The minimal ratio of the element to intersect viewport. If equals to 0, then element should intersect viewport at any positive ratio. Defaults to 0.

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

not_to_be_in_viewport!(locator, options \\ [])

@spec not_to_be_in_viewport!(
  PlaywrightEx.Locator.t(),
  not_to_be_in_viewport_options()
) :: :ok

Like not_to_be_in_viewport/2, but raises PlaywrightEx.ExpectError when the expectation is not met.

not_to_be_ok(api_response)

@spec not_to_be_ok(PlaywrightEx.APIResponse.t()) ::
  :ok | {:error, PlaywrightEx.error()}

The opposite of to_be_ok/1: expect(x).not.toBeOK(...) in JS.

Since Playwright 1.18.

not_to_be_ok!(api_response)

@spec not_to_be_ok!(PlaywrightEx.APIResponse.t()) :: :ok

Like not_to_be_ok/1, but raises PlaywrightEx.ExpectError when the expectation is not met.

not_to_be_visible(locator, options \\ [])

@spec not_to_be_visible(PlaywrightEx.Locator.t(), not_to_be_visible_options()) ::
  :ok | {:error, PlaywrightEx.error()}

The opposite of to_be_visible/2: expect(x).not.toBeVisible(...) in JS.

Since Playwright 1.20.

Options

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

  • :visible (boolean/0) - Since Playwright 1.26.

not_to_be_visible!(locator, options \\ [])

@spec not_to_be_visible!(PlaywrightEx.Locator.t(), not_to_be_visible_options()) :: :ok

Like not_to_be_visible/2, but raises PlaywrightEx.ExpectError when the expectation is not met.

not_to_contain_class(locator, expected, options \\ [])

@spec not_to_contain_class(
  PlaywrightEx.Locator.t(),
  String.t() | [String.t()],
  not_to_contain_class_options()
) :: :ok | {:error, PlaywrightEx.error()}

The opposite of to_contain_class/3: expect(x).not.toContainClass(...) in JS.

Since Playwright 1.52.

Arguments

  • expected - A string containing expected class names, separated by spaces, or a list of such strings to assert multiple elements.

Options

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

not_to_contain_class!(locator, expected, options \\ [])

@spec not_to_contain_class!(
  PlaywrightEx.Locator.t(),
  String.t() | [String.t()],
  not_to_contain_class_options()
) :: :ok

Like not_to_contain_class/3, but raises PlaywrightEx.ExpectError when the expectation is not met.

not_to_contain_text(locator, expected, options \\ [])

The opposite of to_contain_text/3: expect(x).not.toContainText(...) in JS.

Since Playwright 1.20.

Arguments

  • expected - Expected substring or RegExp or a list of those.

Options

  • :ignore_case (boolean/0) - Since Playwright 1.23. Whether to perform case-insensitive match. :ignore_case option takes precedence over the corresponding regular expression flag if specified.

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

  • :use_inner_text (boolean/0) - Whether to use element.innerText instead of element.textContent when retrieving DOM node text.

not_to_contain_text!(locator, expected, options \\ [])

Like not_to_contain_text/3, but raises PlaywrightEx.ExpectError when the expectation is not met.

not_to_have_accessible_description(locator, description, options \\ [])

@spec not_to_have_accessible_description(
  PlaywrightEx.Locator.t(),
  String.t() | Regex.t() | PlaywrightEx.RegExp.t(),
  not_to_have_accessible_description_options()
) :: :ok | {:error, PlaywrightEx.error()}

The opposite of to_have_accessible_description/3: expect(x).not.toHaveAccessibleDescription(...) in JS.

Since Playwright 1.44.

Arguments

  • description - Expected accessible description.

Options

  • :ignore_case (boolean/0) - Whether to perform case-insensitive match. :ignore_case option takes precedence over the corresponding regular expression flag if specified.

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

not_to_have_accessible_description!(locator, description, options \\ [])

@spec not_to_have_accessible_description!(
  PlaywrightEx.Locator.t(),
  String.t() | Regex.t() | PlaywrightEx.RegExp.t(),
  not_to_have_accessible_description_options()
) :: :ok

Like not_to_have_accessible_description/3, but raises PlaywrightEx.ExpectError when the expectation is not met.

not_to_have_accessible_error_message(locator, error_message, options \\ [])

@spec not_to_have_accessible_error_message(
  PlaywrightEx.Locator.t(),
  String.t() | Regex.t() | PlaywrightEx.RegExp.t(),
  not_to_have_accessible_error_message_options()
) :: :ok | {:error, PlaywrightEx.error()}

The opposite of to_have_accessible_error_message/3: expect(x).not.toHaveAccessibleErrorMessage(...) in JS.

Since Playwright 1.50.

Arguments

  • error_message - Expected accessible error message.

Options

  • :ignore_case (boolean/0) - Whether to perform case-insensitive match. :ignore_case option takes precedence over the corresponding regular expression flag if specified.

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

not_to_have_accessible_error_message!(locator, error_message, options \\ [])

@spec not_to_have_accessible_error_message!(
  PlaywrightEx.Locator.t(),
  String.t() | Regex.t() | PlaywrightEx.RegExp.t(),
  not_to_have_accessible_error_message_options()
) :: :ok

Like not_to_have_accessible_error_message/3, but raises PlaywrightEx.ExpectError when the expectation is not met.

not_to_have_accessible_name(locator, name, options \\ [])

@spec not_to_have_accessible_name(
  PlaywrightEx.Locator.t(),
  String.t() | Regex.t() | PlaywrightEx.RegExp.t(),
  not_to_have_accessible_name_options()
) :: :ok | {:error, PlaywrightEx.error()}

The opposite of to_have_accessible_name/3: expect(x).not.toHaveAccessibleName(...) in JS.

Since Playwright 1.44.

Arguments

  • name - Expected accessible name.

Options

  • :ignore_case (boolean/0) - Whether to perform case-insensitive match. :ignore_case option takes precedence over the corresponding regular expression flag if specified.

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

not_to_have_accessible_name!(locator, name, options \\ [])

@spec not_to_have_accessible_name!(
  PlaywrightEx.Locator.t(),
  String.t() | Regex.t() | PlaywrightEx.RegExp.t(),
  not_to_have_accessible_name_options()
) :: :ok

Like not_to_have_accessible_name/3, but raises PlaywrightEx.ExpectError when the expectation is not met.

not_to_have_attribute(locator, name, value \\ nil, options \\ [])

@spec not_to_have_attribute(
  PlaywrightEx.Locator.t(),
  String.t(),
  String.t() | Regex.t() | PlaywrightEx.RegExp.t() | nil,
  not_to_have_attribute_options()
) :: :ok | {:error, PlaywrightEx.error()}

The opposite of to_have_attribute/4: expect(x).not.toHaveAttribute(...) in JS.

Since Playwright 1.20.

Arguments

  • name - Attribute name.
  • value - Expected attribute value.

Options

The options may take the place of value, which is then nil.

  • :ignore_case (boolean/0) - Since Playwright 1.40. Whether to perform case-insensitive match. :ignore_case option takes precedence over the corresponding regular expression flag if specified.

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

not_to_have_attribute!(locator, name, value \\ nil, options \\ [])

@spec not_to_have_attribute!(
  PlaywrightEx.Locator.t(),
  String.t(),
  String.t() | Regex.t() | PlaywrightEx.RegExp.t() | nil,
  not_to_have_attribute_options()
) :: :ok

Like not_to_have_attribute/4, but raises PlaywrightEx.ExpectError when the expectation is not met.

not_to_have_class(locator, expected, options \\ [])

The opposite of to_have_class/3: expect(x).not.toHaveClass(...) in JS.

Since Playwright 1.20.

Arguments

  • expected - Expected class or RegExp or a list of those.

Options

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

not_to_have_class!(locator, expected, options \\ [])

Like not_to_have_class/3, but raises PlaywrightEx.ExpectError when the expectation is not met.

not_to_have_count(locator, count, options \\ [])

@spec not_to_have_count(
  PlaywrightEx.Locator.t(),
  integer(),
  not_to_have_count_options()
) ::
  :ok | {:error, PlaywrightEx.error()}

The opposite of to_have_count/3: expect(x).not.toHaveCount(...) in JS.

Since Playwright 1.20.

Arguments

  • count - Expected count.

Options

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

not_to_have_count!(locator, count, options \\ [])

@spec not_to_have_count!(
  PlaywrightEx.Locator.t(),
  integer(),
  not_to_have_count_options()
) :: :ok

Like not_to_have_count/3, but raises PlaywrightEx.ExpectError when the expectation is not met.

not_to_have_css(locator, name, value, options \\ [])

@spec not_to_have_css(
  PlaywrightEx.Locator.t(),
  String.t(),
  String.t() | Regex.t() | PlaywrightEx.RegExp.t(),
  not_to_have_css_options()
) :: :ok | {:error, PlaywrightEx.error()}

The opposite of to_have_css/4: expect(x).not.toHaveCSS(...) in JS.

Since Playwright 1.20.

Arguments

  • name - CSS property name.
  • value - CSS property value.

Options

  • :pseudo (:before | :after) - Since Playwright 1.60. Pseudo-element to read computed styles from.

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

not_to_have_css!(locator, name, value, options \\ [])

Like not_to_have_css/4, but raises PlaywrightEx.ExpectError when the expectation is not met.

not_to_have_id(locator, id, options \\ [])

@spec not_to_have_id(
  PlaywrightEx.Locator.t(),
  String.t() | Regex.t() | PlaywrightEx.RegExp.t(),
  not_to_have_id_options()
) :: :ok | {:error, PlaywrightEx.error()}

The opposite of to_have_id/3: expect(x).not.toHaveId(...) in JS.

Since Playwright 1.20.

Arguments

  • id - Element id.

Options

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

not_to_have_id!(locator, id, options \\ [])

@spec not_to_have_id!(
  PlaywrightEx.Locator.t(),
  String.t() | Regex.t() | PlaywrightEx.RegExp.t(),
  not_to_have_id_options()
) :: :ok

Like not_to_have_id/3, but raises PlaywrightEx.ExpectError when the expectation is not met.

not_to_have_js_property(locator, name, value, options \\ [])

@spec not_to_have_js_property(
  PlaywrightEx.Locator.t(),
  String.t(),
  term(),
  not_to_have_js_property_options()
) :: :ok | {:error, PlaywrightEx.error()}

The opposite of to_have_js_property/4: expect(x).not.toHaveJSProperty(...) in JS.

Since Playwright 1.20.

Arguments

  • name - Property name.
  • value - Property value.

Options

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

not_to_have_js_property!(locator, name, value, options \\ [])

@spec not_to_have_js_property!(
  PlaywrightEx.Locator.t(),
  String.t(),
  term(),
  not_to_have_js_property_options()
) :: :ok

Like not_to_have_js_property/4, but raises PlaywrightEx.ExpectError when the expectation is not met.

not_to_have_role(locator, role, options \\ [])

@spec not_to_have_role(
  PlaywrightEx.Locator.t(),
  :alert
  | :alertdialog
  | :application
  | :article
  | :banner
  | :blockquote
  | :button
  | :caption
  | :cell
  | :checkbox
  | :code
  | :columnheader
  | :combobox
  | :complementary
  | :contentinfo
  | :definition
  | :deletion
  | :dialog
  | :directory
  | :document
  | :emphasis
  | :feed
  | :figure
  | :form
  | :generic
  | :grid
  | :gridcell
  | :group
  | :heading
  | :img
  | :insertion
  | :link
  | :list
  | :listbox
  | :listitem
  | :log
  | :main
  | :marquee
  | :math
  | :meter
  | :menu
  | :menubar
  | :menuitem
  | :menuitemcheckbox
  | :menuitemradio
  | :navigation
  | :none
  | :note
  | :option
  | :paragraph
  | :presentation
  | :progressbar
  | :radio
  | :radiogroup
  | :region
  | :row
  | :rowgroup
  | :rowheader
  | :scrollbar
  | :search
  | :searchbox
  | :separator
  | :slider
  | :spinbutton
  | :status
  | :strong
  | :subscript
  | :superscript
  | :switch
  | :tab
  | :table
  | :tablist
  | :tabpanel
  | :term
  | :textbox
  | :time
  | :timer
  | :toolbar
  | :tooltip
  | :tree
  | :treegrid
  | :treeitem,
  not_to_have_role_options()
) :: :ok | {:error, PlaywrightEx.error()}

The opposite of to_have_role/3: expect(x).not.toHaveRole(...) in JS.

Since Playwright 1.44.

Arguments

  • role - Required aria role.

Options

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

not_to_have_role!(locator, role, options \\ [])

@spec not_to_have_role!(
  PlaywrightEx.Locator.t(),
  :alert
  | :alertdialog
  | :application
  | :article
  | :banner
  | :blockquote
  | :button
  | :caption
  | :cell
  | :checkbox
  | :code
  | :columnheader
  | :combobox
  | :complementary
  | :contentinfo
  | :definition
  | :deletion
  | :dialog
  | :directory
  | :document
  | :emphasis
  | :feed
  | :figure
  | :form
  | :generic
  | :grid
  | :gridcell
  | :group
  | :heading
  | :img
  | :insertion
  | :link
  | :list
  | :listbox
  | :listitem
  | :log
  | :main
  | :marquee
  | :math
  | :meter
  | :menu
  | :menubar
  | :menuitem
  | :menuitemcheckbox
  | :menuitemradio
  | :navigation
  | :none
  | :note
  | :option
  | :paragraph
  | :presentation
  | :progressbar
  | :radio
  | :radiogroup
  | :region
  | :row
  | :rowgroup
  | :rowheader
  | :scrollbar
  | :search
  | :searchbox
  | :separator
  | :slider
  | :spinbutton
  | :status
  | :strong
  | :subscript
  | :superscript
  | :switch
  | :tab
  | :table
  | :tablist
  | :tabpanel
  | :term
  | :textbox
  | :time
  | :timer
  | :toolbar
  | :tooltip
  | :tree
  | :treegrid
  | :treeitem,
  not_to_have_role_options()
) :: :ok

Like not_to_have_role/3, but raises PlaywrightEx.ExpectError when the expectation is not met.

not_to_have_screenshot(locator_or_page, options \\ [])

@spec not_to_have_screenshot(
  PlaywrightEx.Locator.t() | PlaywrightEx.Page.t(),
  not_to_have_screenshot_options()
) :: :ok | {:error, PlaywrightEx.error()}

The opposite of to_have_screenshot/2: expect(x).not.toHaveScreenshot(...) in JS.

Since Playwright 1.23.

Options

  • :path (String.t/0) - Required. The snapshot file. Must have a .png or .webp extension, the screenshot is captured in the corresponding format. Both formats are lossless. A missing snapshot is written (see :update_snapshots in the configuration of PlaywrightEx.Expect); on failure the -actual, -diff and -previous images are written next to it.

  • :animations (:disabled | :allow) - When set to :disabled, stops CSS animations, CSS transitions and Web Animations. Animations get different treatment depending on their duration:

    • finite animations are fast-forwarded to completion, so they'll fire transitionend event.
    • infinite animations are canceled to initial state, and then played over after the screenshot.

    Defaults to :disabled that disables animations.

  • :caret (:hide | :initial) - When set to :hide, screenshot will hide text caret. When set to :initial, text caret behavior will not be changed. Defaults to :hide.

  • :mask (list of PlaywrightEx.Locator.t/0) - Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink box #FF00FF (customized by :mask_color) that completely covers its bounding box. The mask is also applied to invisible elements, see Matching only visible elements to disable that.

  • :mask_color (String.t/0) - Since Playwright 1.35. Specify the color of the overlay box for masked elements, in CSS color format. Default color is pink #FF00FF.

  • :max_diff_pixel_ratio (number/0) - An acceptable ratio of pixels that are different to the total amount of pixels, between 0 and 1. Default is configurable with config :playwright_ex, :expect (see the configuration in PlaywrightEx.Expect). Note that :threshold defines which pixels are considered different.

  • :max_diff_pixels (integer/0) - An acceptable amount of pixels that could be different. Default is configurable with config :playwright_ex, :expect (see the configuration in PlaywrightEx.Expect). Note that :threshold defines which pixels are considered different.

  • :omit_background (boolean/0) - Hides default white background and allows capturing screenshots with transparency. Not applicable to jpeg images. Defaults to false.

  • :scale (:css | :device) - When set to :css, screenshot will have a single pixel per each css pixel on the page. For high-dpi devices, this will keep screenshots small. Using :device option will produce a single pixel per each device pixel, so screenshots of high-dpi devices will be twice as large or even larger.

    Defaults to :css.

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :style_path (String.t/0 | list of String.t/0) - Since Playwright 1.41. File name containing the stylesheet to apply while making the screenshot. This is where you can hide dynamic elements, make elements invisible or change their properties to help you creating repeatable screenshots. This stylesheet pierces the Shadow DOM and applies to the inner frames.

  • :threshold (number/0) - An acceptable perceived color difference in the YIQ color space between the same pixel in compared images, between zero (strict) and one (lax), default is configurable with config :playwright_ex, :expect (see the configuration in PlaywrightEx.Expect). Defaults to 0.2.

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

  • :clip (map/0) - An object which specifies clipping of the resulting image.

    • :x - x-coordinate of top-left corner of clip area
    • :y - y-coordinate of top-left corner of clip area
    • :width - width of clipping area
    • :height - height of clipping area
  • :full_page (boolean/0) - When true, takes a screenshot of the full scrollable page, instead of the currently visible viewport. Defaults to false.

not_to_have_screenshot!(locator_or_page, options \\ [])

@spec not_to_have_screenshot!(
  PlaywrightEx.Locator.t() | PlaywrightEx.Page.t(),
  not_to_have_screenshot_options()
) :: :ok

Like not_to_have_screenshot/2, but raises PlaywrightEx.ExpectError when the expectation is not met.

not_to_have_text(locator, expected, options \\ [])

The opposite of to_have_text/3: expect(x).not.toHaveText(...) in JS.

Since Playwright 1.20.

Arguments

  • expected - Expected string or RegExp or a list of those.

Options

  • :ignore_case (boolean/0) - Since Playwright 1.23. Whether to perform case-insensitive match. :ignore_case option takes precedence over the corresponding regular expression flag if specified.

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

  • :use_inner_text (boolean/0) - Whether to use element.innerText instead of element.textContent when retrieving DOM node text.

not_to_have_text!(locator, expected, options \\ [])

Like not_to_have_text/3, but raises PlaywrightEx.ExpectError when the expectation is not met.

not_to_have_title(page, title_or_reg_exp, options \\ [])

@spec not_to_have_title(
  PlaywrightEx.Page.t(),
  String.t() | Regex.t() | PlaywrightEx.RegExp.t(),
  not_to_have_title_options()
) :: :ok | {:error, PlaywrightEx.error()}

The opposite of to_have_title/3: expect(x).not.toHaveTitle(...) in JS.

Since Playwright 1.20.

Arguments

  • title_or_reg_exp - Expected title or RegExp.

Options

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

not_to_have_title!(page, title_or_reg_exp, options \\ [])

@spec not_to_have_title!(
  PlaywrightEx.Page.t(),
  String.t() | Regex.t() | PlaywrightEx.RegExp.t(),
  not_to_have_title_options()
) :: :ok

Like not_to_have_title/3, but raises PlaywrightEx.ExpectError when the expectation is not met.

not_to_have_url(page, url, options \\ [])

@spec not_to_have_url(
  PlaywrightEx.Page.t(),
  String.t() | Regex.t() | PlaywrightEx.RegExp.t() | (String.t() -> boolean()),
  not_to_have_url_options()
) :: :ok | {:error, PlaywrightEx.error()}

The opposite of to_have_url/3: expect(x).not.toHaveURL(...) in JS.

Since Playwright 1.20.

Arguments

  • url - Expected URL string, RegExp, or predicate receiving URL to match. When :base_url is provided via the context options and the url argument is a string, the two values are merged via the new URL() constructor and used for the comparison against the current browser URL.

Options

  • :ignore_case (boolean/0) - Since Playwright 1.44. Whether to perform case-insensitive match. :ignore_case option takes precedence over the corresponding regular expression parameter if specified. A provided predicate ignores this flag.

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

not_to_have_url!(page, url, options \\ [])

@spec not_to_have_url!(
  PlaywrightEx.Page.t(),
  String.t() | Regex.t() | PlaywrightEx.RegExp.t() | (String.t() -> boolean()),
  not_to_have_url_options()
) :: :ok

Like not_to_have_url/3, but raises PlaywrightEx.ExpectError when the expectation is not met.

not_to_have_value(locator, value, options \\ [])

@spec not_to_have_value(
  PlaywrightEx.Locator.t(),
  String.t() | Regex.t() | PlaywrightEx.RegExp.t(),
  not_to_have_value_options()
) :: :ok | {:error, PlaywrightEx.error()}

The opposite of to_have_value/3: expect(x).not.toHaveValue(...) in JS.

Since Playwright 1.20.

Arguments

  • value - Expected value.

Options

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

not_to_have_value!(locator, value, options \\ [])

@spec not_to_have_value!(
  PlaywrightEx.Locator.t(),
  String.t() | Regex.t() | PlaywrightEx.RegExp.t(),
  not_to_have_value_options()
) :: :ok

Like not_to_have_value/3, but raises PlaywrightEx.ExpectError when the expectation is not met.

not_to_have_values(locator, values, options \\ [])

@spec not_to_have_values(
  PlaywrightEx.Locator.t(),
  [String.t() | Regex.t() | PlaywrightEx.RegExp.t()],
  not_to_have_values_options()
) :: :ok | {:error, PlaywrightEx.error()}

The opposite of to_have_values/3: expect(x).not.toHaveValues(...) in JS.

Since Playwright 1.23.

Arguments

  • values - Expected options currently selected.

Options

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

not_to_have_values!(locator, values, options \\ [])

@spec not_to_have_values!(
  PlaywrightEx.Locator.t(),
  [String.t() | Regex.t() | PlaywrightEx.RegExp.t()],
  not_to_have_values_options()
) :: :ok

Like not_to_have_values/3, but raises PlaywrightEx.ExpectError when the expectation is not met.

not_to_match_aria_snapshot(locator_or_page, expected \\ nil, options \\ [])

@spec not_to_match_aria_snapshot(
  PlaywrightEx.Locator.t() | PlaywrightEx.Page.t(),
  String.t() | nil,
  not_to_match_aria_snapshot_options()
) :: :ok | {:error, PlaywrightEx.error()}

The opposite of to_match_aria_snapshot/3: expect(x).not.toMatchAriaSnapshot(...) in JS.

Since Playwright 1.49.

Options

The options may take the place of expected, which is then nil.

  • :path (String.t/0) - The snapshot file, in place of expected. Its content is the expected snapshot. A missing snapshot is written, unless :update_snapshots is :none or the matcher is negated. With :update_snapshots set to :all it is always rewritten, with :changed when it differs (see the configuration of PlaywrightEx.Expect).

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

not_to_match_aria_snapshot!(locator_or_page, expected \\ nil, options \\ [])

@spec not_to_match_aria_snapshot!(
  PlaywrightEx.Locator.t() | PlaywrightEx.Page.t(),
  String.t() | nil,
  not_to_match_aria_snapshot_options()
) :: :ok

Like not_to_match_aria_snapshot/3, but raises PlaywrightEx.ExpectError when the expectation is not met.

to_be_attached(locator, options \\ [])

@spec to_be_attached(
  PlaywrightEx.Locator.t() | t(PlaywrightEx.Locator.t()),
  to_be_attached_options()
) ::
  :ok | {:error, PlaywrightEx.error()}

Ensures that Locator points to an element that is connected to a Document or a ShadowRoot.

Usage

Page.get_by_text(page, "Hidden text") |> Expect.to_be_attached!()

Since Playwright 1.33.

Options

  • :attached (boolean/0)

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

to_be_attached!(locator, options \\ [])

@spec to_be_attached!(
  PlaywrightEx.Locator.t() | t(PlaywrightEx.Locator.t()),
  to_be_attached_options()
) ::
  :ok

Like to_be_attached/2, but raises PlaywrightEx.ExpectError when the expectation is not met.

to_be_checked(locator, options \\ [])

@spec to_be_checked(
  PlaywrightEx.Locator.t() | t(PlaywrightEx.Locator.t()),
  to_be_checked_options()
) ::
  :ok | {:error, PlaywrightEx.error()}

Ensures the Locator points to a checked input.

Usage

locator = Page.get_by_label(page, "Subscribe to newsletter")
Expect.to_be_checked!(locator)

Since Playwright 1.20.

Options

  • :checked (boolean/0) - Provides state to assert for. Asserts for input to be checked by default. This option can't be used when :indeterminate is set to true.

  • :indeterminate (boolean/0) - Since Playwright 1.50. Asserts that the element is in the indeterminate (mixed) state. Only supported for checkboxes and radio buttons. This option can't be true when :checked is provided.

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

to_be_checked!(locator, options \\ [])

@spec to_be_checked!(
  PlaywrightEx.Locator.t() | t(PlaywrightEx.Locator.t()),
  to_be_checked_options()
) ::
  :ok

Like to_be_checked/2, but raises PlaywrightEx.ExpectError when the expectation is not met.

to_be_disabled(locator, options \\ [])

@spec to_be_disabled(
  PlaywrightEx.Locator.t() | t(PlaywrightEx.Locator.t()),
  to_be_disabled_options()
) ::
  :ok | {:error, PlaywrightEx.error()}

Ensures the Locator points to a disabled element. Element is disabled if it has "disabled" attribute or is disabled via 'aria-disabled'. Note that only native control elements such as HTML button, input, select, textarea, option, optgroup can be disabled by setting "disabled" attribute. "disabled" attribute on other elements is ignored by the browser.

Usage

locator = Page.locator(page, "button.submit")
Expect.to_be_disabled!(locator)

Since Playwright 1.20.

Options

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

to_be_disabled!(locator, options \\ [])

@spec to_be_disabled!(
  PlaywrightEx.Locator.t() | t(PlaywrightEx.Locator.t()),
  to_be_disabled_options()
) ::
  :ok

Like to_be_disabled/2, but raises PlaywrightEx.ExpectError when the expectation is not met.

to_be_editable(locator, options \\ [])

@spec to_be_editable(
  PlaywrightEx.Locator.t() | t(PlaywrightEx.Locator.t()),
  to_be_editable_options()
) ::
  :ok | {:error, PlaywrightEx.error()}

Ensures the Locator points to an editable element.

Usage

locator = Page.get_by_role(page, :textbox)
Expect.to_be_editable!(locator)

Since Playwright 1.20.

Options

  • :editable (boolean/0) - Since Playwright 1.26.

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

to_be_editable!(locator, options \\ [])

@spec to_be_editable!(
  PlaywrightEx.Locator.t() | t(PlaywrightEx.Locator.t()),
  to_be_editable_options()
) ::
  :ok

Like to_be_editable/2, but raises PlaywrightEx.ExpectError when the expectation is not met.

to_be_empty(locator, options \\ [])

@spec to_be_empty(
  PlaywrightEx.Locator.t() | t(PlaywrightEx.Locator.t()),
  to_be_empty_options()
) ::
  :ok | {:error, PlaywrightEx.error()}

Ensures the Locator points to an empty editable element or to a DOM node that has no text.

Usage

locator = Page.locator(page, "div.warning")
Expect.to_be_empty!(locator)

Since Playwright 1.20.

Options

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

to_be_empty!(locator, options \\ [])

@spec to_be_empty!(
  PlaywrightEx.Locator.t() | t(PlaywrightEx.Locator.t()),
  to_be_empty_options()
) :: :ok

Like to_be_empty/2, but raises PlaywrightEx.ExpectError when the expectation is not met.

to_be_enabled(locator, options \\ [])

@spec to_be_enabled(
  PlaywrightEx.Locator.t() | t(PlaywrightEx.Locator.t()),
  to_be_enabled_options()
) ::
  :ok | {:error, PlaywrightEx.error()}

Ensures the Locator points to an enabled element.

Usage

locator = Page.locator(page, "button.submit")
Expect.to_be_enabled!(locator)

Since Playwright 1.20.

Options

  • :enabled (boolean/0) - Since Playwright 1.26.

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

to_be_enabled!(locator, options \\ [])

@spec to_be_enabled!(
  PlaywrightEx.Locator.t() | t(PlaywrightEx.Locator.t()),
  to_be_enabled_options()
) ::
  :ok

Like to_be_enabled/2, but raises PlaywrightEx.ExpectError when the expectation is not met.

to_be_focused(locator, options \\ [])

@spec to_be_focused(
  PlaywrightEx.Locator.t() | t(PlaywrightEx.Locator.t()),
  to_be_focused_options()
) ::
  :ok | {:error, PlaywrightEx.error()}

Ensures the Locator points to a focused DOM node.

Usage

locator = Page.get_by_role(page, :textbox)
Expect.to_be_focused!(locator)

Since Playwright 1.20.

Options

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

to_be_focused!(locator, options \\ [])

@spec to_be_focused!(
  PlaywrightEx.Locator.t() | t(PlaywrightEx.Locator.t()),
  to_be_focused_options()
) ::
  :ok

Like to_be_focused/2, but raises PlaywrightEx.ExpectError when the expectation is not met.

to_be_hidden(locator, options \\ [])

@spec to_be_hidden(
  PlaywrightEx.Locator.t() | t(PlaywrightEx.Locator.t()),
  to_be_hidden_options()
) ::
  :ok | {:error, PlaywrightEx.error()}

Ensures that Locator either does not resolve to any DOM node, or resolves to a non-visible one.

Usage

locator = Page.locator(page, ".my-element")
Expect.to_be_hidden!(locator)

Since Playwright 1.20.

Options

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

to_be_hidden!(locator, options \\ [])

@spec to_be_hidden!(
  PlaywrightEx.Locator.t() | t(PlaywrightEx.Locator.t()),
  to_be_hidden_options()
) ::
  :ok

Like to_be_hidden/2, but raises PlaywrightEx.ExpectError when the expectation is not met.

to_be_in_viewport(locator, options \\ [])

@spec to_be_in_viewport(
  PlaywrightEx.Locator.t() | t(PlaywrightEx.Locator.t()),
  to_be_in_viewport_options()
) :: :ok | {:error, PlaywrightEx.error()}

Ensures the Locator points to an element that intersects viewport, according to the intersection observer API.

Usage

locator = Page.get_by_role(page, :button)
# Make sure at least some part of element intersects viewport.
Expect.to_be_in_viewport!(locator)
# Make sure element is fully outside of viewport.
Expect.not_to_be_in_viewport!(locator)
# Make sure that at least half of the element intersects viewport.
Expect.to_be_in_viewport!(locator, ratio: 0.5)

Since Playwright 1.31.

Options

  • :ratio (number/0) - The minimal ratio of the element to intersect viewport. If equals to 0, then element should intersect viewport at any positive ratio. Defaults to 0.

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

to_be_in_viewport!(locator, options \\ [])

@spec to_be_in_viewport!(
  PlaywrightEx.Locator.t() | t(PlaywrightEx.Locator.t()),
  to_be_in_viewport_options()
) :: :ok

Like to_be_in_viewport/2, but raises PlaywrightEx.ExpectError when the expectation is not met.

to_be_ok(api_response)

@spec to_be_ok(PlaywrightEx.APIResponse.t() | t(PlaywrightEx.APIResponse.t())) ::
  :ok | {:error, PlaywrightEx.error()}

Ensures the response status code is within 200..299 range.

Usage

Expect.to_be_ok!(response)

Since Playwright 1.18.

to_be_ok!(api_response)

Like to_be_ok/1, but raises PlaywrightEx.ExpectError when the expectation is not met.

to_be_visible(locator, options \\ [])

@spec to_be_visible(
  PlaywrightEx.Locator.t() | t(PlaywrightEx.Locator.t()),
  to_be_visible_options()
) ::
  :ok | {:error, PlaywrightEx.error()}

Ensures that Locator points to an attached and visible DOM node.

To check that at least one element from the list is visible, use PlaywrightEx.Locator.first/1.

Usage

# A specific element is visible.
Page.get_by_text(page, "Welcome") |> Expect.to_be_visible!()

# At least one item in the list is visible.
Page.get_by_test_id(page, "todo-item") |> Locator.first() |> Expect.to_be_visible!()

# At least one of the two elements is visible, possibly both.
Page.get_by_role(page, :button, name: "Sign in")
|> Locator.or_(Page.get_by_role(page, :button, name: "Sign up"))
|> Locator.first()
|> Expect.to_be_visible!()

Since Playwright 1.20.

Options

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

  • :visible (boolean/0) - Since Playwright 1.26.

to_be_visible!(locator, options \\ [])

@spec to_be_visible!(
  PlaywrightEx.Locator.t() | t(PlaywrightEx.Locator.t()),
  to_be_visible_options()
) ::
  :ok

Like to_be_visible/2, but raises PlaywrightEx.ExpectError when the expectation is not met.

to_contain_class(locator, expected, options \\ [])

@spec to_contain_class(
  PlaywrightEx.Locator.t() | t(PlaywrightEx.Locator.t()),
  String.t() | [String.t()],
  to_contain_class_options()
) :: :ok | {:error, PlaywrightEx.error()}

Ensures the Locator points to an element with given CSS classes. All classes from the asserted value, separated by spaces, must be present in the Element.classList in any order.

Usage

<div class='middle selected row' id='component'></div>
locator = Page.locator(page, "#component")
Expect.to_contain_class!(locator, "middle selected row")
Expect.to_contain_class!(locator, "selected")
Expect.to_contain_class!(locator, "row middle")

When an array is passed, the method asserts that the list of elements located matches the corresponding list of expected class lists. Each element's class attribute is matched against the corresponding class in the array:

<div class='list'>
  <div class='component inactive'></div>
  <div class='component active'></div>
  <div class='component inactive'></div>
</div>
locator = Page.locator(page, ".list > .component")
Expect.to_contain_class!(locator, ["inactive", "active", "inactive"])

Since Playwright 1.52.

Arguments

  • expected - A string containing expected class names, separated by spaces, or a list of such strings to assert multiple elements.

Options

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

to_contain_class!(locator, expected, options \\ [])

@spec to_contain_class!(
  PlaywrightEx.Locator.t() | t(PlaywrightEx.Locator.t()),
  String.t() | [String.t()],
  to_contain_class_options()
) :: :ok

Like to_contain_class/3, but raises PlaywrightEx.ExpectError when the expectation is not met.

to_contain_text(locator, expected, options \\ [])

Ensures the Locator points to an element that contains the given text. All nested elements will be considered when computing the text content of the element. You can use regular expressions for the value as well.

Details

When expected parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual text and in the expected string before matching. When regular expression is used, the actual text is matched as is.

Usage

locator = Page.locator(page, ".title")
Expect.to_contain_text!(locator, "substring")
Expect.to_contain_text!(locator, ~r/\d messages/)

If you pass an array as an expected value, the expectations are:

  1. Locator resolves to a list of elements.
  2. Elements from a subset of this list contain text from the expected array, respectively.
  3. The matching subset of elements has the same order as the expected array.
  4. Each text value from the expected array is matched by some element from the list.

For example, consider the following list:

<ul>
  <li>Item Text 1</li>
  <li>Item Text 2</li>
  <li>Item Text 3</li>
</ul>

Let's see how we can use the assertion:

# ✓ Contains the right items in the right order
Page.locator(page, "ul > li") |> Expect.to_contain_text!(["Text 1", "Text 3"])

# ✖ Wrong order
{:error, _} = Page.locator(page, "ul > li") |> Expect.to_contain_text(["Text 3", "Text 2"])

# ✖ No item contains this text
{:error, _} = Page.locator(page, "ul > li") |> Expect.to_contain_text(["Some 33"])

# ✖ Locator points to the outer list element, not to the list items
# (in fact it passes: the list's text contains "Text 3")
:ok = Page.locator(page, "ul") |> Expect.to_contain_text(["Text 3"])

Since Playwright 1.20.

Arguments

  • expected - Expected substring or RegExp or a list of those.

Options

  • :ignore_case (boolean/0) - Since Playwright 1.23. Whether to perform case-insensitive match. :ignore_case option takes precedence over the corresponding regular expression flag if specified.

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

  • :use_inner_text (boolean/0) - Whether to use element.innerText instead of element.textContent when retrieving DOM node text.

to_contain_text!(locator, expected, options \\ [])

Like to_contain_text/3, but raises PlaywrightEx.ExpectError when the expectation is not met.

to_have_accessible_description(locator, description, options \\ [])

Ensures the Locator points to an element with a given accessible description.

Usage

locator = Page.get_by_test_id(page, "save-button")
Expect.to_have_accessible_description!(locator, "Save results to disk")

Since Playwright 1.44.

Arguments

  • description - Expected accessible description.

Options

  • :ignore_case (boolean/0) - Whether to perform case-insensitive match. :ignore_case option takes precedence over the corresponding regular expression flag if specified.

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

to_have_accessible_description!(locator, description, options \\ [])

Like to_have_accessible_description/3, but raises PlaywrightEx.ExpectError when the expectation is not met.

to_have_accessible_error_message(locator, error_message, options \\ [])

@spec to_have_accessible_error_message(
  PlaywrightEx.Locator.t() | t(PlaywrightEx.Locator.t()),
  String.t() | Regex.t() | PlaywrightEx.RegExp.t(),
  to_have_accessible_error_message_options()
) :: :ok | {:error, PlaywrightEx.error()}

Ensures the Locator points to an element with a given aria errormessage.

Usage

locator = Page.get_by_test_id(page, "username-input")
Expect.to_have_accessible_error_message!(locator, "Username is required.")

Since Playwright 1.50.

Arguments

  • error_message - Expected accessible error message.

Options

  • :ignore_case (boolean/0) - Whether to perform case-insensitive match. :ignore_case option takes precedence over the corresponding regular expression flag if specified.

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

to_have_accessible_error_message!(locator, error_message, options \\ [])

Like to_have_accessible_error_message/3, but raises PlaywrightEx.ExpectError when the expectation is not met.

to_have_accessible_name(locator, name, options \\ [])

Ensures the Locator points to an element with a given accessible name.

Usage

locator = Page.get_by_test_id(page, "save-button")
Expect.to_have_accessible_name!(locator, "Save to disk")

Since Playwright 1.44.

Arguments

  • name - Expected accessible name.

Options

  • :ignore_case (boolean/0) - Whether to perform case-insensitive match. :ignore_case option takes precedence over the corresponding regular expression flag if specified.

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

to_have_accessible_name!(locator, name, options \\ [])

Like to_have_accessible_name/3, but raises PlaywrightEx.ExpectError when the expectation is not met.

to_have_attribute(locator, name, value \\ nil, options \\ [])

@spec to_have_attribute(
  PlaywrightEx.Locator.t() | t(PlaywrightEx.Locator.t()),
  String.t(),
  String.t() | Regex.t() | PlaywrightEx.RegExp.t() | nil,
  to_have_attribute_options()
) :: :ok | {:error, PlaywrightEx.error()}

Ensures the Locator points to an element with given attribute.

Usage

locator = Page.locator(page, "input")
Expect.to_have_attribute!(locator, "type", "text")
locator = Page.locator(page, "input")
# Assert attribute existence.
Expect.to_have_attribute!(locator, "disabled")
Expect.not_to_have_attribute!(locator, "open")

Since Playwright 1.20.

Arguments

  • name - Attribute name.
  • value - Expected attribute value.

Options

The options may take the place of value, which is then nil.

  • :ignore_case (boolean/0) - Since Playwright 1.40. Whether to perform case-insensitive match. :ignore_case option takes precedence over the corresponding regular expression flag if specified.

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

to_have_attribute!(locator, name, value \\ nil, options \\ [])

Like to_have_attribute/4, but raises PlaywrightEx.ExpectError when the expectation is not met.

to_have_class(locator, expected, options \\ [])

Ensures the Locator points to an element with given CSS classes. When a string is provided, it must fully match the element's class attribute. To match individual classes use PlaywrightEx.Expect.to_contain_class/3.

Usage

<div class='middle selected row' id='component'></div>
locator = Page.locator(page, "#component")
Expect.to_have_class!(locator, "middle selected row")
Expect.to_have_class!(locator, ~r/(^|\s)selected(\s|$)/)

When an array is passed, the method asserts that the list of elements located matches the corresponding list of expected class values. Each element's class attribute is matched against the corresponding string or regular expression in the array:

locator = Page.locator(page, ".list > .component")
Expect.to_have_class!(locator, ["component", "component selected", "component"])

Since Playwright 1.20.

Arguments

  • expected - Expected class or RegExp or a list of those.

Options

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

to_have_class!(locator, expected, options \\ [])

Like to_have_class/3, but raises PlaywrightEx.ExpectError when the expectation is not met.

to_have_count(locator, count, options \\ [])

@spec to_have_count(
  PlaywrightEx.Locator.t() | t(PlaywrightEx.Locator.t()),
  integer(),
  to_have_count_options()
) :: :ok | {:error, PlaywrightEx.error()}

Ensures the Locator resolves to an exact number of DOM nodes.

Usage

list = Page.locator(page, "list > .component")
Expect.to_have_count!(list, 3)

Since Playwright 1.20.

Arguments

  • count - Expected count.

Options

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

to_have_count!(locator, count, options \\ [])

@spec to_have_count!(
  PlaywrightEx.Locator.t() | t(PlaywrightEx.Locator.t()),
  integer(),
  to_have_count_options()
) :: :ok

Like to_have_count/3, but raises PlaywrightEx.ExpectError when the expectation is not met.

to_have_css(locator, name, value, options \\ [])

Ensures the Locator resolves to an element with the given computed CSS style.

Usage

locator = Page.get_by_role(page, :button)
Expect.to_have_css!(locator, "display", "flex")

Since Playwright 1.20.

Arguments

  • name - CSS property name.
  • value - CSS property value.

Options

  • :pseudo (:before | :after) - Since Playwright 1.60. Pseudo-element to read computed styles from.

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

to_have_css!(locator, name, value, options \\ [])

Like to_have_css/4, but raises PlaywrightEx.ExpectError when the expectation is not met.

to_have_id(locator, id, options \\ [])

Ensures the Locator points to an element with the given DOM Node ID.

Usage

locator = Page.get_by_role(page, :textbox)
Expect.to_have_id!(locator, "lastname")

Since Playwright 1.20.

Arguments

  • id - Element id.

Options

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

to_have_id!(locator, id, options \\ [])

Like to_have_id/3, but raises PlaywrightEx.ExpectError when the expectation is not met.

to_have_js_property(locator, name, value, options \\ [])

@spec to_have_js_property(
  PlaywrightEx.Locator.t() | t(PlaywrightEx.Locator.t()),
  String.t(),
  term(),
  to_have_js_property_options()
) :: :ok | {:error, PlaywrightEx.error()}

Ensures the Locator points to an element with given JavaScript property. Note that this property can be of a primitive type as well as a plain serializable JavaScript object.

Usage

locator = Page.locator(page, ".component")
Expect.to_have_js_property!(locator, "loaded", true)

Since Playwright 1.20.

Arguments

  • name - Property name.
  • value - Property value.

Options

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

to_have_js_property!(locator, name, value, options \\ [])

@spec to_have_js_property!(
  PlaywrightEx.Locator.t() | t(PlaywrightEx.Locator.t()),
  String.t(),
  term(),
  to_have_js_property_options()
) :: :ok

Like to_have_js_property/4, but raises PlaywrightEx.ExpectError when the expectation is not met.

to_have_role(locator, role, options \\ [])

@spec to_have_role(
  PlaywrightEx.Locator.t() | t(PlaywrightEx.Locator.t()),
  :alert
  | :alertdialog
  | :application
  | :article
  | :banner
  | :blockquote
  | :button
  | :caption
  | :cell
  | :checkbox
  | :code
  | :columnheader
  | :combobox
  | :complementary
  | :contentinfo
  | :definition
  | :deletion
  | :dialog
  | :directory
  | :document
  | :emphasis
  | :feed
  | :figure
  | :form
  | :generic
  | :grid
  | :gridcell
  | :group
  | :heading
  | :img
  | :insertion
  | :link
  | :list
  | :listbox
  | :listitem
  | :log
  | :main
  | :marquee
  | :math
  | :meter
  | :menu
  | :menubar
  | :menuitem
  | :menuitemcheckbox
  | :menuitemradio
  | :navigation
  | :none
  | :note
  | :option
  | :paragraph
  | :presentation
  | :progressbar
  | :radio
  | :radiogroup
  | :region
  | :row
  | :rowgroup
  | :rowheader
  | :scrollbar
  | :search
  | :searchbox
  | :separator
  | :slider
  | :spinbutton
  | :status
  | :strong
  | :subscript
  | :superscript
  | :switch
  | :tab
  | :table
  | :tablist
  | :tabpanel
  | :term
  | :textbox
  | :time
  | :timer
  | :toolbar
  | :tooltip
  | :tree
  | :treegrid
  | :treeitem,
  to_have_role_options()
) :: :ok | {:error, PlaywrightEx.error()}

Ensures the Locator points to an element with a given ARIA role.

Note that role is matched as a string, disregarding the ARIA role hierarchy. For example, asserting a superclass role :checkbox on an element with a subclass role :switch will fail.

Usage

locator = Page.get_by_test_id(page, "save-button")
Expect.to_have_role!(locator, :button)

Since Playwright 1.44.

Arguments

  • role - Required aria role.

Options

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

to_have_role!(locator, role, options \\ [])

@spec to_have_role!(
  PlaywrightEx.Locator.t() | t(PlaywrightEx.Locator.t()),
  :alert
  | :alertdialog
  | :application
  | :article
  | :banner
  | :blockquote
  | :button
  | :caption
  | :cell
  | :checkbox
  | :code
  | :columnheader
  | :combobox
  | :complementary
  | :contentinfo
  | :definition
  | :deletion
  | :dialog
  | :directory
  | :document
  | :emphasis
  | :feed
  | :figure
  | :form
  | :generic
  | :grid
  | :gridcell
  | :group
  | :heading
  | :img
  | :insertion
  | :link
  | :list
  | :listbox
  | :listitem
  | :log
  | :main
  | :marquee
  | :math
  | :meter
  | :menu
  | :menubar
  | :menuitem
  | :menuitemcheckbox
  | :menuitemradio
  | :navigation
  | :none
  | :note
  | :option
  | :paragraph
  | :presentation
  | :progressbar
  | :radio
  | :radiogroup
  | :region
  | :row
  | :rowgroup
  | :rowheader
  | :scrollbar
  | :search
  | :searchbox
  | :separator
  | :slider
  | :spinbutton
  | :status
  | :strong
  | :subscript
  | :superscript
  | :switch
  | :tab
  | :table
  | :tablist
  | :tabpanel
  | :term
  | :textbox
  | :time
  | :timer
  | :toolbar
  | :tooltip
  | :tree
  | :treegrid
  | :treeitem,
  to_have_role_options()
) :: :ok

Like to_have_role/3, but raises PlaywrightEx.ExpectError when the expectation is not met.

to_have_screenshot(locator_or_page, options \\ [])

This function will wait until two consecutive locator screenshots yield the same result, and then compare the last screenshot with the expectation.

Usage

Expect.to_have_screenshot!(page, path: "test/snapshots/image.png")

Since Playwright 1.23.

Options

  • :path (String.t/0) - Required. The snapshot file. Must have a .png or .webp extension, the screenshot is captured in the corresponding format. Both formats are lossless. A missing snapshot is written (see :update_snapshots in the configuration of PlaywrightEx.Expect); on failure the -actual, -diff and -previous images are written next to it.

  • :animations (:disabled | :allow) - When set to :disabled, stops CSS animations, CSS transitions and Web Animations. Animations get different treatment depending on their duration:

    • finite animations are fast-forwarded to completion, so they'll fire transitionend event.
    • infinite animations are canceled to initial state, and then played over after the screenshot.

    Defaults to :disabled that disables animations.

  • :caret (:hide | :initial) - When set to :hide, screenshot will hide text caret. When set to :initial, text caret behavior will not be changed. Defaults to :hide.

  • :mask (list of PlaywrightEx.Locator.t/0) - Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink box #FF00FF (customized by :mask_color) that completely covers its bounding box. The mask is also applied to invisible elements, see Matching only visible elements to disable that.

  • :mask_color (String.t/0) - Since Playwright 1.35. Specify the color of the overlay box for masked elements, in CSS color format. Default color is pink #FF00FF.

  • :max_diff_pixel_ratio (number/0) - An acceptable ratio of pixels that are different to the total amount of pixels, between 0 and 1. Default is configurable with config :playwright_ex, :expect (see the configuration in PlaywrightEx.Expect). Note that :threshold defines which pixels are considered different.

  • :max_diff_pixels (integer/0) - An acceptable amount of pixels that could be different. Default is configurable with config :playwright_ex, :expect (see the configuration in PlaywrightEx.Expect). Note that :threshold defines which pixels are considered different.

  • :omit_background (boolean/0) - Hides default white background and allows capturing screenshots with transparency. Not applicable to jpeg images. Defaults to false.

  • :scale (:css | :device) - When set to :css, screenshot will have a single pixel per each css pixel on the page. For high-dpi devices, this will keep screenshots small. Using :device option will produce a single pixel per each device pixel, so screenshots of high-dpi devices will be twice as large or even larger.

    Defaults to :css.

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :style_path (String.t/0 | list of String.t/0) - Since Playwright 1.41. File name containing the stylesheet to apply while making the screenshot. This is where you can hide dynamic elements, make elements invisible or change their properties to help you creating repeatable screenshots. This stylesheet pierces the Shadow DOM and applies to the inner frames.

  • :threshold (number/0) - An acceptable perceived color difference in the YIQ color space between the same pixel in compared images, between zero (strict) and one (lax), default is configurable with config :playwright_ex, :expect (see the configuration in PlaywrightEx.Expect). Defaults to 0.2.

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

  • :clip (map/0) - An object which specifies clipping of the resulting image.

    • :x - x-coordinate of top-left corner of clip area
    • :y - y-coordinate of top-left corner of clip area
    • :width - width of clipping area
    • :height - height of clipping area
  • :full_page (boolean/0) - When true, takes a screenshot of the full scrollable page, instead of the currently visible viewport. Defaults to false.

to_have_screenshot!(locator_or_page, options \\ [])

Like to_have_screenshot/2, but raises PlaywrightEx.ExpectError when the expectation is not met.

to_have_text(locator, expected, options \\ [])

Ensures the Locator points to an element with the given text. All nested elements will be considered when computing the text content of the element. You can use regular expressions for the value as well.

Details

When expected parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual text and in the expected string before matching. When regular expression is used, the actual text is matched as is.

Usage

locator = Page.locator(page, ".title")
Expect.to_have_text!(locator, ~r/Welcome, Test User/)
Expect.to_have_text!(locator, ~r/Welcome, .*/)

If you pass an array as an expected value, the expectations are:

  1. Locator resolves to a list of elements.
  2. The number of elements equals the number of expected values in the array.
  3. Elements from the list have text matching expected array values, one by one, in order.

For example, consider the following list:

<ul>
  <li>Text 1</li>
  <li>Text 2</li>
  <li>Text 3</li>
</ul>

Let's see how we can use the assertion:

# ✓ Has the right items in the right order
Page.locator(page, "ul > li") |> Expect.to_have_text!(["Text 1", "Text 2", "Text 3"])

# ✖ Wrong order
{:error, _} = Page.locator(page, "ul > li") |> Expect.to_have_text(["Text 3", "Text 2", "Text 1"])

# ✖ Last item does not match
{:error, _} = Page.locator(page, "ul > li") |> Expect.to_have_text(["Text 1", "Text 2", "Text"])

# ✖ Locator points to the outer list element, not to the list items
{:error, _} = Page.locator(page, "ul") |> Expect.to_have_text(["Text 1", "Text 2", "Text 3"])

Since Playwright 1.20.

Arguments

  • expected - Expected string or RegExp or a list of those.

Options

  • :ignore_case (boolean/0) - Since Playwright 1.23. Whether to perform case-insensitive match. :ignore_case option takes precedence over the corresponding regular expression flag if specified.

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

  • :use_inner_text (boolean/0) - Whether to use element.innerText instead of element.textContent when retrieving DOM node text.

to_have_text!(locator, expected, options \\ [])

Like to_have_text/3, but raises PlaywrightEx.ExpectError when the expectation is not met.

to_have_title(page, title_or_reg_exp, options \\ [])

Ensures the page has the given title.

Usage

Expect.to_have_title!(page, ~r/.*checkout/)

Since Playwright 1.20.

Arguments

  • title_or_reg_exp - Expected title or RegExp.

Options

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

to_have_title!(page, title_or_reg_exp, options \\ [])

Like to_have_title/3, but raises PlaywrightEx.ExpectError when the expectation is not met.

to_have_url(page, url, options \\ [])

@spec to_have_url(
  PlaywrightEx.Page.t() | t(PlaywrightEx.Page.t()),
  String.t() | Regex.t() | PlaywrightEx.RegExp.t() | (String.t() -> boolean()),
  to_have_url_options()
) :: :ok | {:error, PlaywrightEx.error()}

Ensures the page is navigated to the given URL.

Usage

# Check for the page URL to be 'https://playwright.dev/docs/intro' (including query string)
Expect.to_have_url!(page, "https://playwright.dev/docs/intro")

# Check for the page URL to contain 'doc', followed by an optional 's', followed by '/'
Expect.to_have_url!(page, ~r/docs?\//)

# Check for the page URL to match the URL pattern (Elixir has no URLPattern: a predicate)
Expect.to_have_url!(page, &String.starts_with?(URI.parse(&1).path, "/docs/"))

# Check for the predicate to be satisfied
# For example: verify query strings
Expect.to_have_url!(page, fn url ->
  params = URI.decode_query(URI.parse(url).query || "")
  Map.has_key?(params, "search") and Map.has_key?(params, "options") and params["id"] == "5"
end)

Since Playwright 1.20.

Arguments

  • url - Expected URL string, RegExp, or predicate receiving URL to match. When :base_url is provided via the context options and the url argument is a string, the two values are merged via the new URL() constructor and used for the comparison against the current browser URL.

Options

  • :ignore_case (boolean/0) - Since Playwright 1.44. Whether to perform case-insensitive match. :ignore_case option takes precedence over the corresponding regular expression parameter if specified. A provided predicate ignores this flag.

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

to_have_url!(page, url, options \\ [])

Like to_have_url/3, but raises PlaywrightEx.ExpectError when the expectation is not met.

to_have_value(locator, value, options \\ [])

Ensures the Locator points to an element with the given input value. You can use regular expressions for the value as well.

Usage

locator = Page.locator(page, "input[type=number]")
Expect.to_have_value!(locator, ~r/[0-9]/)

Since Playwright 1.20.

Arguments

  • value - Expected value.

Options

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

to_have_value!(locator, value, options \\ [])

Like to_have_value/3, but raises PlaywrightEx.ExpectError when the expectation is not met.

to_have_values(locator, values, options \\ [])

Ensures the Locator points to multi-select/combobox (i.e. a select with the multiple attribute) and the specified values are selected.

Usage

For example, given the following element:

<select id="favorite-colors" multiple>
  <option value="R">Red</option>
  <option value="G">Green</option>
  <option value="B">Blue</option>
</select>
locator = Page.locator(page, "id=favorite-colors")
Locator.select_option!(locator, ["R", "G"])
Expect.to_have_values!(locator, [~r/R/, ~r/G/])

Since Playwright 1.23.

Arguments

  • values - Expected options currently selected.

Options

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

to_have_values!(locator, values, options \\ [])

Like to_have_values/3, but raises PlaywrightEx.ExpectError when the expectation is not met.

to_match_aria_snapshot(locator_or_page, expected \\ nil, options \\ [])

Asserts that the target element matches the given accessibility snapshot.

Usage

Page.goto!(page, "https://demo.playwright.dev/todomvc/")

Page.locator(page, "body")
|> Expect.to_match_aria_snapshot!("""
- heading "todos"
- textbox "What needs to be done?"
""")
Expect.to_match_aria_snapshot!(page, path: "test/snapshots/body.aria.yml")

Since Playwright 1.49.

Options

The options may take the place of expected, which is then nil.

  • :path (String.t/0) - The snapshot file, in place of expected. Its content is the expected snapshot. A missing snapshot is written, unless :update_snapshots is :none or the matcher is negated. With :update_snapshots set to :all it is always rewritten, with :changed when it differs (see the configuration of PlaywrightEx.Expect).

  • :signal (PlaywrightEx.AbortSignal.t/0) - Since Playwright 1.62. An optional AbortSignal that can cancel the assertion. Aborting the signal fails the assertion like a timeout: if the signal is aborted while the assertion is retrying, or is already aborted before the assertion starts, the assertion fails without retrying further.

    In Elixir, a PlaywrightEx.AbortSignal (PlaywrightEx.AbortController.signal/1).

  • :timeout (number/0 | :infinity) - Time to retry the assertion for in milliseconds, 0 for no timeout. Defaults to :timeout in config :playwright_ex, :expect (5000 if not set, see the configuration in PlaywrightEx.Expect).

    In Elixir, :infinity is the same as 0: no timeout.

to_match_aria_snapshot!(locator_or_page, expected \\ nil, options \\ [])

Like to_match_aria_snapshot/3, but raises PlaywrightEx.ExpectError when the expectation is not met.