Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Karate 如何在空手道框架中运行具有CSV文件的测试场景时创建ID的累积数组(从Json响应中获得)_Karate - Fatal编程技术网

Karate 如何在空手道框架中运行具有CSV文件的测试场景时创建ID的累积数组(从Json响应中获得)

Karate 如何在空手道框架中运行具有CSV文件的测试场景时创建ID的累积数组(从Json响应中获得),karate,Karate,我有一个CSV文件(大约300行)来读取Json负载中传递的值。在对每个CSV文件的行执行此测试场景时,Json响应中会生成一个新ID,即响应包含CSV文件中存在的每一行的ID 例如: 对于CSV第1行,Id=1 对于CSV第2行,Id=2 " " 对于CSV第n行,Id=n Scenario Outline: Create new content value (using CSV file) for movie: <Movie> with Cast: <Cast>

我有一个CSV文件(大约300行)来读取Json负载中传递的值。在对每个CSV文件的行执行此测试场景时,Json响应中会生成一个新ID,即响应包含CSV文件中存在的每一行的ID

例如: 对于CSV第1行,Id=1 对于CSV第2行,Id=2 " " 对于CSV第n行,Id=n

Scenario Outline: Create new content value (using CSV file) for movie: <Movie> with Cast: <Cast>
    When json payload = {'attributes':[{'entity_attribute_id': 41, 'value': '<Genre>'},{'entity_attribute_id': 42, 'value': '<Language>'},{'entity_attribute_id': 39, 'value': '<Movie>'},{'entity_attribute_id': 101,'value': '2020-12-03'}],'entity_type_id': '10'}   
    Given url baseUrl + postContentValues   
    And def cookie = read('content-cookie.txt')
    And header cookie = cookie
    And request payload
    When method post
    Then status 200
    And print response
    And def contentId = response.id
    And print contentId
    And def createdContentIdList = karate.append(contentId)
    And print createdContentIdList
#   And def createdContentIdList = karate.append(contentId)
#   And def createdContentIdList = []
#   And def fun = function(x){ karate.appendTo(createdContentIdList, x) }
#   And karate.forEach(contentId, fun)
#    And print createdContentIdList
    Examples:
    |read('RoughTable.csv')|

Scenario Outline: Pass contentID in URL

    Given url baseUrl + getSpecificContentValue +'<contentValueId>' + '?client=web&'
    When method get
    Then status 200
    And print response

    Examples:
    |contentValueId|
    |contentId     |
场景大纲:为电影创建新内容值(使用CSV文件):使用演员阵容:
当json有效负载={'attributes':[{'entity_attribute_id':41,'value':''''},{'entity_attribute_id':42,'value':'''},{'entity_attribute_id':39,'value':'''''},{'entity_attribute id':101,'value':'2020-12-03'},'entity_type_id':'10'}
给定url baseUrl+postContentValues
def cookie=read('content-cookie.txt')
和头cookie=cookie
和请求有效载荷
当方法发布时
然后状态200
并打印回复
和def contentId=response.id
并打印contentId
和def createdContentId=karate.append(contentId)
并打印CreatedContentList
#和def createdContentId=karate.append(contentId)
#和def createdContentList=[]
#def fun=function(x){karate.appendTo(createdContentList,x)}
#还有空手道。forEach(contentId,fun)
#并打印CreatedContentList
示例:
|读取('RoughTable.csv')|
场景大纲:在URL中传递contentID
给定url baseUrl+getSpecificContentValue+'+'?客户端=web&'
当方法得到
然后状态200
并打印回复
示例:
|contentValueId|
|内容ID|
如果我使用karate.append()或karate.appendTo(),将生成以下CreatedContentList(这是不正确的):

现在,我想创建一个数组(名为ContentID),它包含所有行的ID,如 ContentID=[1,2,3,….n]

并将内容id逐个传递到下一个api的url。

我用空手道怎么做


提前谢谢

不要使用
方案大纲
它不是为跨
方案
-s共享数据而设计的,您只能使用一些预先存在的数据

使用第二个要素文件,请参见以下示例:


另外,请阅读以下内容:

上述问题的解决方案如下:

Feature: Movie List 

Background:
    And configure headers = ('classpath:karate-config.js')

Scenario Outline: Create new content value (using CSV file) for movie: <Movie> with Cast: <Cast>

    When json payload = {'attributes':[{'entity_attribute_id': 41, 'value': '<Genre>'},{'entity_attribute_id': 42, 'value': '<Language>'},{'entity_attribute_id': 39, 'value': '<Movie>'},{'entity_attribute_id': 101,'value': '2020-12-03'}],'entity_type_id': '10'}   
    Given url baseUrl + postContentValues   
    And def cookie = read('content-cookie.txt')
    And header cookie = cookie
    And request payload
    When method post
    Then status 200
    And print response
    And def contentId = response.id

    Given url baseUrl + getSpecificContentValue + contentId + '?client=web&'
    When method get
    Then status 200
    And print response

    Examples:
    |read('RoughTable.csv')|
功能:电影列表
背景:
和configure headers=('classpath:karate config.js')
场景大纲:为电影创建新内容值(使用CSV文件):使用演员阵容:
当json有效负载={'attributes':[{'entity_attribute_id':41,'value':''''},{'entity_attribute_id':42,'value':'''},{'entity_attribute_id':39,'value':'''''},{'entity_attribute id':101,'value':'2020-12-03'},'entity_type_id':'10'}
给定url baseUrl+postContentValues
def cookie=read('content-cookie.txt')
和头cookie=cookie
和请求有效载荷
当方法发布时
然后状态200
并打印回复
和def contentId=response.id
给定url baseUrl+getSpecificContentValue+contentId+'?客户端=web&'
当方法得到
然后状态200
并打印回复
示例:
|读取('RoughTable.csv')|
上述场景的步骤执行如下: Extract CSV record>Pass in JSON payload>Hit API url to get First records response>定义一个变量以复制ID(来自响应)>Pass ID(在上一步中获得)作为下一个API的url参数>响应将给出指定ID的详细信息


注意:此步骤将重复,直到CSV文件的最后一条记录。

我想从JSON有效负载中CSV文件行上获得的JSON响应创建一个数组。每次获取并执行一行>获得JSON响应,该响应具有唯一id>我想要一个列表/数组,其中包含从每个CSV记录生成的所有id感谢您@Peter为查找所有查询的答案提供支持。因此,有两个调用,第二个调用使用第一个调用中返回的id-这就是“hello world”的例子确实如此,所以我不明白是什么让人如此困惑,你能解释一下,这样我就可以修改文档了吗