How to increase wait time in cypress

By default, Cypress uses the global timeout specified in its configuration file (commonly 30 seconds) to locate elements. This means Cypress will automatically retry commands like cy.get() until the element appears or the timeout is reached.

However, in some test scenarios, elements may take longer than the default timeout to load or become visible. In such cases, Cypress allows you to override the default timeout for individual commands instead of changing it globally. This helps you handle exceptions where a specific action or element requires more waiting time.

Example: Setting a Custom Timeout in Cypress

// Wait up to 60 seconds for the element to appear
cy.get(‘.slow-loading-element’, { timeout: 60000 })
.should(‘be.visible’);

In this example, Cypress will wait up to 60 seconds for the element with the class .slow-loading-element to appear before failing the test. This timeout applies only to this specific cy.get() command.


Comparison with Selenium

In Selenium, waiting for elements is typically handled using the WebDriverWait class along with Expected Conditions. For example:

// Example in Java using Selenium WebDriver
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(60));
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(“.slow-loading-element”)));

In this Selenium example:

  • WebDriverWait explicitly waits for up to 60 seconds.
  • It checks repeatedly until the condition (visibilityOfElementLocated) is met or the timeout expires.

Key Differences

FeatureCypressSelenium
Default Timeout30 seconds (configurable via defaultCommandTimeout)No built-in retry, requires explicit waits
Retry MechanismAutomatically retries most commands until timeoutMust define retry logic using WebDriverWait
Syntax for Custom Wait{ timeout: <milliseconds> } in commands like cy.get()WebDriverWait with conditions
Use CaseBest for adjusting wait time per element or actionBest for dynamic conditions and flexible waiting logic

Summary

  • Cypress automatically waits and retries, reducing the need for explicit waits.
  • You can override the default timeout per command to handle slower elements.
  • Selenium, in contrast, requires you to define explicit waits using WebDriverWait.

Both approaches allow flexibility, but Cypress simplifies most waiting scenarios through its built-in retry mechanism.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Subscribe to our YouTube Channel: Testing Talks Latest
Testingtalkslatest.com - A project by CreativeHub IT Solutions.
Contact Us At: support@testingtalkslatest.com
Our Partner websites - Classified Hub , CodesToolbox
Scroll to Top
0
Would love your thoughts, please comment.x
()
x