3

Here are my test results enter image description here

The test timed out and can not show in cypress dashboard. How to set timeout for each test case in cypress?

Ackroydd
  • 1,482
  • 1
  • 13
  • 14
Sang Mai
  • 63
  • 1
  • 6

2 Answers2

2

Please see Mocha timeouts,

Test-specific timeouts may also be applied, or the use of this.timeout(0) to disable timeouts all together.

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

It works because Mocha is integral to Cypress.


Try these simple failing tests which pass Mocha done() but never call it. They fail at the time specified by the timeout.

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);
});
Richard Matsen
  • 20,671
  • 3
  • 43
  • 77
  • this seems to be setting the default command timeout, not setting a timeout for the overall duration of the test. – ldam Nov 10 '21 at 09:30
  • @Idam - No, you are thinking about the Cypress config setting. Look at the linked docs for Mocha timeouts they clearly show this pattern is for individual tests. – Richard Matsen Nov 11 '21 at 18:47
  • I agree that's what the Mocha docs say, but my own two eyes saw that using `this.timeout(1000)` did not end my test after 1 second, instead commands continued to run past the 1 second mark, and any command that took longer than 1 second failed, which is exactly what setting the default command timeout does. Perhaps Cypress does not respect this properly? – ldam Nov 12 '21 at 12:59
  • 1
    If you set the test timeout to 1000 ms and leave the default command timeout at the default 4000 ms, the command does not run any longer than the test timeout, which is logical since the command is part of the test. If you set a test timeout longer than 4000 ms, the commands do run to the increased timeout, but it's not affecting the default because the a next test that has no timeout uses the configured `defaultCommandTimeout`. – Richard Matsen Nov 15 '21 at 00:39
0

I don't think you can. As far as I can see in the docs, there're currently these timeouts you can set up:

  • default command timeout
  • exec timeout
  • task timeout
  • page load timeout
  • request timeout
  • response timeout
pavelsaman
  • 7,399
  • 1
  • 14
  • 32