Table of content

Fixture folder in Cypress IO

Fixtures are used to store the data in external files in cypress, we normally store such data in the Fixtures folder. While executing, Cypress retrieves the test data from the Fixtures folder. Fixtures folder is created by default when we install the cypress npm package.

Based on your project need can also configure other folders for fixtures. 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.

//Syntax 
<Filename>.<parameter_name>
  • 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 parameters called username, password.

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

Example program :

describe("Overriding the fixture file", function () {
  it("try to login", () => {
    cy.visit("http://zero.webappsecurity.com/login.html");
    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.get("#user_login").type(username);
      cy.get("#user_password").type(password);
      cy.contains("Sign in").click();
    });
  });
});

Output :
overriding-fixture-file

0 results
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions