8. Promises, Async/Await & Promise.all()

Why Async/Await is Essential in Playwright

Browser actions take real time. JavaScript uses Promises with three states: - Pending: Operation in progress. - Fulfilled: Operation succeeded. - Rejected: Operation failed.
// 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(),
]);
}

Task

  • Use `await Promise.all([...])` to execute `loadUsers()` and `loadOrders()` concurrently and return the results array.
πŸ’‘Common doubts
Did you like the problem?
Lesson 8 of 36
TypeScript
Loading code editor…
Next