gleewright/page

A browser tab. Every test gets a fresh page in its own isolated context.

Types

A browser tab.

pub type Page

Values

pub fn content(page: Page) -> step.Step(String)

The page’s full HTML.

pub fn evaluate(
  page: Page,
  expression: String,
) -> step.Step(dynamic.Dynamic)

Evaluate a JavaScript expression in the page, e.g. "document.cookie" or "() => window.scrollY". Decode the result with gleam/dynamic/decode.

pub fn full_page_screenshot(
  page: Page,
  path: String,
) -> step.Step(Nil)

Save a screenshot of the whole scrollable page as a PNG.

pub fn get_by_alt_text(
  page: Page,
  text: String,
) -> locator.Locator

Find images by their alt text.

pub fn get_by_exact_text(
  page: Page,
  text: String,
) -> locator.Locator

Find elements whose text is exactly the given text.

pub fn get_by_label(page: Page, text: String) -> locator.Locator

Find form controls by the text of their <label> or aria-label.

pub fn get_by_placeholder(
  page: Page,
  text: String,
) -> locator.Locator

Find inputs by their placeholder text.

pub fn get_by_role(
  page: Page,
  role: role.Role,
) -> locator.Locator

Find elements with the given ARIA role.

page.get_by_role(page, role.Heading)
pub fn get_by_role_exactly_named(
  page: Page,
  role: role.Role,
  name: String,
) -> locator.Locator

Like get_by_role_named, but the accessible name must match exactly. An empty name matches only elements with no accessible name.

pub fn get_by_role_named(
  page: Page,
  role: role.Role,
  name: String,
) -> locator.Locator

Find elements with the given ARIA role and accessible name. The name matches case-insensitively as a substring.

page.get_by_role_named(page, role.Button, "Sign in")
pub fn get_by_test_id(page: Page, id: String) -> locator.Locator

Find elements by their data-testid attribute.

pub fn get_by_text(page: Page, text: String) -> locator.Locator

Find elements containing the given text (case-insensitive substring).

pub fn get_by_title(page: Page, text: String) -> locator.Locator

Find elements by their title attribute.

pub fn go_back(page: Page) -> step.Step(Nil)

Go back in the page’s history.

pub fn go_forward(page: Page) -> step.Step(Nil)

Go forward in the page’s history.

pub fn goto(page: Page, url: String) -> step.Step(Nil)

Navigate to a URL and wait for it to load. Relative URLs are resolved against the base_url of the test config.

pub fn locator(page: Page, selector: String) -> locator.Locator

Find elements matching a CSS or XPath selector. Prefer the get_by_* functions, which match how users see the page.

pub fn new(context: browser.Context) -> step.Step(Page)

Open a new page in a context.

pub fn press(page: Page, key: String) -> step.Step(Nil)

Press a key or key combination on the focused element, e.g. "Tab" or "Control+Enter".

pub fn reload(page: Page) -> step.Step(Nil)

Reload the page.

pub fn screenshot(page: Page, path: String) -> step.Step(Nil)

Save a screenshot of the viewport as a PNG.

pub fn set_content(page: Page, html: String) -> step.Step(Nil)

Replace the page’s HTML. Handy for testing components in isolation.

pub fn title(page: Page) -> step.Step(String)

The page’s title.

pub fn type_text(page: Page, text: String) -> step.Step(Nil)

Type text into the focused element one key at a time.

pub fn url(page: Page) -> String

The current URL of the page.

pub fn wait_for_url(page: Page, url: String) -> step.Step(Nil)

Wait until the page’s URL matches, e.g. after submitting a form. Relative URLs are resolved against the base_url of the test config.

✨ Search Document