Recall & Review
beginner
What is the purpose of asserting request properties in Cypress tests?
Asserting request properties helps verify that the network requests sent by the application have the correct method, URL, headers, and body. This ensures the app communicates properly with the backend.
Click to reveal answer
beginner
How do you intercept a network request in Cypress to assert its properties?
Use cy.intercept() to spy or stub a request. Then use cy.wait() with the alias to get the intercepted request and assert its properties like method, url, headers, or body.
Click to reveal answer
intermediate
Example: How to assert that a POST request has a JSON body with a specific field?
After intercepting and waiting for the request, use expect(request.body).to.have.property('fieldName', 'expectedValue') to check the JSON body contains the field with the right value.
Click to reveal answer
beginner
Why is it important to alias intercepted requests in Cypress?
Aliasing allows you to wait for specific requests and access their details easily. This helps in writing clear assertions about the request properties after the app triggers them.
Click to reveal answer
beginner
What Cypress command lets you check the HTTP method of an intercepted request?
You can check the method by accessing request.method inside cy.wait('@alias').then(({ request }) => { expect(request.method).to.equal('POST') })
Click to reveal answer
Which Cypress command is used to intercept network requests for assertion?
✗ Incorrect
cy.intercept() is used to spy on or stub network requests, enabling assertions on request properties.
How do you wait for an intercepted request to complete before asserting its properties?
✗ Incorrect
cy.wait('@alias') waits for the intercepted request with the given alias to complete.
What property would you check to verify the HTTP method of a request in Cypress?
✗ Incorrect
The HTTP method (GET, POST, etc.) is stored in request.method.
Which assertion checks that a request body contains a field named 'username' with value 'alice'?
✗ Incorrect
The body is an object; checking it has a property 'username' with value 'alice' is done with to.have.property.
Why should you alias intercepted requests in Cypress tests?
✗ Incorrect
Aliasing lets you wait for and access specific intercepted requests for assertions.
Explain how to intercept a POST request and assert that its JSON body contains a specific key-value pair in Cypress.
Think about spying on the request, waiting for it, then checking its body.
You got /5 concepts.
Describe why asserting request properties is important in end-to-end testing with Cypress.
Consider what could go wrong if requests are incorrect.
You got /4 concepts.