Reputation: 11
Could you help to solve the problem in API testing by Cypress. When I set the request headers in options section Cypress ignores them and replaces with default ones. The example of my request:
cy.request({
method: 'POST',
url: 'https://orion.koto.com/api/inn',
Headers: {'sid':'21102xiXXdvsfykg5pj'},
body:'["3211455115"]' ,
})
the request sent by Cypress:
Method: POST URL: https://orion.koto.com/api/inn Headers: {
"Connection": "keep-alive", "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36", "accept": "/",
"accept-encoding": "gzip, deflate", "content-length": 14 } Body: ["3211455115"]
Upvotes: 1
Views: 3867
Reputation: 415
const green_value = "TOTO"
describe('As I have set a green header',()=>{
it('should use this header',()=>{
cy.visit({
method: 'GET',
url: 'https://www.whatismybrowser.com/detect/what-http-headers-is-my-browser-sending',
headers: {
'green': green_value
}
})
})
})
On my side, it work with visit() function. The url used will show you header sent. Hope this code sample can help you to implement request() function.
Upvotes: 2