Search

Cypress Fixtures

Cypress fixtures are used to load data into your test files.



You can add data to your fixture files in any format you prefer in the following,


Click on examples.json under fixtures folder, or create your own file as you like and enter the data you need for your tests.

Now go to your test file, use the following command to load your fixture file.


cy.fixure('fixturefilename')

and assign to a variable by using 'then' function,

cy.fixture('example').then(function(value){
    cy.log(value.dataname)
})

To define it globally, you can add the same fixture code inside 'Before' or 'Before Each' hooks and assign it to a global variable.


let userdetails
 beforeEach("loadfixture",function(){
       cy.fixture('example').then(function(value){
       userdetails=value
        })

Complete code:


describe("testingfixturesuite",()=>{
 let userdetails
 beforeEach("loadfixture",function(){
 cy.fixture('example').then(function(value){
 userdetails=value
        })
    })
 it("test1",()=>{
 cy.visit("https://coderscamp.wixsite.com/codeit")
 cy.contains('Forum').click()
 cy.get('._1quPh').type(userdetails.searchterm1)
 
    })

 it("test2",()=>{
 cy.visit("https://coderscamp.wixsite.com/codeit")
 cy.contains('Forum').click()
 cy.get('._1quPh').type(userdetails.searchterm3)
 
    })
})

19 views0 comments

Recent Posts

See All

A string s is called good if there are no two different characters in s that have the same frequency. Given a string s, return the minimum number of characters you need to delete to make s good. The f

The numeric value of a lowercase character is defined as its position (1-indexed) in the alphabet, so the numeric value of a is 1, the numeric value of b is 2, the numeric value of c is 3, and so on.