How loops affect the state of virtual users

If verification points fail unexpectedly during a run, the cause might be that virtual users in loops do not maintain their original state. To enable each virtual user to enter the loop in the original state, you can modify the test's HTTP options or add custom code.

About this task

By default, the cookie cache for a virtual user is not reset during a test run. This is consistent with a browser's behavior. If a test or schedule contains loops, and a web server sets a cookie during the first iteration of the loop, that cookie is "remembered" on subsequent iterations.

However, in certain instances, you might want to clear all cookies cached for a particular virtual user. For example, if you want each iteration of a loop to appear as a new user, you must reset the cache. If you do not, although the test completes, verification points that you have set within the test may fail.

There are two ways to reset the cookie cache, and each way has different effects.

To reset the cookie cache when looping in the schedule, or when the test follows another test in the schedule, use the following method. This resets the cache whenever the test is entered. Even if your tests do not loop, use this method if you are running back-to-back tests or Siebel tests.

  1. In the Test Navigator, browse to the test and double-click it. The test opens.
  2. On the HTTP options page, select Clear cookie cache when the test starts.


To reset the cookie cache from one loop iteration to the next when you have put a loop around the entire contents of the test, and the loop is inside the test, add custom code to the test and call an API, as follows:

  1. Run the test or schedule to add the current Java libraries to the class path.
  2. Open the test and select the test element located at the point where you want the cookie cache to be reset. Typically, this is at the end of the loop.
  3. Click Add or Insert and select Custom Code.
    Add appends the custom code to the bottom of the selected element (test or test page). Insert adds the custom code above the selected page or page request.
  4. Add the following Java import statement: Import;
  5. Add the following Java code inside the exec method: CookieCacheUtil.clearCookieCache(tes);


The following example shows a custom code addition that resets the cookie cache. The lines that you add to the generated custom code template are shown in bold:
Note: For another example of custom code that sets and clears cookies, see Setting and clearing cookies for a virtual user.
package test;


public class Class1131739398417 implements {
	public Class1131739398417() {
	public String exec(ITestExecutionServices tes, String[] args) {
		return null;