[英]Karate - Unable to use a feature response in another request
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.
从 auth-feature 响应准备 header 时出现同样的错误。 Below is the example for header.
以下是 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.
如果 JSON(或 XML)object 声明中的字符串值包含在 #( 和 ) 之间 - 它将被评估为 JavaScript 表达式。
Please read this part of the docs: https://github.com/karatelabs/karate#rules-for-embedded-expressions请阅读文档的这一部分: https://github.com/karatelabs/karate#rules-for-embedded-expressions
Try this:尝试这个:
* def temp = 'Bearer ' + resp.authToken
* def authHeader = { Authorization: '#(temp)' }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.