模式验证-空手道表达式以检查数组中是否存在值 [英] Schema Validation - Karate expression to check if value exists in array
本文介绍了模式验证-空手道表达式以检查数组中是否存在值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
示例响应
{
"data": [
{
"name": "DJ",
"status": "ACTIVE"
}
]
}
示例功能文件
@ignore
Feature: Sample
@smoke
Scenario: Karate expression to check if value exists in array
Given url url
And path '/test'
When method GET
Then status 200
And def users = response.data
And def possibleStatus = ["ACTIVE", "INACTIVE"]
And def schema =
"""
{
name: '#string',
status: ?
}
"""
And match each users contains schema
是否有一种方法可以使用空手道表达式检查状态为活动"还是不活动"?
Is there a way to check if status is either ACTIVE or INACTIVE using karate expression ?
注意:可以通过编写自定义JS函数来实现.
NOTE: It can be achieved by writing custom JS function.
推荐答案
* def statuses = [ 'ACTIVE', 'INACTIVE' ]
* def response = [{ name: 'DJ', status: 'ACTIVE' }, { name: 'PJ', status: 'INACTIVE' }]
* match each response == { name: '#string', status: '#? statuses.contains(_)' }
这篇关于模式验证-空手道表达式以检查数组中是否存在值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文