https://cypress.io logo
How to use Cypress.intercept() for 2 requests to s...
# i-need-help
w
In my project, there are 2 calls made to the same end point on the page load with different data in body. How can I intercept both the calls separately? First call is made to check the 'Draft' status and another is made to check the 'Submitted" status
g
you might benefit from my paid course https://cypress.tips/courses/network-testing
c
You can setup a route matcher that inspects the request body and conditionally aliases the request. Check out the docs regarding graphql
w
Hi, I have just purchased your course, can you point me to the exact lesson, I am getting 2 intercepted requests as shown in the diagram and I am interested in accessing the response from the second response. The current log is displaying the response from first response

https://cdn.discordapp.com/attachments/1099299956419989566/1099614048892485683/image.png

g
Super. I am not completely sure what you mean. But start with https://cypress.tips/courses/network-testing/lessons/bonus18 and https://cypress.tips/courses/network-testing/lessons/bonus19 and let me know if they don't answer your question. In general, every time you do
cy.wait('@audits')
it uses 1 network call. So if you always want the second one, you do
cy.wait('@audits').wait('@audits')
f
@wide-eye-45012 I'm having the same issue
I'm trying to modify the real response differently in each call. The tests pass when run alone (.only) but when run in the spec they fail because 'response' is undefined
2 Views