简体   繁体   English

如何将一个功能文件的json列表响应作为参数传递给另一功能文件

[英]How to pass the json list response of one feature file as parameter to another feature file

My requirement is, I want to pass the response of first feature file as input to second feature file. 我的要求是,我想将第一个功能文件的响应作为输入传递给第二个功能文件。 The first feature file response is a json list, so the expectation is second feature file should be called for each value of json list. 第一个功能文件响应是一个json列表,因此可以预期的是应该为json列表的每个值调用第二个功能文件。

     Feature: 
      Scenario: identify the reference account
      * def initTestData = read('../inputData.feature')
      *  def accountData = $initTestData.response
      * print “Account Details”+accountData // output of this is a json list  [“SB987658”,”SB984345”]
      * def reqRes = karate.call('../Request.feature', { accountData : accountData })

In Request.feature file we are constructing the url dynamically 在Request.feature文件中,我们正在动态构建url

   Given url BaseUrl + '/account/'+'#(accountId)' -  here am facing issue http://10.34.145.126/account/[“SB987658”,”SB984345”]

My requirement is Request.feature should be called for each value in 'accountData' Json list 我的要求是Request.feature应该为'accountData'Json列表中的每个值调用

I have tried: 我努力了:

 * def resAccountList = karate.map(accountData, function(x){accountId.add(x) }) 
 * def testcaseDetails = call read('../requests/scenarios.feature') resAccountList.accountId

Result is same, accountId got replaced as [“SB987658”,”SB984345”] 结果相同,accountId被替换为[“ SB987658”,“ SB984345”]

my I need to call Request.feature twice http://10.34.145.126/account/SB987658 http://10.34.145.126/account/SB984345 and use the response of each call to the subsequent feature file calls. 我需要两次调用Request.feature http://10.34.145.126/account/SB987658 http://10.34.145.126/account/SB984345并使用每个调用对后续功能文件调用的响应。

I think you have a mistake in karate.map() look at the below example: 我认为您在karate.map()有一个错误, karate.map()以下示例:

* def array = ['SB987658', 'SB984345']
* def data = karate.map(array, function(x){ return { value: x } })
* def result = call read('called.feature') data

And called.feature is: called.feature是:

Feature:

Scenario:
Given url 'https://httpbin.org'
And path 'anything', value
When method get
Then status 200

Which makes 2 requests: 发出2个请求:

https://httpbin.org/anything/SB987658
https://httpbin.org/anything/SB984345

暂无
暂无

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

相关问题 如何传递 karate.prevRequest 和 response 是 arguments 从一个功能文件到另一个功能文件 - How to pass karate.prevRequest and response are the arguments from one feature file to another feature file 如何从一个特征文件表中读取数据并传递值以在空手道的 *.json 文件中设置 json 参数? - How to read data from one feature file table and pass the value to set json parameter in a *.json file in karate? 如何将一个功能的完整响应作为请求传递给另一个功能 - How to pass complete response of one feature as a request to another feature 如果在空手道的 feature2 中调用了 json,则一个 feature1 文件无法运行另一个 feature2 文件 - One feature1 file unable to run another feature2 file if have json called in feature2 in karate 空手道:将变量从一个特征文件传递到另一个作为查询参数 - Karate : Passing variable from one feature file to another as a query parameter @karate 如何将参数传递给加特林模拟类中的特征文件? - @karate How to pass parameter to a feature file in gatling simulation class? 空手道 Api 测试 - 如何将数据从一个特征文件传递到另一个特征文件 - Karate Api Testing - How to pass data from one feature file to another 用.@读取 json 响应。 功能文件失败 - Reading json response with .@. fails in feature file 空手道-如何从响应/通过运行另一个功能文件获取数据 - KARATE - How to get data from response/by running another feature file 空手道无法将JSON传递到功能文件 - Karate Unable to pass JSON into feature file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM