jai*_*ikl 10 javascript cypress
我有一个加载指示器,需要在断言之前等待消失。
我已经看到了一些使用以下内容的方法,但是它似乎对我不起作用,而且我也不希望它成为断言。 cy.get('element, {timeout: 10000}).should('not.exist);
任何提示吗?
Ali*_*ien 31
cypress-wait-until不适合我。我只使用了基本的:
cy.get('.ant-drawer-body').should('not.exist');
Run Code Online (Sandbox Code Playgroud)
它会自动等待。
小智 17
恕我直言,最干净的方法是不要在 get 中使用等待或超时,这是一种反模式。
我建议使用Cypress waitUntil命令并使用以下内容:
cy.waitUntil(function() {
return cy.get('element').should('not.exist');
Run Code Online (Sandbox Code Playgroud)
或根据您可以使用的应用程序代码not.be.visible。
Dio*_*cha 11
如果您特别需要等待,可以wait()在声明之前使用赛普拉斯的功能,并提供超时之前要等待的时间。
但是请注意,这是一种反模式,您可以在文档中找到:
您几乎不需要等待任意时间。赛普拉斯始终有更好的表达方式。
也就是说,如果您的加载指示器绑定到某个网络请求,则可以在声明之前等待它们完成。可以通过以下示例实现此目的:
// Wait for the route aliased as 'getAccount' to respond
// without changing or stubbing its response
cy.server()
cy.route('/accounts/*').as('getAccount')
cy.visit('/accounts/123')
cy.wait('@getAccount').then((xhr) => {
// we can now access the low level xhr
// that contains the request body,
// response body, status, etc
})
Run Code Online (Sandbox Code Playgroud)
有关等待请求的更多信息,请参见此处。
另外,请确保您确实要使用.should('not.exist')而不是.should('not.be.visible')。
| 归档时间: |
|
| 查看次数: |
9918 次 |
| 最近记录: |