Code Monkey home page Code Monkey logo

Comments (6)

NoriSte avatar NoriSte commented on July 26, 2024

You cannot use Cypress' assertions inside cy.waitUntil. cy.wrap already has retry-ability and timeout customization so go with it without using cy.waitUntil!

Your code should look like

  • standard version: cy.wrap('445').should('eq', '44')
  • custom timeout version: cy.wrap('445', {timeout: 20000}).should('eq', '44')
  • (not necessary) waitUntil version without wrap: cy.waitUntil(() => '445' === '44', { timeout: 20000, interval:2000 })
  • (not necessary) waitUntil version with wrap: cy.waitUntil(() => cy.wrap('445').then(myString => myString === '44'), { timeout: 20000, interval:2000 })

The general advice is: do not use cy.waitUntil if you can handle what you need with Cypress built-in functionalities.

Hope it helps, feel free to reopen the issue 😉

from cypress-wait-until.

SovaSlava avatar SovaSlava commented on July 26, 2024

Thank you for your answer!
But my example was only example..

This is real case:
When I visit my site, I can see some numbers in [class="tickers__price-value"]
After sometimes (1-10 seconds) numbers will change.
So, I dont want use cy.wait(10), I'd like end test as soon as numbers has been changed.

    cy.visit('/')
    cy.get('[class="tickers__price-value"]').invoke('text').then(firstDate => {
      cy.get('[class="tickers__price-value"]').invoke('text').should('not.eq', firstDate)
    })
  })

How set timeout there? using cy.waitUntil

from cypress-wait-until.

NoriSte avatar NoriSte commented on July 26, 2024

I have not tested it but this should be enough with cy.waitUntil 😉

cy.visit('/')
cy.get('[class="tickers__price-value"]')
  .invoke('text')
  .waitUntil(
    (firstDate) =>
      cy
        .get('[class="tickers__price-value"]')
        .invoke('text')
        .then((newDate) => newDate !== firstDate),
    {timeout: 20000}
  )

Please let me know if it works 😊

from cypress-wait-until.

SovaSlava avatar SovaSlava commented on July 26, 2024

Your code works perfect)
Big thanks)

from cypress-wait-until.

NoriSte avatar NoriSte commented on July 26, 2024

You're welcome 😊

from cypress-wait-until.

NoriSte avatar NoriSte commented on July 26, 2024

@SlavikDMI I was curious and I'd like to solve your problem with Cypress built-ins too... and I found the solution 😊 you can find everything in this repository and the file you need to checkout is issue.spec.js.

Long story short: in the Cypress docs there is an example of your use case that, applied to your code, looks like the following:

cy.get('[class="tickers__price-value"]')
  .invoke('text')
  .then((firstDate) => {
    cy.get('[class="tickers__price-value"]', { timeout: 20000 }).should(($el) => {
      const newDate = $el.text()
      expect(newDate).to.not.eq(firstDate)
    })
  })
  • the timeout must be set to the cy.get call
  • the text retrieval must be performed inside the .should(...) call

And it works fine 😊

Last but not least: if you have looked for a solution on Google/StackOverflow and you haven't found anything useful... Please help the community doing so

  • raise a new question on StackOverflow
  • explain well your problem and link to all the resources that seemed helpful but they weren't (and why)
  • I'll reply with the solution and you accept it

Doing so:

  • the next time you are looking for the same solution you find it directly searching on Google
  • you'll help other developers with the same problem
  • other useful and alternative solutions could come and we both learn something new

What do you think? 😊

from cypress-wait-until.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.