Assert

Assert module contains assertion functions to check properties of Elements and data extracted from the browser.

All assert functions return a Result with the [AssertionError Str] error.

should_be : a, a -> Result {} [AssertionError Str] where a implements Eq & Inspect

Checks if the value of actual is equal to the expected.

# find button element
button = browser |> Browser.find_element!(Css "#submit-button")?
# get button text
buttonText = button |> Element.get_text!()?
# assert text
buttonText |> Assert.should_be("Roc")

should_contain_text : Str, Str -> Result {} [AssertionError Str]

Checks if the value of actual contains the Str expected.

"github" |> Assert.should_contain_text("git")

should_be_equal_to : Frac a, Frac a -> Result {} [AssertionError Str]

Checks if the value of actual is equal to the expected.

Used to compare Frac numbers.

# find button element
button = browser |> Browser.find_element!(Css "#submit-button")?
# get button text
buttonSize = button |> Element.get_property!("size")?
# assert value
buttonSize |> Assert.should_be_equal_to(20f64)

should_be_greater_than : Num a, Num a -> Result {} [AssertionError Str] where a implements Bool.Eq

Checks if the actual Num is grater than the expected.

3 |> Assert.should_be_greater_than(2)

should_be_greater_or_equal_to : Num a, Num a -> Result {} [AssertionError Str] where a implements Bool.Eq

Checks if the actual Num is grater or equal than the expected.

3 |> Assert.should_be_greater_or_equal_to(2)

should_be_lesser_than : Num a, Num a -> Result {} [AssertionError Str] where a implements Bool.Eq

Checks if the actual Num is grater than the expected.

3 |> Assert.should_be_lesser_than(2)

should_be_lesser_or_equal_to : Num a, Num a -> Result {} [AssertionError Str] where a implements Bool.Eq

Checks if the actual Num is grater or equal than the expected.

3 |> Assert.should_be_lesser_or_equal_to(2)

url_should_be! : Browser, Str => Result {} [ AssertionError Str, WebDriverError Str ]

Checks if the URL is equal to the expected.

This function will wait for the expectation to be met, for the assert_timeout specified in test options - default: 3s.

# assert text
browser |> Assert.url_should_be!("https://roc-lang.org/")

title_should_be! : Browser, Str => Result {} [ AssertionError Str, WebDriverError Str ]

Checks if the title of the page is equal to the expected.

This function will wait for the expectation to be met, for the assert_timeout specified in test options - default: 3s.

# assert text
browser |> Assert.title_should_be!("The Roc Programming Language")

fail_with : Str -> Result [AssertionError Str]

Fails with given error message.

# fail the test
Assert.fail_with!("this should not happen")

should_have_length : List a, U64 -> Result {} [AssertionError Str]

Checks if the length of list is equal to the expected length.

# find all buttons element
buttons = browser |> Browser.find_elements!(Css("button"))?
# assert that there are 3 buttons
buttons |> Assert.should_have_length 3

element_should_have_text! : Element, Str => Result {} [ AssertionError Str, ElementNotFound Str, WebDriverError Str ]

Checks if the Element has expected text.

This function will wait for the Element to meet the expectation, for the assert_timeout specified in test options - default: 3s.

# find button element
button = browser |> Browser.find_element!(Css("#submit-button"))?
# check if button has text "Submit"
button |> Assert.element_should_have_text!("Submit")

element_should_have_value! : Element, Str => Result {} [ AssertionError Str, ElementNotFound Str, WebDriverError Str, PropertyTypeError Str ]

Checks if the Element has expected value.

This function will wait for the Element to meet the expectation, for the assert_timeout specified in test options - default: 3s.

# find input element
input = browser |> Browser.find_element!(Css("#username-input"))?
# check if input has value "fake-username"
input |> Assert.element_should_have_value!("fake-username")

element_should_be_visible! : Element => Result {} [ AssertionError Str, ElementNotFound Str, WebDriverError Str ]

Checks if the Element is visible in the Browser.

This function will wait for the Element to meet the expectation, for the assert_timeout specified in test options - default: 3s.

# find error message element
errorMsg = browser |> Browser.find_element!(Css(".error-msg"))?
# check if the error message element is visible
errorMsg |> Assert.element_should_be_visible!()