使用async await
我想等待一段时间,然后再在cypress中运行命令。但是由于某种原因,下面的代码没有等待。有人可以在这里建议这个问题吗?
(async function doWaitForDialogOpen() {
await new Promise(resolve => setTimeout(resolve, 4000));
cy.get('#iframeID0').then(($iframe)=>{
Cypress.$($iframe).find('html').find('body').find('#someId').find('input').type(100);
})
await doWaitForDialogOpen();
})();
答案 0 :(得分:1)
Cypress具有wait
方法,该方法将等待一段时间。有关更多信息,here
示例:
(async function doWaitForDialogOpen() {
await cy.wait(4000) // waits 4 seconds
const $iframe = await cy.get('#iframeID0')
Cypress.$($iframe)
.find('html')
.find('body')
.find('#someId')
.find('input')
.type(100);
// Do your next steps
})();