Send header in subsequent URL visits through cypress

Viewed 188

I am using Cypress for website integration testing and I am overwriting visit method such that it includes specific attribute in header but this doc says that headers will only be sent for the initial cy.visit() request, not for any subsequent requests.

Is there any workaround for this?

1 Answers

I know this question is asked long time ago but it might help others. I found a workaround to add headers for all requests:

cy.server({
       onAnyRequest:   function (route,  proxy) {
           proxy.xhr.setRequestHeader('CUSTOM-HEADER',  'Header value');
     }
});
Related