【问题标题】:Set timeout for Cypress expect assertion为赛普拉斯期望断言设置超时
【发布时间】:2019-08-12 16:20:50
【问题描述】:

我的问题是我希望赛普拉斯库中的期望断言超时,但似乎无法找到这样做的方法。

我已经尝试在 cypress.conf 中大大增加全局超时时间;但是,这不起作用。

if ($widget.find('report-widget')) {
  SVGCount++;
  expect(barGraphsChange[index]).to.not.equal(undefined)
  console.log(barGraphsChange, index)
  cy.getBarGraphTotal(SVGCount, barGraphsChange[index])
}

如果不是超时,那么一个合理的解决方法也会很好,谢谢!

另请注意: barGraphsChange[index] 在此阶段早些时候正在通过调用的自定义 Cypress 命令进行计算和分配。

【问题讨论】:

    标签: javascript timeout cypress


    【解决方案1】:

    您可以使用should() 自定义您的期望,这将自动重试您的断言,无论是指定的超时时间,还是全局 defaultCommandTimeout(如果没有提供)。 在您的情况下,我可能会想象包装您的对象,指定超时,然后将您的逻辑传递给应该:

    cy.wrap(someFunction, {timeout: 25000}).should(someFunction => expect(someFunction()).to.eq(someValue))
    

    在此处阅读更多信息:https://docs.cypress.io/api/commands/should.html#Function

    【讨论】:

      猜你喜欢
      • 2021-12-22
      • 2021-12-21
      • 1970-01-01
      • 2021-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多