将数组或CSV的每个值作为URL中的参数调用 [英] Calling each value of an array or csv as a parameter in a url
本文介绍了将数组或CSV的每个值作为URL中的参数调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是空手道新手,读过大多数例子,但我不能完全理解它。非常感谢您的帮助!假设我有一个数组,并且我需要调用一个服务并将它的每个值作为参数传递,我该怎么做呢?
提前谢谢。
推荐答案
这样如何:
Scenario Outline:
Given url 'http://httpbin.org'
And path 'get'
And param foo = '<value>'
When method get
Then status 200
Examples:
| value |
| hello |
| world |
在空手道0.9.0和更高版本中,您可以这样做:
Background:
* def data = [{ value: 'hello' }, { value: 'world' }]
Scenario Outline:
Given url 'http://httpbin.org'
And path 'get'
And param foo = '<value>'
When method get
Then status 200
Examples:
| data |
编辑:如果需要转换现有基元数组:
Background:
* def array = ['hello', 'world']
* def data = karate.map(array, function(x){ return { value: x } })
Scenario Outline:
Given url 'http://httpbin.org'
And path 'get'
And param foo = '<value>'
When method get
Then status 200
Examples:
| data |
这篇关于将数组或CSV的每个值作为URL中的参数调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文