我已经检查了几个如何验证响应的选项,但它在我的情况下仍然不起作用。 正如您所看到的(调试采样器),对于last_name 正则表达式有效,我收到一些值,但如果我想将此响应重用为“响应断言”,测试失败,因为我收到“响应为空”。
另外,我想计算“数据”中的对象,所以我使用 http://jsonpath.herokuapp.com/?path=$..book[0,1] 来确保 JSON 文件是正确的。但是“调试采样器”没有显示任何内容:(所以测试再次失败
知道如何解决这个问题吗?
JSON:
{
"page": 2,
"per_page": 6,
"total": 12,
"total_pages": 2,
"data": [
{
"id": 7,
"email": "[email protected]",
"first_name": "Michael",
"last_name": "Lawson",
"avatar": "https://reqres.in/img/faces/7-image.jpg"
},
{
"id": 8,
"email": "[email protected]",
"first_name": "Lindsay",
"last_name": "Ferguson",
"avatar": "https://reqres.in/img/faces/8-image.jpg"
},
{
"id": 9,
"email": "[email protected]",
"first_name": "Tobias",
"last_name": "Funke",
"avatar": "https://reqres.in/img/faces/9-image.jpg"
},
{
"id": 10,
"email": "[email protected]",
"first_name": "Byron",
"last_name": "Fields",
"avatar": "https://reqres.in/img/faces/10-image.jpg"
},
{
"id": 11,
"email": "[email protected]",
"first_name": "George",
"last_name": "Edwards",
"avatar": "https://reqres.in/img/faces/11-image.jpg"
},
{
"id": 12,
"email": "[email protected]",
"first_name": "Rachel",
"last_name": "Howell",
"avatar": "https://reqres.in/img/faces/12-image.jpg"
}
],
您需要在 JSON Extractor 中勾选
Compute concatenation var
,否则您将得到 2 个独立的 JMeter 变量:
lastName_1=Lawson
lastName_2=Ferguson
除了第 1 点之外,您还需要在
Response Assertion中使用
lastName_ALL
您需要在响应断言的“模式匹配规则”中从
Matches
切换到Substring
演示:
更多信息:如何使用 JSON 提取器进行测试