top of page
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)
 
    })
})

41 views0 comments

Recent Posts

See All

Comments

Couldn’t Load Comments
It looks like there was a technical problem. Try reconnecting or refreshing the page.
bottom of page