• Vugen: Loop Through An Array Of Parameters

    Posted on August 13, 2012 by Admin

    I had a situation where I needed to find a specific record within a list. The web page had a list of 300 orders, and I had to find an order with a matching status of “NONE” based on some text displayed. The first thing I had to do was capture all the statuses and put them into an array, and then find a match.
    To get the statuses into an array, I used the ORD=ALL argument with the web_reg_save_param function:

    // Get all 300 orders displayed on this HTML page
    Read Entire Entry

  • Vugen: RTE Protocol Wait/Polling Routine

    Posted on August 8, 2012 by Admin

    While it isn’t the most popular protocol out there, RTE (terminal emulation) continues to serve a need for those testing against “green screen” apps, AS400’s, etc…There are times where you may be waiting on a particular string of text to show up on a screen. You may want to continue polling until the text is there. The script below gives you one idea of how to do this. Note that the X/Y coordinates and field length will be different based on your screen and what you are looking for.

    int rc, i;
    char match[80];

    // Grab some tex Read Entire Entry

  • Vugen: Old School Random Selections With srand

    Posted on August 6, 2012 by Admin

    At the beginning of your script where you declare variables, seed time() with the srand() function:
    char buffer[80];
    int TotalNum, RandNum, i;
    Here is how you might use this. Let’s say you need to use a random selection from a web page. This might be a different check box or drop down selection and you want it to be random each time:
    //First grab the total count of items to choose from using ORD=ALL

    web_reg_save_param(“pCapture”, “LB=something”,
    “RB=something else”, “Ord=All”, LAST);

    web_submit_data(“BLINGBLING”, Read Entire Entry

  • Vugen: Manipulate The Date

    Posted on August 1, 2012 by Admin

    When using the lr_save_datetime function, you may want to advance or decrement more than one day, you have to multiply by the number of days.
    Example code:

    // Display Current Date Only
    lr_output_message(“Current Date: %s”,lr_eval_string(“{Currdate}”));

    // Subtract 30 days from current date
    lr_save_datetime(“%m/%d/%Y”, DATE_NOW – (ONE_DAY*30), “Startdate”);
    lr_output_message(“Previous 30 Days: %s”,lr_eval_string(“{Startdate}”));

    // Advance 30 days from curre Read Entire Entry

  • Vugen: Read A File Stream For Validation

    Posted on July 30, 2012 by Admin

    In this example we are running tasklist.exe in windows to check the existence of a process by looking at the first 13 characters in the file.

    char command[1024];
    int i, total = 0;
    char buffer[12], ch;
    char *filename = lr_eval_string(“C:\\tasklist_{pTime}.txt”);
    long file_stream;

    //Run a system command to open up a DOS prompt and tasklist
    //Save it to a file

    sprintf(command, “tasklist /FI \”IMAGENAME eq MobileEngine.exe\”
    /FI \”STATUS eq running\” /FO TABLE /NH > %s”, filename);
    sys Read Entire Entry

  • Vugen: strcmp Example

    Posted on July 25, 2012 by Admin

    I was asked to post a simple strcmp example for use in Vugen scripting. Here it is:
    if (strcmp(lr_eval_string(“{pParameter}”), “”) == 0)
    lr_error_message(“No parameter value captured. Ending iteration.”);
    return 0;
    lr_output_message(“The parameter value is %s”,
    Anyone care to elaborate in the comments section as to what this code is doing? Read Entire Entry

  • Vugen: Replace Any String With Another

    Posted on July 23, 2012 by Admin

    Here is an easy way to replace anything with anything in a captured string in your LoadRunner Vugen script. It is a function called “string_replace”. Place this in the top of your action section, right after the include but before the main section begins:

    char *string_replace(char *input_string,
    char *substring_to_be_replaced,
    char *substitution_string)


    // strstr function declaration
    char *strstr(const char *s1, const char *s2);

    // newstring variable the new string to be returned
    // increase the buffer size if needed. Read Entire Entry

  • Vugen: Using LAST Value For web_reg_save_param_ex

    Posted on July 16, 2012 by Admin

    Whenever the ORD=ALL attribute is used with the web_reg_save_param_ex function, VuGen creates an array containing the number of instances that are actually captured. It also stores the total count for the number of instances automatically. This count can be referenced by getting the value of “_count”. For example, if the parameter name is ParamName, a separate parameter ParamName_count will be available with number of times the value was captured. This can also serve as index for last values captured. Use the sample code below to Read Entire Entry

  • Vugen: Will This Code Remove Trailing Spaces?

    Posted on July 9, 2012 by Admin

    Let’s have a little fun today – and hopefully I can get some interaction from you C Guru’s out there. How about something cryptic in C? Let’s say I wanted to remove some trailing spaces with as few lines of C code as possible. Will the example below work?
    static char* rtrim( char* s)
    int i;
    if (s){i = strlen(s); while ((–i)>0 && isspace(s[i]) ) s[i]=0;}
    return s;
    Why or why not? Care to explain what this code is doing? Comments are open and welcome. Read Entire Entry

  • Vugen: Gracefully Handle Various HTTP Return Codes

    Posted on July 2, 2012 by Admin

    There may be times where you want to build in logic for how your Vuser reacts to the various types of HTTP status return codes received throughout a script. For example, as web servers get overloaded, they may start sending 503 return codes. If you wanted to try and resubmit and finish out the transaction, this might be a more graceful way to handle the occasional 503 than just giving up and killing the iteration immediately. Of course, as the load continues to increase, the 503’s will become more frequent and eventually you will Read Entire Entry