JSON断言 - 断言多个响应值

问题描述 投票:0回答:1
{
                "id": 280,
                "name": "Kru",
                "description": "alphabetic description",
                "status": 2,
                "condition_type": "1",
                "created_at": "2019-02-05T14:43:04.000Z",
                "updated_at": "2019-02-05T14:43:04.000Z"
            },
            {
                "id": 25,
                "name": "Krut",
                "description": "abckdk eje  jw s",
                "status": 1,
                "condition_type": "0",
                "created_at": "2019-02-05T11:11:02.000Z",
                "updated_at": "2019-02-05T11:11:02.000Z"
            }

我试图断言上述JSON响应。我的测试用例通过如果所述响应具有状态值1以及2和否则失败。现在,我只能断言一次一个值。我怎么能断言两个值?先感谢您。 JSON assertion I implemented

json jmeter assertion
1个回答
0
投票
  1. 添加JSR223 Assertion作为请求的孩子返回上面的JSON
  2. 将下面的代码为“脚本”区域: com.jayway.jsonpath.JsonPath.read(prev.getResponseDataAsString(), '$..status').each { status -> if (!(1..2).contains(status)) { AssertionResult.setFailure(true) AssertionResult.setFailureMessage('Comparison failed, got: ' + status) } }
  3. 就这样,在上面的代码将验证每个status值和评估它是否是12之间包含地。在意想不到的情形发生的相关采样(收费)断言的scope将被标记为失败: enter image description here 退房Scripting JMeter Assertions in Groovy - A Tutorial文章上的JMeter的基于代码的断言概念的更多信息。
© www.soinside.com 2019 - 2024. All rights reserved.