Custom code enables you to perform such tasks as managing
loops, retrieving virtual user information, running external programs
from tests, and customizing data correlation.
You can extend test execution in the following ways:
Manage the behavior of loops. For a code example, see Controlling loops.
Run a batch file or program that sets up the environment needed
for a test and resets the environment afterward. For a code example,
see Running an external program from a test.
Controlling loops
This example demonstrates extending
test execution by using custom code to control loops. It provides sample code
that shows how you can manipulate the behavior of loops within a test to better
analyze and verify test results.
Retrieving the IP address of a virtual user
This example shows how to retrieve
the local IP address of a virtual user. Retrieving IP addresses is particularly
useful when virtual users are using IP aliases.
Printing input arguments to a file
The PrintArgs class prints its input arguments to the file C:\arguments.out.
This class could be used, for example, to print a response returned by the
server.
Counting the number of times that code is executed
The CountAllIterations class counts the number of times code is
executed by all virtual users. The CountUserIterations class counts the number
of times code is executed by an individual virtual user.
Storing and retrieving a string
You can use the getValue() and setValue() methods to store
and retrieve values in variables. Depending on the storage location
that you specify, variables can be shared among tests, or stored locally
in the current test.
Extracting a string or token from its input argument
The ParseResponse class extracts a string from its input argument.
The ExtractToken class extracts a particular token (string) from its input
argument. Both classes can be useful for handling certain types of dynamic
data correlation.
Using transactions and statistics
You
can use custom code to start transactions, gather additional statistics during
a transaction, and stop a transaction.