0

我正在设置 cypress 以在我的工作场所测试我的前端应用程序(使用公司网络),但意识到从前端代码发送到本地和外部 api 端点的 post 请求在 cypress 浏览器上被中止。发布请求在常规浏览器中工作。

猜测:我尝试在我的个人设备上设置测试,它工作正常,因此我们认为 webproxy 可能是原因。

重现步骤:

第 1 步:在 app.js 中插入虚拟发布请求,以模拟加载网站时的发布请求。

// 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));

第 2 步:访问 cypress 测试中的 url

it('Simple test', () => {
    cy.visit("http://localhost:3001");
})

赛普拉斯截图:

中止的帖子请求

赛普拉斯开发工具

4

0 回答 0