怎样才能在报告中打印出Karate日志?

huangapple go评论144阅读模式
英文:

How can I get Karate logs printed in the report?

问题

我在我的logback-test.xml中有以下配置:

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

但是当我运行测试时,我发现当步骤

* assert SchemaUtils.isValid(response, schema)

失败时,在Cucumber报告中我看不到任何调试信息(关于payload以及缺少哪个字段或哪个值错误的描述),类似于:

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

然而我在控制台中是可以看到的:

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

我如何在报告中打印日志?

我已经找到了如何访问先前的请求/响应并将其打印在报告中:

// 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));
        }
    }
})

但我没有找到访问karate日志并将其打印在报告中的方法。

英文:

I have

&lt;logger name=&quot;com.intuit.karate&quot; level=&quot;DEBUG&quot;/&gt;

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: [&quot;PrSKU&quot;]
        level: &quot;error&quot;

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(&#39;afterScenario&#39;, function(){
        var info = karate.info;
        if(info.errorMessage) {
            karate.log(&#39;failed&#39;,info.scenarioType+&#39;:&#39;,info.scenarioName);
            var r = karate.prevRequest;
            if(r) {
                var log = &#39;request: &#39; + r.method + &#39; &#39; + r.uri + &#39;\n&#39; + karate.pretty(r.headers)
                if(r.body) log += &#39;\n&#39; + karate.pretty(r.body)
                karate.log(log);
                karate.log(&#39;response: &#39; + karate.pretty(response));
            }
        }
    })

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

答案1

得分: 1

由于SchemaUtils.isValid(response, schema)似乎是定制的Java代码,我认为如果您抛出任何Exception,错误消息将由Karate打印,并应显示在日志以及HTML报告中。如果没有显示,这可能是一个错误 - 请按照此流程操作:https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue。

英文:

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

huangapple
  • 本文由 发表于 2020年3月15日 22:05:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/60693744.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定