Skip to content Skip to sidebar Skip to footer

Cypress Tests, One Test Is Over, Second Starts

I code cypress tests. When one test is over, I want the second test to begin with some variables whitch the second test will get from the first test. How can I code it? Please help

Solution 1:

You can use setCookie and getCookie:

context('Tests passing values', () => {
    it('test 1', function () {
        //Some code
        cy.setCookie('cookieName', 'valueToSave')
    });
    it('test 2', function () {
        //Some code
        cy.getCookie('cookieName')
            .should('have.property', 'value') //returns the value
            .then(savedValue => {
                //some code
            })
        
    })
})

Solution 2:

you might want to write the variable values from your first test to a file in fixtures (ex., JSON) and read the file in the second test and get the appropriate value.

Post a Comment for "Cypress Tests, One Test Is Over, Second Starts"