I often want to vary the value of a Sampler property such as ‘Retrieve All Embedded Resources from HTML Files’ at runtime. The approach I am about to show will let you change (probably) *ANY* Sampler property at runtime providing you know its name!
Create a simple Test Plan with one HTTP Sampler which here goes to www.bbc.co.uk:
To change the value of ‘Retrieve All Embedded Resources from HTML Files’ at runtime, we need to know its underlying property name. The easiest way to do this is to Enable the property, save the JMX file and then open the JMX file in a text editor. Then Disable the property, save the JMX file and open that one up in a text editor: then spot the difference In the case of a HTTP Sampler, it is:
To change the value of ‘HTTPSampler.image_parser’ during a test, the easiest way is to add a ‘BSF PreProcessor’ to the HTTP Sampler like so:
Dont forget to set the language! Notice the use of the ‘sampler’ object name in the script. It goes without saying that this is the Sampler Context that the PreProcessor applies to. More information on the methods exposed from ‘sampler’ – such as setProperty – can be found here. You can do a lot more with this than you think
Now when you run the test, you will find all of the Content has been downloaded even though it is disabled in the Test Plan:
You could go one step further and use a Jmeter Property that can be changed live during a running test session to represent the Enabled/Disable state of a Sampler property. See my previous post here.