【问题标题】:How to create timeout for should assertion?如何为应该断言创建超时?
【发布时间】:2021-01-24 09:19:21
【问题描述】:

我需要等待显示通知,类似这样

cy.contains('p', 'Data processing is completed').should('be.visible', { timeout: 120000});

根据赛普拉斯文档,可以自定义 should 命令以实现超时:https://docs.cypress.io/api/commands/should.html#Wait-until-the-assertions-pass 但老实说,我无法理解提供的示例如何用于我的任务。有人可以帮忙吗?

【问题讨论】:

    标签: javascript mocha.js cypress chai


    【解决方案1】:

    在 JavaScript 中你应该这样做。

    JS

    setTimeout(function(){ 
        $("p").show(); // Content you want to show
     }, 1000); // Delay you want to add, here it's 1 sec.

    【讨论】:

      【解决方案2】:

      您必须在cy.contains() 中使用timeout,例如:

      cy.contains('p', 'Data processing is completed', {
        timeout: 120000
      }).should('be.visible');
      

      正如cypress docs 中提到的,.should() 将继续重试其指定的断言,直到超时。

      【讨论】:

      • 谢谢 Alapan,这就是我要找的东西
      • 乐于帮助@vitaliy4us :)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-10
      • 2021-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多