Created
June 27, 2011 22:23
-
-
Save trungly/1050000 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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