Prepare for your Playwright interview with this comprehensive guide featuring 30 essential questions and answers. Covering basic concepts to advanced scenarios, this resource helps freshers, 1-3 years experienced candidates, and senior professionals master Playwright automation testing.
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.
2. What are the key advantages of Playwright?
Playwright offers automatic waiting, network interception, built-in assertions, reliable cross-browser execution, and support for modern web features like file uploads/downloads without manual waits.
3. How do you install Playwright?
Install Playwright using npm with npx playwright install after initializing with npm init playwright@latest. This sets up the project structure and downloads required browsers.
4. What is the basic structure of a Playwright test?
A basic Playwright test uses test.describe for test suites, test for individual tests, and follows async/await patterns:
import { test, expect } from '@playwright/test';
test('basic test', async ({ page }) => {
await page.goto('https://example.com');
await expect(page).toHaveTitle('Example');
});
5. What browsers does Playwright support?
Playwright natively supports Chromium (Chrome, Edge), Firefox, and WebKit (Safari) with a single API across all browsers.
6. How do you run Playwright tests in headed mode?
Use npx playwright test --headed to run tests with browsers visible, useful for debugging and demos.
7. What is a Playwright locator?
A locator identifies elements on the page using methods like getByRole(), getByText(), getByLabel(), or CSS selectors for reliable element interaction.
8. How do you launch a specific browser in Playwright?
In your test, use chromium.launch(), firefox.launch(), or webkit.launch() from the browser type module.
9. What is auto-waiting in Playwright?
Playwright automatically waits for elements to be actionable (attached, visible, stable, enabled) before performing actions like click() or fill(), eliminating flaky explicit waits.
10. How do you generate tests using Playwright Codegen?
Run npx playwright codegen https://example.com to record actions and generate test code automatically.
Intermediate Playwright Interview Questions
11. How do you handle multiple tabs/windows in Playwright?
Use context.waitForEvent('page') to capture new pages and interact with them via newPage.
12. Explain Playwright fixtures.
Fixtures like page, context, and browser provide reusable test state. Custom fixtures can be defined in playwright.config.ts.
13. How do you mock network requests in Playwright?
Use page.route() to intercept and mock API responses:
await page.route('**/api/**', route => route.fulfill({ json: { mocked: true } }));
14. What are Playwright test hooks?
Hooks include test.beforeEach() for setup, test.afterEach() for cleanup, test.beforeAll(), and test.afterAll() for suite-level operations.
15. How do you run tests in parallel in Playwright?
Configure workers in playwright.config.ts and use test.describe.configure({ mode: 'parallel' }) for parallel execution.
16. How do you handle authentication state in Playwright?
Save storage state with context.storageState({ path: 'state.json' }) and reuse it in tests via storageState: 'state.json' in config.
17. What is the Page Object Model in Playwright?
POM encapsulates page elements and actions in classes for maintainable tests. Create page classes with locators and methods for interactions.
18. How do you take screenshots in Playwright?
Use await page.screenshot() for full page or await locator.screenshot() for elements. Configure in config for automatic screenshots on failure.
19. How do you assert network events in Playwright?
Listen to page.on('request') and page.on('response') events to verify API calls and responses.
20. How do you upload files in Playwright?
Use await page.setInputFiles('input[type=file]', '/path/to/file') for native file upload support.
Advanced Playwright Interview Questions
21. Explain actionability checks in Playwright.
Before actions, Playwright checks if element is DOM-attached, visible, stable (no animations), receives events, and enabled. This is automatic waiting.
22. How do you handle shadow DOM in Playwright?
Use page.locator('host >> shadow-element') or >> chaining to pierce shadow boundaries.
23. How do you perform API testing with Playwright?
Use request.post('/api/endpoint', { data: { key: 'value' } }) from the APIRequestContext fixture.
24. Scenario: At Zoho, tests fail intermittently on dynamic tables. How would you handle this?
Use locator.first() or locator.nth(index), wait for specific row text with locator.filter({ hasText: 'expected' }), and enable retries in config.
25. How do you generate HTML reports in Playwright?
Configure reporter: [['html']] in playwright.config.ts. View reports in playwright-report/index.html after npx playwright show-report.
26. Scenario: At Salesforce, you need to test geolocation features. How?
Set mock geolocation with context.setGeolocation({ latitude: 51.5074, longitude: -0.1278 }) and grant permissions.
27. How do you handle iframes in Playwright?
Use page.frameLocator('iframe-selector') or page.frame({ url: '**/frame' }) to locate elements inside frames.
28. Scenario: At Atlassian, mobile viewport testing is required. Approach?
Set viewport in config or launch: context.setViewportSize({ width: 375, height: 667 }) for iPhone emulation.
29. How do you debug failing tests in Playwright?
Use --debug flag, test.step() for structured logs, trace viewer with --trace on, and slowMo option in config.
30. Scenario: At Adobe, you must verify downloaded file integrity. Solution?
Monitor download with page.waitForEvent('download'), compute hash with await download.createReadStream(), and compare with expected hash.