You are on page 1of 7

Scripting in Loadrunner 1.

Recording level

HTML-Mode Script describing user actions in the form of web_url, web_link, web_image etc. Best for browser applications without JavaScript

URL-Mode Script describing user actions in the form of web_url. Best for applet and non-browser application

GUI-Mode Record HTML actions as context sensitive GUI functions such as web_text_link.This is the ideal recording level for Oracle Web Applications 11i and PeopleSoft Enterprise. Best for browser applications with JavaScript

2. web_image_check(Within HTML-based scripts (not URL-based scripts) Syntax : web_image_check("","", LAST) Ex: web_image_check("imgae1","src=filepath/image001.jpg",LAST);1

3. web_reg_find It search for a text string for the very next Action function in the script. It scans the buffers as they arrive rather than after a page is received. Syntax : web_reg_find("Text=", LAST); web_reg_find returns 1 (constant LR_FAIL) if it fail. web_reg_find returns 0 (constant LR_PASS) if it successful "NOTFOUND=warning","SaveCount=pCountA","Search=All" Ex: web_reg_find("Text=Google", LAST);

4. Manual Correlation To save and display text , use web_reg_save_param command to extract text after searching it between tokens LB and RB (Left and Right Beacons) non-NULL terminated dynamic data from an HTML page to a parameter. web_reg_save_param("text_extracted","LB=xxx","RB=xxx", LAST); //change LB to LB/ic if you want to ignore case sensitveness

web_reg_save_param("Buffer","LB/ic=","RB=", LAST ); int web_reg_save_param(const char *paramName, , LAST); NotFound is a handling method which invokes when a boundary is not found and it generates an empty string. ERROR, is the default value. EMPTY, no error message and script execution continues. This parameter is optional. LB The left boundary of the data. Boundary parameters are case sensitive; to ignore, add /IC after the boundary. Specify /BIN after boundary to specify binary data. This is must. RB The right boundary of the data. Boundary parameters are case sensitive; to ignore, add /IC after the boundary. Specify /BIN after boundary to specify binary data. This is must. ORD This parameter indicates the number of matches or instance (occurrence). It saves the parameter values in an array, if you specify All. The default value is 1. This parameter is optional. These Attributes are rarely used : RelFrameID The hierarchy level of HTML page relative to requested URL. Search It specifies scope of search. The possible values are Headers, Body, or ALL (searches in both Body and headers). The default value is ALL. SaveOffset The offset of a sub-string of found value, to save to the parameter. The default is 0. Offset value must be non-negative. Savelen It specifies length of the string of found value, to save to the parameter. The default is 1, indicating full length of the string. Convert HTML_TO_URL: convert HTML-encoded data to a URL-encoded data format and HTML_TO_TEXT: convert HTML-encoded data to plain text format Ex: web_reg_save_param("Jsession","LB= Set-Cookie:, "RB=";", "Ord=All", "NotFound=EMPTY", LAST); 5. lr_log_message Sends a message to a log file. Syntax: int lr_log_message (const char * format, exp1,...expn.); Ex: lr_log_message ( Jsession = %s, jsession); lr_output_message Sends a message to the Output window or the Business Process Monitor log files. Syntax: int lr_output_message (const char * format, exp1,...expn.); Ex : lr_output_message( Jsession = %s, jsession); lr_vuser_status_message 2

Sends a string to the Status area of the Controller or Tuning Module Console's Vuser window. It also sends this string to the Vuser log. Not applicable for Application Management. Syntax: int lr_vuser_status_message (const char * format.); Ex : lr_vuser_status_message ( Jsession = %s, jsession);

6. lr_abort The lr_abort function aborts the execution of a script . It stops the execution of the Actions section, executes the vuser_end section, and ends the execution. This function is useful when you need to manually abort a run as a result of a specific error condition. When you end a run using this function, the status is "Stopped." Syntax: void lr_abort( ); Ex: lr_abort( );

7. lr_save_string The lr_save_string function assigns the specified null-terminated string to a parameter. This function is useful in correlating queries. Syntax: int lr_save_string (const char *param_value, const char *param_name); Ex: lr_save_string( buffer, jsession);

8. lr_eval_string The lr_eval_string function returns the input string after evaluating any embedded parameters. If string argument contains only a parameter, the function returns the current value of the parameter. Syntax: char * lr_eval_string (const char * instring ); Ex: lr_eval_string("{jsession}")

9. lr_whoami The lr_whoami function gets information about the Vuser. Syntax: void lr_whoami (int *vuser_id, char **sgroup, int *scid); Ex: lr_whoami(&vuser, &vuser_group, NULL);

10. lr_think_time

lr_think_time allows you to pause test execution during a run. This is especially useful in simulating think time, the time a real user pauses to think between actions. Syntax: void lr_think_time (double time); time is in sec Ex: lr_think_time (10);

11. lr_load_dll The lr_load_dll function loads a DLL (Windows) or shared object (UNIX) allowing you to call an external function when replaying using the C interpreter. Once you load the DLL, you can call any function defined in the DLL, without having to declare it. You can specify a full path for the DLL.

12. web_add_header Adds a user-defined header to the next HTTP request Syntax: int web_add_header (const char *Header, const char *Content ); Ex: web_add_header("Cookie",cookieString);

13. web_cache_cleanup();

14. lr_continue_on_error(1); tells LR to continue execution even on error. lr_continue_on_error(0); tells LR to terminate execution on error C Constants LR_ON_ERROR_NO_ OPTIONS LR_ON_ERROR_ CONTINUE LR_ON_ERROR_SKIP_ TO_NEXT_ACTION LR_ON_ERROR_ SKIP_TO_NEXT_ ITERATION Object Oriented Value (no constants) 0 1 2 3





15. Transaction statements to get transaction timing lr_start_transaction("Start"); lr_start_sub_transaction("substart","start"); lr_end_sub_transaction("substart",LR_AUTO); lr_end_transaction("Start",LR_AUTO);

16. Put lr_set_debug_message before the request for which you want log setting to change 5

lr_set_debug_message(LR_MSG_CLASS_EXTENDED_LOG LR_MSG_CLASS_RESULT_DATA | LR_MSG_CLASS_PARAMETERS LR_MSG_CLASS_FULL_TRACE,LR_SWITCH_ON); /* Actions */ lr_set_debug_message(LR_MSG_CLASS_EXTENDED_LOG LR_MSG_CLASS_RESULT_DATA | LR_MSG_CLASS_PARAMETERS LR_MSG_CLASS_FULL_TRACE,LR_SWITCH_OFF); Type Generic Logging Settings LR_MSG_CLASS_DISABLE_LOG LR_MSG_CLASS_BRIEF_LOG LR_MSG_CLASS_EXTENDED_LOG Extra Settings for Extended Log LR_MSG_CLASS_RESULT_DATA LR_MSG_CLASS_PARAMETERS LR_MSG_CLASS_FULL_TRACE Log Options Flag for unchecking Enable Logging in the Runtime settings. Flag for Standard Log. Flag for Extended Log Flag for Data returned by server. Flag for Parameter substitution. Flag for Advanced Trace. Description

| |

| |

Only on error. Corresponds to Send LR_MSG_CLASS_JIT_LOG_ON_ERROR messages only when an error occurs.

17. In order get the info on the downloaded file use following function after the web_url, etc request send to get PDF or Excel file, we can then use this info to compare the actual size on the server. Size = web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE) Time= web_get_int_property(HTTP_INFO_DOWNLOAD_TIME)

18. C functions: 6

strcat Concatenates two strings. strcmp Compares two strings to determine the alphabetic order. A zero value indicates that both strings are equal. strcpy Copies one string to another. strlen Returns the length of a string. long fp, fp1; char tempy[100]; int sprintf ( char * str, const char * format, ... ); e.g. sprintf(currValue,"{User_Id_%d}",i); char * strtok ( char * str, const char * delimiters ); char *strtok(char * ,char *); mToken =(char *)strtok (lr_eval_string(currValue),mSeperator); fp = fopen(lr_eval_string("C:\\UserId1.txt"),"r"); fscanf(fp,"%s", &tempy); lr_save_string(tempy,"UserId2"); fclose(fp); fp = fopen(lr_eval_string("C:\\UserId1.txt"),"w+"); fprintf(fp,"%s",lr_eval_string("{LoginUserId}")); fclose(fp);

You might also like