Data driven testing with Cypress using fixtures

Quick sample code to use fixtures in Cypress to enable data-driven testing.

Bejoy Jaison |

How to use fixtures with Cypress test automation

Here's a quick example skeleton of how to create a fixture and use it to drive tests from a test spec.

Test Spec

cypress/integration/data-driven-tests.js

import fixtures from '../fixtures/data-driven-tests.json'

describe ("Check out fixtures", () => {
  // Fixture-data-driven tests
  fixtures.forEach((test) => {
    it('Test: ' + test.testName, () => {
      // Test code here
    }) // it()
  }) // fixture
}) // describe

Fixture

cypress/fixtures/data-driven-tests.json

[
  {
    "testName": "Test case 1"
    "testVariable1": "Value 1",
    "testVariable2": "Value 2"
  },
  {
    "testName": "Test case 2"
    "testVariable1": "Value 3",
    "testVariable2": "Value 4"
  }
]

Photo by Nubelson Fernandes on Unsplash

Posted under: Cypress, Test Automation, Agile Engineering

Read similar articles