JMETER -响应Assert->响应为空

58wvjzkj  于 2022-11-09  发布在  其他
关注(0)|答案(1)|浏览(224)

我已经检查了几个选项如何验证响应,它仍然不工作,在我的情况下.正如你可以看到(调试采样器),为last_name正则表达式工作,我收到一些值,但如果我想重用这个响应作为“响应Assert”,测试失败,因为我收到“响应是空”.
JSON Extractor for last_name
Response assertion
Test failed
另外,我想计算“data”中的对象,所以我使用http://jsonpath.herokuapp.com/?path=$..book[0,1]来确保JSON文件是正确的。但是“Debug sampler”没有显示任何内容:(所以测试再次失败
Count of objectsResult打印机
请问有什么办法解决这个问题吗?
JSON格式:

{
"page": 2,
"per_page": 6,
"total": 12,
"total_pages": 2,
"data": [
    {
        "id": 7,
        "email": "michael.lawson@reqres.in",
        "first_name": "Michael",
        "last_name": "Lawson",
        "avatar": "https://reqres.in/img/faces/7-image.jpg"
    },
    {
        "id": 8,
        "email": "lindsay.ferguson@reqres.in",
        "first_name": "Lindsay",
        "last_name": "Ferguson",
        "avatar": "https://reqres.in/img/faces/8-image.jpg"
    },
    {
        "id": 9,
        "email": "tobias.funke@reqres.in",
        "first_name": "Tobias",
        "last_name": "Funke",
        "avatar": "https://reqres.in/img/faces/9-image.jpg"
    },
    {
        "id": 10,
        "email": "byron.fields@reqres.in",
        "first_name": "Byron",
        "last_name": "Fields",
        "avatar": "https://reqres.in/img/faces/10-image.jpg"
    },
    {
        "id": 11,
        "email": "george.edwards@reqres.in",
        "first_name": "George",
        "last_name": "Edwards",
        "avatar": "https://reqres.in/img/faces/11-image.jpg"
    },
    {
        "id": 12,
        "email": "rachel.howell@reqres.in",
        "first_name": "Rachel",
        "last_name": "Howell",
        "avatar": "https://reqres.in/img/faces/12-image.jpg"
    }
],
k97glaaz

k97glaaz1#

1.您需要在JSON Extractor中勾选Compute concatenation var,否则会得到2个单独的JMeter Variables

lastName_1=Lawson
lastName_2=Ferguson

1.除了第1点之外,您还需要在响应Assert中使用lastName_ALL
1.您需要在响应Assert的“模式匹配规则”中从Matches切换到Substring
演示:

更多信息:How to Use the JSON Extractor For Testing

相关问题