如何在cypress中为测试用例设置超时?

问题描述

这是我的测试结果

enter image description here

测试超时,无法在 cypress 仪表板中显示。 如何在cypress中为每个测试用例设置超时时间?

解决方法

我不认为你可以。据我在 docs 中看到的,目前您可以设置以下超时时间:

  • 默认命令超时
  • 执行超时
  • 任务超时
  • 页面加载超时
  • 请求超时
  • 响应超时
,

请参阅Mocha timeouts

也可以应用特定于测试的超时,或者使用 this.timeout(0) 一起禁用超时。

it('should take less than 10 seconds',function() {  // Note NOT arrow function
  this.timeout(10000);
  // test here
});

之所以有效,是因为 Mocha 是 Cypress 不可或缺的一部分。


尝试这些通过 Mocha done() 但从不调用它的简单失败测试。它们在超时指定的时间失败。

it('should take less than 500ms',function(done) {
  this.timeout(500);
});

it('should take less than 2s',function(done) {
  this.timeout(2000);
});

it('should take less than 5s',function(done) {
  this.timeout(5000);
});