如何在柏树中的随机弹出窗口上工作?
我有一个应用程序,其中弹出反馈随机出现在页面中;像弹出窗口一样,将其加载近3000ms后可能会出现在页面上。如何在柏树中处理此弹出。
我尝试了以下代码:
cy.get("div.QSIFeedbackButton").then(($body)=> {
if($body.find('.QSIWebResponsiveDialog-Layout1-SI_0rEzRx2V9yqm1Yq_close-btn > img')){
cy.get('.QSIWebResponsiveDialog-Layout1-SI_0rEzRx2V9yqm1Yq_content').contains('Help us improve our portal!')
cy.get('.QSIWebResponsiveDialog-Layout1-SI_0rEzRx2V9yqm1Yq_close-btn > img').click()
}
else {
cy.log('feed back pop up not found')
}
})
但是当弹出弹出时,这个块总是失败。我想优雅地进行测试,以便即使弹出弹出不显示测试也不会失败&它应该转到其他块。我该如何在测试中执行此操作?
I have an application, where feedback pop up comes in a page randomly; like pop up may or may not come in the page after loading it for nearly 3000ms. How to handle this pop up in cypress.
I tried below code:
cy.get("div.QSIFeedbackButton").then(($body)=> {
if($body.find('.QSIWebResponsiveDialog-Layout1-SI_0rEzRx2V9yqm1Yq_close-btn > img')){
cy.get('.QSIWebResponsiveDialog-Layout1-SI_0rEzRx2V9yqm1Yq_content').contains('Help us improve our portal!')
cy.get('.QSIWebResponsiveDialog-Layout1-SI_0rEzRx2V9yqm1Yq_close-btn > img').click()
}
else {
cy.log('feed back pop up not found')
}
})
But this one always fails in IF block, when the pop up doesn't appear. I want to run the test gracefully, so that even if the pop up doesn't appear test should not fail & it should go to the else block. How can i do this in my test?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用“ MutationObserver”,这是一个事件侦听器,当节点为/节点是从DOM添加或删除时会触发的事件侦听器。然后,您可以检查模态是否显示(或简单的关闭模态按钮):
注意:这是异步的,并且独立于柏树(您的柏树代码不会等待执行此操作,因此您可能会遇到某些问题。同时发生)。
You can use 'MutationObserver' which is an event listener that gets triggered when a node is/nodes are added or removed from the DOM. You can then check whether the modal shows up (or simply the close modal button):
Note: this is asynchronous and independent from cypress (your cypress code is not gonna wait for this to execute so you might face some issue with the actions that are occurring at the same time as this).
如果弹出窗口在一段时间后消失,请使用以下操作:
cy.get('随机弹出ID')。应该(''not.exist)
效果很好,因为它检查了该弹出窗口是否存在于DOM树中,甚至更好,如果可以的话,将testID添加到弹出式
If the popup disappears after some time, use this:
cy.get('random popup id').should('not.exist')
works great, because it checks if that popup exist in the DOM tree, even better if you can add testid to the popup