Cypress: cy.request() fails in 3.5.0

Created on 24 Oct 2019  路  17Comments  路  Source: cypress-io/cypress

Current behavior:

A simple cy.request() test failed after upgrading to 3.5.0.
The URL has two 302 redirects.

https://XXX/backoffice (302)-> https://XXX/backoffice/ (302)-> https://XXX/backoffice/login.zul (200)

          cy.request({
            url: link,
            retryOnStatusCodeFailure: true,
            retryOnNetworkFailure: true,
          });

Cypress Error:

CypressError: cy.request() failed trying to load:

https://XXX/backoffice

We attempted to make an http request to this URL but the request failed without a response.

We received this error at the network level:

  > true

-----------------------------------------------------------

The request we sent was:

Method: GET
URL: https://XXX/backoffice

-----------------------------------------------------------

Common situations why this would fail:
  - you don't have internet access
  - you forgot to run / boot your web server
  - your web server isn't accessible
  - you have weird network configuration settings on your computer

The stack trace for this error is:

Error: true
    at maybeWrapAsError (C:\Users\mriehema\AppData\Local\Cypress\Cache\3.5.0\Cypress\resources\app\packages\server\node_modules\bluebird\js\release\util.js:61:12)
    at C:\Users\mriehema\AppData\Local\Cypress\Cache\3.5.0\Cypress\resources\app\packages\server\node_modules\bluebird\js\release\nodeback.js:38:50
    at Chrome._handleMessage (C:\Users\mriehema\AppData\Local\Cypress\Cache\3.5.0\Cypress\resources\app\packages\server\node_modules\chrome-remote-interface\lib\chrome.js:256:17)
    at WebSocket.<anonymous> (C:\Users\mriehema\AppData\Local\Cypress\Cache\3.5.0\Cypress\resources\app\packages\server\node_modules\chrome-remote-interface\lib\chrome.js:234:22)
    at WebSocket.emit (events.js:194:13)
    at Receiver.receiverOnMessage (C:\Users\mriehema\AppData\Local\Cypress\Cache\3.5.0\Cypress\resources\app\packages\server\node_modules\ws\lib\websocket.js:789:20)
    at Receiver.emit (events.js:194:13)
    at Receiver.dataMessage (C:\Users\mriehema\AppData\Local\Cypress\Cache\3.5.0\Cypress\resources\app\packages\server\node_modules\ws\lib\receiver.js:422:14)
    at C:\Users\mriehema\AppData\Local\Cypress\Cache\3.5.0\Cypress\resources\app\packages\server\node_modules\ws\lib\receiver.js:379:23
    at C:\Users\mriehema\AppData\Local\Cypress\Cache\3.5.0\Cypress\resources\app\packages\server\node_modules\ws\lib\permessage-deflate.js:298:9
    at C:\Users\mriehema\AppData\Local\Cypress\Cache\3.5.0\Cypress\resources\app\packages\server\node_modules\ws\lib\permessage-deflate.js:376:7
    at afterWrite (_stream_writable.js:485:3)
    at onwrite (_stream_writable.js:476:7)
    at InflateRaw.afterTransform (_stream_transform.js:94:3)
    at Zlib.processCallback (zlib.js:560:8)

Desired behavior:

The same tests works in Cypress 3.4.1.
Calling the URL https://XXX/backoffice manually works too (200 after two 302).

Versions

Cypress 3.5.0 with Chrome
Windows 10 and macOS

All 17 comments

Thanks for opening the issue @pitgrap. I know this is likely difficult since this is just failing on your proprietary url, but we'll have to get a working example of the failure on our end. Which will mean. replicating 2 302 redirects or hitting a public url that redirects twice using 302.

We will recreate this, but it will take time, so any clear way to reproduce providing test code will help save some time and also likely isolate the problem further.

When I do a cy.request() to a url that does 2 301 redirects, it doesn't even seem to reflect that it does the 301 redirects - it just responds with status code of 200. I can't yet confirm that the 302 redirects are the source of the problem, which is another reason why we'd like an isolated example.

it('reroutes 301', () => {
  cy.request({
    url: 'http://amazon.com',
    retryOnStatusCodeFailure: true,
  })
})

Thank you for your investigation so far. I know it's not easy to investigate without a way to reproduce it. The URLs we're testing are all internal links. :(

The whole test looks like

  it("check if links are available with valid response code", function() {
    cy.visit("/");
    cy.get("a").each($element => {
      cy.clearCookies();
      cy.wrap($element)
        .should("have.attr", "href")
        .then(link => {
          cy.request({
            url: link,
            retryOnStatusCodeFailure: true,
            retryOnNetworkFailure: true
          });
        });
    });
  });

And this works fine with 3.4.1. After upgrading to 3.5.0 one link fails with the weird error message above. And one difference between this link and the others I could find so far is the double redirection.
Sadly the error message We received this error at the network level: > true did not help. :(

I'm having a similar issue with the new cypress 3.5.0.

In my case, I send a login request with the credentials and the csrf token that I grab from the HTML https://github.com/cypress-io/cypress-example-recipes/blob/master/examples/logging-in__csrf-tokens/cypress/integration/logging-in-csrf-tokens-spec.js#L7
and verify later if my response status is 200 same as example below 馃憞
https://github.com/cypress-io/cypress-example-recipes/blob/master/examples/logging-in__csrf-tokens/cypress/integration/logging-in-csrf-tokens-spec.js#L73

image

There is a request between step 1 and 3 which is automatically done in the background that verifies if its a 302 and its failing there.

https://XXXXXX/auth/token?token=XXXXXXXX

Yesterday afternoon around 3pm PST ( when my cypress updated to 3.5.0) all my mock login tests started failing. It returns a 403 instead of 200.

Cypress version: 3.5.0
Browser: chrome 78

We had to switch to version 3.4.1 to get our tests back to work. If this can be fixed, it would be of great help! 馃憤

I am also getting the error... Had to downgrade to 3.4.1

Same error as the original poster.

Similar problem here, headers are not being sent with this commmand on 3.5.0:

cy.request({ url: `${myUri}`, headers: exchangeHeaders, failOnStatusCode: false });

No problem when running the same on 3.4.1

Are you guys setting cookies for auth during your redirects? @srideeps I notice that you're getting a 403, could that be because the expected cookies are not being set on redirect?

Setting cookies on a redirect is partially broken in 3.5.0, but there is a fix already: #5432

Let me know if this fits your situation.

We are also getting the same error as @pitgrap. In our case, we have 2 requests (tests) that run after each other. The first test passes, the 2nd test we get the same error as @pitgrap. If I skip the first test, and only run the 2nd, it does indeed work without getting this error. Hope that helps. We are also using internal urls otherwise would have no problem sharing.

@flotwig .. yes! that's exactly my situation. Also I'm sorry for not mentioning that we set cookies on re-direct. Hopefully that fix helps us!! and you guys are awesome! we 鉂わ笍 cypress!!

Hey!
I also get this, any more infos needed?

We think this issue may be related to an issue with setting cookies detailed here: https://github.com/cypress-io/cypress/issues/5453#issuecomment-546498106

Please update if you can confirm or deny the cookies being a problem in your situation.

@jennifer-shehane thanks :)
This is indeed happening between a logout step on our tests setup.
Right before a clearCookies

Just checked the code again, we're using cy.clearCookies(); too and it has the info "workaround for #3525".

The code for this is done in cypress-io/cypress#5478, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

Released in 3.6.1.

Works!
Thanks everyone!!

Yes, 3.6.1 is working again. Thank you.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

carloscheddar picture carloscheddar  路  3Comments

jennifer-shehane picture jennifer-shehane  路  3Comments

dkreft picture dkreft  路  3Comments

verheyenkoen picture verheyenkoen  路  3Comments

weskor picture weskor  路  3Comments