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:
and foreach controller:
then added java request child foreach controller:
the test plan following:
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
Post a Comment