Reputation: 121
How to remove empty HTTP request parameters with JS223 Preprocessor from JMeter HTTP sampler?
Example:
HTTP Request
https://restApi/users?username=Leanne+Graham&email=Sincere%40april.biz
Upvotes: 0
Views: 604
Reputation: 167992
I fail to see why would you need to remove empty parameters from the request, well-behaved JMeter test should send the same requests as the real browser, and for browser sending a request parameter without the value is pretty normal
If you still want to remove the request parameters which don't have values using JSR223 PreProcessor and Groovy language the relevant code would be something like:
def newData = new org.apache.jmeter.config.Arguments()
0.upto(sampler.getArguments().size() - 1, { idx ->
def arg = sampler.getArguments().getArgument(idx)
if (!arg.getValue().equals('')) {
newData.addArgument(arg)
}
})
sampler.setArguments(newData)
where sampler
stands for HTTPSamplerProxy
Upvotes: 1