Fluffy.Event (Fluffy v0.5.2)

Copy Markdown View Source

Typed event-wait values and event capture orchestration.

Events annotated "Playwright only" require the Playwright backend when passed to Fluffy.wait_for/4. With the Phoenix backend, capture raises Fluffy.CapabilityError before the action runs. Constructing an event value does not require a session.

Download events accept:

  • :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.

  • :filename - Only capture downloads whose suggested filename matches this exact string or regex.

  • :url - Only capture downloads whose URL matches this absolute string, regex, or URI predicate.

  • :max_bytes (non_neg_integer/0) - Maximum number of response bytes to retain; defaults to 10,000,000.

Dialog events accept:

  • :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.

  • :decision (:accept, :dismiss, {:accept, prompt_text}, or a one-argument function) - Accept, dismiss, accept with prompt text, or decide from the captured dialog.

  • :accept (true or String.t/0) - Compatibility shorthand for accepting, optionally with prompt text.

  • :dismiss (true) - Compatibility shorthand for dismissing the dialog.

File-chooser, page, popup, navigation, request, and response events accept the shared timeout option:

  • :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.

Summary

Functions

Captures and handles the browser dialog opened by the action.

Captures the first download matching the optional filename and URL filters.

Captures the browser file chooser opened by the action.

Captures the first document navigation or URL change. HTTP redirects resolve to their final URL and status.

Captures the first new tab or window anywhere in the session.

Captures the first new tab or window opened by the current page.

Captures the first browser request matching the supplied matcher.

Captures the first browser response matching the supplied matcher.

Types

dialog_option()

@type dialog_option() ::
  {:timeout, non_neg_integer()}
  | {:decision,
     :accept
     | :dismiss
     | {:accept, String.t()}
     | (Fluffy.Dialog.t() -> :accept | :dismiss | {:accept, String.t()})}
  | {:accept, true | String.t()}
  | {:dismiss, true}

download_option()

@type download_option() ::
  {:timeout, non_neg_integer()}
  | {:filename, binary() | struct()}
  | {:url, binary() | struct() | (term() -> term())}
  | {:max_bytes, non_neg_integer()}

network_option()

@type network_option() ::
  {:timeout, non_neg_integer()}
  | {:matcher, String.t() | Regex.t() | (term() -> boolean())}

option()

t()

@type t() :: %Fluffy.Event{key: term(), options: keyword(), type: type()}

timeout_option()

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

type()

@type type() ::
  :dialog
  | :download
  | :file_chooser
  | :navigation
  | :page
  | :popup
  | :request
  | :response

Functions

dialog(key, options \\ [])

(Playwright only)
@spec dialog(term(), [dialog_option()]) :: t()

Captures and handles the browser dialog opened by the action.

download(key, options \\ [])

@spec download(term(), [download_option()]) :: t()

Captures the first download matching the optional filename and URL filters.

Playwright uses the session timeout separately to save the captured download.

file_chooser(key, options \\ [])

(Playwright only)
@spec file_chooser(term(), [timeout_option()]) :: t()

Captures the browser file chooser opened by the action.

page(key, options \\ [])

(Playwright only)
@spec page(term(), [timeout_option()]) :: t()

Captures the first new tab or window anywhere in the session.

Equivalent to Playwright's context.waitForEvent('page'). Use popup/2 to capture only pages opened by the current page.

The session timeout applies separately to initializing the captured page.

popup(key, options \\ [])

(Playwright only)
@spec popup(term(), [timeout_option()]) :: t()

Captures the first new tab or window opened by the current page.

Equivalent to Playwright's page.waitForEvent('popup'); includes tabs opened by target="_blank" links. The opener is fixed when the wait starts, even if the callback switches pages. Use page/2 to capture any new page in the session.

The session timeout applies separately to initializing the captured page.

request(key, matcher, options \\ [])

(Playwright only)
@spec request(term(), String.t() | Regex.t() | (term() -> boolean()), [
  timeout_option()
]) :: t()

Captures the first browser request matching the supplied matcher.

response(key, matcher, options \\ [])

(Playwright only)
@spec response(term(), String.t() | Regex.t() | (term() -> boolean()), [
  timeout_option()
]) :: t()

Captures the first browser response matching the supplied matcher.