是否可以继续执行测试,如果e元素未找到柏树
我有一个情况,需要等待元素(广告),如果可见,则需要单击它,但是如果超时后未找到元素,则需要继续执行测试。
如何用柏树处理情况?
I have a case when I need to wait for element (advertising), if it's visible then needs to click it, but if element wasn't found after timeout then needs to keep executing a test.
How to handle the situation with Cypress ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
赛普拉斯说检查条件元素的方式是
您很可能将其放在测试的顶部,并且运行得太早(没有重试时间仪)。
您可以添加等待30秒的等待,但是每次测试都会延迟。
最好递归地
拦截广告,
这是如果您可以找到网络选项卡中广告的URL,请使用
cy.intercept()
捕获并固定它以停止模态显示。The way Cypress says to check for a conditional element is Element existence
Most likely you put that at the top of the test, and it runs too soon (there's no retry timeoout).
You can add a wait say 30 seconds, but the test is delayed every time.
Better to call recursively
Intercept the advert
Best is if you can find the url for the advert in network tab, use
cy.intercept()
to catch it and stub it out to stop the modal displaying.我尝试了上述解决方案,但似乎在某些情况下参数
$ body
无法包含必要的元素,因为当我们调用cy.get('hody')。因此,我找到了另一个解决方案,使用柏树使用jQuery,这就是:
I tried the above solution, but seems that in some cases parameter
$body
could not contain necessary element, cause it was not loaded when we invokedcy.get('body')
. So, I found another solution, using jQuery via Cypress, here is it: