How can I apply a cypress timeout to a specific `its` call?

How can I increase the timeout for a specific its method call in Cypress?

In Cypress, we can define a timeout for the cy.get() method like this:

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

However, I am wondering if there is a way to define a timeout specifically for the its method, such as:

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

Or do I need to adjust the defaultCommandTimeout in the cypress.json configuration to achieve this? How can I apply a cypress timeout to a specific its call?

I think you can use cy.wait() before its: If you want to add a delay or increase the time to ensure the method is available, you can use cy.wait() before calling its. This way, you can ensure that Cypress waits for a specific amount of time before performing its call:

cy.wait(5000);  // Wait for 5 seconds
cy.window()
  .its('MyClass')
  .should('exist');

Though this approach isn’t as specific as adjusting timeouts, it allows for controlled waiting, which helps when dealing with asynchronous loading, indirectly influencing cypress timeout behavior.

Happy to help :slight_smile:

You can try this way cause this is what worked for me :

Use timeout option with its method: Similar to how you can define a timeout with the cy.get() method, you can also define a specific timeout for the its method by chaining the { timeout: <value> } option directly on its(). This will apply the timeout to this particular call without affecting others:

cy.window()
  .its('MyClass', { timeout: 10000 })  // Set timeout to 10 seconds for this call
  .should('exist');

This solution directly targets the cypress timeout for the its method.

To add up to the solution shared by @dimplesaini.230

If you want to adjust the timeout for all tests globally rather than for individual calls, you can modify the defaultCommandTimeout setting in your cypress.json configuration file:

{
  "defaultCommandTimeout": 10000  // Set global timeout to 10 seconds
}

While this solution doesn’t target the specific its call, it changes the default timeout for all commands, including cypress timeout, which may help with cases like waiting for window properties.