2

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

1

3 Answers 3

4

@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.

Sign up to request clarification or add additional context in comments.

1 Comment

@Bakir Jusufbegovic nice approach +1
1

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.

10 Comments

but then I am not able to assign them values using Regular Expression Extractor.
@bpsingh post the relevant code/screenshots, how was I or anyone suppose to know that fact. Not a magician Sir
Yes semicolon was one problem, it is still not working. I uploaded the screenshot of my loop. I don't know where to add beanshell code, I have tried it in all the places which you can see as disabled in screenshot. Only time it works is when I add some other sampler between two loops(you can see disabled PersistentSyncScope - Upload) and add beanshell code as a post/preprocessor to this sampler.
@bpsingh I don't see the screenshot
Actually I couldn't upload it in answer as I am new on stackoverflow, so added it into your answer and it is saying Thanks for your edit! This edit will be visible only to you until it is peer reviewed. I think you may have to review it
|
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.