如何在空手道功能中遍历数组值 [英] How to loop over array values in a karate feature

查看:81
本文介绍了如何在空手道功能中遍历数组值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图遍历空手道特征文件中的数组值. 在Feature1.feature-Scenario1中,数组["UUID1","UUID2","UUID3"]中有一些值,并且我想调用另一个功能文件(Feature2.feature)(具有用于调用DELETE端点的代码) )的服务

I am trying to loop over array values in a karate feature file. In a Feature1.feature - Scenario1, I have some values in the array ["UUID1","UUID2","UUID3"] and I want to call another feature file (Feature2.feature) (having a code to call a DELETE endpoint) of a service

Feature2.feature:

Feature2.feature:

 @ignore

Feature: Delete

  Background:

    * url baseUrl
    * headers {content-type:'application/json'}

  Scenario: Delete Test Assets

    Given headers {uid: '#(UId)', cid:'#(CId)'}
    And path 'type', Type, 'id', AssetId
    When method delete
    Then status 204

我应该使用哪种方法对Feature1.feature进行循环调用?

What approach should I use to Feature1.feature to call the Feature2.feature in a loop?

推荐答案

如果具有原始数组,则需要在执行循环调用"之前将其转换为JSON对象数组.请参阅karate.mapWithKey()的文档: https://github.com/intuit/karate#json -转换

If you have an array of primitives, you need to convert it into an array of JSON objects before doing a "loop call". Refer to the docs for karate.mapWithKey(): https://github.com/intuit/karate#json-transforms

这样做:

* def data =  ["UUID1","UUID2","UUID3"]
* def data = karate.mapWithKey(data, 'uid')
* call read('second.feature') data

second.feature中:

* headers { uid: '#(uid)' }

当然,如果需要,请阅读call的文档: https://github.com/intuit/karate#data-driven-features

Of course, read the docs for call if needed: https://github.com/intuit/karate#data-driven-features

这篇关于如何在空手道功能中遍历数组值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆