DEV Community

loading...
Cover image for WebdriverIO Important Sync mode Updates

WebdriverIO Important Sync mode Updates

automationbro profile image Dilpreet Johal ・4 min read

In this post, we will go over some of the important updates related to WebdriverIO Sync mode. We will also cover some of the possible changes that will be coming in the WebdriverIO v8. But, before we start talking about WebdriverIO Sync mode, it’s important to understand how the WebdriverIO Async mode works.

WebdriverIO Async mode

By default, WebdriverIO uses async mode to interact with the browser or the mobile device. It runs a set of asynchronous commands which are handled via async/await in JavaScript. However, there are few downsides to using async/await

  • Those unfamiliar with JavaScript or the asynchronous programming finds async/await confusing
  • async/await is quite verbose as it is used for majority of the WebdriverIO commands

Let’s take a look at the sample code below –

Async Mode

There are couple of things to notice here –

  • We are starting the it block with the async keyword and then all the commands are using await keyword such as when finding an element or clicking on an element or any other WebdriverIO command.
  • We can also not chain these functions with each other as that would also throw an error. Each individual command needs to awaited instead.

WebdriverIO Sync mode

So to address some of the above issues, WebdriverIO came up with sync mode and created a @wdio/sync plugin which allows you to run command synchronously through node-fibers. This plugin had some of the following advantages –

  • It got rid of all the async/await from the code as the commands are synchronous now
  • Tests look a lot more easier to read and understand (beginner friendly)

Let’s take a look at the sample code below –

sync mode

In the above simplified example, you will notice that there are no more async/awaits in the second block which is a lot more user friendly to read and understand.


Why WebdriverIO discontinued Sync mode?

WebdriverIO put out a warning on their website mentioning that the Sync mode will no longer be supported as of 14/04/2021 due to some breaking changes in Chromium which will not allow the usage of node-fibers. So, from Node v16 they will officially drop the support for WebdriverIO sync mode.

That being said, there’s an active GitHub thread going on to discuss possible options as listed below –

github-thread

The option the Steering Committee ended up going with was the last one which to accept the fact that WebdriverIO will be asynchronous moving forward.


How the code might look like from WebdriverIO v8?

v8 code

You will continue to use async/await as it is, however, one major change that might possibly occur is that you will be able to chain WebdriverIO commands which is currently not possible in WebdriverIO v7. The advantage of this is that it will make code look a bit cleaner and less verbose.

Note: This is still in works at the time of this article so there might be some updates or changes that could occur. You can follow the thread to get the latest info.


You can still use Sync mode

For those of you that still wants to use Sync mode for now, it is still possible to do that. Here’s what you will need to do –

Check package.json to see @wdio/sync package is installed or not –

  • If installed, you can continue to use the sync mode as usual
  • If not installed, then you can install the package
    • npm i @wdio/sync

Note: WebdriverIO will continue the support for the sync mode until they decide to drop the support for Node v15. As starting, Node v16 the sync mode will not be supported anymore.


My take on all of these changes

I understand it’s going to be a quite big change for a lot of the people that like the sync version of WebdriverIO given its simplicity, just the way I do. But, I would recommend that you start using async mode for your new projects to avoid doing any kind of migrations in the future.

For those with already an existing project in Sync mode will need to use the codemod that will get developed by the WebdriverIO team to do the migration from Sync mode to Async mode.


WebdriverIO Tutorial Series

For those that are following my WebdriverIO video series on YouTube, in the series I am using WebdriverIO v6 with the Sync mode. So you can continue to use the Sync mode by installing the @wdio/sync package or decide to use async mode instead.

I will also be creating videos in the future to show how to use async mode properly once WebdriverIO v8 is out.


Check out the video below to learn more about WebdriverIO Sync mode and the updates related to it –


📧 Subscribe to my mailing list to get access to more content like this as well as free access to Private Facebook community

👍 You can follow my content here as well -

...

I love coffees! And, if this post helped you out and you would like to support my work, you can do that by clicking on the button below and buying me a cup of coffee -

Buy me a coffee

You can also support me by liking and sharing this content.

Thanks for reading!

Discussion (0)

Forem Open with the Forem app