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
cy.wait() does not resolve when the XHR contains static resource-like text in the XHR's query params or hash (like .js
, .html
, .css
)
#7280
Comments
Comparing the screenshots of commands when the test fails versus passes shows that the request for the Have you checked that this behavior actually works within the website (outside of Cypress) when query params are present? with query params without query params |
@jennifer-shehane, yes, when visiting the URL with query params, the request for ads is still an XHR request w/ |
@jennifer-shehane, is there anything that I can do to help for this? The problem occurs whenever there is a combination of a file extension in the url plus any query-string parameter, |
This fails regardless of the I didn't see any evidence of this being a regression.
it('test cy.route()', () => {
cy.on('uncaught:exception', () => {
return false;
});
cy.viewport(1500, 1024)
cy.server()
cy.route(/gampad\/ads\?/).as('waitForAd')
cy.visit('https://www.oregonlive.com/news/2019/12/vaping-related-lung-illness-epidemic-has-likely-peaked-feds-say.html'
, { qs: { answer: 42 }} // comment out this line to pass test
)
cy.wait('@waitForAd')
}) You can see that the request is made in both situations, just one does not get picked up by our |
@jennifer-shehane - yes, this also fails when a question mark, alone, is at the end of the visited URL with a file extension. |
We've identified why this is happening in your case. The presence of query params in the visited URL essentially changes some of the query params in the request made by the securepubads ad. Cypress inherently hides non XHR resources from the Command Log and from being recognized by // Actual REGEX we use to ignore static resources
/\.(jsx?|coffee|html|less|s?css|svg)(\?.*)?$/ The XHR request you wanted to listen to in your case contained some of the keywords we're looking to ignore in the query params of the request (only matching when the main URL contained query params) like below: I've opened a pull request to first remove anything from the query params and the hash before Cypress looks for resources to ignore. #7742 This fixes your issue. Reproducible exampleA better reproducible example of the original issue: it('test cy.route()', () => {
cy.server()
cy.route(/url-with-query-param/, { foo: 'bar' }).as('getQueryParam')
cy.visit('https://example.com')
cy.window().then((win) => {
const xhr = new win.XMLHttpRequest()
// our XHR has `.js` in it, which we normally ignore as XHR resource
xhr.open('GET', '/url-with-query-param?resource=foo.js')
xhr.send()
})
cy.wait('@getQueryParam')
}) |
.js
, .html
, .css
)
The code for this is done in cypress-io/cypress#7742, but has yet to be released. |
Thank you very much, @jennifer-shehane! |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
Current behavior:
Discovered this while trying to test for ad requests for my employer. When a URL with file extension, like .html, and a question mark (for a query string parameter) is visited, the request that is listened for is no longer detected. Remove the question mark, and the request is detected.
Desired behavior:
Before promoting a build in production, we test the build using a query-string parameter, so the wish is for this to work when a query-string parameter is present in the visited URL.
Test code to reproduce
Versions
Cypress Version: Cypress 4.2.0
OS: MacOS Catalina 10.15.2
Browser: Default Chrome browser that is built into Cypress
The text was updated successfully, but these errors were encountered: