空手道特征文件中的无法打印标题 [英] Cant print Headers in karate feature file

查看:63
本文介绍了空手道特征文件中的无法打印标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using karate (https://github.com/intuit/karate) for some API testing and have a test with invalid headers. I would like to print the headers out while debugging, to make sure everything is being set properly. This is how i set and attempt to print, but nothing is working. I can find anything on it in the documentation. Does anybody know? Much appreciated!!

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

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

How to print the headers that will be sent?

推荐答案

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

I'm surprised you don't see the headers in the console and in the log target/karate.log - this should happen by default and you can follow the instructions here: https://github.com/intuit/karate#logging

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

Also refer to the docs for the built-in variables instead of trying to guess them: https://github.com/intuit/karate#responseheaders

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

But if you really want to print the actual headers sent (very rarely needed), you can do this:

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

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

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

I noticed you may be making a common mistake, when you have hyphens in the JSON key - you need to use string quotes:

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

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

And yes, this is explained in the docs as well.

这篇关于空手道特征文件中的无法打印标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆