Hound ExUnit:assert_raise 似乎大大减慢了测试套件的速度
Hound ExUnit: assert_raise seems to considerably slow down the test suite
我为 phoenix 应用程序添加了以下测试:
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 秒才能达到 运行.
为什么这个断言 运行 这么慢?有没有更好的方法来测试某个元素是否不再出现在页面上?
find_element
的第三个参数是重试次数,默认为5
,是Hound尝试寻找元素with a gap of retry_time
milliseconds which defaults to 250的次数。由于该页面已由较早的 find_element
调用加载,您可以通过将重试次数设置为 0
:
来加快此断言
assert_raise Hound.NoSuchElementError, ~r/No element found for class/, fn ->
find_element(:class, "header__button__register", 0)
end
我为 phoenix 应用程序添加了以下测试:
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 秒才能达到 运行.
为什么这个断言 运行 这么慢?有没有更好的方法来测试某个元素是否不再出现在页面上?
find_element
的第三个参数是重试次数,默认为5
,是Hound尝试寻找元素with a gap of retry_time
milliseconds which defaults to 250的次数。由于该页面已由较早的 find_element
调用加载,您可以通过将重试次数设置为 0
:
assert_raise Hound.NoSuchElementError, ~r/No element found for class/, fn ->
find_element(:class, "header__button__register", 0)
end