0
0
Cypresstesting~5 mins

cy.intercept() for request interception in Cypress - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of cy.intercept() in Cypress?

cy.intercept() is used to catch and control HTTP requests made by the application during testing. It helps to spy on, modify, or stub network calls.

Click to reveal answer
beginner
How do you stub a GET request to /api/users with cy.intercept()?

You use cy.intercept('GET', '/api/users', { fixture: 'users.json' }) to replace the real response with a fixture file.

Click to reveal answer
beginner
What does it mean to 'spy' on a request using cy.intercept()?

Spying means watching the request and response without changing them. You can check if the request was made and inspect its details.

Click to reveal answer
intermediate
How can you wait for an intercepted request to complete before continuing a test?

Use cy.wait() with an alias set by cy.intercept(). For example, cy.intercept('GET', '/api/data').as('getData') then cy.wait('@getData').

Click to reveal answer
beginner
Why is intercepting requests useful in testing web applications?

It helps make tests faster, more reliable, and independent of backend changes by controlling network responses and simulating different scenarios.

Click to reveal answer
What does cy.intercept() primarily do in Cypress?
AIntercept CSS styles
BIntercept user clicks
CIntercept and control HTTP requests
DIntercept console logs
How do you alias an intercepted request for later use?
AUsing <code>.as('aliasName')</code>
BUsing <code>.wait('aliasName')</code>
CUsing <code>.get('aliasName')</code>
DUsing <code>.click('aliasName')</code>
Which HTTP method can cy.intercept() handle?
AAll HTTP methods
BOnly POST
COnly GET
DOnly PUT and DELETE
What is a common use of stubbing with cy.intercept()?
ATo block user input
BTo replace real server responses with fake data
CTo speed up CSS rendering
DTo change browser settings
What happens if you do not wait for an intercepted request before asserting results?
ATest will always pass
BTest will reload the page
CTest will skip the request
DTest might fail because the request is not finished
Explain how to use cy.intercept() to stub a POST request and why this is useful.
Think about controlling server responses to test different scenarios.
You got /3 concepts.
    Describe the difference between spying and stubbing with cy.intercept().
    One watches requests, the other changes responses.
    You got /3 concepts.