简体   繁体   English

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

[英]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.

相关问题 空手道框架保存来自 1 个请求的响应,然后在另一个请求中使用 - karate framework save response from 1 request and then use in another request 空手道 API 测试 - 如何在同一功能中使用从 API 1 到另一个 API 的变量(响应输出) - Karate API Testing - How to use a variable (output from response) from API 1 to another API in same feature 空手道-从另一个特征文件中的响应中获取字段的值 - Karate- get value of a field from response in another feature file 空手道-如何从响应/通过运行另一个功能文件获取数据 - KARATE - How to get data from response/by running another feature file 如果在空手道的 feature2 中调用了 json,则一个 feature1 文件无法运行另一个 feature2 文件 - One feature1 file unable to run another feature2 file if have json called in feature2 in karate 当被调用的特性在空手道框架中发出肥皂请求时,无法访问被调用的特性响应值 - Can not access a called feature response values when called feature is making soap request in karate framework 如何传递 karate.prevRequest 和 response 是 arguments 从一个功能文件到另一个功能文件 - How to pass karate.prevRequest and response are the arguments from one feature file to another feature file 空手道API如何捕获响应值以作为请求传递给另一个API - karate API how to capture a response value to pass as request to another API 如何将一个功能的完整响应作为请求传递给另一个功能 - How to pass complete response of one feature as a request to another feature 如何使用空手道将的背景响应值传递给函数值中的另一个功能json - How to pass the background response value of the to another feature json in function value using Karate
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM