Table of content

Fixture folder in cypress

In this fixture folder, the test data are stored. While executing, Cypress contacts the fixture folder automatically to retrieve the test data.

In the fixture folder, create a file named user.json and put below data

  "username": "invalid username",
  "password": "invalid password"

Let us understand, how the values from the user.json file are retrieved with the help of a program.

  • Filename : Filename without extension
  • Parameter_name : The key value given in the JSON file

In the below code, we are retrieving the values from the file called user.json and parameter called username, password.

const username = user.username;
const password = user.password;

Example program :

describe("Overriding the fixture file", function () {
  it("try to login", () => {
    cy.fixture("user").then((user) => {
      const username = user.username;
      //it is mentioned like user.username since we are getting the details form the user.json file 
      const password = user.password;
      cy.contains("Sign in").click();

Output :


Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions