gpt4 book ai didi

events - Cypress 如何在失败时提出请求

转载 作者:行者123 更新时间:2023-12-04 15:49:37 24 4
gpt4 key购买 nike

我试图在测试失败时触发一个操作(这会向我发送一封电子邮件)。

Cypress.on('fail', (error, runnable) => {
cy.request('POST', 'https://mysite/api/', { action: 'cypress', error : error, runnable: runnable })
throw error
})

describe('Test https://xxx/', function() {
it('Visits the Page', function() {
cy.visit('https://xxx/yyy/')
.location('pathname').should('eq', '/yyy/thank-you')
})
})

但是当我执行它时,我得到了这个前提错误:
CypressError: Cypress detected that you returned a promise from a command while also invoking one or more cy commands in that promise.

The command that returned the promise was:

> cy.location()

The cy command you invoked inside the promise was:

> cy.request()

有没有办法从失败事件中调用发布请求?

谢谢

最佳答案

用普通的试试 fetch() .请注意 runnable有循环引用,因此您可能需要为消息提取一些部分。

Cypress.on('fail', (error, runnable) => {
fetch('https://mysite/api/', {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(runnable.title), // body data type must match "Content-Type" header
});
throw error
})

在我的测试中,这不会引发嵌套的 promise 错误,并且我可以在网络选项卡中看到 POST 挂起,因此假设它将与 kosha api 一起使用。

关于events - Cypress 如何在失败时提出请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54405804/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com