web.addCookie

Adds, deletes, or replaces a cookie.

Syntax

web.addCookie( {object} );

JavaScript Object

{  
    name:"<number>",
    value:"<number>",
    domain:"<number>",
    expires:"<number>",
    path:"<number>",
    secure:""
}    

For details on the elements of the Cookie object, see Internet Standards Track document RFC6265.

Property Name
Description
nameThe cookie name.
domainThe domain of the web server.
expiresThe cookie expiration time.
pathThe cookie path
secureNo value.
searchstring
The text string for which to search. This attribute must be a non–empty, null–terminated character string. Use the format "text=string".

Return Values

Not applicable

Parameterization

You can use standard LoadRunner Professional parameterization with all string values in JavaScript objects.

General Information

The web.addCookie function adds, deletes, or edits a cookie. If the name and path match an existing cookie:

  • If the expires date has past, the cookie is deleted.
  • Else, the existing cookie is overwritten.

You can use web.addCookie prior to starting the run to add cookies usually stored in the browser. You can also add a cookie in any case where the automatic handling of cookies is not appropriate for your test.

In a web.addCookie call, the domain attribute is required, though it is generally optional. In normal browsing, if the domain is not specified in a Set–Cookie header, the value of domain is the host name of the server that generated the cookie response. Since this information is not available to the load generator host, domain is required.

Note: Scripts do not read or modify the cookies that are stored by your browser. Instead, each script uses the cookies that are sent to the Vuser by the server host at runtime. These cookies are maintained only temporarily while the script runs. The web–cookie functions (web.addCookie, web.removeCookie, and web.cleanupCookies) manipulate only these temporary cookies.

Example

web.addCookie("client_id=China127B; path=/; expires=Wednesday,09-Nov-2001 23:12:40 GMT; domain=www.mycompany.com")

web.addCookie(
  {
    name:"client_id",
    value: "China127B",
    path: "/",
    expires :"Wednesday,09-Nov-2001 23:12:40 GMT",
    domain : "www.mycompany.com"
  }
);