2. Promises, Async & Await in Automation

Asynchronous Execution in Playwright

Browser actions take time. In JavaScript/TypeScript, every browser operation returns a Promise:
test("example test", async ({ page }) => {
  await page.goto("https://targetqa.com");
  await page.getByRole("button").click();
});

> Critical Rule: If you forget await, your script moves to the next line before the browser completes the click!

Task

  • Add the missing `async` keyword to the function and `await` before `simulateClick`.
💡Common doubts
Did you like the problem?
Lesson 2 of 12
TypeScript
Loading code editor…
Next