Session ID (“sessionid”) is different every time you run an installable cloud app. Obviously, since the execution of the recorded script depends upon the session ID returned by the server, it is necessary to catch the proper “sessionid” from the CreateSession server response and then attach it to the subsequent requests. That is, correlating the session ID in the script for successful replay.
-
Add scripts in the CreateSession for capturing the session ID and assign it to a parameter.
A CreateSession request looks like the following:
web_custom_request("CreateSession", "URL=http://192.168.178.125:5001/api/ServerApi/CreateSession", "Method=POST", "Resource=0", "RecContentType=application/json", "Referer=", "Snapshot=t60.inf", "Mode=HTTP", "EncType=application/json;charset=UTF-8", "Body={\"version\":\"1.0\",\"requestid\":\"52C33A54-6687-40ef-ACA8-4FC34B8066CE\",\"appname\": \"psapi4loadrunner\",\"namespace\":\"Psapi4loadrunner\",\"session\":null,\"type\":31,\ "transaction\":null,\"content\":{\"createsession\":{\"securestring\":\"" "eyJ0aW1lc3RhbXAiOjE2MjQyNjk4MjYsInBheWxvYWQiOiJuQStOK1ZKb1pqRkxFRzBsT0QzMnAzZmtsVlc2Qk xydGZuQ2FqcUJvcTNTY0FORDdYeDZmTDFnMVFGUFhNdk9EVGpWTjgyVERLOTdSMHhHVEhSMmxXZz09Iiwic2lnbm F0dXJlIjoiOUpicHc2OUFwWFYxcEg4UTEraDRodHh4SHlGVnptS2lhWmdNZmJQS1pP UmdBVW9JcHdoTzNTY2krbnltV2NTZ2lidzUyZHhsYjluQlpjQXgyUmd4S2c9PSJ9\"}}}", LAST);
You need to add the following code above the CreateSession request:
-
Add a web_set_max_html_param_len function to be the first line in the script file. It would set the maximum length of the HTML string which LoadRunner can retrieve:
web_set_max_html_param_len("262144");
-
Add a web_reg_save_param function above CreateRequest to capture the session ID and assign it to the parameter “gs_SessionID”.
web_reg_save_param("gs_SessionID","LB=\"sessionid\":\"","RB=\"},\"graceperiod","Search=Body",LAST);
-
-
Replace the session ID with the parameter every time it occurs.
-
Identify the session ID that needs to be correlated. You may do a global search in the script for “session” which is followed by the session ID.
-
Replace every occurrence of the session ID with the parameter <gs_SessionID>.
Taking the ConnectAndCreateTransaction request as an example. The following is the original request. You see the session ID is the string following the “session”.
web_custom_request("ConnectAndCreateTransaction", "URL=http://192.168.178.125:5001/api/ServerApi/ConnectAndCreateTransaction", "Method=POST", "Resource=0", "RecContentType=application/json", "Referer=", "Snapshot=t65.inf", "Mode=HTTP", "EncType=application/json;charset=UTF-8", "Body={\"version\":\"1.0\",\"requestid\":\"D024C3D8-FE54-490e-BAB6-23F8CAB3D8F3\",\"appname\":\"psapi4loadrunner\", \"namespace\":\"Psapi4loadrunner\",\"session\":\"""eyJ0aW1lc3RhbXAiOjE2MjQyNjk4MjgsInBheWxvYWQiOiJ3bmFMV0FuZ2 14S2RnQlhqbFVqQlRNNmswRVUxN2gwaFhpb3pEbm9SakkyOUtkYk9kWlMwWGgxeWtPdTlYRFI5QTFITXZKTVcvRW9IbEppQjY4MVhBQXhHU3U rZlA0Y3YvOEVjMWF5OVNxTzlSUFpEYjJPYTIrektQUmRPSXV2L25yVXYwdDhGNmpzRUY0TzVqUTROMmVhc1piY0c5NkpJTUVCUi9jK25OUEFE cTNiZ1BxWTZtL2dodlhBYW84U3AiLCJzaWduYXR1cmUiOiJQTEo3WDJaRnBVV1FyOXcvK1dwaG4rWnRWK3BPc0taRUhwd0ZReWNYQ2tkZ3RVS WRuUW52QVh5VlgvUUpDTlZFZUVFR0twcGtIOUs0c3FQTDB3SVZqQT09In0=\",\"type\":7,\"transaction\":null,\"content\": {\"connect""\":{\"cachegroup\":\"\",\"cachename\":\"\",\"transactionname\":\"sqlca\",\"params\":\"""eyJ0aW1lc 3RhbXAiOjE2MjQyNjk4MjgsInBheWxvYWQiOiJQK1kvMk5yWmVTUWY0dElIempGMy9vdlk0VFhWY0NWNlFrd2UxVGJkSENHTFNnc2R0allOZU dtNDN2WlB6dFFCLzk0Ulk4dVFOYkNISnZqblltQ3RoTUZCRFJaS21YZmtDWExPRkdjbWt2WXFkSXBEcDRhN0NLUDBVK1gxOGhQQVhiNjJoSXA 3aWp2S0FkZEpNOFU3QmxXbEI5MGx4ZEp5OVVTNU00NzZhaGxZMlRSYlF1NTlWcksxdER0VngxbERKRU80cGFvRVVkM0cxQk5RbUtrcVBqaTda MDFPNDZ3UmNvVVp6MlB1TXkrUG1VNVlvWmF0eUhxRjN3ZExyRlZLIiwic2lnbmF0dXJlIjoiVGJoR2dEeEtLWFg2V3V6bTIwei94WXdKb2FFW TNvUlgxSTkzeDJiS1lncjd0MmFXcmxaUkp0TTh6dEZpVUc4R1Y3VTgrdk""xZL2pQK29lZGxTdW0yWWc9PSJ9\"}}}", LAST);
After replacing the occurrence of the session ID with the parameter <gs_SessionID>, the script will look like the following:
web_custom_request("ConnectAndCreateTransaction", "URL=http://192.168.178.125:5001/api/ServerApi/ConnectAndCreateTransaction", "Method=POST", "Resource=0", "RecContentType=application/json", "Referer=", "Snapshot=t65.inf", "Mode=HTTP", "EncType=application/json;charset=UTF-8", "Body={\"version\":\"1.0\",\"requestid\":\"D024C3D8-FE54-490e-BAB6-23F8CAB3D8F3\", \"appname\":\"psapi4loadrunner\",\"namespace\":\"Psapi4loadrunner\", \"session\":\"""<gs_SessionID>\",\"type\":7,\"transaction\":null,\"content\" :{\"connect""\":{\"cachegroup\":\"\",\"cachename\":\"\",\"transactionname\":\"sqlca\",\"params\":\ """eyJ0aW1lc3RhbXAiOjE2MjQyNjk4MjgsInBheWxvYWQiOiJQK1kvMk5yWmVTUWY0dElIempGMy9vdlk0VFhWY0NWNlFrd2U xVGJkSENHTFNnc2R0allOZUdtNDN2WlB6dFFCLzk0Ulk4dVFOYkNISnZqblltQ3RoTUZCRFJaS21YZmtDW ExPRkdjbWt2WXFkSXBEcDRhN0NLUDBVK1gxOGhQQVhiNjJoSXA3aWp2S0FkZEpNOFU3QmxXbEI5MGx4ZEp5OVVTNU00NzZhaGx ZMlRSYlF1NTlWcksxdER0VngxbERKRU80cGFvRVVkM0cxQk5RbUtrcVBqaTdaMDFPNDZ3UmNvVVp6MlB1T XkrUG1VNVlvWmF0eUhxRjN3ZExyRlZLIiwic2lnbmF0dXJlIjoiVGJoR2dEeEtLWFg2V3V6bTIwei94WXdKb2FFWTNvUlgxSTk zeDJiS1lncjd0MmFXcmxaUkp0TTh6dEZpVUc4R1Y3VTgrdk""xZL2pQK29lZGxTdW0yWWc9PSJ9\"}}}", LAST);
-