cy.request with failOnStatusCode: false not working

See original GitHub issue

Running the call cy.request({url: '/abcde', failOnStatusCode: false}); returns the following error for me.

CypressError: cy.request() failed on:

https://mysite.com/abcde

The response we received from your web server was:

  > 404: Not Found

This was considered a failure because the status code was not '2xx' or '3xx'.

If you do not want status codes to cause failures pass the option: 'failOnStatusCode: false'

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

I actually want the 404 to appear and check do some checks there. I am currently on the last version of Cypress(3.6.1) so that’s not the problem.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
jennifer-shehanecommented, Jan 22, 2021

@yunusHW @gissavem cy.request() does not accept 2, 3, args with an options argument as the last arg as you have written. If you need to pass options, you need to pass a single options argument with all arguments including url, method (if necessary) and failOnStatusCode. Please check the docs: https://on.cypress.io/requesttax

Screen Shot 2021-01-22 at 12 05 28 PM
it('test 500', () => {
  cy.request({
    url: 'https://httpstat.us/500', 
    failOnStatusCode: false 
  }).then((response) => {
    expect(response.status).to.eq(500)
    expect(response.body).to.eq("500 Internal Server Error")
  })
})
0reactions
RealLaucommented, Mar 23, 2021

@jennifer-shehane I tried your sample code, still not working for me. my test code:

/// <reference types="cypress" />

context('Aliasing', () => {
    beforeEach(() => {
    })

    it('test 500', () => {
        cy.request({
            method: "GET",
            url: "http://127.0.0.1:5001" + "/hostui",
            failOnStatusCode: false
        }).then((response) => {
            expect(response.status).to.eq(500)
            expect(response.body).to.eq("500 Internal Server Error")
        })
    })
})

and the output is:


request
GET --- http://127.0.0.1:5001/hostui
CypressError
cy.request() failed trying to load:

http://127.0.0.1:5001/hostui

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: connect ECONNREFUSED 127.0.0.1:5001

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

The request we sent was:

Method: GET
URL: http://127.0.0.1:5001/hostui

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

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 computerLearn more
cypress/integration/custom/HOST.js:8:12
   6 | 
   7 |     it('test 500', () => {
>  8 |         cy.request({
     |            ^
   9 |             method: "GET",
  10 |             url: "http://127.0.0.1:5001" + "/hostui",
  11 |             failOnStatusCode: false

pls help:) Thanks in advance.

I’m using:

➜  node_modules/.bin/cypress -v
Cypress package version: 6.8.0
Cypress binary version: 6.8.0
Electron version: 11.3.0
Bundled Node version: 12.18.3

on macOS BigSure 11.2.3

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to test a bad request in cypress - Stack Overflow
So pass failOnStatusCode: false to not fail on bad status codes: cy.request({ method: 'POST', url: 'https://myrAPI', failOnStatusCode: false ...
Read more >
request - Cypress Documentation
request() requires that the response status code be 2xx or 3xx when failOnStatusCode is true . Assertions. cy.request() will only run assertions you...
Read more >
cypress-io/cypress - Gitter
cy.visit('/404-url', { failOnStatusCode: false }); ... I am facing issues in logging to my application that I am trying to automate.
Read more >
Requested resource not found | Cypress examples (v9.5.0)
Sometimes you use cy.request to get a resource that might not exist. ... INCORRECT, this will NOT WORK, just for DEMO function getTodo(id)...
Read more >
CypressError cy.visit() failed trying to load - Laracasts
I followed the tutorial step by step but the test does not go ... pass the option: failOnStatusCode: false cypress/integration/ex_spec.js:2:5 1 | it('works' ......
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