Fluffy.Expect (Fluffy v0.3.1)

Copy Markdown View Source

Typed locator, active-page, and captured-result assertion values executed by Fluffy.Expect.expect/2.

Page and captured-result constructors use target prefixes such as page_to_have_url/2 and response_to_have_status/3. Import this module to use expect/2, not_/1, and all constructors. For ExUnit-style names, use Fluffy.Assert.

Assertion constructors use fluent to_be_* names for states and to_have_* names for properties.

Every expectation constructor accepts the shared timeout option. Captured-result assertions inspect an already retained result immediately; their timeout option does not wait for another event. Set the capture timeout on Fluffy.wait_for/4.

  • :timeout (non_neg_integer/0) - Maximum time in milliseconds to wait for the operation. Playwright browser bookkeeping and navigation synchronization use the session timeout separately.

to_be_checked/2 additionally accepts:

  • :timeout (non_neg_integer/0) - Maximum time in milliseconds to wait for the operation. Playwright browser bookkeeping and navigation synchronization use the session timeout separately.

  • :checked (boolean/0) - Set to false to expect an unchecked control.

  • :indeterminate (boolean/0) - Expect the browser-owned indeterminate state.

Summary

Functions

Executes an expectation and returns the unchanged or reconciled session.

Negates an expectation while preserving its target and options.

Assertions

Expects the captured dialog's action to equal the supplied value.

Expects the captured dialog's default value to equal the supplied value.

Expects the captured dialog's message to equal the supplied value.

Expects the captured dialog's prompt text to equal the supplied value.

Expects the captured dialog's type to equal the supplied value.

Expects the complete downloaded bytes to equal the supplied binary; no text decoding is performed.

Expects the captured download's content type to equal the supplied value.

Expects the download size in bytes.

Expects the captured download's suggested filename to equal the supplied value.

Expects the captured download URL to match a string, regex, or structured components.

Expects the captured navigation source URL to match a string, regex, or structured components.

Expects the captured navigation's status to equal the supplied value.

Expects the captured navigation URL to match a string, regex, or structured components.

Expects the active page to name the requested opener page.

Expects the active page's normalized main-resource status.

Expects the active page title to equal a string or match a regular expression.

Expects the active page to have the requested URL.

Expects the captured request headers to include every supplied key/value pair. Additional headers are allowed.

Expects the captured request's method to equal the supplied value.

Expects the captured request's page to equal the supplied value.

Expects the captured request's post data to equal the supplied value.

Expects the captured request's resource type to equal the supplied value.

Expects the captured request URL to match a string, regex, or structured components.

Expects the captured response headers to include every supplied key/value pair. Additional headers are allowed.

Expects the captured response's page to equal the supplied value.

Expects the HTTP method of the request that produced this response.

Expects the associated request payload to equal the supplied string. This does not inspect the response body.

Expects the captured response's resource type to equal the supplied value.

Expects the captured response's status to equal the supplied value.

Expects the captured response's status text to equal the supplied value.

Expects the captured response URL to match a string, regex, or structured components.

Locator assertions

to_be_checked(locator, options \\ [])

@spec to_be_checked(Fluffy.Locator.t(), [checked_option()]) :: t()

Expects a checkbox or radio to have Playwright's checked state.

The default is checked. Pass checked: false for unchecked, or indeterminate: true for the browser-owned mixed state. The indeterminate state requires Playwright because it is a DOM property rather than HTML state available to the Static or LiveView drivers.

to_be_disabled(locator, options \\ [])

@spec to_be_disabled(Fluffy.Locator.t(), [option()]) :: t()

to_be_editable(locator, options \\ [])

@spec to_be_editable(Fluffy.Locator.t(), [option()]) :: t()

to_be_enabled(locator, options \\ [])

@spec to_be_enabled(Fluffy.Locator.t(), [option()]) :: t()

to_be_focused(locator, options \\ [])

@spec to_be_focused(Fluffy.Locator.t(), [option()]) :: t()

to_be_visible(locator, options \\ [])

@spec to_be_visible(Fluffy.Locator.t(), [option()]) :: t()

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

@spec to_have_count(Fluffy.Locator.t(), non_neg_integer(), [option()]) :: t()

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

@spec to_have_value(Fluffy.Locator.t(), String.t(), [option()]) :: t()

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

@spec to_have_values(Fluffy.Locator.t(), [term()], [option()]) :: t()

Types

checked_option()

@type checked_option() ::
  {:timeout, non_neg_integer()}
  | {:checked, boolean()}
  | {:indeterminate, boolean()}

kind()

@type kind() ::
  :checked
  | :count
  | :disabled
  | :editable
  | :enabled
  | :focused
  | :opener
  | :status
  | :title
  | :url
  | :value
  | :values
  | :visible
  | :download_content
  | :download_content_type
  | :download_size
  | :download_suggested_filename
  | :download_url
  | :dialog_action
  | :dialog_default_value
  | :dialog_message
  | :dialog_prompt_text
  | :dialog_type
  | :navigation_from_url
  | :navigation_status
  | :navigation_url
  | :request_headers
  | :request_method
  | :request_page
  | :request_post_data
  | :request_resource_type
  | :request_url
  | :response_headers
  | :response_method
  | :response_page
  | :response_post_data
  | :response_resource_type
  | :response_status
  | :response_status_text
  | :response_url

option()

@type option() :: {:timeout, non_neg_integer()}

t()

@type t() :: %Fluffy.Expect{
  expected: term(),
  kind: kind(),
  negated?: boolean(),
  options: keyword(),
  target: target()
}

target()

@type target() ::
  {:locator, Fluffy.Locator.t()}
  | :page
  | {:download, term()}
  | {:dialog, term()}
  | {:navigation, term()}
  | {:request, term()}
  | {:response, term()}

Functions

expect(session, expectation, options \\ [])

@spec expect(Fluffy.Session.t(), t(), [option()]) :: Fluffy.Session.t()

Executes an expectation and returns the unchanged or reconciled session.

not_(expectation)

@spec not_(t()) :: t()

Negates an expectation while preserving its target and options.

Assertions

dialog_to_have_action(key, expected, options \\ [])

@spec dialog_to_have_action(term(), term(), [option()]) :: t()

Expects the captured dialog's action to equal the supplied value.

dialog_to_have_default_value(key, expected, options \\ [])

@spec dialog_to_have_default_value(term(), String.t(), [option()]) :: t()

Expects the captured dialog's default value to equal the supplied value.

dialog_to_have_message(key, expected, options \\ [])

@spec dialog_to_have_message(term(), String.t(), [option()]) :: t()

Expects the captured dialog's message to equal the supplied value.

dialog_to_have_prompt_text(key, expected, options \\ [])

@spec dialog_to_have_prompt_text(term(), term(), [option()]) :: t()

Expects the captured dialog's prompt text to equal the supplied value.

dialog_to_have_type(key, expected, options \\ [])

@spec dialog_to_have_type(term(), term(), [option()]) :: t()

Expects the captured dialog's type to equal the supplied value.

download_to_have_content(key, expected, options \\ [])

@spec download_to_have_content(term(), binary(), [option()]) :: t()

Expects the complete downloaded bytes to equal the supplied binary; no text decoding is performed.

download_to_have_content_type(key, expected, options \\ [])

@spec download_to_have_content_type(term(), String.t(), [option()]) :: t()

Expects the captured download's content type to equal the supplied value.

download_to_have_size(key, expected, options \\ [])

@spec download_to_have_size(term(), non_neg_integer(), [option()]) :: t()

Expects the download size in bytes.

download_to_have_suggested_filename(key, expected, options \\ [])

@spec download_to_have_suggested_filename(term(), String.t(), [option()]) :: t()

Expects the captured download's suggested filename to equal the supplied value.

download_to_have_url(key, expected, options \\ [])

@spec download_to_have_url(term(), Fluffy.Page.url_expectation(), [option()]) :: t()

Expects the captured download URL to match a string, regex, or structured components.

Strings match exactly and regexes match against the complete captured URL. Relative strings are not resolved. Structured keywords use the same path, query, and fragment rules as Fluffy.Expect.page_to_have_url/2.

page_to_have_opener(expected, options \\ [])

@spec page_to_have_opener(term(), [option()]) :: t()

Expects the active page to name the requested opener page.

page_to_have_status(expected, options \\ [])

@spec page_to_have_status(non_neg_integer(), [option()]) :: t()

Expects the active page's normalized main-resource status.

page_to_have_title(expected, options \\ [])

@spec page_to_have_title(Fluffy.Page.title_expectation(), [option()]) :: t()

Expects the active page title to equal a string or match a regular expression.

Like Playwright's toHaveTitle, the assertion retries on Live and Playwright pages and normalizes whitespace before matching.

Options

  • :timeout (non_neg_integer/0) - Maximum time in milliseconds to wait for the operation. Playwright browser bookkeeping and navigation synchronization use the session timeout separately.

page_to_have_url(expected, options \\ [])

@spec page_to_have_url(Fluffy.Page.url_expectation(), [option()]) :: t()

Expects the active page to have the requested URL.

A string matches the complete canonical absolute URL after resolving a relative value against the session base URL. A regular expression matches that complete serialized URL.

A keyword list selects structured components. :path and :fragment are exact serialized component values; omit either to ignore it. :fragment excludes the leading #, and fragment: nil requires no fragment.

:query is a map from decoded parameter names to one value or an ordered list of repeated values. Ordering between distinct names is ignored while repeated-value order is retained. Bare names and names with an empty value both decode to ""; + and %20 both decode to a space. Exact mode is the default. query_mode: :subset permits unrelated names but still requires the complete ordered value list for each requested name.

Structured components

  • :path (String.t/0) - Serialized URL pathname to match exactly.

  • :query - Decoded query names and their ordered value or values.

  • :query_mode - Require the complete query or allow unrelated parameter names. The default value is :exact.

  • :fragment - Serialized fragment without #; nil requires no fragment.

Assertion options

  • :timeout (non_neg_integer/0) - Maximum time in milliseconds to wait for the operation. Playwright browser bookkeeping and navigation synchronization use the session timeout separately.

request_to_have_headers(key, expected, options \\ [])

@spec request_to_have_headers(term(), map(), [option()]) :: t()

Expects the captured request headers to include every supplied key/value pair. Additional headers are allowed.

request_to_have_method(key, expected, options \\ [])

@spec request_to_have_method(term(), String.t(), [option()]) :: t()

Expects the captured request's method to equal the supplied value.

request_to_have_page(key, expected, options \\ [])

@spec request_to_have_page(term(), term(), [option()]) :: t()

Expects the captured request's page to equal the supplied value.

request_to_have_post_data(key, expected, options \\ [])

@spec request_to_have_post_data(term(), String.t(), [option()]) :: t()

Expects the captured request's post data to equal the supplied value.

request_to_have_resource_type(key, expected, options \\ [])

@spec request_to_have_resource_type(term(), String.t(), [option()]) :: t()

Expects the captured request's resource type to equal the supplied value.

request_to_have_url(key, expected, options \\ [])

@spec request_to_have_url(term(), Fluffy.Page.url_expectation(), [option()]) :: t()

Expects the captured request URL to match a string, regex, or structured components.

Strings match exactly and regexes match against the complete captured URL. Relative strings are not resolved. Structured keywords use the same path, query, and fragment rules as Fluffy.Expect.page_to_have_url/2.

response_to_have_headers(key, expected, options \\ [])

@spec response_to_have_headers(term(), map(), [option()]) :: t()

Expects the captured response headers to include every supplied key/value pair. Additional headers are allowed.

response_to_have_page(key, expected, options \\ [])

@spec response_to_have_page(term(), term(), [option()]) :: t()

Expects the captured response's page to equal the supplied value.

response_to_have_request_method(key, expected, options \\ [])

@spec response_to_have_request_method(term(), String.t(), [option()]) :: t()

Expects the HTTP method of the request that produced this response.

response_to_have_request_post_data(key, expected, options \\ [])

@spec response_to_have_request_post_data(term(), String.t(), [option()]) :: t()

Expects the associated request payload to equal the supplied string. This does not inspect the response body.

response_to_have_resource_type(key, expected, options \\ [])

@spec response_to_have_resource_type(term(), String.t(), [option()]) :: t()

Expects the captured response's resource type to equal the supplied value.

response_to_have_status(key, expected, options \\ [])

@spec response_to_have_status(term(), integer(), [option()]) :: t()

Expects the captured response's status to equal the supplied value.

response_to_have_status_text(key, expected, options \\ [])

@spec response_to_have_status_text(term(), String.t(), [option()]) :: t()

Expects the captured response's status text to equal the supplied value.

response_to_have_url(key, expected, options \\ [])

@spec response_to_have_url(term(), Fluffy.Page.url_expectation(), [option()]) :: t()

Expects the captured response URL to match a string, regex, or structured components.

Strings match exactly and regexes match against the complete captured URL. Relative strings are not resolved. Structured keywords use the same path, query, and fragment rules as Fluffy.Expect.page_to_have_url/2.