I want to be able to write log statements, that get added to the karate.log file as well as to the Cucumber Reports that get generated when using standalone karate.jar
.
When I use karate.log
from a javascript function it only adds the log statement to the karate.log
file and not the cucumber report.
I have also tried to do this from a java
function as well by using both slf4j
logger as well as the com.intuit.karate.Logger
class. However both of these only add logs to the karate.log
file and not to the cucumber reports.
I need this because I am writing some common code for which I don't want my QA-Engineers to write * print <>
statements in the karate feature files.
I also looked at the com.intuit.karate.core.ScriptBridge.log(Object... objects)
method which is what I am assuming gets called when you call karate.log(..)
, it looks like it should work, but it isn't working for me.
I am using karate-0.9.4, and here's what my karate-config.js
looks like
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
}
This is because of a bug in karate-0.9.4
which seems to be partially fixed in karate-0.9.5.RC4
release. I have opened a ticket for it on GitHub - https://github.com/intuit/karate/issues/975