如何在空手道框架中编辑已配置的标头 [英] How to edit configured headers in karate framework
问题描述
在我的框架中,我有headers.js文件.我正在使用命令* configure headers = read('headers.js')
在每个功能文件的背景上调用该js文件.如预期的那样,在某些情况下,我需要更改"client-id"值.例如headers.js有一个client-id = xyz,我需要更改client-id = abc来解决几种情况,其余的都使用client-id作为xyz(我的标头有20个不同的值,我不想写需要功能文件中的内容)是否可以修改headers.js文件中的一个值并将其用作请求的标头?
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?
推荐答案
配置的标头始终是最后一个要应用的标头.因此,最适合您的解决方案是创建第二个headers-xyz.js
,并且仅针对那些所需的方案创建* configure headers = read('headers-xyz.js')
.
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')
.
由您决定重构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;
}
这篇关于如何在空手道框架中编辑已配置的标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!