Skip to main content

Waiting and Timeouts

With the Mobilewright engine a test needs no waits of its own. WebdriverIO first waits until the element exists, as it does with every protocol, see Auto-waiting. The engine then waits until the element can be used: an action until the element is visible, enabled and no longer moving, a read until it is visible. This page explains these waits and their timeouts.

wdio.conf.ts
export const config: WebdriverIO.Config = {
// ...
waitforTimeout: 5000, // how long a command waits for its element, in ms
waitforInterval: 100 // the time between two reads of the screen, in ms
}

What a command waits for​

CommandWaits until the element
click(), tap(), setValue(), addValue(), clearValue()is on the screen, is visible, is enabled, and does not move: it is at the same place in two reads of the screen.
getText(), getValue()is on the screen and is visible.

An element is visible if mobilecli says so, or else if it has a size. An element that keeps moving is used where it is when the time is up.

If the time is up, the command fails with the reason:

Element with the selector "login" (accessibility id): element found but not enabled after 5000ms

isDisplayed() and isEnabled() do not wait: they return how the element is now, and false for an element that is not on the screen.

Timeouts​

How long a command waits can be set in three places. The first one in this list that is set is used:

WhereTimeoutInterval
The test, from that line onbrowser.setTimeout({ implicit: 10000 })
The capability mobilecli:optionsactionTimeoutpollInterval
The WebdriverIO configwaitforTimeout (5000)waitforInterval (100)
wdio.conf.ts
export const config: WebdriverIO.Config = {
// ...
capabilities: [{
platformName: 'Android',
'mobilecli:options': {
actionTimeout: 10000,
pollInterval: 200
}
}]
}

An element that is not on the screen at all is waited for by WebdriverIO first, for waitforTimeout. The timeout of the engine starts when the element is there.

browser.setTimeout() only uses implicit. A native app has no page load and no scripts, so pageLoad and script do nothing.

The timeouts of your test framework stay as they are, for example mochaOpts.timeout for the time a whole test can take. See Timeouts.

Give one command more time​

The commands of WebdriverIO have no timeout of their own: $('~login').click({ timeout: 10000 }) is not supported. For one command that needs more time, wait for its element first with the matching wait command:

CommandWait first with
click(), tap(), setValue(), addValue(), clearValue()await $('~login').waitForEnabled({ timeout: 20000 })
getText(), getValue()await $('~message').waitForDisplayed({ timeout: 20000 })
await $('~button-LOGIN').waitForEnabled({ timeout: 20000 })
await $('~button-LOGIN').click()

To give all commands more time from a line on, use browser.setTimeout({ implicit: 20000 }).

Wait without a command​

To wait for a state without acting on the element, use the wait commands of WebdriverIO:

Wait until the elementCommand
is visibleawait $('~message').waitForDisplayed({ timeout: 10000 })
is gone or hiddenawait $('~spinner').waitForDisplayed({ reverse: true })
is enabledawait $('~submit').waitForEnabled()
is disabledawait $('~submit').waitForEnabled({ reverse: true })
existsawait $('~message').waitForExist()

Next steps​

  • Settings: the other waiting settings, such as stabilityDelay and screenFreshTime.
  • Coming from Mobilewright: how the timeouts of Mobilewright map to WebdriverIO.

Welcome! How can I help?

WebdriverIO AI Copilot