Playwright + TS · Lesson 8 of 36
Module 8: Async Programming
Your task
Use await Promise.all([...]) to execute loadUsers() and loadOrders() concurrently and return the results array.
Write it in the editor, then press Check answer (Ctrl + Enter).
Browser actions take real time. JavaScript uses Promises with three states:
// Sequential execution: steps run one after another
async function runLoginSteps() {
await fillUsername();
await fillPassword();
await clickSubmit();
}
// Parallel execution: operations happen simultaneously!
async function loadDashboardData() {
const [profile, notifications] = await Promise.all([
fetchUserProfile(),
fetchNotifications(),
]);
}Asynchronous programming is the single most important concept to master for Playwright automation. Browsers are asynchronous by nature, and every Playwright action returns a Promise. In this lesson, we will demystify Promises, async/await, and Promise.all so you never get caught by unhandled promises or race conditions. Let's master async code!
Part of the Playwright + TS course (Playwright with TypeScript). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.
When two operations must occur concurrently, like triggering a popup click while simultaneously waiting for the popup event: Promise.all([page.waitForEvent('popup'), button.click()]).
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___