Using match each contains for json array items assertion

喜你入骨 提交于 2020-08-09 09:09:33

问题


I would like to add an assertion on skills array containing 'training' in each of the items under response array. how can I do this using match each format * match each response contains { password: 'abc123' }(without using JsonPath expression). I'm expecting my test to be failed for below example since skills array is missing in fourth object.

Scenario: Test scenario

* def response =
"""
[
    {
        id: 1,
        name: "John",
        password: "abc123",
        skills :[ "training", "management"
        ]
    },
    {
        id: 2,
        name: "David",
        password: "abc123",
        skills :[ "training", "management"
        ]
    },
    {
        id: 3,
        name: "David",
        password: "abc123",
        skills :[ "training", "coding"
        ]
    },
    {
        id: 4,
        name: "David",
        password: "abc123"
    }
]
"""

回答1:


Here you go:

* def expectedSkills = ['training']
* match each response contains { skills: '#(^expectedSkills)' }

You know, you should really read the documentation. It will save you a LOT of time :) https://github.com/intuit/karate#schema-validation



来源:https://stackoverflow.com/questions/62880547/using-match-each-contains-for-json-array-items-assertion

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