Learn Protractor & Jasmine Framework for End to End Testing | Chapter 3 | Asynchronous problem in JavaScript

In JavaScript only one thing can happen at a time since it's a single threaded programming language.

Script may not execute in sequence and execution might happen randomly.

In order to solve this problem we incorporate the promise concept.

Promise Concept: A promise is a method / pattern to resolve asynchronous problem in JS.

Promise states are: Pending, Resolved & Rejected.

Synchronous: JS will move to next step only if promise of current existing step is in state Resolved or Rejected.

Asynchronous: JS moves to next step irrespective of state even if promise is pending.

Most of the Protractor methods resolve the promise but there are certain exceptions like retrieving data from web-browser eg: getText() for any field from web-browser where promise needs to be resolved manually.

Aysynchronous problem in JavaScript

 There are 2 methods to resolve Asynchronous:

1. Using promise chaining via then() function


2. Using async and await