Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am storing a variable using vars.put() in JMeter and when i try to use _matchNr, it is returning null. Upon logging the variable in the same file where i am calling _matchNr, it showed correct output (which should meant that variable is not null in itself). So is there a reason, why matchNr is giving null output?

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

I am using this in Beanshell Assertion to check whether transactionAmountResp matches with some other already set variable.

You shouldn't use ${} syntax inside Beanshell/JSR233 script, use vars.get

log.info("this is transaction" + vars.get("transactionAmountResp")); 
int number = Integer.parseInt(vars.get("transactionAmountResp_matchNr")); 
                Okay, but even ${} is giving proper output. But vars.get("transactionAmountResp_matchNr") is giving me null. My question was, if there exists a variable, why would matchNr return null? is there a work-around this?
– V.Bhanderi
                Jun 8, 2020 at 13:56
                @V.Bhanderi matchNr variable is added only if you are getting variable using regular expression, you won't have  transactionAmountResp_matchNr variable if you just put a transactionAmountResp variable in script
– user7294900
                Jun 8, 2020 at 13:57
                Okay, so this is the code flow. I am getting message via Queue (using IBM MQ). I am saving this message in a variable,and then in a beanshell post-processor, perform some string operations on it, and save the data retrieved in a variable named 'transactionAmountResp'. Now i want to use the variable, 'transactionAmountResp_matchNr' in a beanshell assertion.   Sorry for the trouble, I am kind of a beginner in Jmeter.
– V.Bhanderi
                Jun 8, 2020 at 14:08
                @V.Bhanderi you don't automatically have matchNr variable, what value you expect it to hold?
– user7294900
                Jun 8, 2020 at 14:11
  • Don't use Beanshell, since JMeter 3.1 you should be using JSR223 Elements and Groovy language for scripting
  • Don't inline JMeter Functions or Variables into scripts, use code-based equivalents instead
  • You can use normal Response Assertion for comparing 2 JMeter Variables:

  • You can double check JMeter Variables or Properties values using Debug Sampler and View Results Tree listener combination, if the variable is not there it's absolutely expected that you will get null trying to read its value

  • Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.