Chapter 20: Async and await
Automation learning lab
Playwright Automation
Self Study Guide
Start from zero. Learn JavaScript and TypeScript, automate browsers, and build reliable end-to-end tests.
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
- Define an async function
- Await a promise
- Call the function with rejection handling
Example
async function run() {
const value = await Promise.resolve('Ready');
console.log(value);
}
run().catch(console.error);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
60-chapter learning path
Start at chapter 1, or choose any topic. Your progress is tracked separately for each chapter.
JavaScript fundamentals
TypeScript fundamentals
Playwright • setup & locators
Playwright • interactions & assertions
Playwright • framework & debugging
Playwright • real-world automation
Interactive practice lab
Try the controls below and observe the corresponding Playwright locator instructions. This browser demo does not execute Node.js or Playwright Test; copy the code to your local Playwright project to automate it.
Task manager demo
Suggested automation
Actions on the demo update these examples. In your local test use a page that contains the same controls.
Download a standalone lab page, then serve it locally (for example with Python's http.server). Navigate to it in a Playwright test.