Skip to content
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.request() fails in 3.5.0 #5436

Closed
pitgrap opened this issue Oct 24, 2019 · 17 comments · Fixed by #5478
Closed

cy.request() fails in 3.5.0 #5436

pitgrap opened this issue Oct 24, 2019 · 17 comments · Fixed by #5478
Assignees

Comments

@pitgrap
Copy link
Contributor

pitgrap commented Oct 24, 2019

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

@pitgrap pitgrap changed the title cy.request() fails in 3.5.0 cy.request() with two 302 redirects fails in 3.5.0 Oct 24, 2019
@jennifer-shehane
Copy link
Member

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.

@cypress-bot cypress-bot bot added the stage: needs investigating Someone from Cypress needs to look at this label Oct 24, 2019
@jennifer-shehane
Copy link
Member

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,
  })
})

@cypress-bot cypress-bot bot added stage: needs information Not enough info to reproduce the issue and removed stage: needs investigating Someone from Cypress needs to look at this labels Oct 24, 2019
@pitgrap
Copy link
Contributor Author

pitgrap commented Oct 24, 2019

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. :(

@srideeps
Copy link

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! 👍

@mbcopp
Copy link

mbcopp commented Oct 24, 2019

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

Same error as the original poster.

@juanpablolunardi
Copy link

juanpablolunardi commented Oct 25, 2019

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

@pitgrap pitgrap changed the title cy.request() with two 302 redirects fails in 3.5.0 cy.request() fails in 3.5.0 Oct 25, 2019
@flotwig
Copy link
Contributor

flotwig commented Oct 25, 2019

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.

@flotwig flotwig self-assigned this Oct 25, 2019
@danreale
Copy link

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.

@srideeps
Copy link

@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!!

@skjnldsv
Copy link

skjnldsv commented Nov 5, 2019

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

@jennifer-shehane
Copy link
Member

We think this issue may be related to an issue with setting cookies detailed here: #5453 (comment)

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

@skjnldsv
Copy link

skjnldsv commented Nov 5, 2019

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

@pitgrap
Copy link
Contributor Author

pitgrap commented Nov 6, 2019

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

@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review and removed stage: needs information Not enough info to reproduce the issue labels Nov 6, 2019
@cypress-bot cypress-bot bot added stage: pending release and removed stage: needs review The PR code is done & tested, needs review labels Nov 8, 2019
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Nov 8, 2019

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.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Nov 8, 2019

Released in 3.6.1.

@skjnldsv
Copy link

skjnldsv commented Nov 9, 2019

Works!
Thanks everyone!!

@pitgrap
Copy link
Contributor Author

pitgrap commented Nov 11, 2019

Yes, 3.6.1 is working again. Thank you.

@cypress-io cypress-io locked as resolved and limited conversation to collaborators Jan 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
8 participants