After a few blogs with code snippet showing the differences between Loadrunner syntax and NetGend javascript syntax, I got an excellent request: "can you compare a full Loadrunner script with a full NetGend javascript"?
I like this idea because it not only gives a better idea on how the NetGend javascript works in more detail, it also shows the possibility of translating a loadrunner script into (much simpler) NetGend script.
The loadrunner script is based on a real one from production test, it emulates VUsers performing the following actions: 1) login to a conference web site, 2) set up a conference, 3) update the conference 4) cancel the conference and logout.
To save the size of this blog, I combined the vuser_init, vuser_end and action parts together and trimmed the number resources for transactions. By comparing it with NetGend script, you can see
- Assigning to a parameter like "URL" is much simpler with NetGend Script
- NetGend functions
- function names are shorter and easier to remember
- function parameters are shorter too, they are easier to understand.
- Variable substitution is very close between the two scripts
- with Loadrunner, you do it with {VARNAME}
- with NetGend, you do it with ${VARNAME}
- One subtle but important differenence on variable substitution
- In NetGend, it happens in all strings (including all string parameters of functions),
- In Loadrunner, only certain parameters of certain function are capable of doing substitution.
- On NetGend platform, when there are many resources to download, it will spawn many sessions to retrieve the resources at the same time.
Action() //Loadrunner script
{
char Url[20];
sprintf(Url ,"conference.example.com");
lr_save_string (Url,"URL");
web_url("Login_conference.example",
"URL=http://{URL}/",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
EXTRARES,
"Url=/images/bg_content04.gif", "Referer=http://{URL}/loginAction!getCookie.action", ENDITEM,
"Url=/images/bg_loginLeft_bg01.gif", "Referer=http://{URL}/loginAction!getCookie.action", ENDITEM,
LAST);
//lr_think_time(21);
web_submit_form("loginAction!login.action_2",
"Snapshot=t3.inf",
ITEMDATA,
"Name=password", "Value={Password}", ENDITEM,
"Name=vercode", "Value=", ENDITEM,
"Name=qsbycookie", "Value=<OFF>", ENDITEM,
EXTRARES,
"Url=/images/bg_welcome01.gif", "Referer=http://{URL}/mainAction.action", ENDITEM,
"Url=/images/bg_contentHome01.jpg", "Referer=http://{URL}/mainAction.action", ENDITEM,
LAST);
//lr_think_time(8);
web_url("conf2_readyForCreate.action",
"URL=http://{URL}/reserve/conf2_readyForCreate.action",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t7.inf",
"Mode=HTML",
EXTRARES,
"Url=../css/jquery.datepick.css", ENDITEM,
"Url=../images/bg_button07.gif", ENDITEM,
LAST);
lr_start_transaction("reserve");
web_submit_data("conf2_reserve.action",
"Action=http://{URL}/reserve/conf2_reserve.action",
"Method=POST",
"RecContentType=text/html",
"Referer=http://{URL}/reserve/conf2_readyForCreate.action",
"Snapshot=t11.inf",
"Mode=HTML",
ITEMDATA,
"Name=rv.conferenceId_by", "Value=", ENDITEM,
"Name=rv.confStatus", "Value=0", ENDITEM,
"Name=rv.confName", "Value=test_per_update", ENDITEM,
"Name=rv.dateStart", "Value={Date}", ENDITEM,
EXTRARES,
"Url=../images/bg_H02.gif", ENDITEM,
LAST);
lr_end_transaction("reserve");
web_reg_save_param ("conferenceid","LB=<a href=\"/reserve/confView.action?conferenceid="",
RB="\" reserve="">",
LAST);
web_url("conf2_list.action",
"URL=http://{URL}/reserve/conf2_list.action",
"Resource=0",
"RecContentType=text/html",
"Referer=http://{URL}/mainAction.action",
"Snapshot=t6.inf",
"Mode=HTML",
EXTRARES,
"Url=../images/bg_content01.gif", ENDITEM,
"Url=../images/bg_content02.gif", ENDITEM,
LAST);
web_url("conf2_readyForUpdate.action",
"URL=http://{URL}/reserve/conf2_readyForUpdate.action?conferenceid={conferenceid}",
"Resource=0",
"RecContentType=text/html",
"Referer=http://{URL}/reserve/conf2_list.action",
"Snapshot=t14.inf",
"Mode=HTML",
LAST);
lr_think_time (30);
lr_rendezvous("update");
lr_start_transaction("update");
web_submit_data("conf2_update.action",
"Action=http://{URL}/reserve/conf2_update.action",
"Method=POST",
"RecContentType=text/html",
"Referer=http://{URL}/reserve/conf2_readyForUpdate.action?conferenceid={conferenceid}",
"Snapshot=t18.inf",
"Mode=HTML",
ITEMDATA,
"Name=rv.conferenceId_by", "Value={conferenceid}", ENDITEM,
"Name=rv.confStatus", "Value=0", ENDITEM,
"Name=rv.contactphone", "Value=", ENDITEM,
"Name=rv.confName", "Value=test_per_update{NameNumber}", ENDITEM,
"Name=rv.dateStart", "Value=2013-11-28", ENDITEM,
LAST);
lr_end_transaction("update", LR_AUTO);
lr_start_transaction("Cancel");
web_submit_data("conf2_cancel.action",
"Action=http://conference.example.com/reserve/conf2_cancel.action",
"Method=POST",
"RecContentType=text/html",
"Referer=http://conference.example.com/reserve/conf2_list.action",
"Snapshot=t6.inf",
"Mode=HTML",
ITEMDATA,
"Name=conferenceid", "Value={conferenceid}", ENDITEM,
LAST);
lr_end_transaction("Cancel", LR_AUTO);
web_url("logoutAction.action",
"URL=http://{URL}/logoutAction.action",
"Resource=0",
"RecContentType=text/html",
"Referer=http://{URL}/reserve/conf2_list.action",
"Snapshot=t21.inf",
"Mode=HTML",
LAST);
return 0;
}
Here is the equivalent script in NetGend Javascript.
function VUSER() { //NetGend Javascript
URL = "conference.example.com";
action(http, URL);
httpHeader.Refer = "http://${URL}/loginAction!getCookie.action";
spawn( ["/images/bg_content04.gif","/images/bg_loginLeft_bg01.gif"]);
//sleep(21);
http.POSTData = "password=${Password}&vercode=&qsbycookie=<OFF>";
action(http, URL);
httpHeader.Referer = "http://${URL}/mainAction.action";
spawn( ["/images/bg_welcome01.gif","/images/bg_contentHome01.jpg"]);
//sleep(8);
action(http,"http://${URL}/reserve/conf2_readyForCreate.action");
spawn(["../css/jquery.datepick.css", "../images/bg_button07.gif"]);
b."rv.conferenceId_by" = "";
b."rv.confStatus" = 0;
b."rv.confName" = "test_per_update";
b."rv.dateStart" = currentTime();
http.POSTData = combineHttpParam(b);
httpHeader.Referer = "http://${URL}/reserve/conf2_readyForCreate.action";
action(http, "http://${URL}/reserve/conf2_reserve.action");
spawn(["../images/bg_H02.gif"]);
conferenceid = substring(http.replyBody, "<a href=\"/reserve/confView.action?conferenceid=", "\" >");
httpHeader.Refer = "http://${URL}/mainAction.action";
action(http,"http://${URL}/reserve/conf2_list.action");
spawn(["../images/bg_content01.gif", "../images/bg_content02.gif"]);
httpHeader.Referer = "http://${URL}/reserve/conf2_list.action";
action(http, "http://${URL}/reserve/conf2_readyForUpdate.action?conferenceid=${conferenceid}");
sleep(30);
rendv("update", 40); //gather 40 VUsers here before moving on to next step
httHeader.Referer = "http://${URL}/reserve/conf2_readyForUpdate.action?conferenceid=${conferenceid}",
c."rv.conferenceId_by" = conferenceid;
c."rv.confStatus" = 0;
c."rv.contactphone" = "";
c."rv.confName" = "test_per_update${vuserId}";
c."rv.dateStart" = "2013-11-28";
action(http, "http://${URL}/reserve/conf2_update.action");
httpHeader.Referer = "http://conference.example.com/reserve/conf2_list.action";
http.POSTData = "conferenceid=${conferenceid}";
action(http, "http://conference.example.com/reserve/conf2_cancel.action");
httpHeader.Referer = "http://${URL}/reserve/conf2_list.action";
action(http, "http://${URL}/logoutAction.action");
}
No comments:
Post a Comment