CY请求重试
我正在尝试创建一条电子邮件服务,CY请求将获取并返回电子邮件的正文,但是从逻辑上讲,可能没有立即到达电子邮件,所以我认为正确的方法是每3秒获取一次,并且如果没有电子邮件尝试再次获取,因此基本上一遍又一遍地重试同样的操作,以便说每3秒钟2分钟。柏树在API中是否有东西?
it('Should be able to reset password', () => {
let emailContent: string = '';
cy.request(
'GET',
`https://api.testmail.app/api/json?apikey=${TestMailService.APIKEY}&namespace=${TestMailService.NAMESPACE}&tag=test&livequery=true`,
).then((response) => {
emailContent = response.body.emails[0].text;
});
})
h
I am attempting creating an email service where cy request will fetch and return body of an email, but logically there could be a case where email did not arrived right away so i assume the correct way is to fetch every 3 seconds and if there is no email try to fetch again so basically retrying same operation over and over for lets say 2 minutes every 3 seconds. Is there something that cypress already have in the api ?
it('Should be able to reset password', () => {
let emailContent: string = '';
cy.request(
'GET',
`https://api.testmail.app/api/json?apikey=${TestMailService.APIKEY}&namespace=${TestMailService.NAMESPACE}&tag=test&livequery=true`,
).then((response) => {
emailContent = response.body.emails[0].text;
});
})
H
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从文档请求投票
这是一个递归功能,所以我会我在无限呼叫的情况下添加警卫(没有显示电子邮件)。
等待3秒只是
cy.wait(3000)
传递特定电子邮件主题
From the docs Request Polling
It's a recursive function , so I'd add a guard in case of infinite calling (no email shows up).
Waiting 3 seconds is just a
cy.wait(3000)
Passing a specific email subject