Testing interview question · Most asked

Write a Playwright test that logs in and checks the dashboard, and explain how you keep it stable.

Hands-on Asked in Backend Engineer · QA Engineer / SDET · Frontend Engineer · Full Stack Engineer interviews

Members can save this page, take notes and track progress. See membership · Sign in

Summary

Use role- or test-id-based locators, rely on Playwright's auto-waiting assertions, create the test user through an API or fixture rather than the UI, and reuse the logged-in storage state across tests so only one test exercises the login form.

Longer Answer

Stability practices to mention: no waitForTimeout, unique data per test, test.describe.configure({ mode: "parallel" }) with isolated users, traces and screenshots on failure (trace: "on-first-retry"), and running against a dedicated test environment.

Example

import { test, expect } from "@playwright/test";

test("member sees their dashboard after signing in", async ({ page, request }) => {
  const email = `qa+${Date.now()}@example.com`;
  await request.post("/api/test/users", { data: { email, password: "Str0ng-pass!" } });

  await page.goto("/login");
  await page.getByLabel("Email").fill(email);
  await page.getByLabel("Password").fill("Str0ng-pass!");
  await page.getByRole("button", { name: "Sign in" }).click();

  await expect(page).toHaveURL(/\/app\/dashboard/);
  await expect(page.getByRole("heading", { name: /welcome/i })).toBeVisible();
});

Key Points

  • Role and test-id locators.
  • Auto-waiting expect assertions.
  • Create data through APIs.
  • Reuse storage state for login.
  • Traces on failure.

Explanation

What interviewers look for

Clean, stable test code and the reasoning behind each choice.

More Testing questions

← All Testing questions

Last reviewed · By the ByteCamel team · How we write content

Was this page helpful?

Report a mistake