Search code examples
cypress

Hide XHR calls on Cypress test runner


I am trying to hide XHR calls on cypress test runner. I have added the following code in my support/index.js but it still doesn't work.

Cypress.Server.defaults({
  delay:500,
  force404:false,
  ignore: (xhr) => {
    return false;
  },
})

Could anyone please suggest how it works?


Solution

  • Try this, works for me

    Add the following to cypress/support/index.js:

    // Hide fetch/XHR requests
    const app = window.top;
    if (!app.document.head.querySelector('[data-hide-command-log-request]')) {
      const style = app.document.createElement('style');
      style.innerHTML =
        '.command-name-request, .command-name-xhr { display: none }';
      style.setAttribute('data-hide-command-log-request', '');
    
      app.document.head.appendChild(style);
    }
    

    Referred and obtained details https://gist.github.com/simenbrekken/3d2248f9e50c1143bf9dbe02e67f5399