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.






No comments:

Post a Comment