我希望能够编写日志语句,将其添加到karate.log文件以及使用独立karate.jar
时生成的黄瓜报告中。
[当我从javascript函数使用karate.log
时,它仅将log语句添加到karate.log
文件,而不是黄瓜报告。
我还尝试通过使用java
记录器和slf4j
类从com.intuit.karate.Logger
函数中执行此操作。但是,这两个都只会将日志添加到karate.log
文件中,而不会添加到黄瓜报告中。
我需要这个,因为我正在编写一些我不希望我的QA工程师在空手道特征文件中编写* print <>
语句的通用代码。
[我还查看了com.intuit.karate.core.ScriptBridge.log(Object... objects)
方法,这是我假设在您调用karate.log(..)
时会被调用的方法,看起来它应该可以工作,但是对我来说不起作用。
我正在使用空手道-0.9.4,这是我的karate-config.js
的样子
function conf() {
var env = karate.env // set the environment that is to be used for executing the test scripts
var host = '<some-host-name>';
var port = '443';
var protocol = 'https';
var basePath = java.lang.System.getenv('GOPATH') + '/src/karate-tests';
// a custom 'intelligent' default
if (!env) {
env = 'dev';
}
var applicationURL = ((!port || port == '') || (port == '80' && protocol == 'http') || (port == '443' && protocol == 'https'))
? protocol + '://' + host
: protocol + '://' + host + ":" + port;
// Fail quickly if there is a problem establishing connection or if server takes too long to respond
karate.configure('connectTimeout', 30000);
karate.configure('readTimeout', 30000);
// pretty print request and response
//karate.configure('logPrettyRequest', true);
//karate.configure('logPrettyResponse', true);
karate.configure('printEnabled', true);
// do not print steps starting with * in the reports
//karate.configure('report',{showLog: true, showAllSteps: true });
// Turn off SSL certificate check
karate.configure('ssl', true);
var config = {
env: env,
appBaseURL: applicationURL,
sharedBasePath: basePath
};
karate.log("config.sharedBasePath = ", config.sharedBasePath)
karate.log('karate.env = ', config.env);
karate.log('config.appBaseURL = ', config.appBaseURL);
return config
}
我刚刚在0.9.5.RC4中尝试过。如果您正在寻找比这更多的东西-它需要改变空手道。欢迎您的贡献。我不得不说看到这些请求感到惊讶(有些生气)。您为什么如此关注漂亮的报告,而不是专注于测试。我希望您考虑一下。
此其他讨论可能是相关参考文献:https://github.com/intuit/karate/issues/951 | https://github.com/intuit/karate/issues/965
如果您真的想执行此操作,则可以查看此注释中提到的“挂钩”拦截器:https://github.com/intuit/karate/issues/970#issuecomment-557443551
因此在void afterStep(StepResult result, ScenarioContext context);
中-您可以通过调用StepResult
来修改appendToStepLog(String log)
。