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