0
votes

I am facing some trouble using jmeter. This is my use case, I am using CSV data source parameters to construct a HTTP POST request, the request body is read from a CSV column

enter image description here

which contains some placeholders like ${source_id}

enter image description here

I want to replace these placeholders with jmeter parameters which I am initialising through a regex/json extractor(read from the response of last PUT request). I tried using the jmeter variable name in the CSV file but the variable values are not getting substituted. I guess I will have to use the beanshell pre-processor to modify the HTTP POST request body. Can anyone help with the methods I can use to get the HTTP POST request body.

1

1 Answers

3
votes

Something like

String requestBody = sampler.getArguments().getArgument(0).getValue();

should help.

sampler is a shorthand to parent sampler class instance, in your case it will be HTTPSamplerProxy, see the JavaDoc for all available methods and fields.


I would recommend considering migration to JSR223 PreProcessor and Groovy language as it is much faster and less resources consuming than Beanshell. Valid Beanshell code will be valid Groovy code so you should be able to convert to JSR223 elements with no or minimal changes. See Groovy is the New Black article for more details.