Intermediate Cypress test (Intermediate)
30 questions · 35 minutes · Free
cy.intercept, fixtures, custom commands and component testing.
Take the Intermediate Cypress test
What it covers
- cy.intercept and network stubbing
- Cypress fixtures and test data
- Cypress custom commands
- Cypress component testing
- Cypress authentication strategies
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 Cypress 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 Cypress test, with the answers. Samples are taken out of the live test, so you will not meet these when you sit it.
Which of the following statements accurately describes how Cypress component testing operates?
- Cypress component testing cannot be used with frameworks like React or Vue.
- Cypress component testing runs in a real browser but does not require a full app page to be loaded.
- Cypress component testing requires a full app page to be loaded for accurate rendering.
- Cypress component testing is identical to end-to-end testing in functionality.
Answer: B. Cypress component testing runs in a real browser but does not require a full app page to be loaded.
Cypress component testing allows developers to test individual components in a real browser environment, which provides a more accurate rendering context compared to unit testing. However, it does not require the full application page to be loaded, unlike end-to-end testing. This makes component testing faster and more focused on the specific component under test.
What is a common best practice when creating a custom command for API calls in Cypress?
- Avoid using a timeout in the custom command to speed up tests.
- Use a custom command that relies on cy.intercept for all API requests.
- Use a custom command that wraps cy.request and includes a default timeout of 10 seconds.
- Use cy.visit to make API calls and handle responses with cy.get.
Answer: C. Use a custom command that wraps cy.request and includes a default timeout of 10 seconds.
A common mistake when creating a custom command for API calls is not setting an appropriate timeout. Using a default timeout of 10 seconds ensures that the command is more robust and avoids flaky tests due to slow network responses. Other options, like using cy.visit or not handling errors, are not suitable for API calls and do not align with best practices.
You are trying to stub a GET request to '/api/users' using cy.intercept, but the intercept is not working. What is the most likely reason for this issue?
- The response object was not correctly formatted in the intercept.
- The URL pattern in the intercept did not match the request URL.
- The alias was not used correctly in the wait command.
- The intercept was defined after the request was made, so it was not applied.
Answer: D. The intercept was defined after the request was made, so it was not applied.
In Cypress, intercepts must be defined before the request is made. If the intercept is defined after the request, it will not be applied, and the request will not be stubbed or spied on as intended. This is a common mistake when using cy.intercept.
Which approach is better for waiting for a specific network request and asserting on its response when using cy.intercept, and why?
- Using cy.fixture('data.json') to load static data, because it is more efficient for stubbing network requests.
- Using cy.intercept with .as('alias') and cy.wait('@alias') to wait for and assert on the response, because it allows precise control over the request and response, and ensures the test waits for the specific network call to complete.
- Using cy.wait(3000) to wait for the request to complete, because it is simpler and faster to implement.
- Using cy.intercept with a handler function but not aliasing it, because it is unnecessary to wait for the request explicitly.
Answer: B. Using cy.intercept with .as('alias') and cy.wait('@alias') to wait for and assert on the response, because it allows precise control over the request and response, and ensures the test waits for the specific network call to complete.
Using cy.intercept with .as('alias') and cy.wait('@alias') is the correct approach because it allows the test to wait for a specific network call and assert on its response. This is more precise and reliable than using cy.wait(3000) or other alternatives, which are less accurate and can lead to flaky tests.
When deciding between using cy.intercept and cy.request for handling DELETE requests, what is the correct approach?
- Use cy.intercept for stubbing DELETE requests and for making actual DELETE requests to the server because it is more flexible and powerful than cy.request.
- Use cy.intercept for making actual DELETE requests to the server because it allows precise control over the request and response, while using cy.request for stubbing DELETE requests.
- Use cy.request for stubbing DELETE requests and for making actual DELETE requests to the server because it is more flexible and powerful than cy.intercept.
- Use cy.intercept for stubbing DELETE requests because it allows precise control over the request and response, while using cy.request for making actual DELETE requests to the server.
Answer: D. Use cy.intercept for stubbing DELETE requests because it allows precise control over the request and response, while using cy.request for making actual DELETE requests to the server.
cy.intercept is used to stub network requests, including DELETE requests, by defining a handler that returns a static response. This allows you to simulate the behavior of a DELETE request without actually hitting the server. On the other hand, cy.request is used to make actual HTTP requests to the server, which is useful for testing real API behavior. When you need to test the application's behavior in response to a DELETE request without affecting the server, cy.intercept is the appropriate choice. However, if you need to test the actual DELETE request and its impact on the server, cy.request is the right tool.
Frequently asked questions
- How many questions are in the Intermediate Cypress test?
- 30 questions (18 multiple choice, 9 multi-answer, 3 predict-the-output), with 35 minutes to answer them.
- What does the Intermediate Cypress test cover?
- cy.intercept and network stubbing, Cypress fixtures and test data, Cypress custom commands, Cypress component testing, Cypress authentication strategies.
- Is the Intermediate Cypress test free?
- Yes. It is free to take with a readyforhires account.
- What level is the Intermediate Cypress test?
- Intermediate, in Testing & QA.