【问题标题】:Karate- get value of a field from response in another feature file空手道 - 从另一个特征文件中的响应中获取字段的值
【发布时间】:2019-03-20 01:12:50
【问题描述】:

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

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

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

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

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

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

【问题讨论】:

标签: variables karate


【解决方案1】:

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

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

(b.特征) 功能文件 B:

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

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

希望这是你想要的?

【讨论】:

  • 感谢 Ankit。我可以根据需要提取响应和确切的字段。
  • @Ankit 如何从另一个功能文件中调用变量?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-04-14
  • 1970-01-01
  • 1970-01-01
  • 2019-02-06
  • 2018-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多