无法在空手道功能文件中打印 Headers
Cant print Headers in karate feature file
我正在使用空手道 (https://github.com/intuit/karate) 进行一些 API 测试,并且有一个无效 headers 的测试。我想在调试时打印 headers ,以确保一切设置正确。这就是我设置并尝试打印的方式,但没有任何效果。我可以在文档中找到关于它的任何内容。有人知道吗?非常感谢!!
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
如何打印要发送的headers?
我很惊讶你没有在控制台和日志中看到 headers target/karate.log
- 这应该默认发生,你可以按照此处的说明进行操作:https://github.com/intuit/karate#logging
另请参阅 built-in 变量的文档,而不是尝试猜测它们:https://github.com/intuit/karate#responseheaders
但是如果你真的想打印实际发送的headers(很少需要),你可以这样做:
* print 'headers:', karate.prevRequest.headers
这里有解释:https://github.com/intuit/karate#karate-prevrequest
编辑:我注意到你可能犯了一个常见的错误,当你在 JSON 键中有连字符时 - 你需要使用字符串引号:
And headers { Authorization: 'INVALID', 'Content-Type': '#(headerValue)' }
是的,这在文档中也有解释。
我正在使用空手道 (https://github.com/intuit/karate) 进行一些 API 测试,并且有一个无效 headers 的测试。我想在调试时打印 headers ,以确保一切设置正确。这就是我设置并尝试打印的方式,但没有任何效果。我可以在文档中找到关于它的任何内容。有人知道吗?非常感谢!!
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
如何打印要发送的headers?
我很惊讶你没有在控制台和日志中看到 headers target/karate.log
- 这应该默认发生,你可以按照此处的说明进行操作:https://github.com/intuit/karate#logging
另请参阅 built-in 变量的文档,而不是尝试猜测它们:https://github.com/intuit/karate#responseheaders
但是如果你真的想打印实际发送的headers(很少需要),你可以这样做:
* print 'headers:', karate.prevRequest.headers
这里有解释:https://github.com/intuit/karate#karate-prevrequest
编辑:我注意到你可能犯了一个常见的错误,当你在 JSON 键中有连字符时 - 你需要使用字符串引号:
And headers { Authorization: 'INVALID', 'Content-Type': '#(headerValue)' }
是的,这在文档中也有解释。