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), and a soft assertion is locator |> soft() |> to_have_text(expected) (see soft/1). They retry until the expectation is met or the timeout (5 seconds by default, see Configuration below) passes, then return :ok or {:error, %Playwright.ExpectError{}} whose matcherResult mirrors JS; the bang forms raise the Playwright.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")
endConfiguration
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, :expect, timeout: 10_000, update_snapshots: :missingThe keys (other keys raise ArgumentError, at application start for the config files):
:timeout- Default timeout of the matchers in milliseconds. Defaults to5000. Atimeout:option of a matcher wins.:infinityis no limit, and so is0, as in Playwright:0never means "fail at once" (see API conventions).:update_snapshots- Whento_have_screenshotandto_match_aria_snapshotwrite snapshots::all,:changed,:missing,:noneor:default(the default: write missing ones, which fails aPlaywright.Testtest at its end, as upstream's). A snapshot is written to the file itsname:resolves to in aPlaywright.Testtest, or to itspath:. An inline aria snapshot is not written into the test source, so where upstream suggests a rebaseline (an empty snapshot, or any under:allor a mismatch under:changed) the matcher fails with the new snapshot in its message.:ignore_snapshots- Skip the snapshot matchers. Defaults tofalse.:to_pass- Defaults ofPlaywright.Expect.to_pass/2's options,[timeout: 10_000, intervals: [1000]]. Its timeout defaults to0, no limit of its own (the test's timeout bounds it), not:timeout;:infinityis0.:to_have_screenshot- Defaults ofPlaywright.Expect.to_have_screenshot/2's options, as it names them::animations,:caret,:max_diff_pixels,:max_diff_pixel_ratio,:scale,:style_path,:thresholdand:timeout(over the expect:timeout, under a call's), as in[max_diff_pixels: 10], and the config's own:type(:pngor:webp, of an unnamed snapshot) and:path_template(see "Snapshots" inPlaywright.Test).:to_match_aria_snapshot-:children(:contain,:equalor:deep_equal: the/childrenmode of a snapshot that sets none) and:path_template.
The keys are upstream's config keys, snake_case; each takes a keyword list or a map.
Since Playwright 1.17.
The examples alias the modules they use (alias Playwright.{Locator, Page}).
Summary
Types
Options of not_to_be_attached/2, see its docs.
Options of not_to_be_checked/2, see its docs.
Options of not_to_be_disabled/2, see its docs.
Options of not_to_be_editable/2, see its docs.
Options of not_to_be_empty/2, see its docs.
Options of not_to_be_enabled/2, see its docs.
Options of not_to_be_focused/2, see its docs.
Options of not_to_be_hidden/2, see its docs.
Options of not_to_be_in_viewport/2, see its docs.
Options of not_to_be_visible/2, see its docs.
Options of not_to_contain_class/3, see its docs.
Options of not_to_contain_text/3, see its docs.
Options of not_to_have_accessible_description/3, see its docs.
Options of not_to_have_accessible_error_message/3, see its docs.
Options of not_to_have_accessible_name/3, see its docs.
Options of not_to_have_attribute/4, see its docs.
Options of not_to_have_class/3, see its docs.
Options of not_to_have_count/3, 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_js_property/4, see its docs.
Options of not_to_have_role/3, see its docs.
Options of not_to_have_screenshot/2, see its docs.
Options of not_to_have_text/3, see its docs.
Options of not_to_have_title/3, see its docs.
Options of not_to_have_url/3, see its docs.
Options of not_to_have_value/3, see its docs.
Options of not_to_have_values/3, see its docs.
Options of not_to_match_aria_snapshot/3, see its docs.
Options of not_to_pass/2, see its docs.
Options of poll/3, see its docs.
A negated, soft or messaged receiver of any matcher.
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_in_viewport/2, see its docs.
Options of to_be_visible/2, see its docs.
Options of to_contain_class/3, see its docs.
Options of to_contain_text/3, see its docs.
Options of to_have_accessible_description/3, see its docs.
Options of to_have_accessible_error_message/3, see its docs.
Options of to_have_accessible_name/3, see its docs.
Options of to_have_attribute/4, 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_js_property/4, see its docs.
Options of to_have_role/3, see its docs.
Options of to_have_screenshot/2, 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.
Options of to_match_aria_snapshot/3, see its docs.
Options of to_pass/2, see its docs.
Functions
You can specify a custom expect message, for example
Makes the assertion check for the opposite condition.
The opposite of to_be_attached/2: expect(x).not.toBeAttached(...) in JS.
Like not_to_be_attached/2, but raises Playwright.ExpectError when the expectation is not met.
The opposite of to_be_checked/2: expect(x).not.toBeChecked(...) in JS.
Like not_to_be_checked/2, but raises Playwright.ExpectError when the expectation is not met.
The opposite of to_be_disabled/2: expect(x).not.toBeDisabled(...) in JS.
Like not_to_be_disabled/2, but raises Playwright.ExpectError when the expectation is not met.
The opposite of to_be_editable/2: expect(x).not.toBeEditable(...) in JS.
Like not_to_be_editable/2, but raises Playwright.ExpectError when the expectation is not met.
The opposite of to_be_empty/2: expect(x).not.toBeEmpty(...) in JS.
Like not_to_be_empty/2, but raises Playwright.ExpectError when the expectation is not met.
The opposite of to_be_enabled/2: expect(x).not.toBeEnabled(...) in JS.
Like not_to_be_enabled/2, but raises Playwright.ExpectError when the expectation is not met.
The opposite of to_be_focused/2: expect(x).not.toBeFocused(...) in JS.
Like not_to_be_focused/2, but raises Playwright.ExpectError when the expectation is not met.
The opposite of to_be_hidden/2: expect(x).not.toBeHidden(...) in JS.
Like not_to_be_hidden/2, but raises Playwright.ExpectError when the expectation is not met.
The opposite of to_be_in_viewport/2: expect(x).not.toBeInViewport(...) in JS.
Like not_to_be_in_viewport/2, but raises Playwright.ExpectError when the expectation is not met.
The opposite of to_be_ok/1: expect(x).not.toBeOK(...) in JS.
Like not_to_be_ok/1, but raises Playwright.ExpectError when the expectation is not met.
The opposite of to_be_visible/2: expect(x).not.toBeVisible(...) in JS.
Like not_to_be_visible/2, but raises Playwright.ExpectError when the expectation is not met.
The opposite of to_contain_class/3: expect(x).not.toContainClass(...) in JS.
Like not_to_contain_class/3, but raises Playwright.ExpectError when the expectation is not met.
The opposite of to_contain_text/3: expect(x).not.toContainText(...) in JS.
Like not_to_contain_text/3, but raises Playwright.ExpectError when the expectation is not met.
The opposite of to_have_accessible_description/3: expect(x).not.toHaveAccessibleDescription(...) in JS.
Like not_to_have_accessible_description/3, but raises Playwright.ExpectError when the expectation is not met.
The opposite of to_have_accessible_error_message/3: expect(x).not.toHaveAccessibleErrorMessage(...) in JS.
Like not_to_have_accessible_error_message/3, but raises Playwright.ExpectError when the expectation is not met.
The opposite of to_have_accessible_name/3: expect(x).not.toHaveAccessibleName(...) in JS.
Like not_to_have_accessible_name/3, but raises Playwright.ExpectError when the expectation is not met.
The opposite of to_have_attribute/4: expect(x).not.toHaveAttribute(...) in JS.
Like not_to_have_attribute/4, but raises Playwright.ExpectError when the expectation is not met.
The opposite of to_have_class/3: expect(x).not.toHaveClass(...) in JS.
Like not_to_have_class/3, but raises Playwright.ExpectError when the expectation is not met.
The opposite of to_have_count/3: expect(x).not.toHaveCount(...) in JS.
Like not_to_have_count/3, but raises Playwright.ExpectError when the expectation is not met.
The opposite of to_have_css/4: expect(x).not.toHaveCSS(...) in JS.
Like not_to_have_css/4, but raises Playwright.ExpectError when the expectation is not met.
The opposite of to_have_id/3: expect(x).not.toHaveId(...) in JS.
Like not_to_have_id/3, but raises Playwright.ExpectError when the expectation is not met.
The opposite of to_have_js_property/4: expect(x).not.toHaveJSProperty(...) in JS.
Like not_to_have_js_property/4, but raises Playwright.ExpectError when the expectation is not met.
The opposite of to_have_role/3: expect(x).not.toHaveRole(...) in JS.
Like not_to_have_role/3, but raises Playwright.ExpectError when the expectation is not met.
The opposite of to_have_screenshot/2: expect(x).not.toHaveScreenshot(...) in JS.
Like not_to_have_screenshot/2, but raises Playwright.ExpectError when the expectation is not met.
The opposite of to_have_text/3: expect(x).not.toHaveText(...) in JS.
Like not_to_have_text/3, but raises Playwright.ExpectError when the expectation is not met.
The opposite of to_have_title/3: expect(x).not.toHaveTitle(...) in JS.
Like not_to_have_title/3, but raises Playwright.ExpectError when the expectation is not met.
The opposite of to_have_url/3: expect(x).not.toHaveURL(...) in JS.
Like not_to_have_url/3, but raises Playwright.ExpectError when the expectation is not met.
The opposite of to_have_value/3: expect(x).not.toHaveValue(...) in JS.
Like not_to_have_value/3, but raises Playwright.ExpectError when the expectation is not met.
The opposite of to_have_values/3: expect(x).not.toHaveValues(...) in JS.
Like not_to_have_values/3, but raises Playwright.ExpectError when the expectation is not met.
The opposite of to_match_aria_snapshot/3: expect(x).not.toMatchAriaSnapshot(...) in JS.
Like not_to_match_aria_snapshot/3, but raises Playwright.ExpectError when the expectation is not met.
The opposite of to_pass/2: expect(x).not.toPass(...) in JS.
Like not_to_pass/2, but raises Playwright.ExpectError when the expectation is not met.
You can convert any synchronous expect to an asynchronous polling one using Playwright.Expect.poll/3.
Like poll/3, but raises Playwright.ExpectError when the expectation is not met.
By default, failed assertion will terminate test execution. Playwright also supports soft assertions: failed soft assertions do not terminate test execution, but mark the test as failed.
Like to_be_attached/2, but raises Playwright.ExpectError when the expectation is not met.
Ensures the Locator points to a checked input.
Like to_be_checked/2, but raises Playwright.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 Playwright.ExpectError when the expectation is not met.
Ensures the Locator points to an editable element.
Like to_be_editable/2, but raises Playwright.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 Playwright.ExpectError when the expectation is not met.
Ensures the Locator points to an enabled element.
Like to_be_enabled/2, but raises Playwright.ExpectError when the expectation is not met.
Ensures the Locator points to a focused DOM node.
Like to_be_focused/2, but raises Playwright.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 Playwright.ExpectError when the expectation is not met.
Ensures the Locator points to an element that intersects viewport, according to the intersection observer API.
Like to_be_in_viewport/2, but raises Playwright.ExpectError when the expectation is not met.
Ensures the response status code is within 200..299 range.
Like to_be_ok/1, but raises Playwright.ExpectError when the expectation is not met.
Like to_be_visible/2, but raises Playwright.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.
Like to_contain_class/3, but raises Playwright.ExpectError when the expectation is not met.
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.
Like to_contain_text/3, but raises Playwright.ExpectError when the expectation is not met.
Ensures the Locator points to an element with a given accessible description.
Like to_have_accessible_description/3, but raises Playwright.ExpectError when the expectation is not met.
Ensures the Locator points to an element with a given aria errormessage.
Like to_have_accessible_error_message/3, but raises Playwright.ExpectError when the expectation is not met.
Ensures the Locator points to an element with a given accessible name.
Like to_have_accessible_name/3, but raises Playwright.ExpectError when the expectation is not met.
Ensures the Locator points to an element with given attribute.
Like to_have_attribute/4, but raises Playwright.ExpectError when the expectation is not met.
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 Playwright.Expect.to_contain_class/3.
Like to_have_class/3, but raises Playwright.ExpectError when the expectation is not met.
Ensures the Locator resolves to an exact number of DOM nodes.
Like to_have_count/3, but raises Playwright.ExpectError when the expectation is not met.
Ensures the Locator resolves to an element with the given computed CSS style.
Like to_have_css/4, but raises Playwright.ExpectError when the expectation is not met.
Ensures the Locator points to an element with the given DOM Node ID.
Like to_have_id/3, but raises Playwright.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.
Like to_have_js_property/4, but raises Playwright.ExpectError when the expectation is not met.
Like to_have_role/3, but raises Playwright.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.
Like to_have_screenshot/2, but raises Playwright.ExpectError when the expectation is not met.
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.
Like to_have_text/3, but raises Playwright.ExpectError when the expectation is not met.
Ensures the page has the given title.
Like to_have_title/3, but raises Playwright.ExpectError when the expectation is not met.
Ensures the page is navigated to the given URL.
Like to_have_url/3, but raises Playwright.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.
Like to_have_value/3, but raises Playwright.ExpectError when the expectation is not met.
Ensures the Locator points to multi-select/combobox (i.e. a select with the multiple attribute) and the specified values are selected.
Like to_have_values/3, but raises Playwright.ExpectError when the expectation is not met.
Asserts that the target element matches the given accessibility snapshot.
Like to_match_aria_snapshot/3, but raises Playwright.ExpectError when the expectation is not met.
You can retry blocks of code until they are passing successfully.
Like to_pass/2, but raises Playwright.ExpectError when the expectation is not met.
Types
@type not_to_be_attached_options() :: [ attached: boolean(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:attached) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of not_to_be_attached/2, see its docs.
@type not_to_be_checked_options() :: [ checked: boolean(), indeterminate: boolean(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:checked) => boolean(), optional(:indeterminate) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of not_to_be_checked/2, see its docs.
@type not_to_be_disabled_options() :: [signal: Playwright.AbortSignal.t(), timeout: number() | :infinity] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of not_to_be_disabled/2, see its docs.
@type not_to_be_editable_options() :: [ editable: boolean(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:editable) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of not_to_be_editable/2, see its docs.
@type not_to_be_empty_options() :: [signal: Playwright.AbortSignal.t(), timeout: number() | :infinity] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of not_to_be_empty/2, see its docs.
@type not_to_be_enabled_options() :: [ enabled: boolean(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:enabled) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of not_to_be_enabled/2, see its docs.
@type not_to_be_focused_options() :: [signal: Playwright.AbortSignal.t(), timeout: number() | :infinity] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of not_to_be_focused/2, see its docs.
@type not_to_be_in_viewport_options() :: [ ratio: number(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:ratio) => number(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of not_to_be_in_viewport/2, see its docs.
@type not_to_be_visible_options() :: [ signal: Playwright.AbortSignal.t(), timeout: number() | :infinity, visible: boolean() ] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity, optional(:visible) => boolean() }
Options of not_to_be_visible/2, see its docs.
@type not_to_contain_class_options() :: [signal: Playwright.AbortSignal.t(), timeout: number() | :infinity] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of not_to_contain_class/3, see its docs.
@type not_to_contain_text_options() :: [ ignore_case: boolean(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity, use_inner_text: boolean() ] | %{ optional(:ignore_case) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity, optional(:use_inner_text) => boolean() }
Options of not_to_contain_text/3, see its docs.
@type not_to_have_accessible_description_options() :: [ ignore_case: boolean(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:ignore_case) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of not_to_have_accessible_description/3, see its docs.
@type not_to_have_accessible_error_message_options() :: [ ignore_case: boolean(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:ignore_case) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of not_to_have_accessible_error_message/3, see its docs.
@type not_to_have_accessible_name_options() :: [ ignore_case: boolean(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:ignore_case) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of not_to_have_accessible_name/3, see its docs.
@type not_to_have_attribute_options() :: [ ignore_case: boolean(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:ignore_case) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of not_to_have_attribute/4, see its docs.
@type not_to_have_class_options() :: [signal: Playwright.AbortSignal.t(), timeout: number() | :infinity] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of not_to_have_class/3, see its docs.
@type not_to_have_count_options() :: [signal: Playwright.AbortSignal.t(), timeout: number() | :infinity] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of not_to_have_count/3, see its docs.
@type not_to_have_css_options() :: [ pseudo: :before | :after, signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:pseudo) => :before | :after, optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of not_to_have_css/4, see its docs.
@type not_to_have_id_options() :: [signal: Playwright.AbortSignal.t(), timeout: number() | :infinity] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of not_to_have_id/3, see its docs.
@type not_to_have_js_property_options() :: [signal: Playwright.AbortSignal.t(), timeout: number() | :infinity] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of not_to_have_js_property/4, see its docs.
@type not_to_have_role_options() :: [signal: Playwright.AbortSignal.t(), timeout: number() | :infinity] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of not_to_have_role/3, see its docs.
@type not_to_have_screenshot_options() :: [ name: String.t() | [String.t()], path: String.t(), animations: :disabled | :allow, caret: :hide | :initial, mask: [Playwright.Locator.t()], mask_color: String.t(), max_diff_pixel_ratio: number(), max_diff_pixels: integer(), omit_background: boolean(), scale: :css | :device, signal: Playwright.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(:name) => String.t() | [String.t()], optional(:path) => String.t(), optional(:animations) => :disabled | :allow, optional(:caret) => :hide | :initial, optional(:mask) => [Playwright.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) => Playwright.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.
@type not_to_have_text_options() :: [ ignore_case: boolean(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity, use_inner_text: boolean() ] | %{ optional(:ignore_case) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity, optional(:use_inner_text) => boolean() }
Options of not_to_have_text/3, see its docs.
@type not_to_have_title_options() :: [signal: Playwright.AbortSignal.t(), timeout: number() | :infinity] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of not_to_have_title/3, see its docs.
@type not_to_have_url_options() :: [ ignore_case: boolean(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:ignore_case) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of not_to_have_url/3, see its docs.
@type not_to_have_value_options() :: [signal: Playwright.AbortSignal.t(), timeout: number() | :infinity] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of not_to_have_value/3, see its docs.
@type not_to_have_values_options() :: [signal: Playwright.AbortSignal.t(), timeout: number() | :infinity] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of not_to_have_values/3, see its docs.
@type not_to_match_aria_snapshot_options() :: [ name: String.t(), path: String.t(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:name) => String.t(), optional(:path) => String.t(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of not_to_match_aria_snapshot/3, see its docs.
@type not_to_pass_options() :: [intervals: [integer()], timeout: number() | :infinity] | %{ optional(:intervals) => [integer()], optional(:timeout) => number() | :infinity }
Options of not_to_pass/2, see its docs.
@type poll_options() :: [intervals: [integer()], message: String.t(), timeout: number() | :infinity] | %{ optional(:intervals) => [integer()], optional(:message) => String.t(), optional(:timeout) => number() | :infinity }
Options of poll/3, see its docs.
@type t() :: t( Playwright.Locator.t() | Playwright.Page.t() | Playwright.APIResponse.t() | (-> term()) )
A negated, soft or messaged receiver of any matcher.
@type t(actual) :: %Playwright.Expect{ actual: actual, isNot: boolean(), isSoft: boolean(), message: String.t() | nil }
A negated (not_/1), soft (soft/1) or messaged (message/2) receiver: expect(actual).not, expect.soft(actual), expect(actual, message) in JS.
@type to_be_attached_options() :: [ attached: boolean(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:attached) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of to_be_attached/2, see its docs.
@type to_be_checked_options() :: [ checked: boolean(), indeterminate: boolean(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:checked) => boolean(), optional(:indeterminate) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of to_be_checked/2, see its docs.
@type to_be_disabled_options() :: [signal: Playwright.AbortSignal.t(), timeout: number() | :infinity] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of to_be_disabled/2, see its docs.
@type to_be_editable_options() :: [ editable: boolean(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:editable) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of to_be_editable/2, see its docs.
@type to_be_empty_options() :: [signal: Playwright.AbortSignal.t(), timeout: number() | :infinity] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of to_be_empty/2, see its docs.
@type to_be_enabled_options() :: [ enabled: boolean(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:enabled) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of to_be_enabled/2, see its docs.
@type to_be_focused_options() :: [signal: Playwright.AbortSignal.t(), timeout: number() | :infinity] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of to_be_focused/2, see its docs.
@type to_be_in_viewport_options() :: [ ratio: number(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:ratio) => number(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of to_be_in_viewport/2, see its docs.
@type to_be_visible_options() :: [ signal: Playwright.AbortSignal.t(), timeout: number() | :infinity, visible: boolean() ] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity, optional(:visible) => boolean() }
Options of to_be_visible/2, see its docs.
@type to_contain_class_options() :: [signal: Playwright.AbortSignal.t(), timeout: number() | :infinity] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of to_contain_class/3, see its docs.
@type to_contain_text_options() :: [ ignore_case: boolean(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity, use_inner_text: boolean() ] | %{ optional(:ignore_case) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity, optional(:use_inner_text) => boolean() }
Options of to_contain_text/3, see its docs.
@type to_have_accessible_description_options() :: [ ignore_case: boolean(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:ignore_case) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of to_have_accessible_description/3, see its docs.
@type to_have_accessible_error_message_options() :: [ ignore_case: boolean(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:ignore_case) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of to_have_accessible_error_message/3, see its docs.
@type to_have_accessible_name_options() :: [ ignore_case: boolean(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:ignore_case) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of to_have_accessible_name/3, see its docs.
@type to_have_attribute_options() :: [ ignore_case: boolean(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:ignore_case) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of to_have_attribute/4, see its docs.
@type to_have_class_options() :: [signal: Playwright.AbortSignal.t(), timeout: number() | :infinity] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of to_have_class/3, see its docs.
@type to_have_count_options() :: [signal: Playwright.AbortSignal.t(), timeout: number() | :infinity] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of to_have_count/3, see its docs.
@type to_have_css_options() :: [ pseudo: :before | :after, signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:pseudo) => :before | :after, optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of to_have_css/4, see its docs.
@type to_have_id_options() :: [signal: Playwright.AbortSignal.t(), timeout: number() | :infinity] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of to_have_id/3, see its docs.
@type to_have_js_property_options() :: [signal: Playwright.AbortSignal.t(), timeout: number() | :infinity] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of to_have_js_property/4, see its docs.
@type to_have_role_options() :: [signal: Playwright.AbortSignal.t(), timeout: number() | :infinity] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of to_have_role/3, see its docs.
@type to_have_screenshot_options() :: [ name: String.t() | [String.t()], path: String.t(), animations: :disabled | :allow, caret: :hide | :initial, mask: [Playwright.Locator.t()], mask_color: String.t(), max_diff_pixel_ratio: number(), max_diff_pixels: integer(), omit_background: boolean(), scale: :css | :device, signal: Playwright.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(:name) => String.t() | [String.t()], optional(:path) => String.t(), optional(:animations) => :disabled | :allow, optional(:caret) => :hide | :initial, optional(:mask) => [Playwright.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) => Playwright.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.
@type to_have_text_options() :: [ ignore_case: boolean(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity, use_inner_text: boolean() ] | %{ optional(:ignore_case) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity, optional(:use_inner_text) => boolean() }
Options of to_have_text/3, see its docs.
@type to_have_title_options() :: [signal: Playwright.AbortSignal.t(), timeout: number() | :infinity] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of to_have_title/3, see its docs.
@type to_have_url_options() :: [ ignore_case: boolean(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:ignore_case) => boolean(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of to_have_url/3, see its docs.
@type to_have_value_options() :: [signal: Playwright.AbortSignal.t(), timeout: number() | :infinity] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of to_have_value/3, see its docs.
@type to_have_values_options() :: [signal: Playwright.AbortSignal.t(), timeout: number() | :infinity] | %{ optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of to_have_values/3, see its docs.
@type to_match_aria_snapshot_options() :: [ name: String.t(), path: String.t(), signal: Playwright.AbortSignal.t(), timeout: number() | :infinity ] | %{ optional(:name) => String.t(), optional(:path) => String.t(), optional(:signal) => Playwright.AbortSignal.t(), optional(:timeout) => number() | :infinity }
Options of to_match_aria_snapshot/3, see its docs.
@type to_pass_options() :: [intervals: [integer()], timeout: number() | :infinity] | %{ optional(:intervals) => [integer()], optional(:timeout) => number() | :infinity }
Options of to_pass/2, see its docs.
Functions
@spec message(actual | t(actual), String.t()) :: t(actual) when actual: Playwright.Locator.t() | Playwright.Page.t() | Playwright.APIResponse.t() | (-> term())
You can specify a custom expect message, for example:
Page.get_by_text(page, "Name") |> Expect.message("should be logged in") |> Expect.to_be_visible!()This message will be shown in reporters, both for passing and failing expects, providing more context about the assertion.
In Elixir, message/2 wraps the receiver as not_/1 and soft/1 do, in any order with them: locator |> Expect.soft() |> Expect.message("my soft assertion") is a soft assertion with a custom message. The message is the matcher's step title in a Playwright.Test test and the first paragraph of its Playwright.ExpectError. A :message option of poll/3 wins over it.
@spec not_(actual | t(actual)) :: t(actual) when actual: Playwright.Locator.t() | Playwright.Page.t() | Playwright.APIResponse.t() | (-> term())
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.
@spec not_to_be_attached( Playwright.Locator.t() | t(Playwright.Locator.t()), not_to_be_attached_options() ) :: :ok | {:error, Playwright.error()}
The opposite of to_be_attached/2: expect(x).not.toBeAttached(...) in JS.
Since Playwright 1.33.
Options
:attached(boolean/0):signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec not_to_be_attached!( Playwright.Locator.t() | t(Playwright.Locator.t()), not_to_be_attached_options() ) :: :ok
Like not_to_be_attached/2, but raises Playwright.ExpectError when the expectation is not met.
@spec not_to_be_checked( Playwright.Locator.t() | t(Playwright.Locator.t()), not_to_be_checked_options() ) :: :ok | {:error, Playwright.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:indeterminateis 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:checkedis provided.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec not_to_be_checked!( Playwright.Locator.t() | t(Playwright.Locator.t()), not_to_be_checked_options() ) :: :ok
Like not_to_be_checked/2, but raises Playwright.ExpectError when the expectation is not met.
@spec not_to_be_disabled( Playwright.Locator.t() | t(Playwright.Locator.t()), not_to_be_disabled_options() ) :: :ok | {:error, Playwright.error()}
The opposite of to_be_disabled/2: expect(x).not.toBeDisabled(...) in JS.
Since Playwright 1.20.
Options
:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec not_to_be_disabled!( Playwright.Locator.t() | t(Playwright.Locator.t()), not_to_be_disabled_options() ) :: :ok
Like not_to_be_disabled/2, but raises Playwright.ExpectError when the expectation is not met.
@spec not_to_be_editable( Playwright.Locator.t() | t(Playwright.Locator.t()), not_to_be_editable_options() ) :: :ok | {:error, Playwright.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(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec not_to_be_editable!( Playwright.Locator.t() | t(Playwright.Locator.t()), not_to_be_editable_options() ) :: :ok
Like not_to_be_editable/2, but raises Playwright.ExpectError when the expectation is not met.
@spec not_to_be_empty( Playwright.Locator.t() | t(Playwright.Locator.t()), not_to_be_empty_options() ) :: :ok | {:error, Playwright.error()}
The opposite of to_be_empty/2: expect(x).not.toBeEmpty(...) in JS.
Since Playwright 1.20.
Options
:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec not_to_be_empty!( Playwright.Locator.t() | t(Playwright.Locator.t()), not_to_be_empty_options() ) :: :ok
Like not_to_be_empty/2, but raises Playwright.ExpectError when the expectation is not met.
@spec not_to_be_enabled( Playwright.Locator.t() | t(Playwright.Locator.t()), not_to_be_enabled_options() ) :: :ok | {:error, Playwright.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(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec not_to_be_enabled!( Playwright.Locator.t() | t(Playwright.Locator.t()), not_to_be_enabled_options() ) :: :ok
Like not_to_be_enabled/2, but raises Playwright.ExpectError when the expectation is not met.
@spec not_to_be_focused( Playwright.Locator.t() | t(Playwright.Locator.t()), not_to_be_focused_options() ) :: :ok | {:error, Playwright.error()}
The opposite of to_be_focused/2: expect(x).not.toBeFocused(...) in JS.
Since Playwright 1.20.
Options
:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec not_to_be_focused!( Playwright.Locator.t() | t(Playwright.Locator.t()), not_to_be_focused_options() ) :: :ok
Like not_to_be_focused/2, but raises Playwright.ExpectError when the expectation is not met.
@spec not_to_be_in_viewport( Playwright.Locator.t() | t(Playwright.Locator.t()), not_to_be_in_viewport_options() ) :: :ok | {:error, Playwright.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 to0, then element should intersect viewport at any positive ratio. Defaults to0.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec not_to_be_in_viewport!( Playwright.Locator.t() | t(Playwright.Locator.t()), not_to_be_in_viewport_options() ) :: :ok
Like not_to_be_in_viewport/2, but raises Playwright.ExpectError when the expectation is not met.
@spec not_to_be_ok(Playwright.APIResponse.t() | t(Playwright.APIResponse.t())) :: :ok | {:error, Playwright.error()}
The opposite of to_be_ok/1: expect(x).not.toBeOK(...) in JS.
Since Playwright 1.18.
@spec not_to_be_ok!(Playwright.APIResponse.t() | t(Playwright.APIResponse.t())) :: :ok
Like not_to_be_ok/1, but raises Playwright.ExpectError when the expectation is not met.
@spec not_to_be_visible( Playwright.Locator.t() | t(Playwright.Locator.t()), not_to_be_visible_options() ) :: :ok | {:error, Playwright.error()}
The opposite of to_be_visible/2: expect(x).not.toBeVisible(...) in JS.
Since Playwright 1.20.
Options
:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.:visible(boolean/0) - Since Playwright 1.26.
@spec not_to_be_visible!( Playwright.Locator.t() | t(Playwright.Locator.t()), not_to_be_visible_options() ) :: :ok
Like not_to_be_visible/2, but raises Playwright.ExpectError when the expectation is not met.
@spec not_to_contain_class( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | [String.t()], not_to_contain_class_options() ) :: :ok | {:error, Playwright.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(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec not_to_contain_class!( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | [String.t()], not_to_contain_class_options() ) :: :ok
Like not_to_contain_class/3, but raises Playwright.ExpectError when the expectation is not met.
@spec not_to_contain_text( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | Regex.t() | Playwright.RegExp.t() | [String.t() | Regex.t() | Playwright.RegExp.t()], not_to_contain_text_options() ) :: :ok | {:error, Playwright.error()}
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_caseoption takes precedence over the corresponding regular expression flag if specified.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.:use_inner_text(boolean/0) - Whether to useelement.innerTextinstead ofelement.textContentwhen retrieving DOM node text.
@spec not_to_contain_text!( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | Regex.t() | Playwright.RegExp.t() | [String.t() | Regex.t() | Playwright.RegExp.t()], not_to_contain_text_options() ) :: :ok
Like not_to_contain_text/3, but raises Playwright.ExpectError when the expectation is not met.
@spec not_to_have_accessible_description( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | Regex.t() | Playwright.RegExp.t(), not_to_have_accessible_description_options() ) :: :ok | {:error, Playwright.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_caseoption takes precedence over the corresponding regular expression flag if specified.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec not_to_have_accessible_description!( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | Regex.t() | Playwright.RegExp.t(), not_to_have_accessible_description_options() ) :: :ok
Like not_to_have_accessible_description/3, but raises Playwright.ExpectError when the expectation is not met.
@spec not_to_have_accessible_error_message( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | Regex.t() | Playwright.RegExp.t(), not_to_have_accessible_error_message_options() ) :: :ok | {:error, Playwright.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_caseoption takes precedence over the corresponding regular expression flag if specified.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec not_to_have_accessible_error_message!( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | Regex.t() | Playwright.RegExp.t(), not_to_have_accessible_error_message_options() ) :: :ok
Like not_to_have_accessible_error_message/3, but raises Playwright.ExpectError when the expectation is not met.
@spec not_to_have_accessible_name( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | Regex.t() | Playwright.RegExp.t(), not_to_have_accessible_name_options() ) :: :ok | {:error, Playwright.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_caseoption takes precedence over the corresponding regular expression flag if specified.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec not_to_have_accessible_name!( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | Regex.t() | Playwright.RegExp.t(), not_to_have_accessible_name_options() ) :: :ok
Like not_to_have_accessible_name/3, but raises Playwright.ExpectError when the expectation is not met.
@spec not_to_have_attribute( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t(), String.t() | Regex.t() | Playwright.RegExp.t() | nil, not_to_have_attribute_options() ) :: :ok | {:error, Playwright.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_caseoption takes precedence over the corresponding regular expression flag if specified.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec not_to_have_attribute!( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t(), String.t() | Regex.t() | Playwright.RegExp.t() | nil, not_to_have_attribute_options() ) :: :ok
Like not_to_have_attribute/4, but raises Playwright.ExpectError when the expectation is not met.
@spec not_to_have_class( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | Regex.t() | Playwright.RegExp.t() | [String.t() | Regex.t() | Playwright.RegExp.t()], not_to_have_class_options() ) :: :ok | {:error, Playwright.error()}
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(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec not_to_have_class!( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | Regex.t() | Playwright.RegExp.t() | [String.t() | Regex.t() | Playwright.RegExp.t()], not_to_have_class_options() ) :: :ok
Like not_to_have_class/3, but raises Playwright.ExpectError when the expectation is not met.
@spec not_to_have_count( Playwright.Locator.t() | t(Playwright.Locator.t()), integer(), not_to_have_count_options() ) :: :ok | {:error, Playwright.error()}
The opposite of to_have_count/3: expect(x).not.toHaveCount(...) in JS.
Since Playwright 1.20.
Arguments
count- Expected count.
Options
:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec not_to_have_count!( Playwright.Locator.t() | t(Playwright.Locator.t()), integer(), not_to_have_count_options() ) :: :ok
Like not_to_have_count/3, but raises Playwright.ExpectError when the expectation is not met.
@spec not_to_have_css( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t(), String.t() | Regex.t() | Playwright.RegExp.t(), not_to_have_css_options() ) :: :ok | {:error, Playwright.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(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec not_to_have_css!( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t(), String.t() | Regex.t() | Playwright.RegExp.t(), not_to_have_css_options() ) :: :ok
Like not_to_have_css/4, but raises Playwright.ExpectError when the expectation is not met.
@spec not_to_have_id( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | Regex.t() | Playwright.RegExp.t(), not_to_have_id_options() ) :: :ok | {:error, Playwright.error()}
The opposite of to_have_id/3: expect(x).not.toHaveId(...) in JS.
Since Playwright 1.20.
Arguments
id- Element id.
Options
:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec not_to_have_id!( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | Regex.t() | Playwright.RegExp.t(), not_to_have_id_options() ) :: :ok
Like not_to_have_id/3, but raises Playwright.ExpectError when the expectation is not met.
@spec not_to_have_js_property( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t(), term(), not_to_have_js_property_options() ) :: :ok | {:error, Playwright.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(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec not_to_have_js_property!( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t(), term(), not_to_have_js_property_options() ) :: :ok
Like not_to_have_js_property/4, but raises Playwright.ExpectError when the expectation is not met.
@spec not_to_have_role( Playwright.Locator.t() | t(Playwright.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 | String.t(), not_to_have_role_options() ) :: :ok | {:error, Playwright.error()}
The opposite of to_have_role/3: expect(x).not.toHaveRole(...) in JS.
Since Playwright 1.44.
Arguments
role- Required aria role.In Elixir, a role is an atom of the typespec (
:button) or a string, also one the typespec lacks ("mark"): the JS client takes any string.
Options
:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec not_to_have_role!( Playwright.Locator.t() | t(Playwright.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 | String.t(), not_to_have_role_options() ) :: :ok
Like not_to_have_role/3, but raises Playwright.ExpectError when the expectation is not met.
@spec not_to_have_screenshot( Playwright.Locator.t() | Playwright.Page.t() | t(Playwright.Locator.t() | Playwright.Page.t()), not_to_have_screenshot_options() ) :: :ok | {:error, Playwright.error()}
The opposite of to_have_screenshot/2: expect(x).not.toHaveScreenshot(...) in JS.
Since Playwright 1.23.
Options
:name(String.t/0| list ofString.t/0) - Snapshot name. Must have a.pngor.webpextension, the screenshot is captured in the corresponding format. Both formats are lossless.In Elixir, a test of
Playwright.Testresolves it to a file (see "Snapshots" in its docs), and with neither:namenor:pathnames the snapshot after the test. On failure the-actual,-expected,-previousand-diffimages are written to the test's output dir.:path(String.t/0) - The snapshot file, in place of:name, required outside aPlaywright.Testtest. Must have a.pngor.webpextension. A missing snapshot is written (see:update_snapshotsin the configuration ofPlaywright.Expect); on failure the-actual,-expected,-previousand-diffimages 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
transitionendevent. - infinite animations are canceled to initial state, and then played over after the screenshot.
Defaults to
:disabledthat disables animations.- finite animations are fast-forwarded to completion, so they'll fire
: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 ofPlaywright.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, between0and1. Default is configurable withconfig :playwright, :expect(see the configuration inPlaywright.Expect). Note that:thresholddefines which pixels are considered different.:max_diff_pixels(integer/0) - An acceptable amount of pixels that could be different. Default is configurable withconfig :playwright, :expect(see the configuration inPlaywright.Expect). Note that:thresholddefines which pixels are considered different.:omit_background(boolean/0) - Hides default white background and allows capturing screenshots with transparency. Not applicable tojpegimages. Defaults tofalse.: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:deviceoption 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(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:style_path(String.t/0| list ofString.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 withconfig :playwright, :expect(see the configuration inPlaywright.Expect). Defaults to0.2.:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect, to_have_screenshot: [...], else to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: 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 tofalse.
@spec not_to_have_screenshot!( Playwright.Locator.t() | Playwright.Page.t() | t(Playwright.Locator.t() | Playwright.Page.t()), not_to_have_screenshot_options() ) :: :ok
Like not_to_have_screenshot/2, but raises Playwright.ExpectError when the expectation is not met.
@spec not_to_have_text( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | Regex.t() | Playwright.RegExp.t() | [String.t() | Regex.t() | Playwright.RegExp.t()], not_to_have_text_options() ) :: :ok | {:error, Playwright.error()}
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_caseoption takes precedence over the corresponding regular expression flag if specified.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.:use_inner_text(boolean/0) - Whether to useelement.innerTextinstead ofelement.textContentwhen retrieving DOM node text.
@spec not_to_have_text!( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | Regex.t() | Playwright.RegExp.t() | [String.t() | Regex.t() | Playwright.RegExp.t()], not_to_have_text_options() ) :: :ok
Like not_to_have_text/3, but raises Playwright.ExpectError when the expectation is not met.
@spec not_to_have_title( Playwright.Page.t() | t(Playwright.Page.t()), String.t() | Regex.t() | Playwright.RegExp.t(), not_to_have_title_options() ) :: :ok | {:error, Playwright.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(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec not_to_have_title!( Playwright.Page.t() | t(Playwright.Page.t()), String.t() | Regex.t() | Playwright.RegExp.t(), not_to_have_title_options() ) :: :ok
Like not_to_have_title/3, but raises Playwright.ExpectError when the expectation is not met.
@spec not_to_have_url( Playwright.Page.t() | t(Playwright.Page.t()), String.t() | Regex.t() | Playwright.RegExp.t() | (URI.t() -> boolean()), not_to_have_url_options() ) :: :ok | {:error, Playwright.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 receivingURIto match. When:base_urlis provided via the context options and theurlargument is a string, the two values are merged via thenew 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_caseoption takes precedence over the corresponding regular expression parameter if specified. A provided predicate ignores this flag.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec not_to_have_url!( Playwright.Page.t() | t(Playwright.Page.t()), String.t() | Regex.t() | Playwright.RegExp.t() | (URI.t() -> boolean()), not_to_have_url_options() ) :: :ok
Like not_to_have_url/3, but raises Playwright.ExpectError when the expectation is not met.
@spec not_to_have_value( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | Regex.t() | Playwright.RegExp.t(), not_to_have_value_options() ) :: :ok | {:error, Playwright.error()}
The opposite of to_have_value/3: expect(x).not.toHaveValue(...) in JS.
Since Playwright 1.20.
Arguments
value- Expected value.
Options
:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec not_to_have_value!( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | Regex.t() | Playwright.RegExp.t(), not_to_have_value_options() ) :: :ok
Like not_to_have_value/3, but raises Playwright.ExpectError when the expectation is not met.
@spec not_to_have_values( Playwright.Locator.t() | t(Playwright.Locator.t()), [String.t() | Regex.t() | Playwright.RegExp.t()], not_to_have_values_options() ) :: :ok | {:error, Playwright.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(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec not_to_have_values!( Playwright.Locator.t() | t(Playwright.Locator.t()), [String.t() | Regex.t() | Playwright.RegExp.t()], not_to_have_values_options() ) :: :ok
Like not_to_have_values/3, but raises Playwright.ExpectError when the expectation is not met.
@spec not_to_match_aria_snapshot( Playwright.Locator.t() | Playwright.Page.t() | t(Playwright.Locator.t() | Playwright.Page.t()), String.t() | nil, not_to_match_aria_snapshot_options() ) :: :ok | {:error, Playwright.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.
:name(String.t/0) - Name of the snapshot to store in the snapshot folder corresponding to this test. Generates sequential names if not specified.In Elixir, in place of
expected: a test ofPlaywright.Testresolves it to a file (see "Snapshots" in its docs), and with neitherexpected,:namenor:pathnames the snapshot after the test.:path(String.t/0) - The snapshot file, in place ofexpectedor:name. Its content is the expected snapshot. A missing snapshot is written, unless:update_snapshotsis:noneor the matcher is negated. With:update_snapshotsset to:allit is always rewritten, with:changedwhen it differs (see the configuration ofPlaywright.Expect).:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec not_to_match_aria_snapshot!( Playwright.Locator.t() | Playwright.Page.t() | t(Playwright.Locator.t() | Playwright.Page.t()), String.t() | nil, not_to_match_aria_snapshot_options() ) :: :ok
Like not_to_match_aria_snapshot/3, but raises Playwright.ExpectError when the expectation is not met.
@spec not_to_pass((-> term()) | t((-> term())), not_to_pass_options()) :: :ok | {:error, Playwright.error()}
The opposite of to_pass/2: expect(x).not.toPass(...) in JS.
Since Playwright 1.29.
Options
:intervals(list ofinteger/0) - Probe, wait 1s, probe, wait 2s, probe, wait 10s, probe, wait 10s, probe:[1_000, 2_000, 10_000]. Defaults to[100, 250, 500, 1000].:timeout(number/0|:infinity) - Time to retry the callback for in milliseconds. Defaults to0: until the test's timeout (none outside aPlaywright.Testtest), not the matchers':timeout. A default other than0is:to_passinconfig :playwright, :expect(see the configuration inPlaywright.Expect). Within a test, it ends before the test's timeout.In Elixir,
:infinityis the same as0: no timeout.
@spec not_to_pass!((-> term()) | t((-> term())), not_to_pass_options()) :: :ok
Like not_to_pass/2, but raises Playwright.ExpectError when the expectation is not met.
@spec poll((-> term()) | t((-> term())), (term() -> term()), poll_options()) :: :ok | {:error, Playwright.error()}
You can convert any synchronous expect to an asynchronous polling one using Playwright.Expect.poll/3.
The following method will poll given function until it returns HTTP status 200:
Expect.poll!(
fn ->
response = page |> Page.request() |> APIRequestContext.get!("https://api.example.com")
APIResponse.status(response)
end,
&assert(&1 == 200),
# Custom expect message for reporting, optional.
message: "make sure API eventually succeeds",
# Poll for 10 seconds; defaults to 5 seconds. Pass 0 to disable timeout.
timeout: 10_000
)You can also specify custom polling intervals:
Expect.poll!(
fn ->
response = page |> Page.request() |> APIRequestContext.get!("https://api.example.com")
APIResponse.status(response)
end,
&assert(&1 == 200),
# Probe, wait 1s, probe, wait 2s, probe, wait 10s, probe, wait 10s, probe
# ... Defaults to [100, 250, 500, 1000].
intervals: [1_000, 2_000, 10_000],
timeout: 60_000
)You can combine Playwright.Expect.soft/1 with Playwright.Expect.poll/3 to perform soft assertions in polling logic. This allows the test to continue even if the assertion inside poll fails.
fn ->
response = page |> Page.request() |> APIRequestContext.get!("https://api.example.com")
APIResponse.status(response)
end
|> Expect.soft()
|> Expect.poll!(&assert(&1 == 200))In Elixir, the jest matcher is an assertion of the value, as Elixir's generic assertions are ExUnit's. callback raising fails the poll at once, as upstream's; the assertion raising is retried, and its last error is in the timeout's message. Both run in the calling process. Negate in the assertion (&refute(&1 == 200)): a negated receiver raises ArgumentError.
Since Playwright 1.21.
Arguments
assertion- Called with each value ofcallback, the place of a jest matcher (.toBe(200)): an ExUnit assertion (&assert(&1 == 200)), which raises until the value is right.
Options
:intervals(list ofinteger/0) - Probe, wait 1s, probe, wait 2s, probe, wait 10s, probe, wait 10s, probe:[1_000, 2_000, 10_000]. Defaults to[100, 250, 500, 1000].:message(String.t/0) - A custom expect message, for the step title and the error.:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
Like poll/3, but raises Playwright.ExpectError when the expectation is not met.
@spec soft(actual | t(actual)) :: t(actual) when actual: Playwright.Locator.t() | Playwright.Page.t() | Playwright.APIResponse.t() | (-> term())
By default, failed assertion will terminate test execution. Playwright also supports soft assertions: failed soft assertions do not terminate test execution, but mark the test as failed.
# Make a few checks that will not stop the test when failed...
Page.get_by_test_id(page, "status") |> Expect.soft() |> Expect.to_have_text!("Success")
Page.get_by_test_id(page, "eta") |> Expect.soft() |> Expect.to_have_text!("1 day")
# ... and continue the test to check more things.
Page.get_by_role(page, :link, name: "next page") |> Locator.click!()
Page.get_by_role(page, :heading, name: "Make another order") |> Expect.soft() |> Expect.to_be_visible!()Note that soft assertions only work with Playwright test runner.
In Elixir, soft/1 wraps the receiver as not_/1 does, in either order: locator |> Expect.soft() |> Expect.not_() is expect.soft(locator).not, and the not_to_* matchers take a soft receiver too. In a Playwright.Test test, a failed soft matcher returns :ok (the bang form too) and the test fails at the end of its body with all its errors. Outside such a test it fails as any matcher.
@spec to_be_attached( Playwright.Locator.t() | t(Playwright.Locator.t()), to_be_attached_options() ) :: :ok | {:error, Playwright.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(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec to_be_attached!( Playwright.Locator.t() | t(Playwright.Locator.t()), to_be_attached_options() ) :: :ok
Like to_be_attached/2, but raises Playwright.ExpectError when the expectation is not met.
@spec to_be_checked( Playwright.Locator.t() | t(Playwright.Locator.t()), to_be_checked_options() ) :: :ok | {:error, Playwright.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:indeterminateis 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:checkedis provided.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec to_be_checked!( Playwright.Locator.t() | t(Playwright.Locator.t()), to_be_checked_options() ) :: :ok
Like to_be_checked/2, but raises Playwright.ExpectError when the expectation is not met.
@spec to_be_disabled( Playwright.Locator.t() | t(Playwright.Locator.t()), to_be_disabled_options() ) :: :ok | {:error, Playwright.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(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec to_be_disabled!( Playwright.Locator.t() | t(Playwright.Locator.t()), to_be_disabled_options() ) :: :ok
Like to_be_disabled/2, but raises Playwright.ExpectError when the expectation is not met.
@spec to_be_editable( Playwright.Locator.t() | t(Playwright.Locator.t()), to_be_editable_options() ) :: :ok | {:error, Playwright.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(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec to_be_editable!( Playwright.Locator.t() | t(Playwright.Locator.t()), to_be_editable_options() ) :: :ok
Like to_be_editable/2, but raises Playwright.ExpectError when the expectation is not met.
@spec to_be_empty( Playwright.Locator.t() | t(Playwright.Locator.t()), to_be_empty_options() ) :: :ok | {:error, Playwright.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(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec to_be_empty!( Playwright.Locator.t() | t(Playwright.Locator.t()), to_be_empty_options() ) :: :ok
Like to_be_empty/2, but raises Playwright.ExpectError when the expectation is not met.
@spec to_be_enabled( Playwright.Locator.t() | t(Playwright.Locator.t()), to_be_enabled_options() ) :: :ok | {:error, Playwright.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(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec to_be_enabled!( Playwright.Locator.t() | t(Playwright.Locator.t()), to_be_enabled_options() ) :: :ok
Like to_be_enabled/2, but raises Playwright.ExpectError when the expectation is not met.
@spec to_be_focused( Playwright.Locator.t() | t(Playwright.Locator.t()), to_be_focused_options() ) :: :ok | {:error, Playwright.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(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec to_be_focused!( Playwright.Locator.t() | t(Playwright.Locator.t()), to_be_focused_options() ) :: :ok
Like to_be_focused/2, but raises Playwright.ExpectError when the expectation is not met.
@spec to_be_in_viewport( Playwright.Locator.t() | t(Playwright.Locator.t()), to_be_in_viewport_options() ) :: :ok | {:error, Playwright.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 to0, then element should intersect viewport at any positive ratio. Defaults to0.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec to_be_in_viewport!( Playwright.Locator.t() | t(Playwright.Locator.t()), to_be_in_viewport_options() ) :: :ok
Like to_be_in_viewport/2, but raises Playwright.ExpectError when the expectation is not met.
@spec to_be_ok(Playwright.APIResponse.t() | t(Playwright.APIResponse.t())) :: :ok | {:error, Playwright.error()}
Ensures the response status code is within 200..299 range.
Usage
Expect.to_be_ok!(response)Since Playwright 1.18.
@spec to_be_ok!(Playwright.APIResponse.t() | t(Playwright.APIResponse.t())) :: :ok
Like to_be_ok/1, but raises Playwright.ExpectError when the expectation is not met.
@spec to_be_visible( Playwright.Locator.t() | t(Playwright.Locator.t()), to_be_visible_options() ) :: :ok | {:error, Playwright.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 Playwright.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(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.:visible(boolean/0) - Since Playwright 1.26.
@spec to_be_visible!( Playwright.Locator.t() | t(Playwright.Locator.t()), to_be_visible_options() ) :: :ok
Like to_be_visible/2, but raises Playwright.ExpectError when the expectation is not met.
@spec to_contain_class( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | [String.t()], to_contain_class_options() ) :: :ok | {:error, Playwright.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(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec to_contain_class!( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | [String.t()], to_contain_class_options() ) :: :ok
Like to_contain_class/3, but raises Playwright.ExpectError when the expectation is not met.
@spec to_contain_text( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | Regex.t() | Playwright.RegExp.t() | [String.t() | Regex.t() | Playwright.RegExp.t()], to_contain_text_options() ) :: :ok | {:error, Playwright.error()}
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:
- Locator resolves to a list of elements.
- Elements from a subset of this list contain text from the expected array, respectively.
- The matching subset of elements has the same order as the expected array.
- 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_caseoption takes precedence over the corresponding regular expression flag if specified.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.:use_inner_text(boolean/0) - Whether to useelement.innerTextinstead ofelement.textContentwhen retrieving DOM node text.
@spec to_contain_text!( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | Regex.t() | Playwright.RegExp.t() | [String.t() | Regex.t() | Playwright.RegExp.t()], to_contain_text_options() ) :: :ok
Like to_contain_text/3, but raises Playwright.ExpectError when the expectation is not met.
@spec to_have_accessible_description( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | Regex.t() | Playwright.RegExp.t(), to_have_accessible_description_options() ) :: :ok | {:error, Playwright.error()}
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_caseoption takes precedence over the corresponding regular expression flag if specified.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec to_have_accessible_description!( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | Regex.t() | Playwright.RegExp.t(), to_have_accessible_description_options() ) :: :ok
Like to_have_accessible_description/3, but raises Playwright.ExpectError when the expectation is not met.
@spec to_have_accessible_error_message( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | Regex.t() | Playwright.RegExp.t(), to_have_accessible_error_message_options() ) :: :ok | {:error, Playwright.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_caseoption takes precedence over the corresponding regular expression flag if specified.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec to_have_accessible_error_message!( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | Regex.t() | Playwright.RegExp.t(), to_have_accessible_error_message_options() ) :: :ok
Like to_have_accessible_error_message/3, but raises Playwright.ExpectError when the expectation is not met.
@spec to_have_accessible_name( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | Regex.t() | Playwright.RegExp.t(), to_have_accessible_name_options() ) :: :ok | {:error, Playwright.error()}
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_caseoption takes precedence over the corresponding regular expression flag if specified.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec to_have_accessible_name!( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | Regex.t() | Playwright.RegExp.t(), to_have_accessible_name_options() ) :: :ok
Like to_have_accessible_name/3, but raises Playwright.ExpectError when the expectation is not met.
@spec to_have_attribute( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t(), String.t() | Regex.t() | Playwright.RegExp.t() | nil, to_have_attribute_options() ) :: :ok | {:error, Playwright.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_caseoption takes precedence over the corresponding regular expression flag if specified.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec to_have_attribute!( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t(), String.t() | Regex.t() | Playwright.RegExp.t() | nil, to_have_attribute_options() ) :: :ok
Like to_have_attribute/4, but raises Playwright.ExpectError when the expectation is not met.
@spec to_have_class( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | Regex.t() | Playwright.RegExp.t() | [String.t() | Regex.t() | Playwright.RegExp.t()], to_have_class_options() ) :: :ok | {:error, Playwright.error()}
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 Playwright.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(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec to_have_class!( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | Regex.t() | Playwright.RegExp.t() | [String.t() | Regex.t() | Playwright.RegExp.t()], to_have_class_options() ) :: :ok
Like to_have_class/3, but raises Playwright.ExpectError when the expectation is not met.
@spec to_have_count( Playwright.Locator.t() | t(Playwright.Locator.t()), integer(), to_have_count_options() ) :: :ok | {:error, Playwright.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(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec to_have_count!( Playwright.Locator.t() | t(Playwright.Locator.t()), integer(), to_have_count_options() ) :: :ok
Like to_have_count/3, but raises Playwright.ExpectError when the expectation is not met.
@spec to_have_css( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t(), String.t() | Regex.t() | Playwright.RegExp.t(), to_have_css_options() ) :: :ok | {:error, Playwright.error()}
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(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec to_have_css!( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t(), String.t() | Regex.t() | Playwright.RegExp.t(), to_have_css_options() ) :: :ok
Like to_have_css/4, but raises Playwright.ExpectError when the expectation is not met.
@spec to_have_id( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | Regex.t() | Playwright.RegExp.t(), to_have_id_options() ) :: :ok | {:error, Playwright.error()}
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(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec to_have_id!( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | Regex.t() | Playwright.RegExp.t(), to_have_id_options() ) :: :ok
Like to_have_id/3, but raises Playwright.ExpectError when the expectation is not met.
@spec to_have_js_property( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t(), term(), to_have_js_property_options() ) :: :ok | {:error, Playwright.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(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec to_have_js_property!( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t(), term(), to_have_js_property_options() ) :: :ok
Like to_have_js_property/4, but raises Playwright.ExpectError when the expectation is not met.
@spec to_have_role( Playwright.Locator.t() | t(Playwright.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 | String.t(), to_have_role_options() ) :: :ok | {:error, Playwright.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.In Elixir, a role is an atom of the typespec (
:button) or a string, also one the typespec lacks ("mark"): the JS client takes any string.
Options
:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec to_have_role!( Playwright.Locator.t() | t(Playwright.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 | String.t(), to_have_role_options() ) :: :ok
Like to_have_role/3, but raises Playwright.ExpectError when the expectation is not met.
@spec to_have_screenshot( Playwright.Locator.t() | Playwright.Page.t() | t(Playwright.Locator.t() | Playwright.Page.t()), to_have_screenshot_options() ) :: :ok | {:error, Playwright.error()}
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, name: "image.png")
# Outside a Playwright.Test test
Expect.to_have_screenshot!(page, path: "test/snapshots/image.png")Since Playwright 1.23.
Options
:name(String.t/0| list ofString.t/0) - Snapshot name. Must have a.pngor.webpextension, the screenshot is captured in the corresponding format. Both formats are lossless.In Elixir, a test of
Playwright.Testresolves it to a file (see "Snapshots" in its docs), and with neither:namenor:pathnames the snapshot after the test. On failure the-actual,-expected,-previousand-diffimages are written to the test's output dir.:path(String.t/0) - The snapshot file, in place of:name, required outside aPlaywright.Testtest. Must have a.pngor.webpextension. A missing snapshot is written (see:update_snapshotsin the configuration ofPlaywright.Expect); on failure the-actual,-expected,-previousand-diffimages 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
transitionendevent. - infinite animations are canceled to initial state, and then played over after the screenshot.
Defaults to
:disabledthat disables animations.- finite animations are fast-forwarded to completion, so they'll fire
: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 ofPlaywright.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, between0and1. Default is configurable withconfig :playwright, :expect(see the configuration inPlaywright.Expect). Note that:thresholddefines which pixels are considered different.:max_diff_pixels(integer/0) - An acceptable amount of pixels that could be different. Default is configurable withconfig :playwright, :expect(see the configuration inPlaywright.Expect). Note that:thresholddefines which pixels are considered different.:omit_background(boolean/0) - Hides default white background and allows capturing screenshots with transparency. Not applicable tojpegimages. Defaults tofalse.: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:deviceoption 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(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:style_path(String.t/0| list ofString.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 withconfig :playwright, :expect(see the configuration inPlaywright.Expect). Defaults to0.2.:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect, to_have_screenshot: [...], else to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: 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 tofalse.
@spec to_have_screenshot!( Playwright.Locator.t() | Playwright.Page.t() | t(Playwright.Locator.t() | Playwright.Page.t()), to_have_screenshot_options() ) :: :ok
Like to_have_screenshot/2, but raises Playwright.ExpectError when the expectation is not met.
@spec to_have_text( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | Regex.t() | Playwright.RegExp.t() | [String.t() | Regex.t() | Playwright.RegExp.t()], to_have_text_options() ) :: :ok | {:error, Playwright.error()}
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:
- Locator resolves to a list of elements.
- The number of elements equals the number of expected values in the array.
- 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_caseoption takes precedence over the corresponding regular expression flag if specified.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.:use_inner_text(boolean/0) - Whether to useelement.innerTextinstead ofelement.textContentwhen retrieving DOM node text.
@spec to_have_text!( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | Regex.t() | Playwright.RegExp.t() | [String.t() | Regex.t() | Playwright.RegExp.t()], to_have_text_options() ) :: :ok
Like to_have_text/3, but raises Playwright.ExpectError when the expectation is not met.
@spec to_have_title( Playwright.Page.t() | t(Playwright.Page.t()), String.t() | Regex.t() | Playwright.RegExp.t(), to_have_title_options() ) :: :ok | {:error, Playwright.error()}
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(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec to_have_title!( Playwright.Page.t() | t(Playwright.Page.t()), String.t() | Regex.t() | Playwright.RegExp.t(), to_have_title_options() ) :: :ok
Like to_have_title/3, but raises Playwright.ExpectError when the expectation is not met.
@spec to_have_url( Playwright.Page.t() | t(Playwright.Page.t()), String.t() | Regex.t() | Playwright.RegExp.t() | (URI.t() -> boolean()), to_have_url_options() ) :: :ok | {:error, Playwright.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?(&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(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 receivingURIto match. When:base_urlis provided via the context options and theurlargument is a string, the two values are merged via thenew 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_caseoption takes precedence over the corresponding regular expression parameter if specified. A provided predicate ignores this flag.:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec to_have_url!( Playwright.Page.t() | t(Playwright.Page.t()), String.t() | Regex.t() | Playwright.RegExp.t() | (URI.t() -> boolean()), to_have_url_options() ) :: :ok
Like to_have_url/3, but raises Playwright.ExpectError when the expectation is not met.
@spec to_have_value( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | Regex.t() | Playwright.RegExp.t(), to_have_value_options() ) :: :ok | {:error, Playwright.error()}
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(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec to_have_value!( Playwright.Locator.t() | t(Playwright.Locator.t()), String.t() | Regex.t() | Playwright.RegExp.t(), to_have_value_options() ) :: :ok
Like to_have_value/3, but raises Playwright.ExpectError when the expectation is not met.
@spec to_have_values( Playwright.Locator.t() | t(Playwright.Locator.t()), [String.t() | Regex.t() | Playwright.RegExp.t()], to_have_values_options() ) :: :ok | {:error, Playwright.error()}
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(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec to_have_values!( Playwright.Locator.t() | t(Playwright.Locator.t()), [String.t() | Regex.t() | Playwright.RegExp.t()], to_have_values_options() ) :: :ok
Like to_have_values/3, but raises Playwright.ExpectError when the expectation is not met.
@spec to_match_aria_snapshot( Playwright.Locator.t() | Playwright.Page.t() | t(Playwright.Locator.t() | Playwright.Page.t()), String.t() | nil, to_match_aria_snapshot_options() ) :: :ok | {:error, Playwright.error()}
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, name: "body.aria.yml")
# Outside a Playwright.Test test
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.
:name(String.t/0) - Name of the snapshot to store in the snapshot folder corresponding to this test. Generates sequential names if not specified.In Elixir, in place of
expected: a test ofPlaywright.Testresolves it to a file (see "Snapshots" in its docs), and with neitherexpected,:namenor:pathnames the snapshot after the test.:path(String.t/0) - The snapshot file, in place ofexpectedor:name. Its content is the expected snapshot. A missing snapshot is written, unless:update_snapshotsis:noneor the matcher is negated. With:update_snapshotsset to:allit is always rewritten, with:changedwhen it differs (see the configuration ofPlaywright.Expect).:signal(Playwright.AbortSignal.t/0) - Since Playwright 1.62. An optionalAbortSignalthat 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
Playwright.AbortSignal(Playwright.AbortController.signal/1).:timeout(number/0|:infinity) - Time to retry the assertion for in milliseconds,0for no timeout. Defaults to:timeoutinconfig :playwright, :expect(5000if not set, see the configuration inPlaywright.Expect).In Elixir,
:infinityis the same as0: no timeout.
@spec to_match_aria_snapshot!( Playwright.Locator.t() | Playwright.Page.t() | t(Playwright.Locator.t() | Playwright.Page.t()), String.t() | nil, to_match_aria_snapshot_options() ) :: :ok
Like to_match_aria_snapshot/3, but raises Playwright.ExpectError when the expectation is not met.
@spec to_pass((-> term()) | t((-> term())), to_pass_options()) :: :ok | {:ok, term()} | {:error, Playwright.error()}
You can retry blocks of code until they are passing successfully.
Expect.to_pass!(fn ->
response = page |> Page.request() |> APIRequestContext.get!("https://api.example.com")
assert APIResponse.status(response) == 200
end)You can also specify custom timeout and retry intervals:
Expect.to_pass!(
fn ->
response = page |> Page.request() |> APIRequestContext.get!("https://api.example.com")
assert APIResponse.status(response) == 200
end,
# Probe, wait 1s, probe, wait 2s, probe, wait 10s, probe, wait 10s, probe
# ... Defaults to [100, 250, 500, 1000].
intervals: [1_000, 2_000, 10_000],
timeout: 60_000
)Note that by default toPass has timeout 0 and does not respect custom expect timeout.
In Elixir, the callback runs in the calling process and passes once it returns. A failure in it (a raise such as an ExUnit.AssertionError or a Playwright.ExpectError, an exit) is retried; the last one is in the timeout's message. A callback still running at the deadline is not interrupted. A soft receiver (callback |> Expect.soft() |> Expect.to_pass()) works as for any matcher.
In Elixir, to_pass!/2 returns the callback's value of the attempt that passed (to_pass/2: {:ok, value}), which a JS callback assigns to an outer let (an Elixir closure can't):
box =
Expect.to_pass!(fn ->
box = Locator.bounding_box!(locator)
assert box.width == 30
box
end)A soft one that fails returns nil ({:ok, nil}), a negated one (Expect.not_/1) :ok, as not_to_pass/2.
Since Playwright 1.29.
Options
:intervals(list ofinteger/0) - Probe, wait 1s, probe, wait 2s, probe, wait 10s, probe, wait 10s, probe:[1_000, 2_000, 10_000]. Defaults to[100, 250, 500, 1000].:timeout(number/0|:infinity) - Time to retry the callback for in milliseconds. Defaults to0: until the test's timeout (none outside aPlaywright.Testtest), not the matchers':timeout. A default other than0is:to_passinconfig :playwright, :expect(see the configuration inPlaywright.Expect). Within a test, it ends before the test's timeout.In Elixir,
:infinityis the same as0: no timeout.
@spec to_pass!((-> term()) | t((-> term())), to_pass_options()) :: term()
Like to_pass/2, but raises Playwright.ExpectError when the expectation is not met.