0

I try to use aftereach() but it will execute either the testcase is passed or failed. I need to know the context of that should i use for example if condition or what? For example:

describe('TestSuite', function(){

 it('THIS TEST CASE PASSED', function(){

})

it('THIS TEST CASE FAILED', function(){

})

})

I need to make it like this. If the a testcase is passed do the actions
... ... ...
and if the testcase failed do the actions
... ... ...

1 Answers1

0

You didn't give much info about your code, so I will suggest a solution that might not be suited for you. I would use a variable that gets set to "fail" if an assertion fails in the previous test and use that to determine the action in the 2nd test, e.g.

describe('check if first test passed or failed then do A or B', () => {
    let result

    it('test 1', () => {
        cy.request({url: Cypress.env('url')}).its('status').then((status) => {
            if (status === 500) {
                result = 'fail'
            }
        })
    })

        it('test 2', () => {
            if (result === 'fail') {
                cy.log('Previous test failed, so I did Action A')
                Code Action A
            }
            else
            {
                cy.log('Previous test passed, so I did Action B')
                Code Action B
            }

        })
})
cypher_null
  • 632
  • 8
  • 22