Skip to content

Instantly share code, notes, and snippets.

@trungly
Created June 27, 2011 22:23
Show Gist options
  • Save trungly/1050000 to your computer and use it in GitHub Desktop.
Save trungly/1050000 to your computer and use it in GitHub Desktop.
def waitFor(Double timeoutSecs = 5, Double intervalSecs = 0.5, Closure condition) {
intervalSecs = [timeoutSecs, intervalSecs].min()
def loops = Math.ceil(timeoutSecs / intervalSecs)
def pass = condition()
def i = 0
while (!pass && i++ < loops) {
Thread.sleep((intervalSecs * 1000) as long)
pass = condition()
}
if (i >= loops) {
throw new AssertionError("condition did not pass in $timeoutSecs seconds")
}
pass
}
// wait for Javascript to apply the "selected" class before proceeding
def filterId = NewMyMatchesPage.FILTER_NEW
WebElement filterLI = findElementById(filterId)
Long start = System.currentTimeMillis();
waitFor { filterLI.getAttribute("class").contains("selected") }
println "Total time waited for ${filterId} to become selected: ${System.currentTimeMillis() - start}ms"
Long start = System.currentTimeMillis();
waitFor { filterLI.getAttribute("class").contains("selected") }
println "Total time waited for ${filterId} to become selected: ${System.currentTimeMillis() - start}ms"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment