#StackBounty: #cypress How to add header to xhr-request

Bounty: 150

I have the following scenario:

  • A startpage that basically includes other pages through xhr-requests.

  • Some of the xhr-requests are behind an firewall with a single-signon-scheme where each http-request to the server is stripped from a set of headers and then populated according to the users grants.

  • When the request reaches the server it expect some of the reqeusts to have the userId-header.
  • Test-servers are NOT behind “firewall” so we have a plugin in our browsers to emulate the behaviour.

    We would like to run cypress-tests on this page. But we doesn’t seem
    to find how to add this userId-header to the xhr-requests and havn’t
    been able to find an example of this behaviour.

    Could you please provide an example that shows how to do this with a simple example?

An attemt to pseduo-code the scenario:
cy.visit(‘myurl’).interceptBeforeXhr(‘xhr-url’).addHeader(‘xhr-url’, {‘userId’ = ‘username’})


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.