Practice Tests September 11, 2026 14 min read

Playwright Practice Test: 20 Free Questions with Answers (2026)

Test your Playwright knowledge with 20 multiple-choice questions covering locators, assertions, auto-waiting, fixtures, API testing, and CI/CD. Each question includes a detailed explanation — perfect for interview prep, certification study, or self-assessment.

📝

20 Free Practice Questions

Covers the 8 most-tested Playwright topics. Scroll down, answer each question, then check the explanation.

Whether you are preparing for an SDET interview, studying for a Playwright certification, or just want to test how well you actually know the framework, practice questions are the fastest way to find out. Active recall — forcing yourself to retrieve an answer before reading the explanation — has been shown to improve long-term retention by 2–3x compared to passively reviewing documentation.

The 20 questions below are organized by topic: locators, assertions, auto-waiting, fixtures & configuration, API testing, network interception, parallel execution, and CI/CD. Try answering each one before expanding the answer. At the end, tally your score to see where you stand.


Locators (Questions 1–4)

Question 1
What method does Playwright use to find elements by their ARIA role?
  1. page.locator('role=button')
  2. page.getByRole('button')
  3. page.findByRole('button')
  4. page.queryRole('button')
Answer: Bpage.getByRole() is Playwright's recommended locator strategy. It queries the accessibility tree rather than the DOM, making tests more resilient to markup changes. You can also pass a second argument for name filtering: page.getByRole('button', { name: 'Submit' }).
Question 2
Which locator should you use to find an element by its data-testid attribute?
  1. page.locator('[data-testid="login"]')
  2. page.getByTestId('login')
  3. page.findTestId('login')
  4. Both A and B work, but B is recommended
Answer: D — Both page.locator('[data-testid="login"]') and page.getByTestId('login') will locate the element. However, getByTestId() is the recommended approach because it is more readable and the attribute name can be configured globally via testIdAttribute in playwright.config.ts.
Question 3
What does page.getByLabel('Email') target?
  1. Any element with innerText "Email"
  2. A form control associated with a <label> whose text is "Email"
  3. An element with aria-label="Email"
  4. Both B and C
Answer: Dpage.getByLabel('Email') finds form controls associated with a <label> element (via for attribute or nesting) as well as elements with a matching aria-label or aria-labelledby attribute. This makes it ideal for targeting form inputs accessibly.
Question 4
Which chaining method filters a locator to only match elements that also contain specific text?
  1. locator.withText('Save')
  2. locator.filter({ hasText: 'Save' })
  3. locator.contains('Save')
  4. locator.filterByText('Save')
Answer: Blocator.filter({ hasText: 'Save' }) narrows a locator to only match elements whose text content includes "Save". You can also use { has: childLocator } to filter by the presence of a child element. This chaining pattern is fundamental to building robust, specific locators without relying on brittle CSS selectors.

Assertions (Questions 5–7)

Question 5
Which assertion verifies that an element's text content matches exactly?
  1. expect(locator).toHaveText('Hello World')
  2. expect(locator).toContainText('Hello World')
  3. expect(locator).textEquals('Hello World')
  4. expect(locator).toBe('Hello World')
Answer: Aexpect(locator).toHaveText('Hello World') asserts that the element's text content matches the expected string (whitespace is normalized). Use toContainText() when you only need a partial match. Both are auto-retrying assertions — they will keep checking until the timeout expires.
Question 6
What makes Playwright's expect() assertions different from standard Jest assertions?
  1. They support regular expressions
  2. They automatically retry until the condition is met or timeout
  3. They can only be used with locators
  4. They run synchronously without await
Answer: B — Playwright's web-first assertions automatically retry until the expected condition is met or the assertion timeout expires (default 5 seconds). This eliminates the need for manual waits and makes tests more reliable. You must await them because they return promises.
Question 7
How do you assert that the current page URL contains a specific path?
  1. expect(page.url()).toContain('/dashboard')
  2. await expect(page).toHaveURL(/dashboard/)
  3. await expect(page).urlContains('/dashboard')
  4. Both A and B work, but B is recommended
Answer: D — Both work, but await expect(page).toHaveURL(/dashboard/) is recommended because it is an auto-retrying assertion. Option A uses a snapshot of the URL at that instant and will not retry if the page is still navigating. Option B accepts both strings and regular expressions and will wait for the URL to match.

Auto-Waiting (Questions 8–10)

Question 8
Before performing a click() action, which checks does Playwright's auto-waiting mechanism perform?
  1. Waits for the element to be attached to the DOM only
  2. Waits for the element to be visible, stable, enabled, and not obscured
  3. Waits for all network requests to complete
  4. Waits for a fixed 500ms delay
Answer: B — Before clicking, Playwright's auto-waiting ensures the element is: (1) attached to the DOM, (2) visible, (3) stable (not animating), (4) able to receive events (not obscured by another element), and (5) enabled (not disabled). This is called the "actionability" check and is the reason Playwright tests rarely need explicit waits.
Question 9
Which method waits for an element to appear in the DOM without requiring it to be visible?
  1. locator.waitFor()
  2. locator.waitFor({ state: 'attached' })
  3. page.waitForSelector('.item', { state: 'attached' })
  4. Both B and C
Answer: D — Both locator.waitFor({ state: 'attached' }) and page.waitForSelector('.item', { state: 'attached' }) will wait for the element to be in the DOM regardless of visibility. The default state for waitFor() is 'visible', so you must explicitly pass 'attached' if you want to wait for DOM presence only.
Question 10
What happens when Playwright's fill() method targets a disabled input?
  1. It fills the value and ignores the disabled state
  2. It throws an error immediately
  3. It waits for the element to become enabled, then fills it
  4. It returns null without throwing
Answer: C — Like all Playwright actions, fill() performs actionability checks including waiting for the element to be enabled. If the input becomes enabled before the timeout, Playwright fills it. If the timeout expires while the element is still disabled, Playwright throws a TimeoutError. This is part of the auto-waiting mechanism that eliminates manual waitForEnabled patterns.
Practice Tests Course
Want 190+ More Questions Like These?

These 20 questions are just a preview. The full Playwright Automation Practice Tests course includes 190+ exam-style Q&A covering every topic tested in real interviews and certification exams.

  • 190+ real exam-style questions with detailed explanations
  • Covers commands, locators, auto-waiting, API testing, CI/CD
  • MCP AI Agents section — the newest interview topic for 2026
  • 5.0 rating from 131+ learners
Get the Full Practice Tests →

Fixtures & Configuration (Questions 11–13)

Question 11
What is the purpose of Playwright's test.extend() method?
  1. To add extra browsers to the test configuration
  2. To define custom fixtures that can be injected into tests
  3. To extend the default timeout for all tests
  4. To inherit tests from another test file
Answer: Btest.extend() lets you define custom fixtures that are automatically set up and torn down for each test. For example, you can create a todoPage fixture that initializes a Page Object Model class. Fixtures promote code reuse and ensure proper test isolation.
Question 12
In playwright.config.ts, what does the use property inside a project configure?
  1. Which test files to include in the project
  2. Browser-specific options like viewport, baseURL, and headless mode
  3. The number of parallel workers
  4. Test timeout and retry settings only
Answer: B — The use property inside a project configures context options such as viewport, baseURL, headless, screenshot, trace, locale, and permissions. These options are applied to every test in that project. Test file selection uses testDir and testMatch, while workers and retries use their own top-level properties.
Question 13
How do you run tests only from a specific project named "chromium"?
  1. npx playwright test --browser=chromium
  2. npx playwright test --project=chromium
  3. npx playwright test --only chromium
  4. npx playwright test chromium
Answer: Bnpx playwright test --project=chromium runs tests only for the project named "chromium" as defined in your playwright.config.ts. You can specify multiple projects by repeating the flag: --project=chromium --project=firefox. There is no --browser flag in the Playwright test runner.

API Testing (Questions 14–16)

Question 14
Which object does Playwright provide for making API requests without a browser context?
  1. page.request
  2. playwright.request.newContext()
  3. new APIRequest()
  4. browser.fetchAPI()
Answer: Bplaywright.request.newContext() creates a standalone API request context that operates without a browser. This is ideal for API-only tests, setting up test data, or verifying backend state. You can also use the request fixture in tests, which provides a pre-configured API context that shares cookies with the browser context.
Question 15
How do you send a POST request with a JSON body using Playwright's API testing?
  1. request.post(url, { body: JSON.stringify(data) })
  2. request.post(url, { data: { name: 'test' } })
  3. request.fetch(url, { method: 'POST', json: data })
  4. request.sendJSON(url, data)
Answer: Brequest.post(url, { data: { name: 'test' } }) automatically serializes the object to JSON and sets the Content-Type: application/json header. The data property accepts objects (auto-serialized to JSON), strings, or Buffers. There is no sendJSON method.
Question 16
When using page.request in a browser test, what is automatically shared with the browser context?
  1. Nothing — it is completely isolated
  2. Cookies and authentication state
  3. Local storage and session storage
  4. Only the base URL
Answer: B — When you use page.request (or the context-bound context.request), cookies are automatically shared with the browser context. This means if you log in via the UI, subsequent API calls through page.request will include the authentication cookies. Local storage and session storage are not shared.

Network Interception (Questions 17–18)

Question 17
Which method intercepts and modifies network requests in Playwright?
  1. page.on('request', handler)
  2. page.route(urlPattern, handler)
  3. page.intercept(urlPattern, handler)
  4. page.mock(urlPattern, response)
Answer: Bpage.route(urlPattern, handler) intercepts requests matching the URL pattern and lets you fulfill, abort, or modify them. Inside the handler, you can call route.fulfill() to return a mock response, route.abort() to block the request, or route.continue() to let it proceed (optionally with modified headers). page.on('request') is for passive listening only.
Question 18
How do you mock an API endpoint to return a custom JSON response?
  1. page.route('**/api/users', route => route.fulfill({ status: 200, json: [{ id: 1 }] }))
  2. page.route('**/api/users', route => route.fulfill({ status: 200, body: JSON.stringify([{ id: 1 }]), contentType: 'application/json' }))
  3. Both A and B work
  4. Neither — you need a separate mock server
Answer: C — Both approaches work. Option A uses the json shorthand (available in Playwright 1.29+), which automatically stringifies the object and sets the content type. Option B is the explicit approach using body with contentType. The json shorthand is more concise and is the recommended pattern in modern Playwright.

Parallel Execution & CI/CD (Questions 19–20)

Question 19
How does Playwright achieve test isolation when running tests in parallel?
  1. Each test runs in a separate browser process
  2. Each test gets a fresh BrowserContext (isolated cookies, storage, and session)
  3. Tests share a single page but clear state between runs
  4. Playwright locks shared resources with mutexes
Answer: B — Each Playwright test receives a fresh BrowserContext, which provides complete isolation: separate cookies, local storage, session storage, and cache. This is lighter than creating a new browser process for each test but still ensures zero state leakage. Multiple contexts can run in the same browser instance, which is why Playwright's parallel execution is fast.
Question 20
In a GitHub Actions CI pipeline, what is the recommended way to install Playwright browsers?
  1. npx playwright install
  2. npx playwright install --with-deps
  3. apt-get install chromium-browser
  4. Download browsers manually and set PLAYWRIGHT_BROWSERS_PATH
Answer: Bnpx playwright install --with-deps installs both the Playwright browsers and their OS-level dependencies (like libgbm, libnss3, etc.). The --with-deps flag is critical in CI environments where system libraries may not be pre-installed. Without it, browser launch will fail with cryptic dependency errors.

Score Yourself

Tally your correct answers and check where you stand:

  • 18–20 correct: Expert level. You know Playwright inside and out — you are interview-ready.
  • 14–17 correct: Strong foundation. Review the topics you missed and you will be fully prepared.
  • 10–13 correct: Solid basics, but gaps remain. Focus on auto-waiting, fixtures, and API testing.
  • Below 10: Time to study. Start with the Playwright Locators Guide and work through the fundamentals.

No matter your score, the best way to improve is to keep testing yourself. Active recall through practice questions builds the kind of instant-recall knowledge that interviewers and certification exams demand.

Practice Tests Course
Ready for the Full 190+ Question Bank?

These 20 questions gave you a taste. The complete Playwright Automation Practice Tests 2026 course by Asim Noaman includes 190+ exam-style questions with detailed explanations — covering every topic that appears in real Playwright interviews and certification assessments.

  • 190+ real exam-style questions with detailed explanations
  • Covers commands, locators, auto-waiting, API testing, CI/CD
  • MCP AI Agents section — the newest interview topic for 2026
  • 5.0 rating from 131+ learners
  • Lifetime access — new questions added regularly
Get the Full Practice Tests →

Frequently Asked Questions

Are Playwright practice tests worth it for interview preparation?

Yes. Practice tests are one of the most effective ways to prepare for SDET and QA automation interviews. They force you to recall specific API methods, understand auto-waiting behavior, and think through edge cases — exactly what interviewers test. Studies show that active recall via practice questions improves retention 2–3x compared to passive reading.

How many questions are in the Playwright certification exam?

There is no single official Playwright certification exam from Microsoft. However, community-recognized practice test courses like the Playwright Automation Practice Tests 2026 course include 190+ questions covering all major topics: locators, assertions, auto-waiting, API testing, CI/CD, fixtures, and MCP AI Agents. Most employers value demonstrated skills over a certificate.

What is the best way to prepare for a Playwright interview?

The best preparation combines three activities: (1) hands-on practice writing real Playwright tests, (2) studying the official Playwright documentation for API details, and (3) testing yourself with MCQ-style practice questions to identify knowledge gaps. Focus on locators (getByRole, getByTestId), auto-waiting, fixtures, API testing, and CI/CD integration.

What Playwright topics are most commonly tested in quizzes?

The most frequently tested topics are: locator strategies (getByRole, getByLabel, getByTestId, locator), auto-waiting mechanism, assertions (toBeVisible, toHaveText, toHaveURL), fixtures and test isolation, Page Object Model pattern, API testing with request context, network interception, parallel execution, and CI/CD with GitHub Actions.

Can I use these practice questions for certification prep?

Absolutely. These 20 free questions cover the core topics that appear in Playwright certification-style assessments. For comprehensive preparation, the full Playwright Automation Practice Tests 2026 course offers 190+ questions with detailed explanations covering every major topic including the newest MCP AI Agents section.

Asim Noaman
Asim Noaman
Senior QA Automation Engineer & AI Testing Specialist