Monday, September 8, 2014

Find Sub string from captured value in LoadRunner

This article discusses the about how we can find a sub string from a captured LR parameter by specifying an LB and RB in the captured value . We use web_reg_save_param_ex() / web_reg_save_param() or web_reg_save_param_regex() function to capture the dynamic data from the server response.

In majority of the cases the attributes used with the correlation function are good enough to capture the exact dynamic data. We can either use the attributes "SaveLen", "SaveOffset", or text flags to capture the exact dynamic data. We can also use the regular expressions to capture the exact values.

The function that is most helpful in this case is lr_save_param_regexp() where you can pass the LR parameter and specify the regular expression as below:



 lr_save_param_regexp (lr_eval_string("{DynData}"),
                     strlen(lr_eval_string("{DynData}")),
               "RegExp=(to.*?by)",
               "Ordinal=All",
               "ResultParam=reMatchesParam",
               LAST );

Now the above function would retrieve all the occurrence of strings that match the regular expression to and some string followed by by. Now the sample output of the above statement can be as below:

Action.c(7): Notify: Saving Parameter "reMatchesParam_1 = to performance by".
Action.c(7): Notify: Saving Parameter "reMatchesParam_2 = to selenium by".
Action.c(7): Notify: Saving Parameter "reMatchesParam_3 = to management by".
Action.c(7): Notify: Saving Parameter "reMatchesParam_4 = to sales by".


The only problem with the above statement is that, it is introduced in the new version LoadRunner. Below is the "C" implementation of the same.


FindAllSubStrings(char *Src, char *LB, char *RB, char * LRParam)
{

    char buff[1000], temp[100];
    char *pos1, *pos2;
    int offset, i=0;

    // Capture the position of Left boundary
    pos1 = (char *)strstr(Src, LB);
 
    //If the RB and LB both are the same, ensure that you search for RB only after LB
    if(pos1 !=0)
        {
            pos2 = (char *)strstr(pos1 + strlen(LB), RB);
        }
 
    do
    {
        // Make Buff an empty string
        strcpy(buff, "");
     
        // Should return only if both Pos1 and Pos2 are not null
        if(pos1 !=0 && pos2 !=0)
        {
            //Measure the length of the string that is to be saved into the LR parameter
            offset = (int)(pos2 -(pos1+strlen(LB)));
         
            //Save the sub string into the buff variable
            strncat(buff, pos1+strlen(LB), offset);
            i++;
            //Create the LR parameter for example "TestData_i" where i will be incremented wtih each iteration
            sprintf(temp, "%s_%d",LRParam,i);
            //Save the sub string into the parameter "TestData_i"
            lr_save_string(buff, temp);
         
            //change the pointer from where you should look for the next LB and RB
            Src = (char *)(pos2 + strlen(RB));
         
        }
        pos1 = (char *)strstr(Src, LB);
        if(pos1 !=0)
        {
            pos2 = (char *)strstr(pos1 + strlen(LB), RB);
        }
        //Repeat the process until all the values are stored to the LR parameters
     
    }while(pos1 !=0 &&pos2!=0);
 
    //Create an LR parameter that stores the count of sub strings for example "TestData_count"
    sprintf(temp, "%s_count", LRParam);
    //Save the count into the created parameter
    lr_save_int(i, temp);
 
    return 0;
}

The additional advantage of having this function is, because this is a C implementation this function can be used with any version of LoadRunner. The only modification that may be needed to change the size of the variables used in this function.  

The usage of this function is similar to that of Replacer function that I shared earlier.

Please let me know if you have any questions. If you like this article, please hit +1 / Like / Tweet / Comment.

Friday, September 5, 2014

Customizations for performance scripts



Once a navigation has been recorded using the performance testing tool, the recorded script should be customized such that the same script works fine for different users who can choose different things in the same navigation.

Below are the 5 important customizations made to any performance script
Parametrization – To simulate different user inputs, a script should be parametrized. To be more specific, any text field that is seen in the navigation (or the use case) should be parametrized. The best example for this is the user name and password or search text entered in search box. The most common way of parametrization is reading the values from a file.

Correlation – To achieve different user selections, that navigation should be correlated. This also means handling all the dynamic data in a particular request. From the application point of view all the Radio buttons, Drop-down fields, check boxes can be handled by implementing correlation in the script. But the performance tester should also ensure that any other dynamic data that is sent to the server as part of the request should also be handled using correlation.

Page Verification / Validation – Another important aspect of performance testing is validating the response. This can be achieved by having Text validation from the response. A text that is expected in the response should be searched and if the text is found, the request is assumed to be successful else, the request would be considered as a failure. Enough care should be taken while choosing this text that is to be searched for. The text should be static, specific to that particular response and preferably towards the bottom of the response

Transactions – One of most important reasons a performance test is executed is, to figure out the time it takes for the pages to load. To measure this time, the scripts should be included to have transactions

Think time: To simulate the user behavior of waiting between the requests either to read / fill in details (write) or to think if the content is appropriate or not, think time is used in the script.  Once the thread / virtual user receive response for the previous request, they would wait for the specified time before sending the next request.

Irrespective of tool, these customizations (whatever applicable) are made to all the requests in the navigation. Hope this information is helpful. If you like this article, please like it / Share it.