Regarding the custom header in cy.visit() and cy.request() as 'Accept-Language' #25324
Unanswered
mayankrajjaiswal
asked this question in
Questions and Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I want to add a custom header while calling visit() as per the documentation I added the header 'Accept-Language', but the document says that the header will be sent only once.
As per the document: https://docs.cypress.io/api/commands/visit#Arguments
I tried adding the header in three ways as below.
Ex 1:
cy.visit('/', {
headers: {
'Accept-Language': 'fr',
},
});
Ex 2:
cy.visit('/');
cy.request({
url: '/',
headers: {
'Accept-Language': 'fr',
},
});
Ex 3:
cy.visit('/', {
onBeforeLoad(win) {
Object.defineProperty(win.navigator, 'language', {
value: 'fr',
});
},
});
Question: Cypress sends the request to the server then that server actually sends the request for the locale pages to the other server so the 'Accept-Language' header is required throughout the subsequent requests.
Is there any way this can be done by cypress so that the 'Accept-Language' header is attached to all the requests?
I also tried it via cy.request(), but that also did not work.
Regards,
Mayank
Beta Was this translation helpful? Give feedback.
All reactions