![](/img/trans.png)
[英]Karate: Is there a way of getting JSON object keys length from an Examples variable?
[英]Karate: is there a way to apply functions against Examples: variables?
我的空手道考试通过了:
Feature: Armstrong numbers
Background:
* url baseUrl
* configure lowerCaseResponseHeaders = true
Scenario Outline: Find Armstrong numbers in the range from <start> to <end> are <result>
Given path '/armstrongs'
And param start = <start>
And param end = <end>
When method get
Then status 200
And match header content-type contains 'application/json'
And match header content-type contains 'charset=utf-8'
And match response == {numbers:<result>, start:<start>, end:<end>, count: <count>, type:Armstrong}
Examples:
| start | end | result | count
| 1 | 10 | [1,2,3,4,5,6,7,8,9] | 9
| 100 | 1000 | [153, 370, 371, 407] | 4
| 90000 | 100000 | [92727, 93084] | 2
但是,我想做的是没有Examples:部分中的count变量,而是通过这种方式从变量的长度中得出count:
Feature: Armstrong numbers
Background:
* url baseUrl
* configure lowerCaseResponseHeaders = true
Scenario Outline: Find Armstrong numbers in the range from <start> to <end> are <result>
Given path '/armstrongs'
And param start = <start>
And param end = <end>
When method get
Then status 200
And match header content-type contains 'application/json'
And match header content-type contains 'charset=utf-8'
And match response == {numbers:<result>, start:<start>, end:<end>, count: <result>.length, type:Armstrong}
Examples:
| start | end | result
| 1 | 10 | [1,2,3,4,5,6,7,8,9]
| 100 | 1000 | [153, 370, 371, 407]
| 90000 | 100000 | [92727, 93084]
尝试此操作时,出现错误:
Armstrong.feature:15 - net.minidev.json.parser.ParseException: Unexpected token . at position 72.
测试失败。
有没有一种方法可以对示例应用函数:诸如.length之类的变量,以获得预期结果并通过测试?
进行以下更改:
And def result = <result>
And match response == {numbers: '#(result)', start: <start>, end: <end>, count: '#(result.length)', type: 'Armstrong' }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.