async/await. This however can be a confusing concept for people unfamiliar with the language. In addition to that it can make tests very verbose as almost every operation is asynchronous. To simplify its usage WebdriverIO provides the ability to run commands synchronous through
To enable sync mode you only need to add the
@wdio/sync package to your dev dependencies:
The package will be automatically detected by the framework and the environment properly set up to run synchronous.
If you're using
@wdio/sync then you can avoid awaiting for command calls. It is still required to deal with Promises from 3rd-party libraries, you should use browser.call for this to wrap them and make them synchronous too.
fibersfailed to install properly. The package usually comes with pre-built binaries but if your environment doesn't support it these need to be compiled which require node-gyp and Python.
If you decide to run in async mode all WebdriverIO commands return a Promise and need to be awaited to get the result, e.g.:
There can be quite some confusion when handling asynchronous commands manually. The usual problems are:
chaining of element commands:await $('body').click()` // throws `$(...).click is not a function`
You can't chain element calls as you have to await multiple asynchronous functions. To fix this, first await element then trigger the click, like so:const el = await $('body')await el.click()
previous command was not awaited:const el = await $('body')el.waitForExist() // ERROR: await is missing here, you'll get `Unhandled promise rejection`.await el.click()