【问题标题】:Jmeter - How to fail the http request with certain message into the response using JSR223 AssertionJmeter - 如何使用 JSR223 断言使带有某些消息的 http 请求失败到响应中
【发布时间】:2021-10-21 12:45:33
【问题描述】:

在测试我的 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 断言采样器,所以以后我可以扩展和包含其他匹配器

【问题讨论】:

    标签: jmeter


    【解决方案1】:

    类似:

    def hasError = new groovy.json.JsonSlurper().parse(prev.getResponseData()).hasError
    
    if (hasError) {
        AssertionResult.setFailure(true)
        AssertionResult.setFailureMessage('Response data has error')
    }
    

    应该为你解决问题

    更多信息:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多