Chapter 19: Promises
Automation learning lab
Playwright Automation
Self Study Guide
Start from zero. Learn JavaScript and TypeScript, automate browsers, and build reliable end-to-end tests.
Promises
A Promise represents an eventual result. It begins pending and can settle fulfilled or rejected. then handles fulfillment and catch handles rejection. Playwright browser actions return promises because they communicate asynchronously with the browser.
How it works
Step-by-step walkthrough
- Create a resolved promise
- Attach a fulfillment handler
- Observe the output
Example
const result = Promise.resolve('Page ready');
result.then(value => console.log(value))
.catch(error => console.error(error));Returning or awaiting a promise is essential when later work depends on it.
✎ Your practice task
Replace resolve with reject and handle the error.
Knowledge check
What are the two settled promise states?
🌐 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.