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:

  1. __beanshell function allows execute arbitrary beanshell code in place of script
  2. ctx - shortcut instance of jmetercontext class. see javadoc available methods
  3. getcurrentsampler() - aforementioned jmetercontext class method provides access instance of current sampler
  4. 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

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -