空手道-从另一个特征文件中的响应中获取字段的值
Karate- get value of a field from response in another feature file
我有一个场景需要从另一个功能文件的响应中获取特定字段并重新使用它。
场景:-
功能文件 A 处理 POST,我在其中得到响应并将字段 userId 保存在变量 myuser 中。
示例响应:-
{
用户:“123”
等级:"diamond"
}
我将值保存为 *def myuser =response.user
我想从另一个特征文件B调用特征文件A。
我不想将任何参数传递给特征文件 A。
我的代码看起来像
- def ReponseA = 读取('classpath:FeaturefileA.feature')
- def 当前用户 =ResponseA.user
这可能是 incorrect.My 基本需要是从特征文件 A 中获取 myuser 值到特征文件 B 中的变量,并在 sceanrios 中用于特征文件 B.Kindly 建议。谢谢。
(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
的响应
希望这就是你想要的?
我有一个场景需要从另一个功能文件的响应中获取特定字段并重新使用它。
场景:-
功能文件 A 处理 POST,我在其中得到响应并将字段 userId 保存在变量 myuser 中。
示例响应:-
{
用户:“123”
等级:"diamond"
}
我将值保存为 *def myuser =response.user
我想从另一个特征文件B调用特征文件A。 我不想将任何参数传递给特征文件 A。 我的代码看起来像
- def ReponseA = 读取('classpath:FeaturefileA.feature')
- def 当前用户 =ResponseA.user
这可能是 incorrect.My 基本需要是从特征文件 A 中获取 myuser 值到特征文件 B 中的变量,并在 sceanrios 中用于特征文件 B.Kindly 建议。谢谢。
(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
的响应希望这就是你想要的?