Skip to main content

Test Evolve Helper Methods

We also make some useful Helper functions available.

Instructions

  1. Ensure you have Helpers included in your project.
features/support/env.rb
include TestEvolve::Helpers
  1. Use the Helpers in your project

TryWith

  • Use TryWith.attempts to attempt a block of code x times with a sleep of x seconds.
  • The following will attempt the click action 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.time to 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 click action 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.until to 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.
    • nil is default.
  • refresh
    • Use this to trigger a browser refresh between each attempt.
    • false is default.
  • error
    • Use this to pass a specific error class to catch.
    • StandardError is default.