Skip to content

WIP: getById retries #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

bahmutov
Copy link

I have only played with getByTestId for now, but now it works the way Cypress custom commands can retry using Cypress built-in mechanism

For example, on the page there is JS code to remove data test id attribute from the image after 3 seconds. So initially it should be there, then it should not be there.

it('retries should not exist assertion', () => {
  // initially the image is there
  cy.getByTestId('image-with-random-alt-tag')
    .should('exist')
    .should('have.id', 'test-image-with-data-testid')
  // then its attribute is removed
  cy.getByTestId('image-with-random-alt-tag')
    .should('not.exist')
})

get-by-test-id-retry

Copy link
Contributor

@alexkrolick alexkrolick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great 💥

A few questions - the default behavior of getBy* is to throw an error when no elements are found (wrapped in waitForElement) retries in this case.

But it seems like the default Cypress commands return jQuery selectors which can be null, and then check the pending assertions to see if it should throw. This seems closer in behavior to the queryAllBy* queries, which don't throw, and return an array or an empty array.

The current implementation also retries until a timeout, before yielding to the Cypress resolver, which seems like it would take longer than running the query, then the resolver, then the query again, in cases where the retry is triggered by a failed assertion instead of the query itself.

@alexkrolick
Copy link
Contributor

https://github.com/NicholasBoll/cypress-pipe

I wonder if basing the queries on this other plugin get closer to the default behavior

@iamawebgeek
Copy link

I need this retry functionality is there any change this going to be merged or anyone have ideas how to achieve this alternatively?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants