Cypress Fixtures

Cypress fixtures can be used to store test data. Fixture files are stored in fixtures directory. Here is a example.json which stores the firstName and lastName.

{
    "firstName": "Sagar",
    "lastName": "Salunke"
    }
 
                    
We are reading firstName from above file and then entering this value in UI.

describe('Softpost Test', function () {
    
    before(function(){
       //load fixture data
       cy.fixture('example').then(function(data){
          this.data=data
       })
    })

    it('Use fixture data', function (){
       
       cy.visit("https://softpost.org/selenium-test-page")
       
       cy.get('#fn').type(this.data.firstName)
    });
 });

                    
Complex problems, Simple Solutions