2
votes

I have web request like this

    Loop Controller(3)
      moreSamples=true
      startIndex=0
      While Controller(${__javaScript(${moreSamples}==true)})
       SOAP/XML-RPC Request(index=${startIndex})
       Regular Expression Extractor(startIndex=newIndex,moreSamples=samples)

Now problem is I am not able to initialize moreSamples and startIndex in loop. I tried two options:

  1. Make moreSamples and startIndex as user defined variables. Now I am able to change their values using Regular Expression Extractor but not able to reinitialize them in outer loop using BeanShell PostProcessor like this:

    vars.put("moreSamples","false")
    vars.put("startIndex","0")
    
  2. Make moreSamples and startIndex as User Parameters in preprocessor of of while loop but then I am not able to assign them values using Regular Expression Extractor.

Please suggest the mistakes or some new construct which can fit in.

Screenshot:

enter image description here

3

3 Answers

4
votes

@bpsingh,

Can you do following things:

  1. Add UserDefinedVariables on top of your Test Plan with two defined variables: moreSamples, startIndex (like @ant suggested already)

  2. Under the Download - PersistentSyncScope Sampler, you have two regular expression extractors in which I assume you want to extract some values and place it in these two variables from the above. Add BeanShellPostProcessor under the Download - PersistentSyncScope Sampler.

  3. In BeanShellPostProcessor add following code:

vars.put("moreSamples","${REGEX_EXTRACT1}");
vars.put("startIndex","${REGEX_EXTRACT2}");

These two (moreSamples, startIndex) are global variables and changes on them should be visible outside of the loop.

1
votes

Do you have to initialize them from the loop? How about adding those to User Defined Variables?

enter image description here

Or you can do it from your loop as well, the reason why it doesn't work for you is either the fact that you forgot to put the semi-colon ; after your expression(s) :

vars.put("moreSamples","false"); // ; <- was missing
vars.put("startIndex","0"); // ; <- was missing

I used BSF Sampler and it worked for me (don't forget to choose the language -> beanshell if you use this one). Here is my debug sampler (relevant part) :

START.HMS=101818
START.MS=1341821898080
START.YMD=20120709
TESTSTART.MS=1341822195274
moreSamples=false
startIndex=0

Update:

You need not to use both BSF Sampler and user defined variables. You can use either, and I see you have more user defined variables, no need for that. Have one of those at the start of your test. I'm still not clear what your problem is and what you're trying to achieve.

0
votes

Actually problem here is I am using 2 loops and all answers don't take this properly into account.

Since pre/post processors are applied only to samplers not to loops there is no way to reinitialize the variables before while loop. Thus if I add initialize statements in preprocessor, loop run infinitely and if in postprocessor, it never executes. Only way to initialize is adding BSF sampler before while loop but that will spoil the reports as this sampler will also be recorded by listeners.

So only solution I found is run Download - PersistentSyncScope Sampler once and add BSF preprocessor with following scripts

vars.put("moreSamples","false");
vars.put("startIndex","0");

Now add while loop and add Download - PersistentSyncScope Sampler as its child.

That is the only solution till now. Thanks everyone to help me understand the problem.