question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cypress cy.request function sends the POST request to the server but Cypress responds with TIMEOUT

See original GitHub issue

Current behavior:

Cypress cy.request function sends the POST request to the server but Cypress responds with TIMEOUT. From my app perspective all works fine: the POST call is processed correctly; 204 HTTP success code is sent back.

Doesn’t matter how I change the timeout within the cy.request() function it’s always the same.

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

http://localhost:81/operations/api/trains/planning-session/new

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:

  > Error: ESOCKETTIMEDOUT

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

The request we sent was:

Method: POST
URL: http://localhost:81/operations/api/trains/planning-session/new

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

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:

RequestError: Error: ESOCKETTIMEDOUT
    at new RequestError (/Users/kapalkat/projects/frontend/node_modules/cypress/dist/Cypress.app/Contents/Resources/app/packages/server/node_modules/request-promise-core/lib/errors.js:14:15)
    at Request.plumbing.callback (/Users/kapalkat/projects/frontend/node_modules/cypress/dist/Cypress.app/Contents/Resources/app/packages/server/node_modules/request-promise-core/lib/plumbing.js:87:29)
    at Request.RP$callback [as _callback] (/Users/kapalkat/projects/frontend/node_modules/cypress/dist/Cypress.app/Contents/Resources/app/packages/server/node_modules/request-promise-core/lib/plumbing.js:46:31)
    at self.callback (/Users/kapalkat/projects/frontend/node_modules/cypress/dist/Cypress.app/Contents/Resources/app/packages/server/node_modules/request/request.js:186:22)
    at emitOne (events.js:115:13)
    at Request.emit (events.js:210:7)
    at ClientRequest.<anonymous> (/Users/kapalkat/projects/frontend/node_modules/cypress/dist/Cypress.app/Contents/Resources/app/packages/server/node_modules/request/request.js:781:16)
    at Object.onceWrapper (events.js:314:30)
    at emitNone (events.js:105:13)
    at ClientRequest.emit (events.js:207:7)
    at Socket.emitTimeout (_http_client.js:722:34)
    at Object.onceWrapper (events.js:314:30)
    at emitNone (events.js:105:13)
    at Socket.emit (events.js:207:7)
    at Socket._onTimeout (net.js:402:8)
    at ontimeout (timers.js:469:11)
    at tryOnTimeout (timers.js:304:5)
    at Timer.listOnTimeout (timers.js:264:5)

Desired behavior:

The POST is send and cypress doesn’t respond with any error message

Steps to reproduce:

I have created following cy.request():

function createTrainsPlanningSession(name, ignoreIfExists = false) {
    const IGNORED_ERROR_MSG = 'Planning session with that name already exists'

    console.debug("Add new planning session with name: " + name)
    cy.request({
        method: 'POST',
        url: '/operations/api/trains/planning-session/new',
        auth: {
            bearer: window.sessionStorage.getItem('auth_token')
        },
        body: {
            newPlanningSession: name,
            basePlanningSession: " "
        },
        timeout: 120000,
        failOnStatusCode: false
    }).then((resp) => {
        if (!(resp.isOkStatusCode || (ignoreIfExists && resp.body === IGNORED_ERROR_MSG))) {
            const EXCEPTION_MSG = 'Exception when creating planning session'
            console.error(EXCEPTION_MSG + ':\n' + JSON.stringify(resp))
            throw new Error(EXCEPTION_MSG + '.\nCode: ' + JSON.stringify(resp.status) + '\nMessage:' + JSON.stringify(resp.body))
        }
    })

Then I am calling the function like so:

describe('TA-OPL-01: Planning Sessions: Trains', function () {
    const PATH_PLANNING_TRAINS = '/operations/#/menu/planning/trains';

    before(function () {
        cy.login()
    })

    beforeEach(function () {
        cy.setUpAuth()
    })

    it('TA-OPL-01-01: Check Drag and Drop', function () {
        const PLANNING_SESSION_NAME = 'TEST_SESSION15'

        createTrainsPlanningSession(PLANNING_SESSION_NAME, true)

        cy.visit(PATH_PLANNING_TRAINS + "/list")
        cy.waitForLoad()
    })
})

Versions

checked with versions 2.1.0 and on new version: 3.0.1 System Version: macOS 10.13.5 (17F77) browser: Chrome

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
kapalkatcommented, Jun 11, 2018

OK seems I have found a solution and it’s provided by Cypress:) There is an option in configuration file: “responseTimeout”. Default value is set to 30000. I have change it to 60000 and works like a charm. Closing the issue.

0reactions
ganeshac123commented, Oct 21, 2021

configuration responseTimeout where is it?

Read more comments on GitHub >

github_iconTop Results From Across the Web

intercept - Cypress Documentation
reply () function can be used to send a stub response for an intercepted request. By passing a string, object, or StaticResponse to...
Read more >
How to avoid timeout error for cy.request()? - Stack Overflow
I am using cy.request() method to send API requests and read the response in my cypress tests. But sometimes the tests fail with...
Read more >
Cypress cy.intercept Problems - Gleb Bahmutov
* Intercept the first matching request and send the response object. * Do nothing on the second and other requests. * @param {string} ......
Read more >
@cypress/request - npm
Read timeout: Time to wait for a server to send response headers (and start the response body) before aborting the request. Connection timeout: ......
Read more >
How to wait for a request to finish before moving on with Cypress
In the first line inside of the beforeEach function callback, I use cy.intercept() to intercept an HTTP request of type GET for a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found