'Post request with body is aborted on cypress browser but not in regular browser
I am working on setting up cypress to test my frontend application in my workplace (uses a corporate network), but realized that post request sent from the frontend code to a local and external api endpoint is being aborted on the cypress browser. The post request works in the regular browser.
Guesses: I tried setting up the test on my personal device and it works fine, thus we thought webproxy might the cause.
Steps to reproduce:
Step 1: Insert dummy post request to app.js to simulate post request on loading the website.
// Post request aborted
await fetch('http://dummy.restapiexample.com/api/v1/create', {method: "POST", body: JSON.stringify(data)}).then(res => console.log(res));
await fetch('http://dummy.restapiexample.com/api/v1/create', {method: "POST", body: {}}).then(res => console.log(res));
await fetch('https://localhost:5001/api/dummyEndpoint', {method: "POST", body: JSON.stringify(data)}).then(res => console.log(res));
await fetch('https://localhost:5001/api/dummyEndpoint', {method: "POST", body: {}}).then(res => console.log(res));
Step 2: Visit the url in a cypress test
it('Simple test', () => {
cy.visit("http://localhost:3001");
})
Cypress screenshots:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
