空手道特征文件中的无法打印标题

时间:2018-07-30 18:24:42

标签: karate

我正在使用空手道(https://github.com/intuit/karate)进行一些API测试,并进行了带有无效标头的测试。我想在调试时打印出标题,以确保所有设置都正确。这是我设置并尝试打印的方式,但是没有任何效果。我可以在文档中找到任何内容。有人知道吗非常感谢!

Given path '/metadata/project/' + projectID + '/graph/' + graphID
And headers { Authorization: 'INVALID', Content-Type:#(headerValue)}
And request graphJSON
* print headers // prints nothing
* print requestHeaders  // prints nothing
* print requestHeader   // prints nothing
* print header // prints nothing
When method put
Then status 401 // this passes, so i know the header is being set
* print response // prints correctly
* print responseHeaders //prints correctly

如何打印将要发送的标题?

1 个答案:

答案 0 :(得分:1)

我很惊讶您没有在控制台和日志target/karate.log中看到标题-默认情况下应该会发生,您可以按照此处的说明进行操作:https://github.com/intuit/karate#logging

也请参考文档中的内置变量,而不要尝试猜测它们:https://github.com/intuit/karate#responseheaders

但是,如果您真的想打印发送的实际标题(很少需要),则可以执行以下操作:

* print 'headers:', karate.prevRequest.headers

在此进行解释:https://github.com/intuit/karate#karate-prevrequest

编辑:我注意到当JSON键中带有连字符时,您可能会犯一个常见错误-您需要使用字符串引号:

And headers { Authorization: 'INVALID', 'Content-Type': '#(headerValue)' }

是的,文档中也对此进行了解释。