Skip to content

Add configurable wait time when grabbing root html element #269

Closed
@geb-bot

Description

@geb-bot

Originally created by Craig Atkinson.

When running Geb tests on our slow CI server, we run into exceptions similar to this one about every 100 tests.

{noformat}
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"tag name","selector":"html"}
Command duration or timeout: 576 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.37.1', revision: 'a7c61cbd68657e133ae96672cf995890bad2ee42', time: '2013-10-21 09:08:07'
System info: host: 'cloud01', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.0-24-generic', java.version: '1.6.0_38'
Session ID: 5ee2f1f0-0287-44fd-bfd0-459e7a5a01b6
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=LINUX, acceptSslCerts=true, javascriptEnabled=true, browserName=firefox, rotatable=false, locationContextEnabled=true, version=19.0.2, cssSelectorsEnabled=true, databaseEnabled=true, handlesAlerts=true, browserConnectionEnabled=true, nativeEvents=false, webStorageEnabled=true, applicationCacheEnabled=true, takesScreenshot=true}]
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:307)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByTagName(RemoteWebDriver.java:372)
at org.openqa.selenium.By$ByTagName.findElement(By.java:336)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:299)
at geb.navigator.factory.BrowserBackedNavigatorFactory.getBase(BrowserBackedNavigatorFactory.groovy:33)
at geb.content.NavigableSupport.getNavigator(NavigableSupport.groovy:39)
at geb.content.NavigableSupport.$(NavigableSupport.groovy:72)
at geb.content.PageContentTemplateFactoryDelegate.methodMissing(PageContentTemplateFactoryDelegate.groovy:34)
at Page.groovy:11)
at geb.content.PageContentTemplate.invokeFactory(PageContentTemplate.groovy:97)
at geb.content.PageContentTemplate.create_closure1(PageContentTemplate.groovy:59)
at geb.content.PageContentTemplate.create(PageContentTemplate.groovy:82)
at geb.content.PageContentTemplate.get(PageContentTemplate.groovy:54)
at geb.content.NavigableSupport.getContent(NavigableSupport.groovy:45)
at geb.content.NavigableSupport.propertyMissing(NavigableSupport.groovy:129)
at Page.groovy:25)
{noformat}

I tested a couple different ways to solve this exception, and one that has worked well thus far (stopped NoSuchElementExceptions in 9 runs of 179 tests) is to add a wait into the root html element parsing in BrowserBackedNavigatorFactory.

{noformat}
Navigator getBase() {
WebDriverWait wait = new WebDriverWait(browser.driver, 10)

WebElement rootHtmlElement = wait.until(ExpectedConditions.presenceOfElementLocated(By.tagName("html")))

createFromWebElements(Collections.singletonList(rootHtmlElement))

}
{noformat}

Notes on the implementation:

Config value to enable/disable the timeout

Config value for the timeout value

Wrap the exception that Selenium throws if the timeout is reached

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions