Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL encode variable in Jmeter

I need to encode a variable in Jmeter, but it isn't a parameter. For example:

URL path: /folder/guest/id;token=${token}/profile?details=yes

I want to encode the ${token} variable, and only the token variable. I know that you can select encode in the parameters section, but this isn't a parameter.

Does anyone know how to do this?

like image 210
BlackHatSamurai Avatar asked Jan 29 '13 22:01

BlackHatSamurai


People also ask

How to reference variables in JMeter?

Referencing a variable in a test element is done by bracketing the variable name with '${' and '}'. Functions are referenced in the same manner, but by convention, the names of functions begin with "__" to avoid conflict with user value names*.

What is content encoding in JMeter?

Content encoding This is the character encoding to be used, and is not related to the Content-Encoding HTTP header. So the blank value is normal given you are recording HTTP GET requests.

What does the p function return in JMeter?

Per the JMeter user guide __property(): The property function returns the value of a JMeter property. If the property value cannot be found, and no default has been supplied, it returns the property name.


2 Answers

JMeter as of version 2.10 now includes a urlencode function.

${__urlencode(${token})}

See http://jmeter.apache.org/usermanual/functions.html

like image 125
Irate Pirate Avatar answered Sep 18 '22 15:09

Irate Pirate


The best way I found to do this was to use a JavaScript function:

${__javaScript(encodeURIComponent('${token}'))}

So the request would be:

/folder/guest/id;token= ${__javaScript(encodeURIComponent('${token}'))}/profile?details=yes
like image 42
BlackHatSamurai Avatar answered Sep 16 '22 15:09

BlackHatSamurai