Testleaf

Top 30 Playwright Interview Questions and Answers (2025 Updated Guide)

Playwright Interview Questions and Answers

 

If you’re preparing for a QA automation interview, mastering Playwright can help you stand out from the crowd. This 2025 updated guide covers the most common and advanced Playwright interview questions — including real-world coding scenarios, differences from Selenium, and hands-on best practices. 

Whether you’re a beginner or an experienced automation engineer, this article will help you gain clarity and confidence for your next interview. 

Beginner-Level Playwright Interview Questions 

1. What is Playwright? 

Answer:
Playwright is a modern end-to-end testing framework developed by Microsoft, designed to automate browsers (Chromium, Firefox, WebKit).
It supports cross-browser, cross-platform, and multi-language testing (JS/TS, Python, Java, .NET). 

2. How do you handle waiting / synchronization issues in Playwright? 

Answer:
Playwright auto-waits for elements to become actionable before performing any action.
Still, you can use: 

await page.waitForSelector(‘#submit’);
await expect(page.locator(‘#success’)).toBeVisible();
await page.waitForLoadState(‘networkidle’);
 

Types: 

  • Auto-wait → built-in for actions like .click(), .fill() 
  • Explicit wait → page.waitForSelector(), expect(locator).toBeVisible() 
  • No implicit waits like Selenium (Playwright avoids flakiness by design). 

Other Recommended Reads: api automation interview questions

 

3. How do you run tests in parallel or in multiple browsers/devices/contexts? 

Answer: 

  • Parallel Execution: Each test runs in an isolated worker. 
  • Multiple Browsers/Devices: Defined via projects in playwright.config.ts 

 

export default defineConfig({ 

  fullyParallel: true, 

  workers: 4, 

  projects: [ 

    { name: ‘chromium’, use: { browserName: ‘chromium’ } }, 

    { name: ‘firefox’, use: { browserName: ‘firefox’ } }, 

    { name: ‘webkit’, use: { browserName: ‘webkit’ } }, 

  ], 

}); 

4. How do you run Playwright tests headlessly vs headed? 

Answer: 

  • Headless: For CI/CD environments (default). 
  • Headed: For debugging or local runs. 

npx playwright test –headed
npx playwright test –headless
 

Or in config: 

use: { headless: false } 

 

Playwright automation testing

 

5. How do you manage environment configuration (dev/stage/prod)? 

Answer: 

  • Use .env files or JSON config files. 
  • Access variables via process.env. 

Example: 

BASE_URL=https://staging.example.com
 export default defineConfig({
 use: { baseURL: process.env.BASE_URL }
}); 

 

6. What makes a “good API”? What best practices do you follow? 

Answer:
A good API is consistent, predictable, secure, and well-versioned. 

Best Practices: 

  • Proper HTTP verbs (GET, POST, PUT, DELETE) 
  • Correct status codes (200, 201, 400, 404, 500) 
  • Consistent naming conventions 
  • Pagination & filtering 
  • Versioning (/v1/users) 
  • Proper authentication (OAuth/JWT) 
  • Meaningful error messages 

7. How do you handle authentication & authorization in APIs? 

Answer: 

  • Fetch token via a login request, reuse it across tests. 

const api = await request.newContext({
 extraHTTPHeaders: { Authorization: `Bearer ${token}` }
}); 

 

8. How do you ensure your test automation code is maintainable and scalable? 

Answer: 

  • Centralize locators and common logic. 
  • Use fixtures for setup/teardown. 
  • Parameterize environment/config. 
  • Implement clear naming conventions and folder structure. 
  • Continuous refactoring, DRY principle, and TypeScript typings. 

 

9. How do you build custom fixtures in Playwright? 

Answer:
Fixtures let you share setup/teardown logic. 

import { test as base } from ‘@playwright/test’;

type MyFixtures = { loginPage: LoginPage };
const test = base.extend<MyFixtures>({
 loginPage: async ({ page }, use) => {
   const login = new LoginPage(page);
   await use(login);
 },
});
 

Intermediate-Level Playwright Interview Questions 

10. What is the difference between browser, context, and page in Playwright? 

Object  Description 
Browser  Top-level instance (e.g., Chromium). 
Context  Isolated incognito-like session within a browser. 
Page  Represents a single tab in a browser context. 

 

11. How do you select elements? What are locators? 

Answer:
Locators are Playwright’s recommended way to find elements.
They are lazy-evaluated and auto-wait. 

const loginBtn = page.locator(‘button:has-text(“Login”)’);
await loginBtn.click(); 

 

12. What is a fixture in Playwright Test? 

Answer:
A fixture is a reusable setup resource (like browser context, page, API client).
Playwright provides built-in fixtures like page, context, request.
You can extend them for custom object 

Babu's Gen AI

13. How do you handle file uploads or downloads? 

Upload: 

await page.setInputFiles(‘input[type=”file”]’, ‘tests/data/sample.pdf’);
 

Download: 

const [download] = await Promise.all([
 page.waitForEvent(‘download’),
 page.click(‘text=Download File’),
]);
await download.saveAs(‘downloads/file.pdf’); 

 

14. Difference between page.locator(selector).click() and page.click(selector) 

Method  Behavior 
page.locator().click()  Uses Locator API (auto-wait, retries). ✅ 
page.click()  Executes immediately (can be 

 flaky). ⚠️ 

Additional Resources: product based companies in bangalore

 

15. How to assert something in Playwright Test? 

Use expect() API: 

await expect(page).toHaveURL(/dashboard/);
await expect(locator).toBeVisible();
await expect(locator).toHaveText(‘Welcome’); 

 

16. Difference between page.waitForLoadState(‘networkidle’) and waitForNavigation() 

Method  Purpose 
waitForLoadState(‘networkidle’)  Waits for no network connections for 500ms. 
waitForNavigation()  Waits for a navigation event triggered by an action. 

Use waitForLoadState when waiting for background requests, not full navigation. 

 

17. How to use test hooks and where to place them? 

Hooks manage setup/cleanup: 

test.beforeAll(…)
test.beforeEach(…)
test.afterEach(…)
test.afterAll(…)

Placed inside test.describe() or globally in test files.
Best practice: use hooks for test data setup and teardown. 

 

18. How do you generate and publish HTML / Allure / custom reports? 

HTML report: 

npx playwright test –reporter=html
 

Allure report: 

npm install –save-dev allure-playwright
npx playwright test –reporter=allure-playwright
 

Publishing in GitHub Actions: 

– run: npx playwright test –reporter=html
– uses: actions/upload-artifact@v4
 with:
   name: report
   path: playwright-report/
 

 

19. Can Playwright be used for API testing? How? 

Yes.
Playwright provides APIRequestContext to perform REST API testing. 

const api = await request.newContext();
const res = await api.get(‘https://api.example.com/users’);
expect(res.status()).toBe(200);
 

Advanced Playwright Interview Questions for Experienced Testers 

20. How do you create an API request context with authentication? 

const api = await request.newContext({
 baseURL: ‘https://api.example.com‘,
 extraHTTPHeaders: {
   Authorization: `Bearer ${token}`,
   ‘Content-Type’: ‘application/json’,
 },
});
 

Selenium training in chennai

21. How do you chain API calls (use one response to feed another)? 

const createUser = await api.post(‘/users’, { data: { name: ‘John’ } });
const id = (await createUser.json()).id;
const getUser = await api.get(`/users/${id}`);
expect(getUser.status()).toBe(200);
 

22. What is Playwright’s APIRequestContext and how is it used for API testing? 

It represents an isolated API session that can: 

  • Send REST requests 
  • Store cookies, headers, and auth data 
  • Reuse between tests 

 

23. How do you architect a Playwright test suite for a large codebase? 

Best practice structure: 

├── pages/
├── api/
├── fixtures/
└── utils/
├── tests/
│   ├── ui/
│   └── api/
├── playwright.config.ts
└── package.json
 

Principles: 

  • Reusable page & API classes 
  • Configurable environments 
  • Modular utilities & fixtures 
  • Parallel-safe test data setup 

 

24. How to parallelize tests safely when they share resources? 

  • Avoid shared mutable data. 
  • Use unique test data per worker (uuid, timestamp). 
  • Isolate environments using fixtures. 

 

25. Basic JS: What’s the difference between == and ===? 

Operator  Meaning 
==  Equality with type coercion 
===  Strict equality, no type conversion 

Example: 

‘5’ == 5   // true
‘5’ === 5  // false
 

26 : How do you handle dropdowns with <select> and <option> in Playwright? 

Answer:
In Playwright, you handle <select> dropdowns using the selectOption() method. It allows selecting an option by value, label, or index. For multi-select dropdowns, you can pass an array of values. 

Example: 

import { test, expect } from ‘@playwright/test’;

test(‘Select dropdown option’, async ({ page }) => {
 await page.goto(‘https://example.com’);

 // Select by value
 await page.selectOption(‘#country’, ‘ca’); // Canada

 // Select by label
 await page.selectOption(‘#country’, { label: ‘United Kingdom’ });

 // Select by index
 await page.selectOption(‘#country’, { index: 0 }); // United States

 // Verify selection
 const selectedValue = await page.$eval(‘#country’, el => (el as HTMLSelectElement).value);
 expect(selectedValue).toBe(‘us’);
});
 

Key Points: 

  • Works only with <select> elements. 
  • Can select by value, label, or index. 
  • Supports multi-select: await page.selectOption(‘#multi’, [‘us’, ‘uk’]). 
  • Playwright automatically handles the dropdown; no manual click needed. 

Teaching

27 : How do you handle a dropdown that dynamically loads options based on previous selection? 

Answer: 

  • First, select the parent dropdown option using selectOption(). 
  • Wait for the child dropdown to be populated using page.waitForSelector() or locator.waitFor(). 
  • Then, select the desired child option. 

Example: 

await page.selectOption(‘#country’, ‘us’);
await page.waitForSelector(‘#state option:not(:empty)’);
await page.selectOption(‘#state’, ‘ca’); // Select California 

28: Difference between var, let, and const 

Feature  var  let  const 
Scope  Function-scoped  Block-scoped  Block-scoped 
Redeclaration  Allowed  Not allowed  Not allowed 
Re-assignment  Allowed  Allowed  Not allowed (must be initialized) 
Hoisting  Yes (initialized as undefined)  Yes (temporal dead zone)  Yes (temporal dead zone) 
Use case  Legacy code  Modern variables  Constants / immutable references 

Key points: 

  • Use let for variables that change. 
  • Use const for values that shouldn’t change. 
  • Avoid var in modern JavaScript due to scoping issues. 

 

29: How do Promises to differ from callbacks? 

Feature  Callbacks  Promises 
Syntax  Function passed as argument  Object with .then() / .catch() 
Handling async  Nested or “callback hell”  Chainable, avoids nested callbacks 
Error handling  Needs try/catch inside callback  Built-in .catch() for errors 
Execution  Executes immediately when function runs  Executes asynchronously and resolves later 

Example: 

// Callback
doSomething(function(result) {
 doSomethingElse(result, function(newResult) {
   console.log(newResult);
 });
});

// Promise
doSomething()
 .then(result => doSomethingElse(result))
 .then(newResult => console.log(newResult))
 .catch(error => console.error(error));
 

Summary for Interview: 

  • Promises provide better readability and error handling than callbacks. 
  • Helps avoid “callback hell” for complex async code. 

 

30: What is Hoisting? 

Definition:
Hoisting is JavaScript’s behavior of moving variable and function declarations to the top of their scope during compilation. 

Key Points: 

  • Only declarations are hoisted, not initializations. 
  • var variables are hoisted with value undefined. 
  • let and const are hoisted but in a temporal dead zone (TDZ) until initialization. 
  • Function declarations are fully hoisted, but function expressions are not. 

Example: 

console.log(a); // undefined
var a = 10;

console.log(b); // ReferenceError
let b = 20;

foo(); // Works
function foo() { console.log(‘Hello’); }

bar(); // Error
const bar = function() { console.log(‘Hi’); } 

 

Playwright vs Selenium — Key Differences 

Feature  Playwright  Selenium 
Auto-waiting  ✅ Built-in  ❌ Manual waits 
Browser Contexts  ✅ Yes  ❌ Needs multiple drivers 
Network Mocking  ✅ Easy  ⚠️ Limited 
Speed  ⚡ Fast (CDP protocol)  🐢 Slower (HTTP JSON wire) 
API Testing  ✅ Built-in  ❌ External tools needed 

💡 Pro Tip: Prefer page.locator() over page.click() for more reliable element handling. 

 

Bonus: Real-Time Playwright Coding Questions 

  1. Write a Playwright script to log into a website and verify the title. 
  2. How do you capture screenshots and videos in Playwright? 
  3. Demonstrate API testing with Playwright using APIRequestContext. 
  4. How do you handle multiple tabs and pop-ups? 

 

Playwright Framework Best Practices 

  • Use Page Object Model (POM) for scalability. 
  • Integrate with CI/CD tools like Jenkins or GitHub Actions. 
  • Implement test tagging for selective execution. 
  • Maintain reusable test data and environment configs. 

Online Classes

Playwright Interview Preparation Tips 

✅ Practice automation challenges on GitHub repositories. 

✅ Review Playwright’s official documentation weekly. 

✅ Mock interviews help improve confidence. 

✅ Learn Playwright with real projects — not just syntax. 

Playwright Interview Preparation Tips

 

Conclusion: How to Prepare for a Playwright Interview 

Playwright is redefining automation with speed, reliability, and built-in testing features. Whether you’re transitioning from Selenium or starting fresh, understanding these questions and concepts will make you interview-ready. 

If you want hands-on mastery, explore a Playwright course online that blends practical frameworks and interview guidance — the key to building your automation career in 2025. 

 

FAQs 

Q1. What is Playwright used for? 

Playwright is used for end-to-end web automation testing across browsers and devices. 

Q2. Is Playwright better than Selenium? 

Yes. Playwright offers faster execution, auto-waiting, and API testing support. 

Q3. What are the most asked Playwright topics in interviews? 

Locators, waits, fixtures, POM, API testing, and Playwright vs Selenium. 

 

We Also Provide Training In:
Author’s Bio:

Dilip

As a Senior SDET with 8+ years in testing and development, I build scalable automation platforms ensuring quality at speed. Passionate about mentoring and innovation, I equip teams with real-time solutions and high-impact frameworks, driving excellence through continuous learning. Let’s shape the future of quality engineering together.

Dilipkumar Rajendran
Senior SDET | Playwright & Selenium Expert

                                                                         LinkedIn Logo

 

Accelerate Your Salary with Expert-Level Selenium Training

X