Difference between revisions of "LoadRunner Code Snippets"
Jump to navigation
Jump to search
PeterHarding (talk | contribs) |
PeterHarding (talk | contribs) |
||
Line 84: | Line 84: | ||
if (atoi(lr_eval_string("{alert_count}")) > 0) { | if (atoi(lr_eval_string("{alert_count}")) > 0) { | ||
sprintf(msgbuf, "No longer possible to process any bids for this bid invitation"); | |||
userLog(msgbuf); | |||
return 0; | |||
} | |||
</pre> | </pre> | ||
Revision as of 18:03, 16 April 2008
Detect a Pattern in a Page
//------------------------------------------------------------------------- // Warning - You are already logged on to the system in the following sessions: web_reg_find("Text=You are already logged on to the system", "SaveCount=warning_count", LAST); lr_think_time(2); web_text_link("Log On", "Snapshot=t3.inf", DESCRIPTION, "Text=Log On", ACTION, "UserAction=Click", LAST); lr_end_transaction("login", LR_AUTO); sprintf(msgbuf, "Logged in..."); userLog(msgbuf); //------------------------------------------------------------------------- if (atoi(lr_eval_string("{warning_count}")) > 0) { sprintf(msgbuf, "Warning - You are already logged on to the system"); userLog(msgbuf); web_text_link("Continue", "Snapshot=t35.inf", DESCRIPTION, "Text=Continue", ACTION, "UserAction=Click", LAST); } //------------------------------------------------------------------------- lr_think_time(3); lr_start_transaction("CreateBid"); web_text_link("CreateBid", "Snapshot=t4.inf", DESCRIPTION, "Text=Create Bid", "FrameName=menu", ACTION, "UserAction=Click", LAST); lr_end_transaction("CreateBid", LR_AUTO); sprintf(msgbuf, "CreateBid done..."); userLog(msgbuf); //------------------------------------------------------------------------- // <input type="hidden" name="MessLine" value="No longer possible to process any bids for this bid invitation"> lr_think_time(3); web_reg_find("Text=value=\"No longer possible to process any bids for this bid invitation", "SaveCount=alert_count", LAST); lr_start_transaction("select_93"); web_text_link("select_93", "Snapshot=t5.inf", DESCRIPTION, "Text=93", "FrameName=IACFrame", ACTION, "UserAction=Click", LAST); lr_end_transaction("select_93", LR_AUTO); sprintf(msgbuf, "select_93 done..."); userLog(msgbuf); //------------------------------------------------------------------------- if (atoi(lr_eval_string("{alert_count}")) > 0) { sprintf(msgbuf, "No longer possible to process any bids for this bid invitation"); userLog(msgbuf); return 0; }
Find and Extract Multiple Instances in a Page
Here we are looking for invoices in an invoice list...
//----- At 'Invoice Search Screen' ----------------------------------------- web_reg_find("Text=iCMS v3.1.4.07 Invoice List", LAST); web_reg_save_param("pageID", "LB=input type=\"hidden\" name=\"pageID\" value=\"", "RB=\"", LAST); // Look for lines like "<!------------------------ Invoice 427738 ---" web_reg_save_param("invoice", "LB=!------------------------ Invoice ", "RB= ---", "ORD=ALL", LAST); web_submit_data("icms_5", "Action=https://test403d.xxxx.com.au/icms-servlet/icms", "Method=POST", "RecContentType=text/html", "Referer=https://test403d.xxxx.com.au/icms-servlet/icms", "Snapshot=t22.inf", "Mode=HTTP", ITEMDATA, "Name=pageID", "Value={pageID}", ENDITEM, "Name=tfLastName", "Value=A", ENDITEM, "Name=tfFirstName", "Value=", ENDITEM, "Name=tfEmployeeNumber", "Value=", ENDITEM, "Name=listCompanies", "Value=", ENDITEM, "Name=listManagementUnits", "Value=", ENDITEM, "Name=tfAccountNumber", "Value=", ENDITEM, "Name=tfInvoiceNumber", "Value=", ENDITEM, "Name=rbInvoiceStatus", "Value=Y", ENDITEM, "Name=listExpenseStatuses", "Value=1", ENDITEM, "Name=listPeriods763", "Value=", ENDITEM, "Name=listPeriods762", "Value=", ENDITEM, "Name=rbResultFormat", "Value=InvoiceList", ENDITEM, "Name=btnSearch", "Value=Search", ENDITEM, LAST); //----- At 'Invoice List' page - <Go> to view invoice ---------------------- no_invoices = atoi(lr_eval_string('{invoice_count}')); for (i = 1; i < no_invoices; i++) { sprintf(invoice_param_str, "{invoice_%s}", i); sprintf(invoice_no, lr_eval_string(invoice_param_str)); ViewInvoice(invoice_no) } //----- Back at 'Invoice List' page ----------------------------------------