When working with any kind of LoadRunner Java-based vuser type, any string that appears within the script may be parameterised. This differs significantly from all of the C-based vuser types, where only functions that are labelled as “parameterizable” may be parameterised without explicitly calling lr_eval_string().

This is a simple example of parameterisation with a Java-based script:

lr.save_string("jumped", "myParam");
String message = "the quick brown fox <myParam> over the lazy dog";
lr.output_message(message);

Rather than trying to do something that is theoretically impossible such as overloading the String class to handle this extra functionality, the LoadRunner developers did the simplest thing that could possibly work. They added a pre-compilation step that does a simple find-and-replace, with every <Parameter> automatically replaced with “+lr.eval_string(“<Parameter>”)+”.

lr.save_string("jumped", "myParam");
String message = "the quick brown fox "+lr_eval_string("<myParam>")+" over the lazy dog";
lr.output_message(message);

The only unintended side-effect of this is that it now makes it possible to get a stack overflow while “compiling” (see my Introduction to LoadRunner CORBA Vusers for a work-around).

 

Published On: April 25, 2005Tags: ,

8 Comments

  1. Stuart Moncrieff May 3, 2005 at 7:21 pm

    Now that I think about it, you could easily implement the same thing with a preprocessor macro for C-based LoadRunner scripts.

  2. Subuhi July 19, 2007 at 12:46 am

    Great Detail Stuart, Very useful info:-) appreciate your putting the article.

    Thanks

  3. Subuhi July 19, 2007 at 12:46 am

    Great Detail Stuart, Very useful info:-) appreciate your putting the article.

    Thanks

  4. PerfArch October 8, 2008 at 9:19 pm

    Does LR9.1 supports JDK1.4.2_08? As my Java Cleint Server application is developed in JDK1.4.2_08 environment.

  5. SlipperCC April 22, 2011 at 11:35 am

    I read this and it’s extremely helpful. Thank you. I also read your other articles about scripting with ‘Java Record Replay’ protocol.

  6. Sourav July 14, 2015 at 8:06 pm

    Thanks for the article Stuart.
    Is there a way to implement VTS or SQUID in Jave record replay scripts on LR?

  7. Anshul Chaurasia April 16, 2021 at 2:17 am

    web.reg_save_param(“CorrelationID”,
    “LB=”,
    “RB=”,
    LAST);

    • Anshul Chaurasia April 16, 2021 at 2:18 am

      How can we implement web_reg_save_param in here..

Comments are closed.