I'm new to cypress and I just hit this problem I seem unable to solve.
What I'm trying to do is this: on an eshop page, there's this "Show More Products" button (sorry for the language :)):
If I click it, I'll see more products on the page. I need to be able to click this button for as long as I can see it on the page. The reason is there might be many products and clicking the button just once will not get me to the end of the list, so I still might not be able to see all the products.
The way I see it, this is a simple while loop with a condition.
And now comes cypress and its asynchronous nature and the page on Conditional Testing I've skimmed through the page, looked for information here and on stackoverflow, tried out some code, but the result is still the same, I have not solved this simple problem. How would you go about this?
Well, now after I've written all this, there might be one option... I have information about how many pages there're (on the right side in the pic). But it just feels like a horrible solution anyway.
cy.get
, and then chain.then
after the.get
, you can use that return value in the body of the.then
.tryShowMoreProducts
function that would check for the button and click it if it's present, thereby visiting the next page. In that case you're not explicitly returning anything. I've gotten some code to work in our tests that involve returning a Promise, then usingcy.wrap
and other similar features to get the code that uses the return value to run at the right time, but I'm far from an expert. It's still a "throw code at the wall until something sticks" exercise, for the most part.