如何循环遍历空手道功能中的数组值
How to loop over array values in a karate feature
我正在尝试遍历空手道功能文件中的数组值。
在 Feature1.feature - 场景 1 中,我在数组 ["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?
如果您有一个基元数组,则需要在执行 "loop call" 之前将其转换为一个 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
我正在尝试遍历空手道功能文件中的数组值。 在 Feature1.feature - 场景 1 中,我在数组 ["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?
如果您有一个基元数组,则需要在执行 "loop call" 之前将其转换为一个 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