How can I get Karate logs printed in the report?

烈酒焚心 提交于 2020-04-16 03:58:05

问题


I have

<logger name="com.intuit.karate" level="DEBUG"/>

in my logback-test.xml. But when I run my tests I see that when the step

* assert SchemaUtils.isValid(response, schema)

fails, I do not see any debug information in the Cucumber report (with the payload and description on which field is missing or which value is wrong), like:

error: object instance has properties which are not allowed by the schema: ["PrSKU"]
        level: "error"

I do see it in the console though:

{content_type=, value=21:54:25.380 assertion failed: assert evaluated to false: SchemaUtils.isValid(response, schema)21:54:25.413

How can I get logs printed in the report?

I found how to access previous request/response and the print it in the report:

// setup global hook to log details only on failed scenarios
    karate.configure('afterScenario', function(){
        var info = karate.info;
        if(info.errorMessage) {
            karate.log('failed',info.scenarioType+':',info.scenarioName);
            var r = karate.prevRequest;
            if(r) {
                var log = 'request: ' + r.method + ' ' + r.uri + '\n' + karate.pretty(r.headers)
                if(r.body) log += '\n' + karate.pretty(r.body)
                karate.log(log);
                karate.log('response: ' + karate.pretty(response));
            }
        }
    })

But I did not find the way how to access karate logs and then print them in the report.


回答1:


Since SchemaUtils.isValid(response, schema) seems to be custom Java code, I think if you throw any Exception the error message will be printed by Karate and should appear in the log as well as HTML report. If it does not, it can be a bug - so please follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue



来源:https://stackoverflow.com/questions/60693744/how-can-i-get-karate-logs-printed-in-the-report

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!