Skip to content

Coding practice

Playwright Coding Questions

10 hands-on challenges with prompts and solution sketches for Playwright interview rounds.

Challenge set

10 coding questions

1. Goto and Assert

javascript

Open a page and assert title.

test("home title", async ({ page }) => {
  await page.goto("/");
  await expect(page).toHaveTitle(/PHPKINGDOM/);
});

2. Click and Fill

javascript

Fill a form and submit.

await page.getByLabel("Email").fill("a@b.com");
await page.getByRole("button", { name: "Sign in" }).click();

3. Locator Role

javascript

Query by role and name.

await expect(page.getByRole("heading", { name: "Interview Questions" })).toBeVisible();

4. Wait for Response

javascript

Wait for an API response.

const [response] = await Promise.all([
  page.waitForResponse("**/api/users"),
  page.getByRole("button", { name: "Load" }).click(),
]);
expect(response.ok()).toBeTruthy();

5. Screenshot

javascript

Capture a screenshot on failure path.

await page.screenshot({ path: "artifacts/home.png", fullPage: true });

6. Storage State

javascript

Reuse authenticated storage state.

test.use({ storageState: "playwright/.auth/user.json" });

7. Network Mock

javascript

Mock an API route.

await page.route("**/api/posts", async (route) => {
  await route.fulfill({ json: [{ id: 1, title: "Hello" }] });
});

8. Mobile Project

javascript

Emulate a mobile viewport.

test.use({ viewport: { width: 390, height: 844 } });

9. File Upload

javascript

Upload a file input.

await page.setInputFiles('input[type="file"]', "tests/fixtures/resume.pdf");

10. Soft Assertions

javascript

Use soft expects for multiple checks.

await expect.soft(page.getByText("Ready")).toBeVisible();
await expect.soft(page.getByText("Draft")).toBeVisible();