Created
October 7, 2019 15:26
-
-
Save cblavier/1acccfd914e4cd6a51af0cf500dff6f8 to your computer and use it in GitHub Desktop.
Wait helpers, used with Elixir hound browser testing library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyApp.WaitHelper do | |
use Hound.Helpers | |
def wait_until(fun), do: wait_until(1000, fun) | |
def wait_until(0, fun), do: fun.() | |
def wait_until(timeout, fun) do | |
fun.() | |
rescue | |
Hound.NoSuchElementError -> retry(timeout, fun) | |
Hound.Error -> retry(timeout, fun) | |
ExUnit.AssertionError -> retry(timeout, fun) | |
RuntimeError -> retry(timeout, fun) | |
end | |
defp retry(timeout, fun) do | |
:timer.sleep(10) | |
wait_until(max(0, timeout - 10), fun) | |
end | |
def click_and_wait(element, sleep_duration \\ 100) do | |
click(element) | |
:timer.sleep(sleep_duration) | |
end | |
def click_and_confirm_and_wait(element) do | |
click(element) | |
accept_dialog() | |
:timer.sleep(100) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment