[英]How to loop over array values in a karate feature
我正在尝试遍历空手道功能文件中的数组值。 在 Feature1.feature - Scenario1 中,我在数组 ["UUID1","UUID2","UUID3"] 中有一些值,我想调用另一个功能文件 (Feature2.feature)(有一个调用 DELETE 端点的代码) 服务
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
我应该对 Feature1.feature 使用什么方法来循环调用 Feature2.feature?
如果您有一个基元数组,则需要在执行“循环调用”之前将其转换为 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.