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
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
- What's the difference between mocks, stubs, fakes and spies?
- What causes flaky tests and how do you fix them?
- What is the test pyramid, and is it still relevant?
- What makes a good unit test?
- How would you design a test strategy for a new web application?
- How do you write reliable integration tests that use a database?
- Your end-to-end test suite is flaky and takes an hour. How do you fix it?
- A critical bug reached production even though all tests passed. What do you do?