Executing a client side session creating Java Script in loadrunner using web_js_run (web protocol)

In web applications unique user Session Id's are used for security reason. These Session ID's can be created either on the server side or on the client side. If they are created on the server side then we can correlate those session ID's in our loadrunner scripts. But in my case these Session ID's were created using Java Script in the client side (Browser). So these Java Scripts have to be executed in loadrunner to create the session id's and they have to be consumed in our script.

Lets see how we can do it.

When the application launch URL is executed it gets a response with the below Java Script embedded in it to create session id.

Java Script to create client side session id:

        function uuid() {
            var chars = '0123456789abcdef'.split('');

            var uuid = [], rnd = Math.random, r;
            uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
            uuid[14] = '4'; // version 4

            for (var i = 0; i < 36; i++) {
                if (!uuid[i]) {
                    r = 0 | rnd() * 16;

                    uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r & 0xf];
                }
            }

            return uuid.join('');
        }


  • Copy this code in a notepad and save the file with extension '.js'. In my case I have saved the file as 'Cookie1.js'
  • Place this file inside the loadrunner script where it need to be executed.
  • In Vugen goto Design --> Insert in Script --> New Step --> Steps Toolbox --> Search & Select web_js_run. Below dialog box opens.


Under General Tab

  • Select the Code option and call the function using its name. In my case it is uuid(). Since there are no arguments the function is blank.
  • Enter a parameter name in Result parameter field to save the output of the Java Script. I have given 'output' as the parameter name. This is the parameter which has to be passed in the place of session id inside the script.


Under Sources Tab
  • Click Add. In the resulting pop up select File and enter the file path. Since we have placed file directly inside the script folder, it is sufficient to mention only the file name. In my case is 'Cookie1.js'




  • Thats it now click OK and the below web_js_run function will be generated in the script. When we run the script, session id will be created and saved in the parameter output, which can be seen in the replay log.






For loop to iterate a block of script in loadrunner


C Program:

int Max = 10; //no. of times for loop should run
int i =0; //initializing the loop

Action()
{

lr_start_transaction();
Web Request
lr_end_transaction();


for(i = 0; i<Max;i++) //For loop will run 10 times
{
lr_start_transaction(); //Block of the loadrunner script
Web Request
lr_end_transaction();
}

lr_start_transaction();
Web Request
lr_end_transaction();

return 0;
}

Loadrunner scripting for Rest API services - web_custom_request

In this post we will see how to script a Rest API call in load runner.

Rest API details:

URL : https://10.36.133.105:8104/belocc/v2/belea/dealer/B1234/rep/B1234/smsession/10/consignments?access_token=800004e-c7ca-400b-9004-48c8aef00000

Method Type: 
POST (Apart from POST other methods used in Rest API's are GET, PUT, PATCH & DELETE)

Mode: HTTP

Encoding Type: application/json

Request Body:
{
    "code":"0032906789",
    "entries":[
        {
            "CEntryNumber":"",
            "orderEntry":{
            "entryNumber":"1",
            "quantity":"2"
            }
        }
       
    ]
}

Convert the Request body to the below loadrunner format (i.e) place '\' before every '"'.

{\"code\":\"0032906789\",\"entries\":[{\"CEntryNumber\":\"\",\"orderEntry\":{\"entryNumber\":\"1\",\"quantity\":\"2\"}}]}

save the formatted request body in a character pointer.

char *JsonReqInit;

char *JsonReqFinal;

JsonReqInit = "{\"code\":\"0032906789\",\"entries\":[{\"CEntryNumber\":\"\",\"orderEntry\":{\"entryNumber\":\"1\",\"quantity\":\"2\"}}]}";   //save the string in a C variable.

lr_save_string(lr_eval_string(JsonReqInit),"JsonReqFinal");

Goto Design --> Insert in Script --> New Step

Then Steps Tool search window will open in the right pane, search for web_custom_request and open it.



Enter the details in each field and click ok. Below request will get generated in the script.

web_custom_request("Rest_API",
"URL=https://10.36.133.105:8104/belocc/v2/belea/dealer/B1234/rep/B1234/smsession/10/consignments?access_token=800004e-c7ca-400b-9004-48c8aef00000",
"Method=POST",
"TargetFrame=",
"Resource=0",
"Referer=",
"Mode=HTTP",
"EncType=application/json",
"Body={JsonReqFinal}",      //Pass the variable in the body of the web_custom_request.
LAST);

what is GC Suspension Time or GC Pause Time?


Garbage Collection:

When a Java application is running, it is creating new objects, but after a certain time, those objects will not be used, which will be considered as "garbage". Eventually, we'll start getting a lot of garbage, and memory will be used for objects which aren't being used anymore. If this keeps going on, at one point the Java Virtual Machine will run out of space to make new objects, leading to heap memory issues.
That's where the garbage collector steps in.
The garbage collector will look for objects which aren't being used anymore, and gets rid of them, freeing up the heap memory so other new objects can use that piece of memory. It is a form of automatic memory management.

Stop-the-world:
Stop-the-world will occur no matter which GC algorithm you choose. Stop-the-world means that the JVM is stopping the application from running to execute a GC. When stop-the-world occurs, every thread (including application threads) except for the threads needed for the GC will stop their tasks. The interrupted tasks will resume only after the GC task has completed.
The time for which the stop the world event occurs is called as the GC Suspension time or GC Pause time which has a direct impact on response time and throughput. GC tuning often means reducing this stop-the-world time.
The lesser the GC Suspension time better the response time and throughput of the application.