本文介绍了赛普拉斯(Cypress):有什么方法可以检查元素的隐身性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的应用程序中,当用户执行一些需要与服务器通信的操作时-顶部面板上将显示一个加载栏。完成操作后-加载栏将消失。在测试中,我们在移动之前将其用作检查进行下一步。
在硒中,我正在检查加载条的消失,如下所示

In our application when user do some actions that require communicatiion with server -a loading bar will be displayed on top panel.Once the action completed-Loading bar will be disappeared.In tests we are using this as a check before we move to next step.In selenium i am checking the disappearance of loading bar as shown below

WebDriverLongWait.Until(ExpectedConditions.InvisibilityOfElementLocated(By.Id("loading-bar")));

是否有类似的方法可以检查Cypress中某个元素的隐身性

Is there a similar way to check invisibility of an element in Cypress

而不是等待加载栏,而是在等待请求完成

instead of waiting for loading bar i am waiting for the request to finish

as shown below cy.server()
            cy.route('POST','**/saveExpression').as('saveExpression')
            cy.get('.IEE-save-button',{ timeout: 100000 }).contains('Apply Expression').click();

            cy.wait('@saveExpression').then((xhr)=>

            {
                cy.contains('browse',{timeout: 60000}).click()
            })


推荐答案

在这种情况下,最好使用 .should('not.be.visible')。要放置在您的示例中,如下所示,

In this scenario, it's ideal to use .should('not.be.visible'). To place in your example as below,

cy.get('#loading-bar').should('not.be.visible')

由于加载栏指示器取决于某些网络请求,因此您可以等待XHR要求在断言之前完成。您可以使用柏树的功能。例如:

Since loading bar indicator is dependent on some network request, you can wait for the XHR request to finish before making an assertion. You could use the wait() function of cypress. For instance:

// Wait for the route aliased as 'getAccount' to respond
cy.server()
cy.route('/accounts/*').as('getAccount')
cy.visit('/accounts/123')
cy.wait('@getAccount').then((xhr) => {
  cy.get('#loading-bar').should('not.be.visible')
})

这篇关于赛普拉斯(Cypress):有什么方法可以检查元素的隐身性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 04:23