Evgeny Tkachenko
Evgeny Tkachenko

Reputation: 13

How can I get Karate logs printed in the report?

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.

Upvotes: 1

Views: 4459

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58058

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

Upvotes: 1

Related Questions