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.

Procedure

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 com.ibm.rational.test.lt.execution.http.util.CookieCacheUtil;
  5. Add the following Java code inside the exec method: CookieCacheUtil.clearCookieCache(tes);

Example

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;

import com.ibm.rational.test.lt.execution.http.util.CookieCacheUtil;
import com.ibm.rational.test.lt.kernel.services.ITestExecutionServices;

public class Class1131739398417 implements
		com.ibm.rational.test.lt.kernel.custom.ICustomCode2 {
		
	public Class1131739398417() {
	}
	public String exec(ITestExecutionServices tes, String[] args) {
		CookieCacheUtil.clearCookieCache(tes);
		return null;
	}
 }