Cypress: Mute certain XHR requests which are convoluting test log on UI

Created on 11 Jan 2018  路  9Comments  路  Source: cypress-io/cypress

  • Operating System: MacOs
  • Cypress Version: 1.4.1
  • Browser Version: Chrome 63 & Electron 53
  • React: 16.2.0
  • web3: 1.0.0-beta.27

Is this a Feature or Bug?

Feature / question

Current behavior:

E2E testing dapp using web3. The app uses web3 which is polling a port regularly. This filling up test run logs on cypress UI. XHR events are all around while running and it's logging even after successful finish it makes really hard to follow tests. It also makes the UI very unresponsive.

Desired behavior:

Would be great to silence / mute certain XHR calls in the log.
There might a way (e.g. overriding event? but I couldn't figure out..)

How to reproduce:

Run any dapp in cypress then the logs will be filled

Test code:

N/A

Additional Info (images, stack traces, etc)

image

image

question

Most helpful comment

You can already do this.

It's documented here: https://on.cypress.io/server#Syntax

And to change the global defaults you can do it here: https://on.cypress.io/cypress-server#Notes

All 9 comments

You can already do this.

It's documented here: https://on.cypress.io/server#Syntax

And to change the global defaults you can do it here: https://on.cypress.io/cypress-server#Notes

thank you, it works like a charm :)

@szerintedmi Can you please let me know a sample code of how did you silence the XHR Request on the log. I am not running the API but UI Tests, so not sure what to do in this case

@moinuddin14 Did you try to place the code below in cypress/support/index.js

Cypress.Server.defaults({
  delay: 500,
  force404: false,
  whitelist: (xhr) => {
    // handle custom logic for whitelisting
    return true;
  }
})

Whitelisting all the XHR requests will break the stubbing feature, because a whitelisted request will be invisible to the Cypress.Server. You probably don't want to do that. See #7362.

How can we do this in cypress 5.1.0
Please help

Cypress.Server.defaults({
delay: 500,
force404: false,
whitelist: (xhr) => {
// handle custom logic for whitelisting
return true;
}
})

this code doesn't work in Cypress 5.1.0
and the using ignore in the same place is throwing an error.

Cypress.Server.defaults({
delay: 500,
force404: false,
whitelist: (xhr) => {
// handle custom logic for whitelisting
return true;
}
})

this code doesn't work in Cypress 5.1.0
and the using ignore in the same place is throwing an error.

5.0.0 | Renamed聽whitelist聽option to聽ignore

try this

Cypress.Server.defaults({
delay: 500,
force404: false,
ignore: (xhr) => {
// handle custom logic for whitelisting
return true;
}
})

It's working. Thank you.

Was this page helpful?
0 / 5 - 0 ratings