Skip to content
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

Get is not retrying itself #904

Closed
AyWa opened this issue Nov 11, 2017 · 3 comments
Closed

Get is not retrying itself #904

AyWa opened this issue Nov 11, 2017 · 3 comments

Comments

@AyWa
Copy link

AyWa commented Nov 11, 2017

  • Operating System: Mac OS Sierra 10.12.6
  • Cypress Version: 1.0.3
  • Browser Version: chrome 62.0.3202.89 64 bits

Is this a Feature or Bug?

It is a bug. Or I didn't get the documentation
get will automatically retry itself until assertions you've chained all pass.

Current behavior:

  cy.wait(['@getRoles'])
  cy.get(".myClass1 .myClass2") // time out was just to test
    .contains("Something")

Little tricky but when my apps mount the 'get' will target 3 element and after the request that I wait (and the rerender of react) the number of element will be 5.
Maybe my app rerender is too slow but it seems like the get will always target those 3 elements. (if i put a wait of 100ms before it the get it will target the 5)

will automatically retry itself until assertions you've chained all pass. seems to not working

Desired behavior:

Check if the selector change state when its direct chainer is not successfull

How to reproduce:

add an element after a timeout.

Test code:

  cy.wait(['@getRoles'])
  cy.get(".myClass1 .myClass2") // time out was just to test
    .contains("Something")
@jennifer-shehane
Copy link
Member

The state of your application that Cypress is looking for if the example you provided is that there are any elements that exist on the page matching .myClass1 .myClass2 with the content Something within those elements. The get will no longer retry if it finds this situation on the page.

If you want the tests to not continue until 5 elements are found in the get, you will need to write an assertion to that effect (so that the get will retry until that assertion is true).

Something like:

  cy.wait(['@getRoles'])
  cy.get(".myClass1 .myClass2").should("have.length", 5)
    .contains("Something")

Let me know if I understood your question correctly and if this solves it.

@AyWa
Copy link
Author

AyWa commented Nov 11, 2017

Thx for your answer. Yeah I understand. I thought 'contains' was an assertion and so it will work like a have length

@AyWa AyWa closed this as completed Nov 11, 2017
@brian-mann
Copy link
Member

Contains has a default assertion that it will retry until it finds an element with the matching content.

However it is independently run from the get. Once the get resolves the contains begins to run, scoped to whatever elements the get returned.

That's different than an assertion - an assertion acts as a "guard" on whatever it is chained to, preventing it from resolving until all of the associated assertions pass.

Have you read our guides? Specifically this one: https://docs.cypress.io/guides/core-concepts/introduction-to-cypress.html

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

No branches or pull requests

3 participants