https://cypress.io logo
Hey. I want to check a page for links to product c...
# e2e-testing
c
Hey. I want to check a page for links to product collections, then visit each collection page and check it for products. When the test visits these pages,
cy.get
cannot find anything in the DOM. I am new to Cypress, so maybe my assumptions about how thing work are wrong. The code is in the comment.
Copy code
// Check if there are any product collections
Cypress.Commands.add('checkProductCollections', () => {
    cy.visit('/products/collections')
    cy.get('.css-grid').within(() => {
        // Visit each collection and check for products
        cy.get('.card__link').each(($el, index, $list) => {
            cy.visit($el[0].href)
            cy.get('.list-products').within(() => {
                cy.get('list-products__product')
            })
        })
    })
})