Search code examples
typescriptimportautomated-testscypressfixtures

Cypress fixtures best practice


On the Cypress docs they recommend to use fixtures this way

cy.fixture('logo.png').then((logo) => { // load data from logo.png }) but I found it messy, and limiting because I can't reach this info outside a running test so I'm using

import cred from "../fixtures/login_creds.json"

Is there a downside to using import? of course I'm using it inside a cy method

cy.get(inputEmail).type(cred.email)

Solution

  • There's nothing wrong with importing a fixture.

    It can be useful for data-driven tests.

    import sites from '../fixtures/sites.json'
    
    sites.forEach(site => {
    
      it(`test ${site}`, () => {
        cy.visit(site)
        ...
      })
    })