SDET Unicorns

WebdriverIO Important Sync mode Updates

Table of Content

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 –

kIUO8UWUqA ppnH tipqjAvHrOro8wtYLZsAuHtLyeChu3AOytNi3DrvODh8K4UfklXjSyBWQz394rq18SpeEzdiwdGbgT4rzYtz3K8jp1XtQWa0BLrSVYtSq7lKvJym5dk72o4gzho

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 –

7a1usKcYdRDj7KkSG4wKaG7G8qHxVa2hK Dwk7tWKjlSM7rWfdVMbvBH93TECmaxjpgnQ45HW0zuhYJPNHHWJ 2lxgewcfXJv1w9f2gwcRdbVMGrLI

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 –

IeoBlvxUQ4VBPqoZg GglHehlLhEbGMile49jvqbcG4GJJIYCtAu2DkZqw1kmghSNNf2VbYh9kQ10INKGzH27n3aqnGJDLBvVqnfF9wnOA9COVk1TbOn9DN9Ueh3W2Ei yKTSoYPhOE

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?

smMePM6CelJYmTKIm2JaTM

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 –


I hope this post helped you out, let me know if you have any questions in the comments below!

Happy testing! 

My Resources

Thrive Suite: The all-in-one WordPress theme I used to create my blog.
Jasper AI: My favorite AI writing tool.
Surfer SEO:  A tool to help you rank your content on the first page of Google.

Write Content Faster

5/5

Write blog posts that rank for affiliate terms!

Join our mailing list

Unlock the Secrets to Becoming a SDET Pro in the Industry!

Stay ahead of the curve! Join our mailing list for exclusive insights, tips, and the latest industry updates delivered straight to your inbox

Table of Content

Related Post

7 Principles of Software Testing

7 Principles of Software Testing with Examples

Software testing plays a crucial role in the software development life cycle as it helps ensure the quality, reliability, and performance of the final product. Software testing is not just about finding defects; it also provides valuable insights into the overall quality of the software. By conducting effective software testing, it shows how well the application behaves in different scenarios and whether it meets user expectations.

Read More »
Differences Between CI/CD and DevOps

Key Differences Between CI/CD and DevOps

Software development is far from a simple journey that involves merely executing code and launching applications. It often presents challenges, as it’s rare to get everything right from the start. Each time you implement new or frequent code changes, you inadvertently introduce potential issues that can be time-consuming to resolve. This complexity necessitates a structured approach to ensure smooth production.

Read More »