1

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 Answers1

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

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • Thanks Peter Yes, Throwing an exception works and the message appears in the report. I am trying to find another way how to do that without failing the test with the exception. – Evgeny Tkachenko Mar 15 '20 at 23:27
  • @EvgenyTkachenko isn't it simple. return a `Map` that has 2 entrires - a boolean `result` and a String `message`. then just use `print` – Peter Thomas Mar 16 '20 at 01:50
  • Thanks That's the option I will go with. I hoped there is the way to post all logs or error logs from Java to the katate cucumber report – Evgeny Tkachenko Mar 16 '20 at 16:15
  • @EvgenyTkachenko you can if you don't mind importing `com.intuit.karate.Logger` and also see this: https://stackoverflow.com/a/57079152/143475 – Peter Thomas Mar 16 '20 at 16:26
  • import com.intuit.karate.Logger; private static final Logger LOGGER = new Logger(); LOGGER.info("1!!!!!!!!!!!!!!!!!!!!"); @Peter This helps to log to the console or to the file but not to the Cucumber report Thanks for helping me out – Evgeny Tkachenko Mar 16 '20 at 17:42
  • The problem is that I do not see any logs in the cucumber-html report. I use karate 0.9.4 and parallel runner and logback.xml with – Evgeny Tkachenko Mar 17 '20 at 12:21
  • @EvgenyTkachenko follow this process if you think this is a problem: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue – Peter Thomas Mar 17 '20 at 12:22