Cypress tests, one test is over, second starts

Viewed 74

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 me

2 Answers

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
            })
        
    })
})

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.

Related