为赛普拉斯期望断言设置超时

Set timeout for Cypress expect assertion

我的问题是我想对来自 Cypress 库的 expect 断言进行超时处理,但似乎无法找到这样做的方法。

我已经尝试在 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 命令进行计算和分配。

您可以使用 should() 自定义您的期望,这将自动重试指定超时的断言,或者如果提供了 none 则为全局默认 CommandTimeout。 在你的情况下,我可能会想象包装你的对象,指定超时,然后将你的逻辑传递给 should:

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

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