The SetCookieFixedValue class sets a Cookie for a virtual user, and the ClearCookies class clears all cookies for a virtual user.The SetCookieFixedValue class sets a Cookie, defined in the newCookie variable, for a virtual user just as if the server had returned a Set-Cookie.
Set and clear cookies for a virtual user
package test; import com.ibm.rational.test.lt.kernel.services.ITestExecutionServices; import com.ibm.rational.test.lt.execution.http.cookie.IHTTPVirtualUserInfo; import com.ibm.rational.test.lt.kernel.IDataArea; import java.text.ParseException; /** * The SetCookieFixedValue class sets a Cookie, defined in the newCookie * variable, for a virtual user just as if the server had returned a Set-Cookie. */ public class SetCookieFixedValue implements com.ibm.rational.test.lt.kernel.custom.ICustomCode2 { /** * Create using the no-arg constructor. */ public SetCookieFixedValue() { } public String exec(ITestExecutionServices tes, String[] args) { String newCookie = "MyCookie=CookieValue;path=/;domain=.ibm.com"; IDataArea dataArea = tes.findDataArea(IDataArea.VIRTUALUSER); IHTTPVirtualUserInfo httpInfo = (IHTTPVirtualUserInfo)dataArea.get(IHTTPVirtualUserInfo.KEY); try { httpInfo.getCookieCache().setCookie(newCookie); } catch (ParseException e) { tes.getTestLogManager().reportMessage("Unable to parse Cookie " + newCookie); } return null; } }The ClearCookies class clears all Cookies for a virtual user. For information on how cookies are treated in tests and schedules, see Cookies - How loops affect the state of virtual users.package test; import com.ibm.rational.test.lt.kernel.services.ITestExecutionServices; import com.ibm.rational.test.lt.execution.http.util.CookieCacheUtil; /** * The ClearCookies class clears all Cookies for a virtual user. */ /** * @author IBM Custom Code Samples */ public class ClearCookies implements com.ibm.rational.test.lt.kernel.custom.ICustomCode2 { /** * Create using no-arg constructor. */ public ClearCookies() { } public String exec(ITestExecutionServices tes, String[] args) { CookieCacheUtil.clearCookieCache(tes); return null; } }