MENU

Saturday, 28 June 2025

 

 Playwright Interview Questions

Playwright has rapidly become a favorite among automation engineers for its speed, reliability, and powerful feature set. If you're eyeing a role in test automation, particularly one that leverages Playwright, being prepared for a range of questions is crucial.

This blog post provides a comprehensive list of Playwright interview questions, from fundamental concepts to more advanced topics and real-world problem-solving scenarios, designed to help you showcase your expertise.

Foundational Playwright Concepts

These questions assess your basic understanding of Playwright's architecture, key components, and core functionalities.

  1. What is Playwright, and how does it fundamentally differ from Selenium?

    • Hint: Discuss architecture (WebDriver protocol vs. direct browser interaction), auto-waiting, browser support, isolated contexts, multi-language support.

  2. Explain the relationship between Browser, BrowserContext, and Page in Playwright.

    • Hint: Hierarchy, isolation, use cases for each (e.g., BrowserContext for user sessions, Page for tabs).

  3. What are Playwright's auto-waiting capabilities, and why are they significant for test stability?

    • Hint: Explain what it waits for (visible, enabled, stable, detached/attached) and how it reduces explicit waits and flakiness.

  4. Describe the various types of locators in Playwright and when you would choose one over another.

    • Hint: Discuss getByRole, getByText, getByLabel, getByPlaceholder, getByAltText, getByTitle, getByTestId, CSS, XPath. Emphasize "Web-First" locators.

  5. How do you handle different types of waits in Playwright (beyond auto-waiting)? Provide examples.

    • Hint: waitForLoadState, waitForURL, waitForSelector, waitForResponse/waitForRequest, waitForEvent, waitForFunction.

  6. What is playwright.config.js used for, and name at least five key configurations you'd typically set there?

    • Hint: testDir, use (baseURL, headless, viewport, timeouts, trace), projects, reporter, retries, workers, webServer.

  7. Explain Playwright's expect assertions. What are "soft assertions" and when would you use them?

    • Hint: Auto-retrying nature of expect. Soft assertions (expect.soft) to continue test execution even after an assertion failure.

  8. How do you set up and tear down test environments or data using Playwright's test runner? (Think Hooks and Fixtures)

    • Hint: beforeEach, afterEach, beforeAll, afterAll, and custom test fixtures for reusable setup/teardown.

  9. Can Playwright be used for API testing? If so, how?

    • Hint: request fixture, page.route(), mocking.

  10. What is Trace Viewer, and how does it aid in debugging Playwright tests?

    • Hint: Visual timeline, screenshots, DOM snapshots, network logs, console messages for post-mortem analysis.

Advanced Concepts & Scenarios

These questions delve deeper into Playwright's powerful features and challenge your problem-solving abilities.

  1. You need to test an application that requires users to log in. How would you handle authentication efficiently across multiple tests to avoid repeated logins?

    • Hint: storageState, browserContext.storageState(), reusing authenticated contexts.

  2. Explain Network Interception (page.route()) in Playwright. Provide a scenario where it would be indispensable.

    • Hint: Mocking API responses, simulating network errors/delays, blocking third-party scripts.

  3. How do you perform visual regression testing using Playwright? What are the limitations or common pitfalls?

    • Hint: toMatchSnapshot(), pixel comparison, handling dynamic content, screenshot stability.

  4. Your application has an iframe for a payment gateway. How would you interact with elements inside this iframe using Playwright?

    • Hint: frameLocator(), accessing frame content.

  5. Describe how Playwright facilitates parallel test execution. What are the benefits and potential considerations?

    • Hint: workers, fullyParallel, isolated browser contexts, benefits (speed, isolation), considerations (shared resources, reporting).

  6. How would you handle file uploads and downloads in Playwright? Provide a code snippet for each.

    • Hint: setInputFiles(), waitForEvent('download').

  7. Your tests are running fine locally but consistently fail on CI/CD with "Timeout" errors. What steps would you take to debug and resolve this?

    • Hint: Check CI logs, use Trace Viewer, adjust timeouts (CI vs. local), check network conditions, ensure webServer is stable.

  8. You need to test a responsive website across different device viewports and mobile emulations. How would you configure your Playwright tests for this?

    • Hint: projects, devices presets, viewport in use configuration.

  9. How would you debug a Playwright test script interactively in your IDE?

    • Hint: page.pause(), DEBUG=pw:api environment variable, VS Code debugger integration.

  10. Can you explain the concept of Test Fixtures in Playwright beyond simple beforeEach/afterEach? Provide a scenario for a custom fixture.

    • Hint: Reusable setup/teardown logic, passing resources (like API clients) to tests, complex setups (e.g., a logged-in user fixture, a database connection fixture).

Real-Time / Scenario-Based Questions

These questions test your practical application of Playwright knowledge in realistic situations.

  1. Scenario: "Our e-commerce application has a product filter that updates the product list asynchronously without a full page reload. When a filter is applied, a small loading spinner appears for 2-5 seconds, then disappears, and the product count updates. How would you ensure your Playwright test reliably waits for the new product list to load after applying a filter?" * Expected Answer: Combine waitForResponse (for the filter API call) with locator.waitFor({ state: 'hidden' }) (for the loading spinner) and then expect(page.locator('.product-item')).toHaveCount(...) (which auto-waits for elements).

  2. Scenario: "You need to automate a checkout flow where after clicking 'Place Order,' the page navigates to an order confirmation page, but there's an intermediate redirect and a few seconds of network activity before the final content renders. How would you write a robust wait for the order confirmation to be fully displayed?" * Expected Answer: Use page.waitForURL('**/order-confirmation-success-url', { timeout: 30000 }) combined with waitUntil: 'networkidle' or waitForLoadState('networkidle'). Then, verify a key element on the confirmation page using expect().toBeVisible().

  3. Scenario: "Your application has a complex form with conditional fields. When you select 'Option A' from a dropdown, 'Field X' becomes visible, and 'Field Y' becomes hidden. How would you automate filling out 'Field X' only after 'Option A' is selected and 'Field Y' is confirmed hidden?" * Expected Answer: await page.selectOption('#dropdown', 'Option A'); then await expect(page.locator('#fieldX')).toBeVisible(); and await expect(page.locator('#fieldY')).toBeHidden(); before filling fieldX. Playwright's auto-waiting with expect assertions would handle the dynamic visibility.

  4. Scenario: "You're getting intermittent failures on your CI pipeline, specifically when tests interact with a 'Save' button. The error message is often 'Element is not enabled'. What could be the cause, and how would you investigate and fix it?" * Expected Answer: Discuss auto-waiting not being enough if an element is disabled. Suggest locator.waitFor({ state: 'enabled' }) before the click. Debugging with Trace Viewer (npx playwright test --trace on), video recording, and console logs. Check for JavaScript errors preventing enablement.

  5. Scenario: "Your team wants to implement data-driven testing for user login with 100 different user credentials. How would you structure your Playwright tests and manage this test data effectively?" * Expected Answer: Use a JSON or CSV file for data. Employ test.each() from @playwright/test to iterate over the data. Briefly mention separating data from logic, and potential need for API-driven data setup if users need to be created dynamically.


This comprehensive list should provide a strong foundation for your blog post and help automation engineers confidently approach Playwright interviews!

0 comments:

Post a Comment

Popular Posts