Sarang
Sarang

Reputation: 688

What is different between props and vars object in JMeter

Im new in load and performance testing so could anyone explain me, what is difference between vars object and props object in JMeter beanshell script.

Im also bit confuse about JMeter variable and properties.

Thanks.

Upvotes: 20

Views: 21575

Answers (2)

Adnan
Adnan

Reputation: 2547

As per Blazemeter Blog

vars

vars (JMeter variables) is the most frequently used component. It’s an instance of the org.apache.jmeter.threads.JMeterVariables class and provides read/write access to current variables, is capable of enumerating/changing existing variables, creating new ones, and obtaining nested properties. All JMeter variables are Java strings. If you need to put something else to a JMeter variable, you’ll need to cast it to the string first. The following code snippet demonstrates how to save previous sampler response data into a JMeter variable.

byte [] samplerdata = ctx.getPreviousResult().getResponseData();
String samplerdatastring = new String(samplerdata);
vars.put("samplerdata",samplerdatastring);

props

Basically, this is the same as “vars,” but it exposes JMeter properties instead. See JavaDoc on java.util.Properties and JMeter documentation on JMeter properties for more information. The primary distinction between props and vars is that props have a “global” scope, whereas the scope of “vars” is limited to the current thread group.

Refer to this link.

Upvotes: 7

Iske
Iske

Reputation: 1200

The most simplest explanation would be that variables(vars) are not shared between threads, and properties(props) ARE shared.

Usage:

vars - ( JMeterVariables) - gives read/write access to variables:

  • vars.get(key);
  • vars.put(key,val);

  • vars.putObject("OBJ1",new Object());

  • vars.getObject("OBJ2");

props - (JMeterProperties - class java.util.Properties):

  • props.get("START.HMS");
  • props.put("PROP1","1234");

You can refer to this link to get more info on vars and props.

Upvotes: 25

Related Questions