Using Java Request Sampler inside a ForEach controller in Jmeter -


i trying use java request sampler inside foreach controller.

this custom sampler

public class clientsampler extends abstractjavasamplerclient {      string name;      @override     public arguments getdefaultparameters() {         arguments defaultparameters = new arguments();         defaultparameters.addargument("name", "tarek");         return defaultparameters;     }      @override     public void setuptest(javasamplercontext context) {         name = context.getparameter("name");     }      @override     public sampleresult runtest(javasamplercontext context) {            system.out.println(name);     } } 

in jmeter create user defined variables 5 variables:

enter image description here

and foreach controller:

enter image description here

then added java request child foreach controller:

enter image description here

the test plan following:

enter image description here

when start test output is:

first first first first first 

expected:

first second third fourth fifth 

even if set start , end indexes in foreach controller result same.

using http sampler inside foreach controller works great, when using java requests result not expected.

can explain why getting output?

i solved it.

the problem because misunderstood how works:

jmeter calls setuptest(javasamplercontext context) once before test starts , calls runtest(javasamplercontext context) in each loop (i though calls setuptest @ beginning of each loop).

so added

name = context.getparameter("name"); 

inside runtest , result how should be.

@override public sampleresult runtest(javasamplercontext context) {        name = context.getparameter("name");             system.out.println(name); } 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -