Schema Validation - Karate expression to check if value exists in array

[亡魂溺海] 提交于 2019-12-11 10:06:52

问题


Sample Response

{
    "data": [
    {
        "name": "DJ", 
        "status": "ACTIVE"
    } 
    ]
}

Sample Feature File

@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 ?

NOTE: It can be achieved by writing custom JS function.


回答1:


* def statuses = [ 'ACTIVE', 'INACTIVE' ]
* def response = [{ name: 'DJ', status: 'ACTIVE' }, { name: 'PJ', status: 'INACTIVE' }]
* match each response == { name: '#string', status: '#? statuses.contains(_)' }


来源:https://stackoverflow.com/questions/55103176/schema-validation-karate-expression-to-check-if-value-exists-in-array

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!