cypress.get(element) fails without waiting or retrying
See original GitHub issueCurrent behavior:
The cypress.get(element)
function fails without waiting or retrying if the element is not visible on the page.
Desired behavior:
The cypress.get(element)
function should wait and find the dom element in the page or timeout after the default timeout if the element is not visible in the page.
Steps to reproduce:
Non-working code:
describe('Starts a chat conversation', () => {
describe('When visiting /chat ', () => {
it('creates a new chat and the the chat bot starts sending messages', () => {
cy.loginAs(clientWithMembership); // custom command that execute an http call
const url = getChatUrl();
cy.visit(url);
cy.get('div[data-cy=chat-message-container]').should('have.length', 1); // Fails without waiting
});
});
});
Working code: (adding a wait before checking if the element exists)
describe('Starts a chat conversation', () => {
describe('When visiting /chat ', () => {
it('creates a new chat and the the chat bot starts sending messages', () => {
cy.loginAs(clientWithMembership); // custom command that execute an http call
const url = getChatUrl();
cy.visit(url);
cy.wait(3000);
cy.get('div[data-cy=chat-message-container]').should('have.length', 1);
});
});
});
Versions
Cypress: 3.0.1 Mocha: 4.0.1 Browser: Chrome
Issue Analytics
- State:
- Created 5 years ago
- Comments:20 (8 by maintainers)
Top Results From Across the Web
Retry-ability - Cypress Documentation
What you'll learn How Cypress retries commands and assertions When commands are retried and ... Expect fails the test without waiting for the...
Read more >Waiting in Cypress and how to avoid it - Filip Hric
Cypress will wait for the element to appear in DOM and will retry while it can. If 4 seconds are not enough, you...
Read more >Can I prevent Cypress cy.get from failing if no elements are ...
get () has a built-in retry of 5 seconds, whereas Cypress.$(listItemTitle) is synchronous. What happens if you cy.wait(5000) before counting ...
Read more >3 Practices to Reduce Flakiness in Cypress Tests - Atomic Spin
and the assertion fails, Cypress will only retry the .find() command, instead of starting from the beginning of the chain and retrying .get()...
Read more >Solving The Element Is Detached From DOM Error In Cypress
And if everything fails, if there is no observable application property to wait for - then add the cy.wait(xxx) command to wait for...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@dan19 It does appear from the information provided that Cypress attempted to retry for the duration of the timeout (4000ms), and did not find the DOM selector to have a length of 1. Could you try increasing the timeout of the actual
get
to see if this helps?Also, make sure you are following some of our recommendations on waiting for you app to load before getting an element in your tests. https://on.cypress.io/using-cypress-faq#How-do-I-wait-for-my-application-to-load
@mikhaildzarasovvineti If you want to purely wait for an element to be present on the page, you can increase the timeout that Cypress waits for an element to be present.
cy.get('button', {timeout: 60000}
.