我为凤凰应用程序添加了以下测试:
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
它测试用户是否可以使用有效凭证进行注册 如果我注释掉最后一个断言,测试需要0.7秒才能运行 如果我单独尝试上一个断言,则测试需要6.1秒才能运行。
为什么这个断言运行得如此之慢?有没有更好的方法来测试元素不再出现在页面上?
答案 0 :(得分:1)
tf.inv
的第三个参数是默认为find_element
的重试次数,是Hound尝试查找元素with a gap of retry_time
milliseconds which defaults to 250的次数。由于早期的5
调用已经加载了页面,因此您可以通过将重试次数设置为find_element
来加速此断言:
0