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
javascriptOpen a page and assert title.
test("home title", async ({ page }) => {
await page.goto("/");
await expect(page).toHaveTitle(/PHPKINGDOM/);
}); 2. Click and Fill
javascriptFill a form and submit.
await page.getByLabel("Email").fill("a@b.com");
await page.getByRole("button", { name: "Sign in" }).click(); 3. Locator Role
javascriptQuery by role and name.
await expect(page.getByRole("heading", { name: "Interview Questions" })).toBeVisible(); 4. Wait for Response
javascriptWait 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
javascriptCapture a screenshot on failure path.
await page.screenshot({ path: "artifacts/home.png", fullPage: true }); 6. Storage State
javascriptReuse authenticated storage state.
test.use({ storageState: "playwright/.auth/user.json" }); 7. Network Mock
javascriptMock an API route.
await page.route("**/api/posts", async (route) => {
await route.fulfill({ json: [{ id: 1, title: "Hello" }] });
}); 8. Mobile Project
javascriptEmulate a mobile viewport.
test.use({ viewport: { width: 390, height: 844 } }); 9. File Upload
javascriptUpload a file input.
await page.setInputFiles('input[type="file"]', "tests/fixtures/resume.pdf"); 10. Soft Assertions
javascriptUse soft expects for multiple checks.
await expect.soft(page.getByText("Ready")).toBeVisible();
await expect.soft(page.getByText("Draft")).toBeVisible();