本文介绍了空手道中的For循环无法按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用下面的代码从数组中获取JSON响应,但只能获取到位置12.脚本正在传递,但是我希望可以打印出超过218个值.
I am using below code to get the JSON response from the array but I am able to get only till a position of 12. the script is passing but I am expecting more than 218 values to get printed.
Feature: Verify Branches
Background: For loop implementation
Given url ''
When method GET
Then status 200
* def i = 000
* def z = response.locations[i].zip
* def p = response.locations[i].phone
* def fun =
"""
function(locations){
for (var i = 0; i < response.locations.length; i++)
{
print(i)
print('Element at Location ' + i +':' + p)
}
}
"""
Scenario: Validate the locations
Given url ''
When method GET
Then status 200
* call fun z
* print z.length
z.length应该给我218,但给z给出218,它打印10,而给p给出12.
z.length should give me 218 but giving 218 for z it is printing 10 and for p it is printing 12.
推荐答案
请在空手道中使用match each
.您无需以编程方式进行操作.
Please use match each
in Karate. You never need to programmatically do it.
* def data = { foo: [{ bar: 1, baz: 'a' }, { bar: 2, baz: 'b' }, { bar: 3, baz: 'c' }]}
* match each data.foo == { bar: '#number', baz: '#string' }
这篇关于空手道中的For循环无法按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!