Prepare for your Playwright interview with these 30 essential questions and answers. This guide covers basic, intermediate, and advanced topics to help freshers, candidates with 1-3 years of experience, and those with 3-6 years build confidence in end-to-end testing using Playwright.
Basic Playwright Interview Questions
1. What is Playwright?
Playwright is an open-source end-to-end testing framework developed by Microsoft for automating Chromium, Firefox, and WebKit browsers. It supports cross-browser, cross-platform, and multi-language testing with JavaScript/TypeScript, Python, Java, and .NET.[1][2][3]
2. What are the key features of Playwright?
Key features include auto-waiting for elements, network interception, cross-browser support, headless mode, codegen for test generation, and built-in assertions. It handles modern web apps reliably without manual waits.[1][2][3]
3. How do you install Playwright?
Install Playwright using npm with npm init playwright@latest. This sets up the project, installs browsers, and creates a basic configuration file.[5]
4. What is the difference between npm and npx in Playwright?
npm is a package manager to install and manage libraries like Playwright. npx executes packages without installation, such as running tests with npx playwright test
5. How do you run Playwright tests?
Run tests using npx playwright test. Use flags like --headed for UI mode or --project=chromium for specific browsers.[5]
6. What is a Playwright fixture?
A fixture provides reusable setup like page or browser objects. Use test.use({ baseURL: 'https://example.com' }) in tests for consistent state.[4]
7. Explain test.describe, test.beforeEach, and other hooks in Playwright.
test.describe groups tests. test.beforeEach runs setup before each test, like creating test data. Other hooks include beforeAll and afterEach.[4]
8. How do you generate reports in Playwright?
Configure reports in playwright.config.ts with reporter: 'html'. Run tests to generate HTML reports viewable via npx playwright show-report
9. What is CodeGen in Playwright?
CodeGen records user actions in the browser and generates test code. Run npx playwright codegen demo.playwright.dev/todos to auto-generate locators and actions.[4]
10. How do you perform cross-browser testing in Playwright?
Set projects in playwright.config.ts for browsers like chromium, firefox, webkit. Run npx playwright test --project=all to execute across browsers.[5]
Intermediate Playwright Interview Questions
11. How does Playwright handle waiting and synchronization?
Playwright uses auto-waiting before actions. It checks if elements are attached, visible, stable, and enabled, eliminating explicit waits.[1][3]
12. What are actionability checks in Playwright?
Actionability checks ensure elements are ready: attached to DOM, visible, stable (no animations), receives events, and enabled before clicks or inputs.[3]
13. How do you locate elements in Playwright?
Use locators like page.getByRole('button', { name: 'Submit' }), getByText, getByLabel, or CSS page.locator('button.submit').[1]
14. How do you handle dynamic elements in Playwright?
Use locator.waitFor(), .nth(index) for lists, text selectors, or network waits for backend responses.[2]
15. Explain Page Object Model (POM) in Playwright.
POM encapsulates page elements and actions in classes. Create a LoginPage class with locators and methods like fillCredentials() for maintainability.[1]
class LoginPage {
constructor(page) { this.page = page; }
async login(user, pass) {
await this.page.getByLabel('Username').fill(user);
await this.page.getByLabel('Password').fill(pass);
await this.page.getByRole('button', { name: 'Log in' }).click();
}
}
16. How do you store and reuse login state?
Use context.storageState() to save authenticated state. Load it with use: { storageState: 'state.json' } in config or tests.[4]
17. What are Playwright hooks for test data setup?
Use test.beforeEach(async ({ page }) => { await page.goto('/login'); }) to create fresh data or login before each test.[4]
18. How do you mock network requests in Playwright?
Use page.route('**/api/**', route => route.fulfill({ json: { mocked: true } })) to intercept and mock API responses.[3]
19. How do you handle file uploads in Playwright?
Use await page.setInputFiles('input[type=file]', '/path/to/file.txt') for single or multiple files.[3]
20. How do you run tests in parallel?
Playwright runs tests in parallel by default. Configure workers: 4 in config. Use test.describe.configure({ mode: 'parallel' }).[4]
Advanced Playwright Interview Questions
21. How do you reduce flaky tests in Playwright?
Avoid flakiness with auto-waits, stable locators, retries via retries: 2 in config, and network mocks. Use trace viewer for debugging.[4]
22. Explain API testing with Playwright.
Use request = await context.request.post('https://api.example.com/users', { data: { name: 'John' } }). Assert with expect(response.ok()).toBeTruthy()
23. How do you verify image integrity in Playwright?
Download image bytes with await response.body(), compute hash like SHA256, and compare with expected hash.[4]
const crypto = require('crypto');
const hash = crypto.createHash('sha256').update(imageBytes).digest('hex');
24. What is the test pyramid in Playwright context?
Focus on more unit/component tests at base, fewer API tests, and minimal E2E UI tests for faster, reliable suites.[4]
25. How do you implement test tagging in Playwright?
Tag tests with test('login @smoke', async ({ page }) => { ... }). Run selectively: npx playwright test @smoke
26. Scenario: At Zoho, tests fail intermittently on Swiggy's checkout page due to animations. How to fix?
Disable animations with await page.addStyleTag({ content: '* { animation: none !important; }' }) or use stable locators with auto-waits.[2]
27. Scenario: In a Salesforce-like app at Adobe, handle shadow DOM elements.
Pierce shadow DOM with page.locator('host-element >>> inner-selector') or .locator('css=host ::slotted(inner)').[1]
28. How do you integrate Playwright with CI/CD?
Use GitHub Actions or Jenkins with npx playwright test --project=chromium in workflows. Set shards for parallel execution.[1][4]
29. Scenario: At Atlassian, verify PDF download content.
Intercept download with page.expectDownload(), then read PDF buffer with a library like pdf-parse to assert text.[3]
30. Explain serial vs parallel execution and when to use each.
Parallel for speed on independent tests. Serial with test.describe.configure({ mode: 'serial' }) for dependent tests like workflows.[4]