简体   繁体   English

如何在空手道功能中循环数组值

[英]How to loop over array values in a karate feature

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在 Feature1.feature - Scenario1 中,我在数组 ["UUID1","UUID2","UUID3"] 中有一些值,我想调用另一个功能文件 (Feature2.feature)(有一个调用 DELETE 端点的代码) 服务

Feature2.feature: Feature2.特征:

 @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

What approach should I use to Feature1.feature to call the Feature2.feature in a loop?我应该对 Feature1.feature 使用什么方法来循环调用 Feature2.feature?

If you have an array of primitives, you need to convert it into an array of JSON objects before doing a "loop call".如果您有一个基元数组,则需要在执行“循环调用”之前将其转换为 JSON 对象数组。 Refer to the docs for karate.mapWithKey() : https://github.com/intuit/karate#json-transforms请参阅karate.mapWithKey()的文档: https ://github.com/intuit/karate#json-transforms

So do this:所以这样做:

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

And in second.feature :second.feature中:

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

Of course, read the docs for call if needed: https://github.com/intuit/karate#data-driven-features当然,如果需要,请阅读文档以供callhttps ://github.com/intuit/karate#data-driven-features

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM