Top 50 Playwright Interview Questions and Answers

Testers Talk
8 min readAug 19, 2024

--

Interview questions could varies from company to company or person to person, Interviewer may ask basic questions sometimes or advanced level questions.

playwright interview questions and answers

Read my previous article :

Below are the list of most frequently asked playwright interview questions.

Playwright Interview Questions :

  1. What is Playwright?
  2. What are the key advantages of Playwright over Selenium?.
  3. Explain Playwright Architecture.
  4. Explain different types of selectors supported by Playwright.
  5. How do you handle different types of waits in Playwright?
  6. Why we use async & await in Playwright?
  7. What is the difference between page.evaluate and page.context.evaluate?
  8. Explain the concept of page objects in Playwright.
  9. How do you handle iframes in Playwright?.
  10. How do you handle authentication pop-ups in Playwright?.
  11. Explain how to handle file uploads in Playwright?.
  12. How do you perform parallel testing with Playwright?.
  13. How do you capture network requests and responses in Playwright?.
  14. Explain how to use Playwright for mobile emulation.
  15. How do you handle browser permissions in Playwright?.
  16. How do you troubleshoot Playwright test failures?.
  17. How to increase test timeout in Playwright?.
  18. Can you explain how to select drop down list value in Playwright?.
  19. How to verify dropdown list values?.
  20. Can Playwright supports for running same tests in multiple environments such as QA, Staging, PROD etc.
  21. How to set particular test timeout?.
  22. What is purpose of using codegen in Playwright?
  23. How to write more readable tests in Playwright?.
  24. Can you explain your current project Playwright Automation Framework?.
  25. Explain different types of assertions in Playwright?.
  26. How to run tests in headless mode in Playwright?.
  27. How to run specific spec file in Playwright?.
  28. How to debug the Playwright test?.
  29. Explain how to overcome strict mode violation exception in Playwright?.
  30. How to verify any text on the web page in Playwright?.
  31. How do you implement page object model in Playwright?
  32. How do you add screenshot & video into Playwright Test Report?
  33. Can you explain how to perform Data Driven Testing in Playwright?
  34. Explain how do you group tests and run tests in Playwright?
  35. How to read environment file properties in Playwright?
  36. How do you automatically rerun failed tests in Playwright?
  37. Explain HOOKS in Playwright.
  38. How do you perform Mouse actions in Playwright?
  39. How do you perform Keyboard actions in Playwright?
  40. Write a sample code for Drag and Drop in Playwright?
  41. How to skip test in Playwright?
  42. Can you explain Visual Testing in Playwright?
  43. Explain opening multiple browser sessions in Playwright?
  44. Can we generate multiple types of Test Report in Playwright?
  45. How to integrate Allure Report with Playwright?
  46. Does Playwright supports for API Testing?
  47. Write a sample code for POST, GET API requests in Playwright API Testing?
  48. Write a sample code for PUT, PATCH, DELETE API requests in Playwright API Testing?
  49. How do you pass query parameters in Playwright API Testing?
  50. How to upgrade Playwright to latest stable version?

Playwright Interview Questions & Answers :

  1. What is Playwright?

Playwright is a Node.js library for automation testing that allows you to write end-to-end tests for web applications, mobile app, REST api’s.. It provides a single API to automate Chromium, Firefox, and WebKit with Java, C#, JavaScript, TypeScript, or Python.

2. What are the key advantages of Playwright over Selenium?.

  • Built-in Test Report
  • Test Generator accurately using Codegen.
  • Built-in Locator Generator.
  • No flaky tests
  • Faster
  • Parallel Execution
  • Cross-browser compatibility: Supports Chromium, Firefox, and WebKit.
  • Headless mode: Can run tests without a UI.
  • Asynchronous execution: Improves performance.
  • Modern API: Easier to use and maintain.
  • Built-in features: Network interception, video recording, tracing.

3. Explain Playwright Architecture.

Playwright architecture

· Client: In the client side our automation test code will be written in different languages such as javascript, python, c# .net etc.

· Server: The server communicates between client and web browser engines such as chrome, firefox, edge etc.

Playwright uses CDP to communicate with chromium or chrome browser, similarly playwright has implemented CDP to communicate with other browser such as firefox webkit etc.

· WebSocket Protocol: WebSocket connection is established to the server from client by using process called Web Socket Handshake, WebSocket sends response as soon as it gets request in real time. Connection will be not terminated until unless connection is closed by either client or server.

· CDP (Chrome DevTools Protocol):

· Client & Server Communication: When test is triggered Client converts automation test into JSON format and sends to server over WebSocket Protocol

- Playwright communicates all the request over single websocket protocol connection.

  • Test failure & test flakiness is less as because executing all the tests over single websocket connection.

4. Explain different types of selectors supported by Playwright.

  • CSS selectors
  • XPath selectors
  • Text selectors
  • Accessibility selectors

I. By Role

Example — await page.getByRole(‘link’,{name: ‘value’}).click();

II. By Label

Example — await page.getByLabel(‘value’,{exact : true}).fill(‘value’);

III. By Alt Text

Example — await page.getByAltText(‘text’).click();

IV. By Test Id

Example — await page.getByTestId(‘value).fill(‘testers talk’);

V. By Text

Example — await page.getByText(‘any text’).click(); //partial

//complete text should be present

Example — await page.getByText(‘any text’, {exact :true}).click();

VI. By Title

Example — await page.getByTitle(‘cypress by testers talk).click();

VII. XPath

Example — await page.locator (“xpath=//*[@attr=’value’]”).click();

VIII. CSS Selector

Example — await page.locator (“css=//*[@attr=’value’]”).click();

IX. By Placeholder

Example — await page.ByPlaceholder (‘value]).click();

5. How do you handle different types of waits in Playwright?

  • waitForSelector: Waits for an element to appear.
  • waitForNavigation: Waits for navigation to complete.
  • waitForTimeout: Waits for a specific time.
  • waitForEvent: Waits for a specific event.

6. Why we use async() & await() in Playwright?

· -> async() is a function, await is valid inside async() function only.

-> Zero or more await expressions can be written inside async() function

  • When each time async functions is called, it returns a new promise value. Which will be resolved with the value returned by the async function or rejected with an exception.

7. What is the difference between page.evaluate and page.context.evaluate?

  • page.evaluate executes JavaScript in the page context.
  • page.context.evaluate executes JavaScript in the browser context.

8. Explain the concept of page objects in Playwright.

Page objects are a design pattern that encapsulates the behavior of a web page into a class. It improves test readability and maintainability.

9. How do you handle iframes in Playwright?.

  • Use page.frame() to get a reference to the iframe.
  • Use page.waitForFrame() to wait for an iframe to load.
  • Switch to the iframe using page.goto() or frame.goto()

10. How do you handle authentication pop-ups in Playwright?.

Use browserContext.authenticate() to provide credentials for authentication pop-ups.

11. Explain how to handle file uploads in Playwright?.

Use input.uploadFile() to set the file path for file input elements.

12. How do you perform parallel testing with Playwright?.

  • Use a test runner like Jest or Mocha with parallel execution options.
  • Configure Playwright to use multiple workers.

13. How do you capture network requests and responses in Playwright?.

  • Use page.route() to intercept network requests.
  • Use request.fulfill() or request.abort() to modify or block requests.

14. Explain how to use Playwright for mobile emulation.

  • se browser.newContext() with isMobile set to true.
  • Set viewport size and user agent.
  • Simulate touch events.

15. How do you handle browser permissions in Playwright?.

Use page.setPermissions() to grant or deny permissions.

16. How do you troubleshoot Playwright test failures?.

  • Use debugging tools provided by Playwright.
  • Check test logs and console output.
  • Inspect the page DOM.
  • Use video recording to analyze test failures.

17. How to increase test timeout in Playwright?.

In Playwright config file we can set timeout based on need

Example:

 timeout: 7 * 60 * 1000,

18. Can you explain how to select drop down list value in Playwright?.

Drop down value can selected by using 2 ways

a) Using value or text

 dropDownList.selectOption('5');

b) Using label

await page.getByLabel('Choose a color').selectOption({ label: 'Blue' });
// Multiple selected items
await page.getByLabel('Choose multiple colors').selectOption(['red', 'green', 'blue']);

19. How to verify dropdown list values?.

await expect(dropDownList).toHaveValue('2');
await expect(dropDownList).toContainText('Aug');

20. Can Playwright supports for running same tests in multiple environments such as QA, Staging, PROD etc.

21. How to set particular test timeout?.

Ans:

test.seTimeOut(5*60*1000);

22. What is purpose of using codegen in Playwright?

23. How to write more readable tests in Playwright?.

Ans:

 await test.step('Go to URL', async () => {
await homepage.goto();
});

24. Can you explain your current project Playwright Automation Framework?.

Ans: Explain about folder structure, Next what exactly each folder contains

How we are managing test data, login sessions etc.

Here is example framework:

https://github.com/BakkappaN/PlaywrightBaseAutomationFramework

25. Explain different types of assertions in Playwright?.

26. How to run tests in headless mode in Playwright?.

27. How to run specific spec file in Playwright?.

28. How to debug the Playwright test?.

Ans: Put the break point in test then right click on the right arrow icon, select the option as “Debug Test”

29. Explain how to overcome strict mode violation exception in Playwright?.

Ans: a) Use first() function to find first matching element.

b) Identify element using different locator or attributes.

30. How to verify any text on the web page in Playwright?.

31. How do you implement page object model in Playwright?

32. How do you add screenshot & video into Playwright Test Report?

33. Can you explain how to perform Data Driven Testing in Playwright?

Data Driven Testing using JSON File & CSV File.

34. Explain how do you group tests and run tests in Playwright?

35. How to read environment file properties in Playwright?

36. How do you automatically rerun failed tests in Playwright?

37. Explain HOOKS in Playwright.

38. How do you perform Mouse actions in Playwright?

39. How do you perform Keyboard actions in Playwright?

40. Write a sample code for Drag and Drop in Playwright?

41. How to skip test in Playwright?

42. Can you explain Visual Testing in Playwright?

43. Explain opening multiple browser sessions in Playwright?

Ans: Here is a sample code

 // Create chromium browser object
const browser = await chromium.launch();

// Create context object for each browser
const context1 = await browser.newContext();
const context2 = await browser.newContext();

// Create new page
const page1 = await context1.newPage();
const page2 = await context2.newPage();

// Using page object perform actions
await page1.goto('https://youtube.com/playlist?list=PLUeDIlio4THEgPRVJRqZRS8uw8hhVNQCM&si=-US8rBdfw1kxRBnt');
await page1.locator('#contents > ytd-playlist-video-renderer:nth-child(1)').click()
await page1.waitForTimeout(5000);

await page2.goto('https://youtube.com/playlist?list=PLUeDIlio4THEgPRVJRqZRS8uw8hhVNQCM&si=-US8rBdfw1kxRBnt');

// Closing both the browsers
await browser.close();

44. Can we generate multiple types of Test Report in Playwright?

Ans:

45. How to integrate Allure Report with Playwright?

46. Does Playwright supports for API Testing?

Ans: Yes

47. Write a sample code for POST, GET API requests in Playwright API Testing?

48. Write a sample code for PUT, PATCH, DELETE API requests in Playwright API Testing?

Ans:

GitHub Link: https://github.com/BakkappaN/PlaywrightAPITestingTutorial/tree/main/tests

49. How do you pass query parameters in Playwright API Testing?

50. How to upgrade Playwright to latest stable version?

Ans:

Install latest stable Playwright version

npm install -D @playwright/test@latest

Install latest browsers

npx playwright install --with-deps

I HOPE IT HELPED YOU…KEEP VISITING…KEEP LEARNING…!!!

Read my next article:

Reference: https://playwright.dev/docs

Subscribe & get latest software testing updates: https://www.youtube.com/@testerstalk?sub_confirmation=1

Learn more about Playwright:

  • > Playwright Automation Full Course
  • > Playwright API Testing Crash Course
  • > Playwright with Azure DevOps Complete guide

-> Testing Microsoft CRM application using Playwright

===== Playwright GitHub Repositories =====

-> Playwright Automation Full Course https://github.com/BakkappaN/PlaywrightTutorialFullCourse

-> Playwright API Testing Crash Course https://github.com/BakkappaN/PlaywrightAPITestingTutorial

-> Playwright with Azure DevOps Pipeline https://github.com/BakkappaN/PlaywrightAzureDevopsPipeline

-> Playwright with CRM Application Testing https://github.com/BakkappaN/MicrosoftD365CRMPlaywrightFramework

-> Playwright with JavaScript Framework [UI + API] https://github.com/BakkappaN/PlaywrightBaseAutomationFramework

-> Playwright with TypeScript Framework [UI + API] https://github.com/BakkappaN/Playwright-TypeScript-Framework

#playwright #apitesting #qa #softwaretesting #crm #javascript #typescript #ado #azuredeveops #framework #fullcourse #codegen #test #e2e #testing #automation #testerstalk #bakkappan #git #github #selenium #framework #test #tutorials

Playwright Full Course Playlist:

Connect with me on LinkedIn : www.linkedin.com/in/bakkappa-n

Join to LinkedIn Group : https://www.linkedin.com/groups/10393547/

Subscribe my channel to get daily updates: https://www.youtube.com/@testerstalk?sub_confirmation=1

--

--

Testers Talk

Become Best Tester: Software Testing, Playwright, Cypress, Selenium, Postman, Rest Assured, API Testing, Test Automation, Framework, QA, SDET, Test Automation.