Kekers_Dev
Kekers_Dev

Reputation: 75

JMeter functions and variables

I'm new to JMeter so this question may sound absolutely dumb...

I have a loop in which a variable (let's say it is called "raw") is being changed and written to file every iteration. The variable contains HTML encoded text so it has to be converted into plain text. I found out this can be done using __unescapeHtml function. When I tried using it worked but I ended up always receiving the same text as on the first iteration. Then I learned that I have to use vars.get instead of ${} to access a variable. So I changed ${__unescapeHtml("${raw}")} to ${__unescapeHtml(vars.get("raw")} which kind of helped: vars.get is getting the new value of raw each iteration but __unescapeHtml didn't work at all now - it just returns the encoded text from raw. I didn't succeded finding anything about this exact problem so I'm kind of stuck.

Upvotes: 1

Views: 252

Answers (2)

Felix Schumacher
Felix Schumacher

Reputation: 331

I assume, that you are using the expression ${...} inside a JSR-223 sampler or similar context. The user manual for JSR-223 Sampler states, that those scripts can be cached by JMeter. That is why you only get the values from the first time the context gets created.

The same is true for simple variable evaluations as ${varname}, as for function calls like ${__unescapeHtml(...)}.

The solution here is:

  • don't use ${...} inside of JSR-223 contexts, that might be cached.
  • you can however pass those expressions (${...}) into the context by using them as parameters through the input labeled Parameters on the JSR-223 Sampler – again assuming, that you are using it.
  • you can use the features, that your chosen JSR-223 context gives you, as you have done, by using the StringEscapeUtils#unescapeHtml4

Upvotes: 1

Kekers_Dev
Kekers_Dev

Reputation: 75

Ended up using

import org.apache.commons.lang3.StringEscapeUtils

...

StringEscapeUtils.unescapeHtml4(vars.get("raw"))

Don't know if it is a good way to do this but at least it works.

Upvotes: 1

Related Questions