Hi. I have problem with loop in this command. Increment does not stop at 4 (PRODUCTS_AMOUNT). Anyone have idea why? Thanks
Cypress.Commands.add("addRandomProductToCart", () => {
let producsCounter = 0;
const PRODUCTS_AMOUNT = 4;
const MAX_AMOUNT = 15;
const addToCart = () => {
ProductCard.availableQuantity.should("be.visible")
ProductCard.quantityInput.should("be.visible")
ProductCard.quantityMinus.should("be.visible")
ProductCard.quantityPlus.should("be.visible")
ProductCard.addToCartButton.should("be.visible")
ProductCard.addToCartButton.click()
}
for(let i = 0; i < MAX_AMOUNT; i++) {
cy.visit(getRandomItem(productCardsUrls));
cy.get("body").then(body => {
if (body.find(".showavailability > p").length > 0) {
addToCart();
producsCounter++
} else {
ProductCard.notifyIfAvailable.should("contains.text", "Powiadom mnie gdy produkt będzie dostępny")
}
})
if (producsCounter === PRODUCTS_AMOUNT) {
break;
}
}
})