无法在空手道功能文件中打印标题

1ak*_*sha 2 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
Run Code Online (Sandbox Code Playgroud)

如何打印将发送的标题?

Pet*_*mas 5

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

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

但是如果你真的想打印发送的实际标题(很少需要),你可以这样做:

* print 'headers:', karate.prevRequest.headers
Run Code Online (Sandbox Code Playgroud)

这在这里解释:https : //github.com/intuit/karate#karate-prevrequest

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

And headers { Authorization: 'INVALID', 'Content-Type': '#(headerValue)' }
Run Code Online (Sandbox Code Playgroud)

是的,这也在文档中进行了解释。

  • 我期待信息位于 https://github.com/intuit/karate#headers 部分 (2认同)