Skip to content

Instantly share code, notes, and snippets.

@cblavier
Created October 7, 2019 15:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cblavier/1acccfd914e4cd6a51af0cf500dff6f8 to your computer and use it in GitHub Desktop.
Save cblavier/1acccfd914e4cd6a51af0cf500dff6f8 to your computer and use it in GitHub Desktop.
Wait helpers, used with Elixir hound browser testing library
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