空手道 - 无法在另一个请求中使用功能响应
我无法使用一次调用的响应来准备新的有效负载。 从 auth-feature 响应准备标头时也会出现相同的错误。 下面是标题的示例。
Background:
* url baseUrl
* def resp = call read('classpath:auth-token.feature') { username: 'xxx', password: 'xxx' }
* def token = resp.authToken
* print 'token is ' , token
* def authHeader = { Authorization: Bearer '#(token)' }
* print 'header is ' ,authHeader
第一个打印工作正常,但第二个打印无法解析。
23:54:09.217 [main] INFO com.intuit.karate - [print] token is xxxxxx.eyJzdWIiOiJUTVVQQFRNVVAiLCJvYm8iOiJmYWxzZSIsImV4cCI6MTY0NjQ1NjY0OX0.xxxxxx
23:54:09.222 [main] INFO com.intuit.karate - [print] header is {
"Authorization": "Bearer '#(token)'"
}
文档说
如果 JSON(或 XML)对象声明中的字符串值是 包含在 #( 和 ) 之间 - 它将被评估为 JavaScript 表达。
I'm unable to use the response of one call to prepare a new payload.
Same error is coming in preparing a header from auth-feature response.
Below is the example for header.
Background:
* url baseUrl
* def resp = call read('classpath:auth-token.feature') { username: 'xxx', password: 'xxx' }
* def token = resp.authToken
* print 'token is ' , token
* def authHeader = { Authorization: Bearer '#(token)' }
* print 'header is ' ,authHeader
First print works fine but the second is unable to resolve.
23:54:09.217 [main] INFO com.intuit.karate - [print] token is xxxxxx.eyJzdWIiOiJUTVVQQFRNVVAiLCJvYm8iOiJmYWxzZSIsImV4cCI6MTY0NjQ1NjY0OX0.xxxxxx
23:54:09.222 [main] INFO com.intuit.karate - [print] header is {
"Authorization": "Bearer '#(token)'"
}
The documentation says
if a string value within a JSON (or XML) object declaration is
enclosed between #( and ) - it will be evaluated as a JavaScript
expression.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请阅读文档的这一部分: https://github.com/karatelabs/ karate#rules-for-embedded-expressions
试试这个:
Please read this part of the docs: https://github.com/karatelabs/karate#rules-for-embedded-expressions
Try this: