繁体   English   中英

空手道-从另一个特征文件中的响应中获取字段的值

[英]Karate- get value of a field from response in another feature file

我有一个场景,我需要从另一个功能文件的响应中获取特定字段并重新使用它。

场景:- 功能文件 A 处理 POST,在那里我得到响应并将字段 userId 保存在变量 myuser 中。
示例响应:- { 用户:“123”层:“钻石”}

我将值保存为 *def myuser =response.user

我想从另一个功能文件 B 调用功能文件 A。我不想将任何参数传递给功能文件 A。我的代码看起来像

  • def ResponseA = read('classpath:FeaturefileA.feature')
  • def currentuser =ResponseA.user

这可能是不正确的。我的基本需求是将功能文件 A 中的 myuser 值获取到功能文件 B 中的变量,并在功能文件 B 的场景中使用。请告知。 谢谢你。

(a.feature) 功能文件 A: POST 方法,它为您提供如下响应:

{ user:"123" tier:"diamond" }

(b.feature) 特征文件 B:

 * def fileA = call read('../FOLDER NAME/a.feature')
 * def fileAResponse = fileA.response
 * print fileAResponse

b.feature 中的上述代码将打印 a.feature 的响应

希望这是你想要的吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM