Wednesday, June 10, 2009

Fixing URLs

Motivation
For some tests, the URL to visit is extracted from the previous request using one of the PostProcessors (usually the Regex PostProcessor). However a URL containing parameters should normally have ampersands(&) escaped . This causes problems because JMeter will not automatically unescape these URL's

Solution
Use a javascript function to unescape the urls.

Sample
Assume that the Regex Post processor has extracted the url into a variable named returnUrl, then in the next HTTPSampler (Path field), instead of using ${returnUrl} use the function below.
${__javaScript('${returnUrl}'.replace(/amp;/gi\,''))}

This will simply replace amp; with a blank string so that a URL of the form http://www.yoursite.com/page?param1=value1&param2=value2 becomes
http://www.yoursite.com/page?param1=value1&param2=value2

Note that we don't need to do this for encoded values like %2F or whatever because that is taken care by the webserver

No comments: