在JMeter中,如何根据两个jmeter变量计算出的值来验证json中返回的值?

时间:2019-03-29 15:09:30

标签: jmeter

我正在从此json中提取$ .matching_results:

{
  "matching_results": 5,
  "enrichments": {
    "keywords": [
      {
        "text": "shore of Mobile Bay",
        "relevance": 0.809978
      }
    ],
    "concepts": [
      {
        "text": "Mobile, Alabama",
        "relevance": 0.972324
      },
      {
        "text": "Birmingham, Alabama",
        "relevance": 0.954301
      }
    ]
  },
  "session_token": "1_e7R7s9QIt28pN8p3_TzjR8acCX"
}

,我想将其与两个变量的乘积进行比较 ${__BeanShell(${__evalVar(numAssetThreads)}*${__evalVar(numAssetLoops)})}

我尝试了上面的表达式和这个表达式 ${__BeanShell(String.valueOf(${__evalVar(numAssetThreads)}*${__evalVar(numAssetLoops)}))}

并且我尝试了在没有指定Match as a regular expression的情况下进行的尝试。

我也尝试过 ${__BeanShell(${__V(numAssetThreads)}*${__V(numAssetLoops)})}

在所有情况下,我都会收到类似以下错误消息:

Assertion failure: true
Assertion failure message: Value expected to match regexp '5 ', but it did not match: '5'

Assertion error: false
Assertion failure: true
Assertion failure message: Value expected to be '2 ', but found '2'

如何使它正常工作?

1 个答案:

答案 0 :(得分:0)

Value expected to match regexp '5 ', but it did not match: '5'

there is a space after 5  here --^

以某种方式删除此空间,您的断言应该开始起作用。

请注意,自JMeter 3.1起,您应该考虑以以下方式迁移到__groovy() function

  1. Groovy与现代Java功能兼容,而Beanshell停留在Java 5语法上
  2. Groovy在Java SDK之上提供了"syntax sugar"
  3. Groovy performance is much better comparing to Beanshell