Karate 架构验证-用于检查数组中是否存在值的空手道表达式
样本响应Karate 架构验证-用于检查数组中是否存在值的空手道表达式,karate,Karate,样本响应 { "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
{
"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
示例功能文件
{
"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
有没有办法用空手道表情来检查状态是活动的还是不活动的
注意:可以通过编写自定义JS函数来实现
* def statuses = [ 'ACTIVE', 'INACTIVE' ]
* def response = [{ name: 'DJ', status: 'ACTIVE' }, { name: 'PJ', status: 'INACTIVE' }]
* match each response == { name: '#string', status: '#? statuses.contains(_)' }