Reputation: 679
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
Reputation: 1811
Instead of specifying this in individual tests I updated my cypress.json
with the following...
{
"defaultCommandTimeout": 10000
}
Upvotes: 4
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
Reputation: 287
For me, I just do this wherever I wanted to wait
cy.get('ELEMENT', {timeout:50000})
Upvotes: 19
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
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
Reputation: 622
Place this in the its block before you want it used:
Cypress.config('defaultCommandTimeout', 10000);
Cypress.config() documentation
Upvotes: 39
Reputation: 3741
It seems that this should work (not tested it though):
cy.window().its({ timeout: 10000 }, 'MyClass')
Upvotes: -3