在空手道中编辑(更新,删除)标题之一

时间:2019-01-22 06:31:36

标签: karate

我的头文件位于.js文件中,我正在使用

读取该头文件
* configure headers = read('classpath:services/Headers/distheader.js')

问题1

  • 如何在运行时使用脚本数据编辑此文件中的头之一? 我尝试设置* header 'xyz' = 'value',但没有对其进行编辑。

问题2

  • 如果要删除其中一个标头,怎么可能?

1 个答案:

答案 0 :(得分:1)

因此您90%的方案都是“幸福之路”,并且您已配置了headers JS。

现在,您需要一些方案来具有更多(或更少的标题)。一种选择是对这些方案的标题进行硬编码,请注意,您可以执行* configure headers = null来禁用“自动”标题。然后使用header(或headers)关键字并手动构建标题。

另一种选择是,您可以调用headers函数并获取JSON-然后先进行突变(添加/删除键),然后再手动设置。例如:

# you can disable headers if needed
* configure headers = null

# headers.feature is: function(){ return { a: 1, b: 2 } }
* def fun = read('headers.feature')
* def temp = fun()
* remove temp.a
* set temp.c = 3

Given url 'https://httpbin.org'
And path 'anything'
And headers temp
When method get
Then status 200

所以上面的优点是万一您的标头例程很复杂,您可以重复使用它-但仍具有细粒度的控制。