Manually Create a Java Script

This task describes how to manually create and edit a custom Java script using the Java Vuser protocol.

Note: To work with Java scripts, make sure that your Java environment is set up. For details, see Set up the environment for Java protocols.

  1. Create a new script:

    1. Open VuGen.

    2. Select File > New Script and Solution or click the New Solution button . The Create a New Script dialog box opens.

    3. From the Protocol list, select Java Vuser and click OK. VuGen displays a Java Vuser script template in the right pane.

  2. Insert your code into the script, in the Actions class, which is displayed in the right pane when the script template opens. For details, see Classes and methods.

  3. Insert additional API functions

    VuGen provides Java-specific functions for Java Vuser scripts. These functions are all static methods of the lrapi.lr class.

    The Java API functions are classified into several categories: Transaction, Command Line Parsing, Informational, String, Message, and Runtimefunctions.

    For more information about each of these functions, see the Function Reference (select the relevant version). Note that when you create a new Java Vuser script, the import lrapi.* is already inserted into the script.

  4. Insert additional Java functions

    To use additional Java classes, import them at the beginning of the script as shown below.

    Make sure that the additional classes are thread-safe and scalable.

    import java.io.*;
    import lrapi.*;
    public class Actions
    {
    ...
    }
    
  5. Set the classpath

    Set the classpath to the Java classes in Runtime Settings > Java Environment > Classpath. These files are then used as a reference, but are not contained in the script's folder.

  6. Add script enhancements

    Enhance your script with rendezvous points, transactions, output messages, and other elements. For more information, see Enhance a Java script.

Note: If additional files are required during replay, add them as follows: In the Solution Explorer pane, right click the Extra Files node and select Add Files to Script. The files are copied to the script's folder.

Back to top

See also: