空手道 - 无法在另一个请求中使用功能响应

Karate - Unable to use a feature response in another request

我无法使用一次调用的响应来准备新的负载。 从 auth-feature 响应准备 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

第一次打印工作正常,但第二次无法解析。

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)'"
}

文档说

if a string value within a JSON (or XML) object declaration is enclosed between #( and ) - it will be evaluated as a JavaScript expression.

请阅读这部分文档:https://github.com/karatelabs/karate#rules-for-embedded-expressions

试试这个:

* def temp = 'Bearer ' + resp.authToken
* def authHeader = { Authorization: '#(temp)' }