在这个Cypress测试中,我试图利用cy.waitUntil npm包等待加载旋转器不存在,然后继续运行测试,而不会出现CI中测试失败的竞争条件(目前,测试失败是因为在组件完成加载之前在页面上发出命令)。
在第一次尝试中,我试图通过从包装器div上的属性“data-”获得它的状态断言,该属性的值依赖于呈现自旋器的相同逻辑。
cy.waitUntil(
() => {
let stillLoading = null
cy.get('[data-cy-isLoading]')
.then(val => (stillLoading = val[0].attributes[1].value))
.then(() => {
if(stillLoading === 'false'){
return true
}
})
},
{
timeout: 8000,
description: 'Await loading spinner',
}
)
如果符合 if (stillLoading === 'false')条件并返回True,则cy.waitUntill命令仍将无限期地继续重试,而不退出waitUntil命令并继续进行测试。
这种变化也不起作用。
cy.waitUntil(
() => {
let done;
let stillLoading;
cy.get('[data-cy-isLoading]')
.then(val => (stillLoading = val[0].attributes[1].value))
.then(() => {
if(stillLoading === 'false'){
done = true
}
})
done ? expect(done).to.be.true : false
},
{
timeout: 8000,
description: 'Await loading spinner',
}
)
接下来,我试图通过对命令/断言使用超时来简单地断言旋转器本身的存在。
!!cy.get('[data-cy="spinningCircle"]', {timeout: 10000}).should('not.be.visible')
!!cy.get('[data-cy="spinningCircle"]', {timeout: 10000}).should('not.exist')
当元素数据-cy=旋圆无法定位时,它们也无法工作,因为它们失败了。
发布于 2022-07-20 08:42:01
我以前做过这样成功的事情
cy.waitUntil(() => {
return cy.get('[data-cy-isLoading]:visible')
.should('have.length.lessThan', 1):
},
{
errorMsg: 'loading indicator still present after 10000ms',
timeout: 10000,
interval: 500
});
https://stackoverflow.com/questions/68037823
复制相似问题