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 19 of 60~12 min • Beginner
Chapter 19JavaScript

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

  1. Create a resolved promise
  2. Attach a fulfillment handler
  3. Observe the output

Example

JavaScript
const result = Promise.resolve('Page ready');
result.then(value => console.log(value))
  .catch(error => console.error(error));
Expected result: Page ready
💡 Point to remember
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