Jmeter - 如何使用 JSR223 断言将带有特定消息的 http 请求失败到响应中
Jmeter - How to fail the http request with certain message into the response using JSR223 Assertion
在测试我的 API 时,当请求出现问题时,我收到如下消息:
{
"errorTimeStamp": "2021-10-21T14:08:11.7298099+02:00",
"errorMessage": "Ticket with id 0 not found",
"errorCode": 1001,
"hasError": true
}
如何将 httpRequest 标记为失败(红色进入查看结果树)基于:"hasError": true
我更喜欢使用 JSR223 断言采样器,所以以后我可以扩展并包含其他匹配器
类似于:
def hasError = new groovy.json.JsonSlurper().parse(prev.getResponseData()).hasError
if (hasError) {
AssertionResult.setFailure(true)
AssertionResult.setFailureMessage('Response data has error')
}
应该能帮到你
更多信息:
在测试我的 API 时,当请求出现问题时,我收到如下消息:
{
"errorTimeStamp": "2021-10-21T14:08:11.7298099+02:00",
"errorMessage": "Ticket with id 0 not found",
"errorCode": 1001,
"hasError": true
}
如何将 httpRequest 标记为失败(红色进入查看结果树)基于:"hasError": true
我更喜欢使用 JSR223 断言采样器,所以以后我可以扩展并包含其他匹配器
类似于:
def hasError = new groovy.json.JsonSlurper().parse(prev.getResponseData()).hasError
if (hasError) {
AssertionResult.setFailure(true)
AssertionResult.setFailureMessage('Response data has error')
}
应该能帮到你
更多信息: