Filipm64
Filipm64

Reputation: 47

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 me

Upvotes: 1

Views: 143

Answers (2)

Rosen Mihaylov
Rosen Mihaylov

Reputation: 1427

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

Upvotes: 3

Jeeva
Jeeva

Reputation: 448

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.

Upvotes: 0

Related Questions