JMeter, encoding all parameters

1.8k views Asked by At

I'm looking for some advice on encoding in JMeter. I am currently working on a system that uses https and .aspx urls, and therefore need to encode all parameters within my post requests.As it stands i am copying and pasting web-forms from Fiddler to generate my test scripts. Is there a less labour intensive way to encode all my parameters of the web-form, because i am having to tick to encode each individual parameters.

1

There are 1 answers

0
Dmitri T On
  1. Most probably you are doing something weird, given you record your requests using JMeter's HTTP(S) Test Script Recorder JMeter should populate request parameters on its own including parameters values encoding if required. Check out JMeter Proxy Step by Step for details on how to perform recording of your test scenarios.
  2. JMeter .jmx scripts are basically XML files so you should be able to open JMeter script in your favourite text editor, locate the following line:

    <boolProp name="HTTPArgument.always_encode">false</boolProp>
    

    and replace it with

    <boolProp name="HTTPArgument.always_encode">true</boolProp>
    
  3. You can substitute non-encoded parameters with their encoded equivalents using JSR223 PreProcessor and the following Groovy code:

    org.apache.jmeter.config.Arguments args = sampler.getArguments()
    sampler.getArguments().removeAllArguments()
    args.each {
        sampler.addEncodedArgument(it.getName(), it.getValue())
    }
    

    The above code will amend all the samplers in JSR223 PreProcessor's scope and substitute parameters values with their encoded equivalents. This approach can be resource intensive so use it wisely and if there is a possibility consider alternatives described in points 1 and/or 2. Just in case see Apache Groovy - Why and How You Should Use It to get familiarized with the concept of Groovy scripting in JMeter tests.