Assert
Assert
module contains assertion functions to check properties of Elements
and data extracted from the browser.
All assert functions return a Task
with the [AssertionError Str]
error.
shouldBe : a, a -> Task.Task {} [AssertionError Str] where a implements Eq & Inspect
Checks if the value of actual is equal to the expected.
# find button element button = browser |> Browser.findElement! (Css "#submit-button") # get button text buttonText = button |> Element.getText! # assert text buttonText |> Assert.shouldBe! "Roc"
shouldContainText : Str, Str -> Task.Task {} [AssertionError Str]
Checks if the value of actual contains the Str
expected.
"github" |> Assert.shouldContainText! "git"
shouldBeEqualTo : Frac a, Frac a -> Task.Task {} [AssertionError Str]
Checks if the value of actual is equal to the expected.
Used to compare Frac
numbers.
# find button element button = browser |> Browser.findElement! (Css "#submit-button") # get button text buttonSize = button |> Element.getProperty! "size" # assert value buttonSize |> Assert.shouldBeEqualTo! 20f64
shouldBeGreaterThan : Num a, Num a -> Task.Task {} [AssertionError Str] where a implements Bool.Eq
Checks if the actual Num
is grater than the expected.
3 |> Assert.shouldBeGreaterThan! 2
shouldBeGreaterOrEqualTo : Num a, Num a -> Task.Task {} [AssertionError Str] where a implements Bool.Eq
Checks if the actual Num
is grater or equal than the expected.
3 |> Assert.shouldBeGreaterOrEqualTo! 2
shouldBeLesserThan : Num a, Num a -> Task.Task {} [AssertionError Str] where a implements Bool.Eq
Checks if the actual Num
is grater than the expected.
3 |> Assert.shouldBeGreaterThan! 2
shouldBeLesserOrEqualTo : Num a, Num a -> Task.Task {} [AssertionError Str] where a implements Bool.Eq
Checks if the actual Num
is grater or equal than the expected.
3 |> Assert.shouldBeLesserOrEqualTo! 2
urlShouldBe : Browser, Str -> Task.Task {} [ 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 assertTimeout specified in test options - default: 3s.
# assert text browser |> Assert.urlShouldBe! "https://roc-lang.org/"
titleShouldBe : Browser, Str -> Task {} [ 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 assertTimeout specified in test options - default: 3s.
# assert text browser |> Assert.titleShouldBe! "The Roc Programming Language"
failWith : Str -> Task.Task [AssertionError Str]
Fails with given error message.
# fail the test Assert.failWith! "this should not happen"
shouldHaveLength : List a, U64 -> Task.Task {} [AssertionError Str]
Checks if the length of list is equal to the expected length.
# find all buttons element buttons = browser |> Browser.findElements! (Css "button") # assert that there are 3 buttons buttons |> Assert.shouldHaveLength! 3
elementShouldHaveText : Element, Str -> Task {} [ 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 assertTimeout specified in test options - default: 3s.
# find button element button = browser |> Browser.findElement! (Css "#submit-button") # check if button has text "Submit" button |> Assert.elementShouldHaveText! "Submit"
elementShouldHaveValue : Element, Str -> Task {} [ 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 assertTimeout specified in test options - default: 3s.
# find input element input = browser |> Browser.findElement! (Css "#username-input") # check if input has value "fake-username" input |> Assert.elementShouldHaveValue! "fake-username"
elementShouldBeVisible : Element -> Task {} [ 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 assertTimeout specified in test options - default: 3s.
# find error message element errorMsg = browser |> Browser.findElement! (Css ".error-msg") # check if the error message element is visible errorMsg |> Assert.elementShouldBeVisible!