【问题标题】:How to loop over array values in a karate feature如何在空手道功能中循环数组值
【发布时间】:2020-02-17 11:01:36
【问题描述】:

我正在尝试循环遍历空手道功能文件中的数组值。 在 Feature1.feature - Scenario1 中,我在数组 ["UUID1","UUID2","UUID3"] 中有一些值,我想调用另一个功能文件 (Feature2.feature)(有一个调用 DELETE 端点的代码) 服务

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 使用什么方法来循环调用 Feature2.feature?

【问题讨论】:

标签: loops automation bdd karate


【解决方案1】:

如果您有一个基元数组,则需要在执行“循环调用”之前将其转换为 JSON 对象数组。请参阅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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2018-12-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-02
  • 2020-10-13
  • 1970-01-01
  • 2018-06-11
相关资源
最近更新 更多