How to edit configured headers in karate framework

ⅰ亾dé卋堺 提交于 2021-02-05 07:13:51

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!