gleewright/expect
Assertions about the page. Assertions on locators and pages retry until they pass or their timeout (5 seconds by default) runs out, so there’s no need to wait for the page to settle first.
use _ <- step.try(
page.get_by_role(page, role.Heading)
|> expect.locator
|> expect.to_have_text("Welcome back"),
)
use _ <- step.try(expect.page(page) |> expect.to_have_url("/dashboard"))
page.get_by_text(page, "Loading")
|> expect.locator
|> expect.not
|> expect.to_be_visible
Types
Something to make assertions about: a Locator or a Page.
pub opaque type Expectation(subject)
Values
pub fn equal(actual: a, expected: a) -> step.Step(Nil)
Two values are equal. Useful for checking values read with the query
functions in gleewright/locator, which don’t retry.
pub fn locator(
locator: locator.Locator,
) -> Expectation(locator.Locator)
Make assertions about the elements matched by a locator.
pub fn not(
expectation: Expectation(subject),
) -> Expectation(subject)
Invert the assertion that follows.
pub fn to_be_attached(
expectation: Expectation(locator.Locator),
) -> step.Step(Nil)
The element is in the page (though possibly not visible).
pub fn to_be_checked(
expectation: Expectation(locator.Locator),
) -> step.Step(Nil)
The checkbox or radio button is checked.
pub fn to_be_disabled(
expectation: Expectation(locator.Locator),
) -> step.Step(Nil)
The element is disabled.
pub fn to_be_editable(
expectation: Expectation(locator.Locator),
) -> step.Step(Nil)
The element is editable.
pub fn to_be_empty(
expectation: Expectation(locator.Locator),
) -> step.Step(Nil)
The element has no text, or the input has no value.
pub fn to_be_enabled(
expectation: Expectation(locator.Locator),
) -> step.Step(Nil)
The element is enabled.
pub fn to_be_focused(
expectation: Expectation(locator.Locator),
) -> step.Step(Nil)
The element has focus.
pub fn to_be_hidden(
expectation: Expectation(locator.Locator),
) -> step.Step(Nil)
The element is hidden or not in the page.
pub fn to_be_visible(
expectation: Expectation(locator.Locator),
) -> step.Step(Nil)
The element is visible.
pub fn to_contain_text(
expectation: Expectation(locator.Locator),
text: String,
) -> step.Step(Nil)
The element’s text contains the given text.
pub fn to_have_accessible_name(
expectation: Expectation(locator.Locator),
name: String,
) -> step.Step(Nil)
The element has the given accessible name.
pub fn to_have_attribute(
expectation: Expectation(locator.Locator),
name: String,
value: String,
) -> step.Step(Nil)
The element has an attribute with the given value.
pub fn to_have_class(
expectation: Expectation(locator.Locator),
class: String,
) -> step.Step(Nil)
The element has the given CSS class, amongst any others.
pub fn to_have_count(
expectation: Expectation(locator.Locator),
count: Int,
) -> step.Step(Nil)
The locator matches exactly this many elements.
pub fn to_have_id(
expectation: Expectation(locator.Locator),
id: String,
) -> step.Step(Nil)
The element has the given id.
pub fn to_have_text(
expectation: Expectation(locator.Locator),
text: String,
) -> step.Step(Nil)
The element’s text is exactly the given text, ignoring surrounding whitespace.
pub fn to_have_text_matching(
expectation: Expectation(locator.Locator),
pattern: String,
) -> step.Step(Nil)
The element’s text matches a JavaScript regular expression.
pub fn to_have_texts(
expectation: Expectation(locator.Locator),
texts: List(String),
) -> step.Step(Nil)
The texts of all the matched elements are exactly the given texts, in order.
pub fn to_have_title(
expectation: Expectation(page.Page),
title: String,
) -> step.Step(Nil)
The page’s title is exactly the given title.
pub fn to_have_title_matching(
expectation: Expectation(page.Page),
pattern: String,
) -> step.Step(Nil)
The page’s title matches a JavaScript regular expression.
pub fn to_have_url(
expectation: Expectation(page.Page),
url: String,
) -> step.Step(Nil)
The page’s URL is the given URL. Relative URLs are resolved against the
base_url of the test config.
pub fn to_have_url_matching(
expectation: Expectation(page.Page),
pattern: String,
) -> step.Step(Nil)
The page’s URL matches a JavaScript regular expression.
pub fn to_have_value(
expectation: Expectation(locator.Locator),
value: String,
) -> step.Step(Nil)
The input’s value is the given value.
pub fn true(condition: Bool, message: String) -> step.Step(Nil)
A condition holds, failing with the given message if it doesn’t.
pub fn within(
expectation: Expectation(subject),
milliseconds: Int,
) -> Expectation(subject)
Retry the assertion for up to the given number of milliseconds instead of the default 5 seconds.