Reputation: 101
I have this header which is in a .js
file and I am reading this header using
* configure headers = read('classpath:services/Headers/distheader.js')
Question #1
* header 'xyz' = 'value'
but it doesn't edit it.Question #2
Upvotes: 4
Views: 3736
Reputation: 58058
So 90% of your scenarios are "happy path", and you have a headers
JS configured.
Now you need some scenarios to have more (or less headers). One option is to hard-code the headers for those scenarios, note that you can do * configure headers = null
to disable the "auto" headers. Then use the header
(or headers
) keyword and build headers manually.
Another option is that you can invoke the headers function and get a JSON - and then mutate (add / remove keys) before setting headers manually. For example:
# 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
So the advantage above is in case your headers routine is complex, you can re-use it - but still have fine-grained control.
For more ideas, see: https://stackoverflow.com/a/76672675/143475
Upvotes: 3