问题
In my framework I have headers.js file. I am calling that js file on background of every feature file using the command * configure headers = read('headers.js')
. This working as expected, some scenarios I need to change the 'client-id' value. For example headers.js has a client-id=xyz, I need to change client-id=abc for couple of scenarios rest all are using client-id as xyz (my headers have 20 different values, I don't want to write that in require feature files) Is there any way to modify one value from the headers.js file and use that as a header for the request?
回答1:
The configured headers always is the last to be applied. So the best solution for you is to create a second headers-xyz.js
and for only those needed scenarios do * configure headers = read('headers-xyz.js')
.
It is up to you to refactor the js code so that you can re-use most of it. For example, this might work:
function() {
var fun = karate.read('headers.js');
var res = fun();
res['client-id'] = 'xyz';
return res;
}
来源:https://stackoverflow.com/questions/49392114/how-to-edit-configured-headers-in-karate-framework