Intermediate Playwright test (Intermediate)
30 questions · 35 minutes · Free
Fixtures, network mocking, saved login state, the trace viewer and page objects.
Take the Intermediate Playwright test
What it covers
- Playwright fixtures
- Playwright network interception and mocking
- Playwright authentication state
- Playwright trace viewer
- Page objects in Playwright
Interview format
- Questions: 30 questions — 18 multiple choice, 9 multi-answer, 3 predict-the-output
- Time: 35 minutes, timed from the first question
- Difficulty: Intermediate
- Skill area: Testing & QA
- Price: Free
Earn a certificate
The Intermediate Playwright test is one of the 8 tests of the QA Automation Engineer learning path. Pass it and the other 7 tests at 70% or more and readyforhires issues you a verifiable certificate in your name, with its own code and verify link to share or add to LinkedIn.
Sample questions
5 sample questions from the Intermediate Playwright test, with the answers. Samples are taken out of the live test, so you will not meet these when you sit it.
In the following code snippet from a Playwright fixture, where does the test execution occur? `await use(p); // test runs here`
- Teardown code
- The test runs here
- Setup code
- Fixture registration
Answer: B. The test runs here
In Playwright fixtures, the code between `await use(value)` is where the test runs. This is the main execution block for the test, and it is the only part that is executed during the test. The code before `await use(value)` is setup, and the code after is teardown.
When comparing the Trace Viewer with Lighthouse for performance analysis, which statement is correct?
- The Trace Viewer provides detailed performance insights like network timing, DOM snapshots, and action sequences, making it ideal for debugging and analyzing test failures; for general performance profiling, tools like Lighthouse are more suitable.
- The Trace Viewer is the best tool for general performance profiling because it records all network and timing data during test execution.
- The Trace Viewer is only useful for capturing console logs and does not provide any performance insights.
- The Trace Viewer and Lighthouse serve the same purpose and can be used interchangeably for performance profiling.
Answer: A. The Trace Viewer provides detailed performance insights like network timing, DOM snapshots, and action sequences, making it ideal for debugging and analyzing test failures; for general performance profiling, tools like Lighthouse are more suitable.
The Playwright Trace Viewer is primarily a debugging tool that captures detailed execution traces, including network timings, DOM snapshots, and action sequences, which are useful for analyzing test failures and understanding test flow. For general performance profiling, tools like Lighthouse are more appropriate because they focus on performance metrics like load time, rendering, and accessibility. The Trace Viewer is not designed for comprehensive performance analysis but for debugging and understanding test behavior.
Which method is used to create a custom fixture in Playwright with setup and teardown logic?
- Use the `page.route` method to create a custom fixture and define setup and teardown logic.
- Use the `context.route` method to create a custom fixture and define setup and teardown logic.
- Use the `browser.newContext` method to create a custom fixture and define setup and teardown logic.
- Use the `test.extend` method to create a custom fixture and define setup and teardown logic.
Answer: D. Use the `test.extend` method to create a custom fixture and define setup and teardown logic.
Custom fixtures in Playwright are created using the `test.extend` method, which allows you to define setup and teardown logic by using the `use` parameter. This ensures that each test gets a fresh fixture instance unless the scope is explicitly set to `worker`. Other options either incorrectly describe the fixture creation method or refer to unrelated concepts.
Which of the following is the correct method to mock an HTTP response in Playwright by returning a predefined JSON object?
- Use `route.fetch()` to mock the response by fetching the actual response and then modifying it.
- Use `route.fulfill()` to mock the response and return a predefined JSON object.
- Use `route.abort()` to mock the response by aborting the request entirely.
- Use `route.continue()` to forward the request to the actual server and mock the response.
Answer: B. Use `route.fulfill()` to mock the response and return a predefined JSON object.
When mocking HTTP responses in Playwright, the correct approach is to use `route.fulfill()` to define the response that should be returned for a specific request. This allows you to provide a predefined JSON object or any other response data, which is useful for testing scenarios without relying on actual backend services. Other options such as using `route.continue()` or `route.abort()` do not mock the response and allow the original request to proceed, which is not suitable for mocking scenarios.
How should you implement authentication with an API key in a Playwright test suite?
- Use a custom fixture to store the API key in the context and reuse it across tests.
- Use the request fixture to send an API key in the headers of the request.
- Use the page object model to inject the API key into the page's URL as a query parameter.
- Use the storageState feature to persist the API key in the browser context.
Answer: B. Use the request fixture to send an API key in the headers of the request.
When using API keys for authentication, the recommended approach is to use the request fixture provided by Playwright. This allows you to send the API key directly in the headers of the request, which is secure and efficient. Other approaches like using page objects or fixtures for authentication are not suitable for API key authentication, as they are typically used for scenarios like login flows or session management.
Frequently asked questions
- How many questions are in the Intermediate Playwright test?
- 30 questions (18 multiple choice, 9 multi-answer, 3 predict-the-output), with 35 minutes to answer them.
- What does the Intermediate Playwright test cover?
- Playwright fixtures, Playwright network interception and mocking, Playwright authentication state, Playwright trace viewer, Page objects in Playwright.
- Is the Intermediate Playwright test free?
- Yes. It is free to take with a readyforhires account.
- What level is the Intermediate Playwright test?
- Intermediate, in Testing & QA.