Timeouts
Each command in WebdriverIO is an asynchronous operation. A request is fired to the Selenium server (or a cloud service like Sauce Labs), and its response contains the result once the action has completed or failed.
Therefore, time is a crucial component in the whole testing process. When a certain action depends on the state of a different action, you need to make sure that they get executed in the right order. Timeouts play an important role when dealing with these issues.
Selenium timeouts
Session Script Timeout
A session has an associated session script timeout that specifies a time to wait for asynchronous scripts to run. Unless stated otherwise, it is 30 seconds. You can set this timeout like so:
await browser.setTimeout({ 'script': 60000 })
await browser.executeAsync((done) => {
console.log('this should not fail')
setTimeout(done, 59000)
})
Session Page Load Timeout
A session has an associated session page load timeout that specifies a time to wait for the page loading to complete. Unless stated otherwise, it is 300,000 milliseconds.
You can set this timeout like so:
await browser.setTimeout({ 'pageLoad': 10000 })
The
pageLoad
keyword is a part of the official WebDriver specification, but might not be supported for your browser (the previous name ispage load
).
Session Implicit Wait Timeout
A session has an associated session implicit wait timeout. This specifies the time to wait for the implicit element location strategy when locating elements using the findElement
or findElements
commands ($
or $$
, respectively, when running WebdriverIO with or without the WDIO testrunner). Unless stated otherwise, it is 0 milliseconds.
You can set this timeout via:
await browser.setTimeout({ 'implicit': 5000 })