TestingDocs.com logoTestingDocs.com
Automation learning lab
TestingDocs • Self-paced course

Playwright Automation
Self Study Guide

Start from zero. Learn JavaScript and TypeScript, automate browsers, and build reliable end-to-end tests.

60 chaptersBeginner friendlyHands-on practice
JavaScript / Chapter 20 of 60~12 min • Beginner
Chapter 20JavaScript

Async and await

An async function always returns a promise. await suspends that function until the awaited value settles, then returns the fulfillment value or throws the rejection. It does not block the entire JavaScript runtime. Playwright tests usually use async callbacks and await actions.

How it works

Step-by-step walkthrough

  1. Define an async function
  2. Await a promise
  3. Call the function with rejection handling

Example

JavaScript
async function run() {
  const value = await Promise.resolve('Ready');
  console.log(value);
}
run().catch(console.error);
Expected result: Ready
💡 Point to remember
Avoid forgetting await before browser actions and web-first assertions.

✎ Your practice task

Await two resolved promises in order.

Knowledge check

What does an async function return?

🌐 Continue learning