Store Jmeter sampler properties value using beanshell preprocessor -
i've test plan tcp sampler host , port defined using tcp sampler config.
i have defined 'port' value tcp connection defined in tcp sampler config , need value (tcpsampler.port=3001) part of request server.
i trying use beanshell pre-processor capture , store on user defined variable.
any idea how achieve this.
advanced help.
put following code "text send" input
tcpsampler.port=${__beanshell(ctx.getcurrentsampler().getport();,port)}
broken down consists of:
- __beanshell function allows execute arbitrary beanshell code in place of script
ctx
- shortcut instance of jmetercontext class. see javadoc available methods- getcurrentsampler() - aforementioned jmetercontext class method provides access instance of current sampler
- getport method of tcpsampler class in case tcp sampler
so __beanshell function executes script , saves result port
variable can later accessed anywhere in current thread group.
for beanshell preprocessor (if still want use it) relevant code like:
int port = sampler.getport(); vars.put("port", string.valueof(port));
see how use beanshell: jmeter's favorite built-in component guide comprehensive information on beanshell scripting in apache jmeter. `
Comments
Post a Comment