2

In the loadrunner script i want to parse the json response i received and want to check whether the response is correct. For that i have the following code :

web_set_max_html_param_len("999999");

web_custom_request("JsonData", 
    "URL=https://localhost:8080/testpgm", 
    "Method=POST", 
    "RecContentType=application/json", 
      LAST);

web_reg_save_param("JsonData",
    "LB=",
    "RB=",
    "Search=Body",
    LAST);

web_js_run(
"Code=getEmployee(LR.getParam('JsonData'));",
"ResultParam=Names", 
SOURCES, 
"File=getEMP.js",ENDITEM, 
LAST); 

The javascript code is as follows :

function getEmployee(stringData)
{ 
    var data = JSON.parse(stringData); 
    var index = data[data.length-1];
    var value = data.ItemLists{0}.Items{0}.NamedValues{0}.Value{1}.name;
    return value; 
} 

It doesn't work and I get the following error :

Action.c(43): web_js_run started    [MsgId: MMSG-26355]
Action.c(43): Error -26000: Error from JS Engine: "C:\Users\admin\Documents\VuGen\Scripts\Web1\getEMP.js:5:SyntaxError: missing ; before statement
"   [MsgId: MERR-26000]
Action.c(43): Error -35051: Failed to run the JavaScript code   [MsgId: MERR-35051]
Action.c(43): Warning -26379: Pending web_reg_save_param/reg_find/create_html_param[_ex] request(s) are deleted and will be handled as "not found"      [MsgId: MWAR-26379]
Action.c(43): Error -26377: No match found for the requested parameter "JsonData". Check whether the requested boundaries exist in the response data. Also, if the data you want to save exceeds 999999 bytes, use web_set_max_html_param_len to increase the parameter size    [MsgId: MERR-26377]
Action.c(43): Error -26374: The above "not found" error(s) may be explained by header and body byte counts being 0 and 0, respectively.     [MsgId: MERR-26374]
Action.c(43): web_js_run highest severity level was "ERROR"     [MsgId: MMSG-26391]
user3530656
  • 121
  • 4
  • 14
  • What did you try to do here: "var value = data.ItemLists{0}.Items{0}.NamedValues{0}.Value{1}.name;"? I think you mean var value = data.ItemLists[0].Items[0].NamedValues[0].Value[1].name; – Buzzy Jan 29 '15 at 08:57
  • Yes. that's correct. – user3530656 Jan 29 '15 at 10:28
  • Can you post you jsondata? You can try the js function inside chrome to see if it functionall all correct. Simple html file like this can help you to do it – Shambu Jan 29 '15 at 11:26

1 Answers1

0

Correlation function(web_reg_save_param) should be placed before the request. Try

web_set_max_html_param_len("999999");

web_reg_save_param("JsonData",
    "LB=",
    "RB=",
    "Search=Body",
    LAST);


web_custom_request("JsonData", 
    "URL=https://localhost:8080/testpgm", 
    "Method=POST", 
    "RecContentType=application/json", 
      LAST);


web_js_run(
"Code=getEmployee(LR.getParam('JsonData'));",
"ResultParam=Names", 
SOURCES, 
"File=getEMP.js",ENDITEM, 
LAST); 
Karthick PKa
  • 114
  • 6