问题描述
我试图遍历空手道特征文件中的数组值.在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
这篇关于如何在空手道功能中遍历数组值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!