Playwright & Cypress interview questions

25 questions from the Playwright & Cypress course, each with the correct answer and an explanation. Try to answer before you open the answer.

End-to-End Testing Foundations

1. Which is the best use of an E2E test?

  1. Checking that a CSS class name is spelled correctly
  2. Checking every branch of a tax calculation function
  3. Checking that a user can complete checkout from cart to confirmation
  4. Checking the return type of a helper function
Show answer

Answer: Checking that a user can complete checkout from cart to confirmation

E2E tests are expensive, so spend them on critical journeys.

Lesson: What End-to-End Tests Are For

2. Where does Cypress execute your test code?

  1. Inside the browser, alongside the application under test
  2. Only in a separate Node.js process over a remote protocol
  3. On a cloud service that must be paid for
  4. Inside the web server that hosts the app
Show answer

Answer: Inside the browser, alongside the application under test

This in-browser design is the main architectural difference from Playwright.

Lesson: Playwright Versus Cypress Architecture

3. What does setting baseURL (Playwright) or baseUrl (Cypress) allow?

  1. Automatically generating tests
  2. Running tests without a browser
  3. Skipping the need for a running app
  4. Visiting relative paths such as "/" or "/login" in tests
Show answer

Answer: Visiting relative paths such as "/" or "/login" in tests

One place to point the whole suite at an environment.

Lesson: Setting Up Both Tools

Playwright Basics

4. Why does each Playwright test get a new browser context?

  1. To download a new browser each time
  2. To isolate cookies and storage so tests do not affect each other
  3. To share login state automatically between tests
  4. To make tests run in a fixed order
Show answer

Answer: To isolate cookies and storage so tests do not affect each other

Isolation is the default.

Lesson: Tests and Fixtures

5. What does Playwright do before clicking a locator?

  1. Clicks immediately and fails if the element is missing
  2. Waits for the element to be visible, stable, enabled and able to receive events
  3. Sleeps for a fixed one second
  4. Reloads the page
Show answer

Answer: Waits for the element to be visible, stable, enabled and able to receive events

Actionability checks remove most manual waits.

Lesson: Locators and Auto-Waiting

6. Why is `await expect(locator).toHaveText('Saved')` better than comparing textContent() once?

  1. It ignores letter case automatically
  2. It runs faster because it never waits
  3. It works without a page
  4. It retries until the text matches or the timeout expires
Show answer

Answer: It retries until the text matches or the timeout expires

Web-first assertions absorb timing differences.

Lesson: Web-First Assertions

Playwright in Depth

7. What does a setup project with dependencies achieve?

  1. Runs the login once and lets other projects start already authenticated
  2. Runs every test twice
  3. Disables browser isolation completely
  4. Stores passwords in the HTML report
Show answer

Answer: Runs the login once and lets other projects start already authenticated

Saved storageState is loaded into each new context.

Lesson: Authentication with storageState

8. Which call returns a fake response from a route handler?

  1. route.abort()
  2. route.continue()
  3. route.fulfill()
  4. page.goto()
Show answer

Answer: route.fulfill()

continue passes through; abort fails the request.

Lesson: Network Mocking with page.route

9. In a Playwright fixture, what happens after `await use(value)` returns?

  1. The browser is reinstalled
  2. The test has not started yet
  3. The test has finished, so teardown code can run
  4. The fixture is shared with every other worker
Show answer

Answer: The test has finished, so teardown code can run

Code before use is setup; code after is teardown.

Lesson: Page Objects and Custom Fixtures

Cypress Basics

10. Why can you not write `const el = await cy.get('button')`?

  1. Cypress commands are enqueued and are not promises
  2. cy.get only works in component tests
  3. TypeScript forbids await in tests
  4. cy.get returns a plain string
Show answer

Answer: Cypress commands are enqueued and are not promises

Use .then() or aliases to work with yielded values.

Lesson: Commands and Chaining

11. Which part of `cy.get('li').should('have.length', 3)` is retried?

  1. Only the click that follows
  2. Neither; it runs exactly once
  3. Only the assertion, against the first result
  4. Both the cy.get query and the length assertion, until it passes or times out
Show answer

Answer: Both the cy.get query and the length assertion, until it passes or times out

Queries and their assertions retry together.

Lesson: Retry-Ability and Assertions

12. What does `cy.wait('@getTodos')` do?

  1. Pauses for a fixed number of milliseconds
  2. Waits until the aliased intercepted request has happened
  3. Reloads the page until todos appear
  4. Creates a new fixture file
Show answer

Answer: Waits until the aliased intercepted request has happened

Alias-based waits are deterministic.

Lesson: Stubbing and Waiting with cy.intercept

Cypress in Depth

13. What does cy.session do on the second call with the same id?

  1. Always runs the login form again
  2. Restores the cached cookies and storage instead of running setup again
  3. Deletes all cookies permanently
  4. Skips the test
Show answer

Answer: Restores the cached cookies and storage instead of running setup again

Setup runs once per id; later calls restore and optionally validate.

Lesson: Custom Commands and cy.session

14. What does Cypress component testing render?

  1. A text description of the component
  2. The full deployed application
  3. A server-side HTML snapshot only
  4. A single mounted component in a real browser via the project's dev server
Show answer

Answer: A single mounted component in a real browser via the project's dev server

Faster and more focused than full E2E flows.

Lesson: Component Testing

15. Where does code registered with on('task', ...) run?

  1. In the Node.js process, so it can reach databases and the file system
  2. Inside the application under test
  3. In the browser console only
  4. On the Cypress Cloud servers
Show answer

Answer: In the Node.js process, so it can reach databases and the file system

cy.task bridges from the browser to Node.

Lesson: Fixtures and Test Data

Writing Reliable Tests

16. Which change most directly reduces flakiness?

  1. Selecting elements by nth-child CSS
  2. Increasing every sleep to ten seconds
  3. Replacing fixed sleeps with retrying assertions on the expected state
  4. Making tests depend on the previous test's data
Show answer

Answer: Replacing fixed sleeps with retrying assertions on the expected state

Wait for conditions, not durations.

Lesson: Avoiding Flaky Tests

17. Why add the worker index or a timestamp to created data names?

  1. Because the API rejects short names
  2. To make the HTML report sort alphabetically
  3. So tests running in parallel do not collide on the same records
  4. To slow tests down deliberately
Show answer

Answer: So tests running in parallel do not collide on the same records

Unique data enables parallel, order-independent tests.

Lesson: Test Data and Resetting State

18. What does `trace: 'on-first-retry'` do in Playwright?

  1. Records a trace when a failed test is retried, for later inspection
  2. Records traces for every passing test
  3. Retries tests forever
  4. Disables screenshots
Show answer

Answer: Records a trace when a failed test is retried, for later inspection

Traces cost time, so record them when they help.

Lesson: Debugging Failures

Beyond Functional Tests

19. Why should visual baselines be generated in the same environment as CI?

  1. Screenshots only work on Linux
  2. Baselines are encrypted per machine
  3. CI cannot read PNG files
  4. Font rendering and anti-aliasing differ across operating systems and browsers
Show answer

Answer: Font rendering and anti-aliasing differ across operating systems and browsers

Same environment, comparable pixels.

Lesson: Visual Comparisons

20. What is a limitation of automated accessibility scans?

  1. They only work in Firefox
  2. They catch only a portion of issues; manual keyboard and screen-reader testing is still needed
  3. They require a paid licence
  4. They cannot run inside E2E tests
Show answer

Answer: They catch only a portion of issues; manual keyboard and screen-reader testing is still needed

Automate what you can, test the rest by hand.

Lesson: Accessibility Checks

21. By default, what does cy.request do when the response status is 500?

  1. Retries forever
  2. Fails the test, unless failOnStatusCode is set to false
  3. Ignores the status silently
  4. Converts it to a 200
Show answer

Answer: Fails the test, unless failOnStatusCode is set to false

Turn the check off when testing error responses deliberately.

Lesson: API Testing

CI and Scale

22. Why enable retries only in CI?

  1. CI cannot run a test only once
  2. Retries make tests run faster locally
  3. Local runs do not support assertions
  4. Locally you want to see failures immediately; in CI retries reduce noise while flaky tests are reported
Show answer

Answer: Locally you want to see failures immediately; in CI retries reduce noise while flaky tests are reported

Retries are a safety net, not a fix.

Lesson: Running in CI

23. What does `npx playwright test --shard=2/4` do?

  1. Runs the second of four roughly equal portions of the suite
  2. Runs every test four times
  3. Uses two workers for four browsers
  4. Skips half of the tests permanently
Show answer

Answer: Runs the second of four roughly equal portions of the suite

Combine shards with a CI matrix and merged reports.

Lesson: Parallelism and Sharding

24. Which requirement points most clearly towards Playwright?

  1. Writing tests with Mocha-style describe and it
  2. Wanting a test runner that lives inside the browser
  3. Testing WebKit, Firefox and Chromium with several tabs in one test
  4. Needing assertions on DOM elements
Show answer

Answer: Testing WebKit, Firefox and Chromium with several tabs in one test

Both tools assert on the DOM; architecture drives the other differences.

Lesson: Choosing a Tool and Migrating

25. Which belongs on an E2E checklist?

  1. Fixed sleeps after every click
  2. Tests share one account and must run in sequence
  3. Each test creates its own data and can run in any order
  4. Selectors based on nth-child and styling classes
Show answer

Answer: Each test creates its own data and can run in any order

Isolation and stable selectors keep suites reliable.

Lesson: An E2E Testing Checklist

← Back to the course