我知道Cypress is not big on conditional testing,但是来自硒网络驱动程序的背景,我非常习惯在测试中使用这种逻辑。
我正在测试一个KaiOS app,它不会像滚动设备那样使用翻页而不是滚动来使用户更容易阅读。
当前,由于KaiOS基于Firefox OS,因此以与设备类似的方式在计算机上使用该应用程序的唯一方法是使用Firefox。问题在于,在cypress上运行测试时,即使在使用Firefox时,页面翻页也无法正常工作,因此,当我们翻页时,页面跳转到的页面与设备或Firefox上的页面不同。
因此,由于我不确定如何找到所需的元素,因此我需要不断翻动页面并寻找它,然后与之交互。
我尝试过a bunch of different things without success。
我需要的很简单:
答案 0 :(得分:4)
我已经在issues you raised中进行了回复,但我也会在此处编写解决方案以帮助其他用户。
好吧,您需要逐步
简单
BarValue
最简单的方法是利用公开的StringFormat='{}{0:P0}'
jQuery实例并自己检查元素是否存在。
cy.visit('<your url>')
Cypress.$
是cy.visit('<your url>')
cy.waitUntil(() => !!Cypress.$('#elementToBeChecked').length)
期望的() => !!Cypress.$('#elementToBeChecked').length
,它返回一个布尔值,checkFunction
重试该布尔值,直到返回waitUntil
。
waitUntil
true
对于确保che cy.visit('<your url>')
cy.waitUntil(() => {
if (!Cypress.$('#elementToBeChecked').length) {
return cy.flipPage().then(() => false)
} else {
return true
}
})
解析为cy.flipPage().then(() => false
很有用。 checkFunctin
将调用false
,直到返回waitUntil
。
完成
checkFunction
如果您想更详细地说明为什么需要true
来完成像您这样的任务,请看一下here。
希望有帮助?
答案 1 :(得分:1)
尝试使用https://github.com/NoriSte/cypress-wait-until有条件地在页面上执行操作