首页 > 解决方案 > Jmeter - matchNr 返回 null

问题描述

我在 JMeter 中使用 vars.put() 存储一个变量,当我尝试使用 _matchNr 时,它返回 null。在我调用_matchNr的同一文件中记录变量后,它显示了正确的输出(这应该意味着变量本身不为空)。那么,为什么 matchNr 给出空输出是有原因的?

log.info("this is transaction" + "${transactionAmountResp}"); 
log.info("this is transaction_match" + 
vars.get("transactionAmountResp_matchNr")); 
int number = Integer.parseInt("${transactionAmountResp_matchNr}"); 

我在 Beanshell Assertion 中使用它来检查 transactionAmountResp 是否与其他已设置的变量匹配。

标签: jmeterbeanshelljmeter-5.0

解决方案


你不应该${}在 Beanshell/JSR233 脚本中使用语法,使用vars.get

log.info("this is transaction" + vars.get("transactionAmountResp")); 

int number = Integer.parseInt(vars.get("transactionAmountResp_matchNr")); 

推荐阅读