3. Async, Await & Promise Handling

Why Playwright is Fully Asynchronous

Browsers run in separate processes. Every interaction returns a Promise.
// ✅ Correct: Await every browser command
async function performLogin(page) {
  await page.goto("https://targetqa.com/login");
  await page.getByLabel("Email").fill("user@targetqa.com");
  await page.getByRole("button", { name: "Sign in" }).click();
}

// Parallel operations with Promise.all:
const [response] = await Promise.all([
page.waitForResponse("**/api/login"),
page.getByRole("button", { name: "Sign in" }).click(),
]);

Task

  • Implement executeAllTasks:
  • 1. Accept tasks array of async functions.
  • 2. Execute all tasks in parallel using Promise.all and return their resolved values.
💡Common doubts
Did you like the problem?
Lesson 3 of 18
JavaScript
Loading code editor…
Next