cypressautomation-testing

Cypress Infinite Scroll


How can I scroll down and find a text with Cypress framework in "https://the-internet.herokuapp.com/infinite_scroll"? The text I want to find is "doloremque quasi voluptatibus fugiat ipsa eos quas culpa sed omnis nostrum enim quisquam."


Solution

  • You'll want to use recursion to do this.cypress-recurse is great for this.

    const textToFind = 'doloremque quasi voluptatibus fugiat ipsa eos quas culpa sed omnis nostrum enim quisquam.'
    recurse(
      () => {
        return cy.contains('.text-selector', 
        textToFind).should(Cypress._.noop)
      },
      ($text) => $text.length > 0 },
      {
        timeout:60_000, // you can alter these options
        delay:1_000,
        error: 'Could not find text',
      },
    )