Cypress: cy.request does not work with followRedirect: false and Set-Cookie in 3.5.0

Created on 11 Nov 2019  路  10Comments  路  Source: cypress-io/cypress

Hi! 馃憢

We have a test where we want to test redirects, unfortunately it breaks after update to cypress 3.6.1 from 3.3.2:

it('test', () => {
    cy.request({
      url: '/pages/somePage',
      followRedirect: false,
    }).then(resp => {
      expect(resp.status).to.eq(302)
      expect(resp.redirectedToUrl).to.eq("https://example.com/")
    })
})

Error

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

http://localhost:8000/pages/somePage

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:

  > The "url" argument must be of type string. Received type undefined

Versions

3.6.1

topic regression v3.5.0

Most helpful comment

I can confirm this error.

If followRedirect: false is defined, the error The "url" argument must be of type string. Received type undefined is thrown

All 10 comments

This issue was introduced today in 3.6.1. No problems on 3.6.0. Direct requests work fine, but as soon as you start using options and path, it breaks.

This request is broken since 3.6.1:

cy.request({
        url: Cypress.config('baseUrl') + '/auth/realms/' + Cypress.env('shortcode') + '/protocol/openid-connect/auth',
        followRedirect: false,
        qs: {
            scope: 'name,email',
            response_type: 'code',
            approval_prompt: 'auto',
            redirect_uri: Cypress.config('baseUrl') + '/userauth',
            client_id: 'account'
        }
})

When I remove path and either followRedirect or QS the error is gone. Only removing 1 argument or only removing path will result in same error. Obviously I need all to make the request I need.

No path still errors:

cy.request({
        url: Cypress.config('baseUrl'),
        followRedirect: false,
        qs: {
            scope: 'name,email',
            response_type: 'code',
            approval_prompt: 'auto',
            redirect_uri: Cypress.config('baseUrl') + '/userauth',
            client_id: 'account'
        }
})

No path and no one less argument, error gone:

cy.request({
        url: Cypress.config('baseUrl'),
        // followRedirect: false,
        qs: {
            scope: 'name,email',
            response_type: 'code',
            approval_prompt: 'auto',
            redirect_uri: Cypress.config('baseUrl') + '/userauth',
            client_id: 'account'
        }
})

Sorry for the edits. Made some formatting errors.

I can confirm this error.

If followRedirect: false is defined, the error The "url" argument must be of type string. Received type undefined is thrown

Looks like if options.followRedirect is false, currentUrl isn't set within sendPromise before it's used here. (Was changed from options.url in #5478)

I confirm. Same issue for me in 3.6.1. Version 3.6.0 works fine

Same over here, if I have followRedirect: false defined on 3.6.1 it breaks but not on 3.6.0

@MattFisher is correct, the error occurs because currentUrl is not set if followRedirect is false.

The bug is even more specific than just followRedirect: false - we definitely have tests for basic usage of followRedirect: false. This bug will only happen if you're setting followRedirect: false and your final redirect has a Set-Cookie header. Updated the title to reflect this.

Opened a PR to resolve this: #5704

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

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

Released in 3.7.0.

Was this page helpful?
0 / 5 - 0 ratings