Await and Async

Typescript and Javascript is asynchronous. This means in our test which has multiple steps there is no guarantee that they will be executed one after the other.

Let us consider an example where we typically try to login to a website. 

Say, I want to book the book travel tickets. Below are the steps we follow manually. 

Step1: Go to the Travel website URL 

Step2: Provide Username and Password 

Step3: Click on Login button to get into the application

If we can notice, all these steps are sequential in nature. if we try to miss step2 and with out credentials clicking on Login button would not take us to the application. 

Similarly, as we are trying to do automation (web automation), we should ensure all these steps are followed in sequence in above scenario. And we are relying on Typescript/Javascript to enable this automation. But we should understand that these are asynhronous. Meaning the steps can be executed in any order. So to tell the Playwright that by default the function used in test (2nd parameter) is asynchronous and that is the reason I ask playwright to wait until each step is completed using "await" keyword.

Note: Async and Await usually used in combination.

import {test} from '@playwright/test'; 

test('My First Test', async() => { 
// Playwright steps 
// await step1 
// await step2 
.............. 
.............. });

Comments

Popular posts from this blog

Why do we need Node.js as a pre-requisite before installing Playwright?

What is spec.ts?