英文:
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
<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
得分: 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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论