-
Notifications
You must be signed in to change notification settings - Fork 3.3k
cy.intercept by request cause #14525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Related work: #14843 We will need to collect this kind of data for 14843. We will probably use CDP/foxdriver to do this, not WebExtensions, since WebExtensions do not work in headless Chrome. They also do not work completely in Electron. |
Btw -
Give Cypress 7.0 a try, we've fixed a lot of confusion around URL matching in 7: https://docs.cypress.io/guides/references/migration-guide#cy-intercept-changes |
@flotwig Will give 7.0 a go (perhaps next week?), thank you! Things do look a lot clearer (really love how you now can override a particular request by redefining a handler for it!) but I can't really see how this could help in this particular case. Could you elaborate, please? :-) |
Oh, never mind, I misunderstood why you needed to use |
This will be added in #25075, see PR for API details. |
The code for this is done in cypress-io/cypress#25075, but has yet to be released. |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
What would you like?
Allow matching routes by its cause (e. g.
image
orxmlhttprequest
):Why is this needed?
My current application uses same URLs on API and UI side (e. g.
https://127.0.0.1:3000/orders
on the frontend querieshttps://127.0.0.1:4000/orders
on the backend). I need to stub the API call, then open the page on the frontend as usual.cy.route
was handling only API requests, so simplecy.route("/orders")
would work alright independent of the environment – if the backend was on a different hostname (e. g. CI could use a staging instance instead of localhost),cy.route
would still match it. Withcy.intercept
, the only way to match API calls right now is to add a hostname, e. g.:This looks acceptable but it's another configuration variable to keep up to date, and can be avoided. :-)
Implementation suggestion
If I get this correctly, this can't be implemented using just the current setup with running a proxy server. However, we could use the extension running in the browser to match the routes we need using the
webRequest.onBeforeRequest
(Mozdev, Chrome docs) API. If we can't move all intercepting business to the extension (why?), we could use it to add an HTTP header to all requests (X-Cypress-Cause: xmlhttprequest
) and match that on the proxy side as usual.P. S. Thank you all for your great work!
The text was updated successfully, but these errors were encountered: