Before send the query in HTTP Sampler I need to make some changes of this query in beanshell preprocessor. So, the question is how to access to current sampler body data from beanshell preprocessor? I can get Name,Path,IP, etc ( for example sampler.getPropertyAsString("HTTPSampler.domain")) but have no idea how to get the body data.
2 Answers
Kindly find answers below (assuming that we're talking about HTTP Request)
- Name:
sampler.getName()
- IP:
sampler.getUrl().getHost()
- Path:
sampler.getUrl().getPath()
If you need request parameters:
Arguments arguments = sampler.getArguments(); for (int i=0;i<arguments.getArgumentCount();i++) { Argument argument = arguments.getArgument(i); String name = argument.getName(); String value = argument.getValue(); // do what you need }
If you need more information refer to HTTPSamplerProxy JavaDoc
If it is not HTTP Request you can figure out what class this sampler
variable refers to as
log.info(sampler.getClass().getName());
figure out class name from jmeter.log file and look for JavaDoc.
For more information regarding Beanshell scripting refer to How to use BeanShell: JMeter's favorite built-in component guide.
Thanks @Dmitri T
I was getting
13:28:13 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import org.apache.jmeter.protocol.http.control.Header; sampler.getHeaderManag . . . '' : Typed variable declaration : Class: Arguments not found in namespace
error while using
Arguments arguments = sampler.getArguments();
for (int i=0;i<arguments.getArgumentCount();i++)
{
Argument argument = arguments.getArgument(i);
String name = argument.getName();
String value = argument.getValue();
// do what you need
}
After importing
import org.apache.jmeter.config.Argument;
import org.apache.jmeter.config.Arguments;
I solved this