将消息从Java类记录回空手道报告 [英] Logging Messages from Java Class back to the Karate Report
问题描述
我们有一个场景,我们必须发布一个json请求,然后验证UI中的一些动作.因此,我们有一个空手道功能文件,它会命中一个请求,然后再从功能文件中调用一个Java类. Java类将运行我们的Selenium Webdriver测试.在java方法中,我们很少有断言/信息消息,我们想重新登录空手道报告.
We have a scenario where we have to post a json request and then validate few actions in the UI. So we have a karate feature file which hits a request and after that we are invoking a java class from within the feature file. The java class would run the Selenium Webdriver test of us. In the java methods we have few Assertions/Info Messages which we would like to log back to the Karate Reports.
空手道中是否有一种方法可以将这些消息从Java类写入空手道测试报告中?
Is there a way in Karate with which we can write these messages from my Java Class to the Karate Test Reports?
推荐答案
如果使用空手道并行运行器,它旨在收集记录到包 cucumber-html-report .
If you use the Karate parallel runner it is designed to collect anything logged to package com.intuit.karate
, which will then appear in the cucumber-html-report.
因此,您可以尝试使用相同的slf4j Logger
-可能会起作用.
So you can try using the same slf4j Logger
- and it might work.
更好的方法可能是将Map
返回空手道从Java代码中获取所有需要记录的信息.然后,您所需要做的就是使用 print
关键字.我实际上会推荐这种方法,它应该不那么复杂,并且不假定您使用的是Cucumber HTML报告.您甚至可以在获取的JSON上使用match
关键字执行空手道断言,请参考以下示例:
A better way might be to just return a Map
back to Karate from your Java code, with all the information you need to log. Then all you need to do is use the print
keyword. I would recommend this approach actually, it should be less complicated and it does not assume that you are using the Cucumber HTML reporting. You could even do Karate asserts with the match
keyword on the JSON that you get, refer to this example: dogs.feature
.
这篇关于将消息从Java类记录回空手道报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!