Suyash
Suyash

Reputation: 625

JMeter use beanshell variable in HTTP Request

I'm an absolute rookie here (JAVA i mean), spent hours looking for a solution, now i just want to shoot myself.
I want to create a string in the beanshell assertion which is placed right above the HTTP Request.

Upvotes: 12

Views: 66466

Answers (3)

UBIK LOAD PACK
UBIK LOAD PACK

Reputation: 34566

If you don't know Java well, you can use any of BSF or JSR223 Test elements and then select Javascript language as scripting language

http://jmeter.apache.org/usermanual/component_reference.html#JSR223_Sampler

Upvotes: 3

Dragan Stanisavljevic
Dragan Stanisavljevic

Reputation: 99

If you need to pass value from one bean shell sampler to another, you should use variables.

vars.put("a", "something")

In other sampler, you should have something like:

String otherSampler = vars.get("a")

About debugging Shell Samplers - It is not so easy. I suggest to use SampleResult object. How to use it, you can see here Debugging Bean Shell Sampler

Upvotes: 2

Aliaksandr Belik
Aliaksandr Belik

Reputation: 12873

In BeanShell Assertion description section you can find the following:

 vars -  JMeterVariables  - e.g. vars.get("VAR1"); vars.put("VAR2","value"); vars.putObject("OBJ1",new Object()); 
 props - JMeterProperties (class java.util.Properties) - e.g. props.get("START.HMS"); props.put("PROP1","1234");

So to set jmeter variable in beanshell code (BeanShell Assertion sampler in your case) use the following:

String docid = "abcd";
vars.put("docid",docid);

or simply

vars.put("docid","abcd");

and then you can refer it as ${docid}, as you've done in your HTTP Request.

Upvotes: 24

Related Questions