automatictester

my thoughts on test automation

Timeouts in Selenium Webdriver

If you’re chasing timeout-related issue with your Selenium tests, it’s good to know what types of timeouts you can play with.


Timeouts set within your code

There are 3 timeouts which can be set under driver.manage().timeouts():

  • Selenium implicit waits are managed by implicitlyWait(). This setting will manage how long Selenium waits for element to appear before throwing NoSuchElementException.
  • Those of you who make use of JavascriptExecutor, can be interested in setScriptTimeout(). If script execution takes longer than specified, TimeoutException is thrown.
  • You can specify non-default value for pageLoadTimeout(). This parameter manages wait times for loading page by browser before throwing TimeoutException.

Timeouts set in Selenium Grid environment

If you run your tests in a Grid, there are a few timeouts which can be of your interest. Those are specified as command line parameters when running selenium-server-standalone-.jar:

  • newSessionWaitTimeout, which defaults to no timeout. If specified, new test must be allocated an execution node within that time. If it’s not, an exception is thrown: org.openqa.selenium.WebDriverException: Error forwarding the new session Request timed out waiting for a node to become available.
  • timeout, which specifies how long particular test which started execution can remain idle, before terminating client session. With this timeout, test which hangs without any communication with browser will not utilise execution node for ever. This is the exception you can find in your stack trace: org.openqa.selenium.WebDriverException: Session [] was terminated due to TIMEOUT.
  • browserTimeout, which is considered to be a safety net for timeout above.

Vendor-specific timeouts

If you make use of Sauce Labs or BrowserStack, it’s good to know if there is anything specific you should know about.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: