In this loadrunner tutorial, you will learn about lr_whoami function
This is a very important function to be used in LoadRunner. When we have to take the information of virtual user which is executing the script, we use this function. So the basic purpose of this function is to return information about the Vuser executing the script.
Let us see the function syntax first. Then we will elaborate it for better understanding. It is written in C Language in the syntax given below.
void lr_whoami ( int *vuser_id, char *sgroup, , int *scid );
We can see that there are three parameters in the function. Now let us understand its parameters, one by one.
vuser_id – It is a pointer that is used to store the Vuser ID number.
sgroup – It is a pointer used to store the name of the Vuser Group.
scid – It is a pointer to store the Scenario or Session step ID number.
We may say that this function lr_whoami function is used to get information about the Vuser. One more thing to be kept in mind is that the sgroup parameter is a pointer that is used to store constant data and we should only read it and do not do any modification in it. Also, it to be noted that memory for the string is allocated automatically and we do not need to allocate memory explicitly in the script.
Let us understand it with the help of an example. In the following example, we can see that the LoadRunner function lr_whoami retrieves information about a Vuser and places it into a message string. The message string contains Vuser login information that connects with a server.
Point to be noted here is that this LoadRunner function will show the information of Vuser which is currently executing the script, as we know that any script is executed by virtual user. We should not allocate any memory for vuser_group because it is allocated automatically in LoadRunner and the tool itself take care of the memory while declaring and executing them in the script. This function does not have any use when there is no virtual user in the script. Let us see the code below to understand it better.
// declaring two variables for storing Virtual user id and scenario ID
int id, acid;
// declaring virtual user group variable which is used to show the name of the Virtual user group.
// LoadRunner function lr_whoami will retrieve retrieves information about a Vuser and will place it places it into a message string.
lr_whoami(&id, &vuser_group, &scid);
//printing the information Virtual user ID, Scenario ID and Name of Virtual group
lr_message( “Group: %s, vuser id: %d, scenario id %d”, vuser_group, id, scid);
One thing that should be noted is that if we need to access the scenario ID, we will need to add the scenario attribute to the runtime settings. It is available in the general tab. We just need to add a scenario to the Additional Attributes on the General tab. It is very important to do so because If the scenario attribute is not added to the runtime settings, it will always show scenario as zero (0).
One more thing to be noted is that If you do not want to retrieve one or more of the parameters, replace the parameter name with NULL in the shown LoadRunner function. Also, we cannot use parameterization for any argument in this function. Parameterization means replacing single data with multiple data which is not possible in this function. One more thing to be noted that function doesn’t return any value. It just retrieves the information related to the virtual user which we can print in the log window of LoadRunner.
You should also read all the loadrunner functions