toasty
toasty

Reputation: 679

Increase Timeout for specific its-Method of cypress.io

With cypress.io get-Method we can define a timeout only valid for this specific get-method call:

cy.get('.mobile-nav', { timeout: 10000 })

Is there a way to define a timeout for a specific its-method call like:

cy.window().its('MyClass')

Or do I need to increase defaultCommandTimeout in cypress.json?

Upvotes: 41

Views: 78873

Answers (7)

CWSites
CWSites

Reputation: 1811

Instead of specifying this in individual tests I updated my cypress.json with the following...

{
 "defaultCommandTimeout": 10000
}

Upvotes: 4

Ish
Ish

Reputation: 29606

My web app was launching over 6 XHR (which is over the default limit of chrome) requests upon login, so request I am intercepting occasionally takes more than default 5000

Cypress.config('requestTimeout', 10000);

Upvotes: 0

Maria
Maria

Reputation: 287

For me, I just do this wherever I wanted to wait

cy.get('ELEMENT', {timeout:50000})

Upvotes: 19

Alexander Yachinkovsky
Alexander Yachinkovsky

Reputation: 501

I'd prefer to set timeout for a specific test instead of modifying global config.

it('should do something', {
  defaultCommandTimeout: 10000
}, () => {
  // ...
})

https://docs.cypress.io/guides/core-concepts/writing-and-organizing-tests.html#Allowed-config-values

Upvotes: 39

maxime1992
maxime1992

Reputation: 23813

Based on Joel's answer, here's what I did to restore to the default timeout right after:

const DEFAULT_COMMAND_TIMEOUT = Cypress.config().defaultCommandTimeout;

// there's no easy way to increase the timeout when using
// `its` command therefore we need to save the current
// timeout, change it globally, and restore it after
Cypress.config('defaultCommandTimeout', 15000);

return cy
  .window()
  .its('something')
  .should('exist')
  .then(() => {
    Cypress.config('defaultCommandTimeout', DEFAULT_COMMAND_TIMEOUT);
  });

Upvotes: 4

Joel
Joel

Reputation: 622

Place this in the its block before you want it used:

Cypress.config('defaultCommandTimeout', 10000);

Cypress.config() documentation

Upvotes: 39

Mr. J.
Mr. J.

Reputation: 3741

It seems that this should work (not tested it though):

cy.window().its({ timeout: 10000 }, 'MyClass')

Upvotes: -3

Related Questions