How to get the cookies values generated by javascript.

Hi All,

I am having issues correlating a dynamic values which was generated by a javascript code.

It seems the application is setting its cookies based from the javascript code and it don't apprear from the server response. I can't find a way to manually parse the data and add it manually in the cookies at the runtime.

Text in bold are the variable I am trying to get its value so I can manually add the cookie in the runtime.

Login.c(14):             function setSessionIDandRedirect() {\r\n
Login.c(14):                 var id = "-1";\r\n
Login.c(14):                 var url = OktaURL() + '/api/v1/sessions/me';\r\n
Login.c(14):                 var xhr = new XMLHttpRequest();\r\n
Login.c(14):                 xhr.open('GET', url);\r\n
Login.c(14):                 xhr.withCredentials = true;\r\n
Login.c(14):                 xhr.send(null);\r\n
Login.c(14):                 xhr.onreadystatechange = function () {\r\n
Login.c(14):                     if (xhr.readyState === 4) {\r\n
Login.c(14):                         if (xhr.status === 200) {\r\n
Login.c(14):                             var sess = JSON.parse(this.responseText);\r\n
Login.c(14):                             setCookie("OKTA_ID", sess.id, 1);\r\n
Login.c(14):                             location.href = window.location.pathname.toLowerCase().replace("login.aspx", "OktaSSO.aspx");\r\n
Login.c(14):                         } else {\r\n
Login.c(14):                             console.log('Error: ' + xhr.status); // An error occurred during the request.\r\n
Login.c(14):                             alert("Authentication Failed with Error\\n\\n" + xhr.status);\r\n
Login.c(14):                         }
Login.c(14):                     }
Login.c(14):                 };
Login.c(14):                 return id;
Login.c(14):             }



1 Reply
Respected Contributor.
Respected Contributor.

Re: How to get the cookies values generated by javascript.


To get the cookie values we can use the Html mode with keeping the Non-Html (Record wthin the current step) , once you have keep and select the cookies as Generate web_add_cookies functions option selected in the HTTP properties->Advanced tab of LoadRunner.

 In Runtime settings of LoadRunner -> Preferences Tab use the option Use WinInet replay instead of Sockets(windows only) mostly the script get pass with proper handling of all cookies in the application.

For adding the cookies manually in the desired location of the script , we need to pass the cooke from the Additional Attributes tab (runtime settings option) of the loadrunner, like cookie name and cookie value. (it help you ).


Surya Kosuri.

The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.