如何在报告中打印空手道日志? [英] How can I get Karate logs printed in the report?

查看:88
本文介绍了如何在报告中打印空手道日志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有

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

在我的logback-test.xml中.但是当我运行测试时,我会看到步骤

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

* assert SchemaUtils.isValid(response, schema)

失败,我在Cucumber报告中看不到任何调试信息(带有有效负载和缺少哪个字段或哪个值错误的描述),例如:

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.

推荐答案

由于SchemaUtils.isValid(response, schema)似乎是自定义Java代码,我认为如果抛出任何Exception,则错误消息将由空手道打印,并应出现在日志以及HTML报告.如果不是,则可能是一个错误-因此,请按照以下过程进行操作:

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

这篇关于如何在报告中打印空手道日志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆