View Source Pages (Pages v0.8.0)

Entry point for interacting with pages.

Pages are built around Pages.Driver.t/0 structs. Drivers hold state about the current connection, implement @behavior Pages.Driver and must implement the String.Chars protocol to transform themselves into HTML.

available-drivers

Available drivers

Link to this section Summary

Functions

Simulates clicking on an element at selector with title title. Set the method param to :post to click on a link that has data-method=post.

Instantiates a new page.

Render a change to the element at selector with the value value. See Phoenix.LiveViewTest.render_change/2 for a description of the value field.

Sends a hook event to the live view. See Phoenix.LiveViewTest.render_hook/3 for more information.

Performs an upload of a file input and renders the result. See Phoenix.LiveViewTest.file_input/4 for a description of the upload field.

Re-renders the page.

Submits a form without specifying any attributes. This function will submit any values currently set in the form HTML.

Fills in a form with attributes and submits it. Hidden parameters can by send by including a fifth enumerable.

Fills in a form with attributes without submitting it.

Visits path.

Finds a phoenix component with an id matching child_id, and passes it to the given function. This is helpful when a site implements stateful LiveView components, and messages should be directed to a process other than the parent LiveView pid.

Link to this section Types

@type attrs_t() :: Keyword.t() | map()
@type http_method() :: :get | :post
@type live_view_upload() :: %Phoenix.LiveViewTest.Upload{
  cid: term(),
  config: term(),
  element: term(),
  entries: term(),
  pid: term(),
  ref: term(),
  selector: term(),
  view: term()
}
@type page_type_t() :: :live_view
@type text_filter() :: binary() | Regex.t()

Link to this section Functions

Link to this function

click(page, title, selector)

View Source
Link to this function

click(page, method, title, selector)

View Source

Simulates clicking on an element at selector with title title. Set the method param to :post to click on a link that has data-method=post.

@spec new(Plug.Conn.t()) :: Pages.Driver.t()

Instantiates a new page.

Link to this function

render_change(page, selector, value)

View Source
@spec render_change(Pages.Driver.t(), HtmlQuery.Css.selector(), Enum.t()) ::
  Pages.Driver.t()

Render a change to the element at selector with the value value. See Phoenix.LiveViewTest.render_change/2 for a description of the value field.

Link to this function

render_hook(page, event, value_attrs)

View Source
@spec render_hook(Pages.Driver.t(), binary(), attrs_t()) :: Pages.Driver.t()

Sends a hook event to the live view. See Phoenix.LiveViewTest.render_hook/3 for more information.

Link to this function

render_upload(page, upload, entry_name, percent \\ 100)

View Source
@spec render_upload(Pages.Driver.t(), live_view_upload(), binary(), integer()) ::
  Pages.Driver.t()

Performs an upload of a file input and renders the result. See Phoenix.LiveViewTest.file_input/4 for a description of the upload field.

@spec rerender(Pages.Driver.t()) :: Pages.Driver.t()

Re-renders the page.

Link to this function

submit_form(page, selector)

View Source

Submits a form without specifying any attributes. This function will submit any values currently set in the form HTML.

Link to this function

submit_form(page, selector, schema, attrs)

View Source
@spec submit_form(Pages.Driver.t(), HtmlQuery.Css.selector(), atom(), attrs_t()) ::
  Pages.Driver.t()

Fills in a form with attributes and submits it. Hidden parameters can by send by including a fifth enumerable.

arguments

Arguments

namedecription
pageThe current page struct.
selectorA CSS selector matching the form.
schemaAn atom representing the schema of the form. Attributes will be nested under this key when submitted. See Schema.
attrsA map of attributes to send.
hidden_attrsAn optional map or keyword of hidden values to include.

schema

Schema

This atom determines the key under which attrs will be nested when sent to the server, and corresponds to the atom which an t:Ecto.Changeset.t/0 serializes to, or the value of :as passed to Phoenix.HTML.Form.form_for/4.

notes

Notes

When used with LiveView, this will trigger phx-submit with the specified attributes, and handles phx-trigger-action if present.

Link to this function

submit_form(page, selector, schema, form_attrs, hidden_attrs)

View Source
@spec submit_form(
  Pages.Driver.t(),
  HtmlQuery.Css.selector(),
  atom(),
  attrs_t(),
  attrs_t()
) ::
  Pages.Driver.t()

See Pages.submit_form/4 for more information.

Link to this function

update_form(page, selector, schema, attrs)

View Source
@spec update_form(Pages.Driver.t(), HtmlQuery.Css.selector(), atom(), attrs_t()) ::
  Pages.Driver.t()

Fills in a form with attributes without submitting it.

arguments

Arguments

See submit_form/4 for a full description of arguments.

notes

Notes

When used with LiveView, this will trigger phx-change with the specified attributes, and handles phx-trigger-action if present.

@spec visit(Pages.Driver.t(), Path.t()) :: Pages.Driver.t()

Visits path.

Link to this function

with_child_component(page, child_id, fun)

View Source
@spec with_child_component(
  Pages.Driver.t(),
  child_id :: binary(),
  (Pages.Driver.t() -> term())
) ::
  Pages.Driver.t()

Finds a phoenix component with an id matching child_id, and passes it to the given function. This is helpful when a site implements stateful LiveView components, and messages should be directed to a process other than the parent LiveView pid.

examples

Examples

Pages.with_child_component(page, "chat-component", fn child ->
  Pages.submit_form(child,
    [test_role: "new-chat-message"],
    :chat_message,
    contents: "Hi there!")
end)