How to get the exception that was thrown when a Cucumber test failed in Java?

前端 未结 7 750
攒了一身酷
攒了一身酷 2021-01-13 02:07

I can perform actions on test failure by using:

@After
public void afterTest(Scenario scenario) {
    if (scenario.isFailed()) {
        /*Do stuff*/
    }
}         


        
7条回答
  •  臣服心动
    2021-01-13 02:43

    For cucumber-js https://www.npmjs.com/package/cucumber/v/6.0.3

    import { After } from 'cucumber'
    
    After(async function(scenario: any) {
        const exception = scenario.result.exception
        if (exception) {
            this.logger.log({ level: 'error', message: '-----------StackTrace-----------' })
            this.logger.log({ level: 'error', message: exception.stack })
            this.logger.log({ level: 'error', message: '-----------End-StackTrace-----------' })
        }
    })
    

提交回复
热议问题