Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.