I am trying to get the result of the test (each scenario ) in After hook [Referring https://stackoverflow.com/questions/66153949/get-test-status-after-each-test-in-cypress]
Cypress.mocha.getRunner().suite.ctx.currentTest.state
I am getting error "Property 'mocha' does not exist on type Cypress & CyEventEmitter"
I am using Cypress,Typescript with cucumber ,but since mocha is default with cypress , cypress.mocha should work in after hook
Any idea in how to fix this issue?
tsconfig.json file
{
"compilerOptions": {
"target": "es2016",
"lib": ["es6"],
"module": "commonjs",
"types": ["cypress","cypress-xpath","node"],
"resolveJsonModule": true,
"esModuleInterop": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true
}
}
Do I need change anything in tsconfig.json file ?
Update : I could solve the error(TypeScript Property 'mocha' does not exist on type Cypress & CyEventEmitter) by using [Referring link https://github.com/cypress-io/cypress/issues/2972#issuecomment-671779458] (Cypress as any).mocha.getRunner().suite...
But I am now facing Cannot read properties of undefined (reading 'state') Any help on this ?
Update: Cannot read properties of undefined (reading 'state') This resolved after replacing after hook with afterEach,Complete Resolution Provided in the Comment section
Note I am using cypress 12,node 18,cypress-cucumber-preproccesor 4.3