This post is going to be in-line with, what I have planned to speak in the flagship Selenium conference in Austin, Texas in April
Difference between NodeJs webdriver Bindings with other Language Bindings.
Asynchronous
WebDriver’s JavaScript API is entirely asynchronous and every command results in a promise.
How do we solve Asynchronous ?
Callbacks ?
Promises ?
Now, firstly – What is promise ?
Simplest explanation: It is an easy way to avoid writing pyramid of doom
One main thing about the WebdriverJs is PROMISE MANAGER:
Promise Manager helps us to write tests in JavaScript just like other Synchronous bindings like Java
- WebDriverJS uses a promise “manager” to coordinate the scheduling and execution of all commands.
- The promise manager maintains a queue of scheduled tasks, executing each once the one before it in the queue is finished.
- Tasks are enqueued using the execute() function. Tasks always execute in a future turn of the event loop, once those before it in the queue (if there are any) have completed.
WebDriverJs with Promise Manager
Equivalent Java code
Now, what?
Deprecating Promise Manager
Removing it in favor of native language constructs.
1. Generators
To help with debugging, tests can be written with generators and WebDriver’s promise.consume function (or equivalent, from libraries like task.js).
2. Async Await
- The need to use promise.consume/task.js will be eliminated in TC39with the introduction of async functions
- An ES2016 language specification
- Grabbed from C#
- No callbacks, No promises, No control flow