Test Evolve Helper Methods
We also make some useful Helper functions available.
Instructions
- Ruby
- Ensure you have Helpers included in your project.
features/support/env.rb
include TestEvolve::Helpers
- Use the Helpers in your project
TryWith
- Use
TryWith.attemptsto attempt a block of code x times with a sleep of x seconds. - The following will attempt the
clickaction 3 times, with a half second pause between each try. If it fails all 3 times it will throw an error.
TryWith.attempts(attempts: 3, sleep: 0.5) do
TestEvolve.browser.button(id: "button").click
end
- Use
TryWith.timeto attempt a block of code as many times as it can in x seconds with a sleep of x seconds. - The following will attempt the
clickaction as many times as it can in 3 seconds, with a half second pause between each try. If it fails all times it will throw an error.
TryWith.time(timeout: 3, sleep: 0.5) do
TestEvolve.browser.button(id: "button").click
end
- Use
TryWith.untilto attempt a block of code until it returns true or reaches timeout with a sleep of x seconds. - The following will check if the element is present as many times as it can in 3 seconds, with a half second pause between each try, until it returns true.
TryWith.until(timeout: 3, sleep: 0.5) do
TestEvolve.browser.button(id: "button").present?
end
There are some other useful arguments which you can pass to the methods above:
message- Use this to display a custom message on each attempt.
nilis default.
refresh- Use this to trigger a browser refresh between each attempt.
falseis default.
error- Use this to pass a specific error class to catch.
StandardErroris default.