我正在编写一个代码块来监视对话框及其内容。我编写了一个while循环,它将跟踪一些活动进度,其中状态值为
“现状:正在进行中”
而当进度完成时,
“状况:已完成”。
在while循环中,我编写了一个if/else块
while(true)
{
if(cy.get('<locator>').contains('progress',{matchCase:false}))
{
statements
}
else
{
statements
}
}在这里,while循环会重复执行,直到出现"Status : In Progress“值,
也就是说,if条件变为真,但当进程完成,状态更改为“已完成”时,它将失败并引发AssertionError,并停止测试用例而不进入else块。
我有一些语句需要在条件失败时执行,而不是返回AssertionError控件。
我该怎么做?
发布于 2021-03-16 21:57:11
在Cypress文档中有一个关于条件测试的很好的指南。当谈到您的例子时,我假设这样的东西可以起作用:
while(true)
{
// Get the element first and use .then() command to proceed with it
cy.get('<locator>').then(($btn) => {
// assert on the text
if ($btn.text().includes('progress')) {
// do your statements
} else {
// do other statements
}
})
}或者类似的东西。我希望这能帮上忙!
https://stackoverflow.com/questions/66654547
复制相似问题