Packages
pages
0.2.4
4.1.0
4.0.0
3.5.0
3.4.2
3.4.1
3.4.0
3.3.0
3.2.0
3.1.0
3.0.1
3.0.0
2.3.0
2.2.1
2.2.0
2.1.1
2.1.0
2.0.0
1.3.1
1.3.0
1.2.0
1.1.0
1.0.3
1.0.2
1.0.1
1.0.0
0.14.0
0.13.4
0.13.3
0.13.2
0.13.1
0.13.0
0.12.0
0.11.1
0.11.0
0.10.1
0.10.0
0.9.0
0.8.0
0.7.1
0.7.0
0.6.2
0.6.1
0.6.0
0.5.7
0.5.6
0.5.5
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.4.3
0.4.2
0.4.1
0.4.0
0.3.1
0.3.0
0.2.6
0.2.5
0.2.4
0.2.3
0.2.2
0.2.1
0.2.0
0.1.0
Page pattern for interacting with web pages
Current section
Files
Jump to
Current section
Files
lib/pages.ex
defmodule Pages do
# @related [test](test/pages_test.exs)
@moduledoc """
Entry point for interacting with pages.
Pages are built around `t: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
- `t:Pages.Driver.Conn.t/0` - Given a `t:Plug.Conn.t/0`, this driver will be used.
- `t:Pages.Driver.LiveView.t/0` - Given a `t:Plug.Conn.t/0` with inner data that
appears as if a `Phoenix.LiveView` is configured, this driver will be used.
"""
@type attrs_t() :: Keyword.t() | map()
@type page_type_t() :: :live_view
@type html_t() :: Floki.html_tree()
@doc "Instantiates a new page."
@spec new(Plug.Conn.t()) :: Pages.Driver.t()
def new(%Plug.Conn{assigns: %{live_module: _}} = conn), do: Pages.Driver.LiveView.new(conn)
def new(%Plug.Conn{} = conn), do: Pages.Driver.Conn.new(conn)
@doc "Simulates clicking on an element at `selector` with title `title`."
@spec click(Pages.Driver.t(), binary(), Pages.Css.selector()) :: Pages.Driver.t()
def click(%module{} = page, title, selector), do: module.click(page, title, selector)
@doc "Submits a form without specifying any attributes."
@spec submit_form(Pages.Driver.t(), Pages.Css.selector()) :: Pages.Driver.t()
def submit_form(%module{} = page, selector), do: module.submit_form(page, selector)
@doc "Fills in a form with `attributes` and submits it."
@spec submit_form(Pages.Driver.t(), Pages.Css.selector(), atom(), attrs_t()) :: Pages.Driver.t()
def submit_form(%module{} = page, selector, schema, attrs), do: module.submit_form(page, selector, schema, attrs)
@doc "Fills in a form with `attributes` without submitting it."
@spec update_form(Pages.Driver.t(), Pages.Css.selector(), atom(), attrs_t()) :: Pages.Driver.t()
def update_form(%module{} = page, selector, schema, attrs), do: module.update_form(page, selector, schema, attrs)
@doc "Visits `path`."
@spec visit(Pages.Driver.t(), Path.t()) :: Pages.Driver.t()
def visit(%module{} = page, path), do: module.visit(page, path)
end