Skip to main content

Choosing a Value

The Select the replacement value page in the Eggplant Performance Generation Rules Wizard is where you provide a method of obtaining a value for use in a generation rule. The actual name of the page and how the value is used depend on the rule type:

The Different Methods

These are the different ways you can choose a value. Descriptions of each method follow:

Value from Data Dictionary

This method enables you to obtain a dynamic value, which can be different during a test depending on the virtual user (VU) running the script, and the data sources available. The VirtualUserScript API provides a method called getString(string key), which returns different values from a data dictionary during a test.

For example, getString("Email") might return a different email address for each VU, from a data source containing a list of email addresses.

The text you enter in the Key box is passed as the key parameter to the getString(string key) method, and refers to the column or key in the data source from which the value should be obtained.

You do not need to provide quotes around the string.

For more information about data sources, refer to Parameterizing Virtual User Scripts.

note

If you choose this method, you must create a matching data binding in any tests in which the generated script is used. For information about defining data bindings, see Data Source Bindings.

Value from Data Dictionary (with default)

This method is very similar to Data value. The difference is that an extra parameter is passed to getString(string key, string default), which provides a default value if the key cannot be found in any data sources bound to the VU running the script.

This option is only available for Replace rule types. The default value is the text to replace, i.e., the original text before replacement occurs. This means that, if the key is not found in any data sources, the script behaves in the same way as the original recording.

Fixed Value

This method enables you to obtain a fixed value. The text you enter in the Text box is the string that will be inserted into the script. You do not need to put quotes around the string.

What was Recorded

This method, which is only available for Verify rule types, enables you to obtain the value from the recording, and then insert it into the script. It is a convenient way to make the VU verify that the responses received during the test are the same as or similar to the responses received during recording.

Function Call

This method enables you to obtain a custom value, which can be different during a test. The recommended way to use this method is to define a function in your Custom Virtual User Script Source file, and then enter the name of the function with parentheses and any required parameters in the Code to insert box.

Or, enter any function in the VirtualUserScript API that returns a string, for example getVUName() or getProgressPoint().

You can use four special macros in the Code to execute blocks of code, and the correct variable will be substituted for the macro when the script is generated. The context for these blocks of code is always the same: a Request object has been created using a particular Url object, and then Request.send() has been called and the resulting response returned as a Response object.

Because these objects are stored in variables with different names depending on where they appear in the generated script, it is difficult to refer to them directly. Using the macros within the code blocks eliminates this difficulty:

  • $url - replaced with current Url variable name.
  • $request - replaced with current Request variable name.
  • $response - replaced with current Response variable name.
  • $index - replaced with the current request index (an integer literal).

You can use these macros anywhere you would normally use these variables, such as parameters to a method in your custom VU script.

The text you enter in the Function call box is inserted directly into the script.

warning

If you enter text that is not valid Java or C# code, your generated script will not compile.