Skip to content

Before in a forEach loop #20934

Apr 6, 2022 · 1 comments · 3 replies
Discussion options

You must be logged in to vote

It sounds like cypress-each would help you out here. You'll have the visit inside the it block and group all your tests together.

import 'cypress-each'

const array = [
    ['/', 'Home page'],
    ['/about', 'About Page'],
    ['/contact', 'Contact Page']
]

describe('iterate and hit each page', () => {
    it.each(array)('%s page has %s header', (page, header) => {
        cy.visit(page)
        cy.contains('h1', header).should('be.visible')
    })
})

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Ilie-c
Comment options

@Ilie-c
Comment options

Answer selected by Ilie-c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants