I have the following Groovy code that uses Geb (0.13.1):
class LaunchGeb {
static void main(String[] args) {
FirefoxDriver firefoxDriver = new FirefoxDriver()
Browser browser = new Browser(driver: firefoxDriver)
Browser.drive(browser) {
to(GoogleHomepage)
at(GoogleHomepage)
search().value('gmail')
searchButton.click()
at(GoogleSearchResultsPage)
quit()
}
}
}
class GoogleSearchResultsPage extends Page {
static at = {
title == 'gmail - Google Search'
}
}
When I run this it throws an exception at the "at checker" for GoogleSearchResultsPage because it claims the page title is still "Google":
Exception in thread "main" Assertion failed:
title == 'gmail - Google Search'
| |
| false
Google
at org.codehaus.groovy.runtime.InvokerHelper.assertFailed(InvokerHelper.java:402)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.assertFailed(ScriptBytecodeAdapter.java:650)
So on a hunch, I sprinkled in a Thread.sleep in between the time I click the searchButton and the time I run the at checker:
search().value('gmail')
searchButton.click()
Thread.sleep(5000)
at(GoogleSearchResultsPage)
When I make this change, the code now runs perfectly (no exceptions).
So I ask: is it typical/standard for Geb code to add pauses/sleeps into its execution so that we can wait for browsers to finish loading pages or resolving resources/backend calls? Using Thread.sleep is generally regarded as an anti-pattern and I guess I'm wondering if I can make my Geb code my reactive/responsive here. Ideas?