Thursday, January 08, 2009

Cognos8 performance testing-Loadrunner scripts

Note: This post is kind of out-of-date and some patterns are not good, so please read《Scripting a Basic IBM Cognos 8 Report Execution using LoadRunner》post from official http://www.ibm.com/developerworks/data/library/cognos/page406.html

I want to share my experience of writing loadrunner scripts for Cognos BI, basically here I just describe how to run the reports in cognos viewer:
general steps:
1. recording the initial scripts, using Ajax(click & scripts), not web(click & scripts)

2. recording web(Http&html) initial scripts (due to some generating reports requests simply using Ajax(click & scripts) can not be processed properly)

3. copy some web(Http&html) initial scripts into Ajax(click & scripts) initial scripts

4. do parametrized and correlation on both scripts

5. content check & transaction added

6. some C coding needed to adjust more dynamic situation, for example you will wirting some string processing, file read/wirte or logic sentences: loop or if-then- else and so on.

7. testing with more accounts and tuning the scripts

code samples:(just an idea, not the real code you can directly use :) )

// minimum set of correlation parameters
web_reg_save_param("m_tracking_para7_2",
"LB=\"tracking\": \"",
"RB=\",",
"Notfound=warning",
LAST);

web_reg_save_param("ui_conversation_para7_2",
"LB=\"conversation\": \"",
"RB=\",",
"Notfound=warning",
LAST);

web_reg_save_param("caf_para7_2",
"LB=\"caf\": \"",
"RB=\",",
"Notfound=warning",
LAST);

web_reg_save_param("action_state_para7_2",
"LB=\"action_state\": \"",
"RB=\",",
"Notfound=warning",
LAST);
//reminder: set the Notfound=warning, instead of default value Notfound=error, we do not //want to see any errors in the console when we might not use these parameters

//transaction get started
lr_start_transaction("XLS_view");

// get the XLS format path from html source, i just found there are two patterns in response source
//or you can use the "status":"complete/working", as the indicator as well, this can make your scripts shorter
web_reg_find("Text=sURL = '/cgi-bin/reporting.cgi/gd/",
"SaveCount=XLS_path_Count1_7",
LAST);

web_reg_find("Text=sURL = '/cgi-bin/reporting.cgi/gd/",
"SaveCount=XLS_path_Count2_7",
LAST);

// send the request to the cognos server to generate XLS format reports
web_submit_data("reporting.cgi_17",
"Action={servername1}/cgi-bin/reporting.cgi",
"Method=POST",
"RecContentType=text/html",
"Referer={servername1}/cgi-bin/reporting.cgi",
"Snapshot=t17.inf",
"Mode=HTML",
ITEMDATA,
"Name=b_action", "Value=cognosViewer", ENDITEM,
"Name=ui.gateway", "Value=/cgi-bin/reporting.cgi", ENDITEM,
"Name=ui.action", "Value=run", ENDITEM,
"Name=ui.object", "Value=/content/folder[@name='{custom_folder_name1_new}'] /folder[@name='Performance Test Reports']/query[@name='AD_HOC_Report']", ENDITEM,
"Name=run.outputFormat", "Value=XLWA", ENDITEM,
"Name=run.outputLocale", "Value=en", ENDITEM,
"Name=run.prompt", "Value=true", ENDITEM,
"Name=ui.name", "Value=AD_HOC_Report", ENDITEM,
"Name=ui.runOptions", "Value=true", ENDITEM,
LAST);

//get the int number of XLS path occurrence in the HTML source
i =atoi(lr_eval_string("{XLS_path_Count1_7}"));

j =atoi(lr_eval_string("{XLS_path_Count2_7}"));

// if number of XLS path occurrence more than once, including once, then get transaction done

if (i!=0||j!=0) { //find the XLS path without waiting dialaug popup

lr_end_transaction("XLS_view7",LR_AUTO);
}

// else if number of XLS path occurrence does not happen, then use "wait" action
if (i==0&&j==0) {

//wait until the XLS path come back
while(i==0&&j==0){
web_reg_find("Text=sURL = '/cgi-bin/reporting.cgi/gd/",
"SaveCount=XLS_path_Count3_7",
LAST);

web_reg_find("Text=sURL = '/cgi-bin/reporting.cgi/gd/",
"SaveCount=XLS_path_Count4_7",
LAST);
//wait action
web_submit_data("reporting.cgi_19",
"Action={servername1}/cgi-bin/reporting.cgi",
"Method=POST",
"RecContentType=text/html",
"Snapshot=t19.inf",
"Mode=HTML",
ITEMDATA,
"Name=b_action", "Value=cognosViewer",ENDITEM,
"Name=cv.id", "Value=_NS_",ENDITEM,
"Name=ui.action", "Value=wait",ENDITEM,
"Name=cv.actionState","Value={action_state_para7_2}",ENDITEM,
"Name=ui.primaryAction", "Value=runSpecification",ENDITEM,
"Name=run.outputFormat", "Value=XLWA",ENDITEM,
"Name=ui.conversation", "Value={ui_conversation_para7_2}",ENDITEM,
"Name=m_tracking", "Value={m_tracking_para7_2}",ENDITEM,
"Name=ui.cafcontextid", "Value={caf_para7_2}",ENDITEM,
"Name=cv.responseFormat", "Value=data",ENDITEM,
LAST);

i=atoi(lr_eval_string("{XLS_path_Count3_7}"));

j=atoi(lr_eval_string("{XLS_path_Count4_7}"));

k++;

if (k>5) {

lr_error_message("XLS view failed by: %s",lr_eval_string("{username1}"));
lr_exit(LR_EXIT_ACTION_AND_CONTINUE ,LR_FAIL);
break;
}

}

//get the XLS path in wait action response data
web_reg_save_param("XLS_src_path7",
"LB=sURL = '/cgi-bin/reporting.cgi/gd/",
"RB='",
"Notfound=warning",
LAST);

web_reg_save_param("XLS_src_path7_2",
"LB=sURL = '/cgi-bin/reporting.cgi/gd/",
"RB='",
"Notfound=warning",
LAST);

web_submit_data("reporting.cgi_29",
"Action={servername1}/cgi-bin/reporting.cgi",
"Method=POST",
"RecContentType=text/html",
"Snapshot=t29.inf",
"Mode=HTML",
ITEMDATA,
"Name=b_action", "Value=cognosViewer",ENDITEM,
"Name=cv.id", "Value=_NS_",ENDITEM,
"Name=ui.action", "Value=wait",ENDITEM,
"Name=cv.actionState","Value={action_state_para7_2}",ENDITEM,
"Name=ui.primaryAction", "Value=runSpecification",ENDITEM,
"Name=run.outputFormat", "Value=XLWA",ENDITEM,
"Name=ui.conversation", "Value={ui_conversation_para7_2}",ENDITEM,
"Name=m_tracking", "Value={m_tracking_para7_2}",ENDITEM,
"Name=ui.cafcontextid", "Value={caf_para7_2}",ENDITEM,
"Name=cv.responseFormat", "Value=data",ENDITEM,
LAST);

//choose one XLS path value, and get the XLS report from cognos server
if (strlen(lr_eval_string("{XLS_src_path7}"))) {

web_url("XLSviewer",
"URL={servername1}/cgi-bin/reporting.cgi/gd/{XLS_src_path7}",
LAST);
}

else if (strlen(lr_eval_string("{XLS_src_path7_2}"))) {

web_url("XLSviewer",
"URL={servername1}/cgi-bin/reporting.cgi/gd/{XLS_src_path7_2}",
LAST);
}
//transaction get done
lr_end_transaction("XLS_view",LR_AUTO);

}

this is my test scripts not the formal one, but it indicates that there are two cases for reporting generation, one is run the reports without extra wait, second is you have to wait for a certain time to get the reports done, so it is different from scripts perspective. if you have any better solutions, please leave a message to me.

the limitation of My solution here can not get the reports download time that means it can not include client side process time,so it is not the real user experiecne. you can wirte some C code to fopen, lr_eval_string_ext, fwrite to simulate the client side download action, but it will cause your scripts slower and slower(memory issue by LR??), so i just ignore this to make a trade-off, find a server problem is sufficient to me right now :)

if you met any problems or questions, you can share in this blog and freely discuss.
---Cheng Chi

No comments:

Post a Comment