I've added the following test for a phoenix application:
navigate_to("/")
registration_page_link = find_element(:class, "header__button__register")
registration_page_link |> click()
form = find_element(:class, "form__register")
email_field = find_within_element(form, :class, "input--email")
first_name_field = find_within_element(form, :class, "input--first_name")
last_name_field = find_within_element(form, :class, "input--last_name")
password_field = find_within_element(form, :class, "input--password")
confirm_password_field = find_within_element(form, :class, "input--confirm_password")
submit_button = find_within_element(form, :class, "form__submit")
email_field |> fill_field("john.doe@email.com")
first_name_field |> fill_field("John")
last_name_field |> fill_field("Doe")
password_field |> fill_field("12345678")
confirm_password_field |> fill_field("12345678")
submit_button |> submit_element()
alert = find_element(:class, "alert--success")
alert_text = visible_text(alert)
name = find_element(:class, "header__user_name")
name_text = visible_text(name)
assert alert_text == "Congratulations John! You have successfuly registered."
assert name_text == "John D."
assert_raise Hound.NoSuchElementError, ~r/No element found for class/, fn ->
find_element(:class, "header__button__register")
end
It tests that the user can register with valid credentials.
If I comment out the last assertion, the test take 0.7 seconds to run.
If I try with the last assertion alone, the test takes 6.1 seconds to run.
How come this assertion runs so much slower ? Is there a better way to test that an element does not appear on the page anymore ?
find_element
's third argument is the number of retries which defaults to 5
and is the number of times Hound tries to find the element with a gap of retry_time
milliseconds which defaults to 250. Since the page is already loaded by the earlier find_element
calls, you can speed up this assertion by setting number of retries to 0
:
assert_raise Hound.NoSuchElementError, ~r/No element found for class/, fn ->
find_element(:class, "header__button__register", 0)
end