Introduction to VuGen Script: Learn the first component of LoadRunner with recording and creating a basic VuGen script
In this Hands-On LoadRunner Training Series, a brief Introduction on LoadRunner was given in our previous tutorial.
In this tutorial, we will start with ‘VuGen’ (Virtual User Generator) which is the first component of the LoadRunner tool. It is used to capture the network traffic (or requests) and create scripts that emulate the real user actions on a web Application (or a Desktop application).
=> Click Here For Complete Series of LoadRunner Tutorials
How does a Web Application Work?
Before starting with VuGen, let us first understand how a Web Application works.
Web applications are hosted on Servers and can be accessed via the internet through a client (browser for example). The client sends a request and the server processes the request and sends the response back (request/response is often referred to as network traffic).
The client and the server clearly understand each other’s language because they follow a standard ‘set of rules’ for communication which is called the ‘protocol’. There are many types of protocols but the most commonly used one on the web is the ‘hyper-text transfer protocol’ or the ‘http’ which almost all of us are aware of.
Other examples of commonly used protocols are https, FTP, SAP Web protocol, Oracle NCA protocol etc.
On a high-level, these are the sequence of events that take place when a user performs the actions on a Web Application:
- The user types the URL on the client/browser (Example: http://google.com).
- Browser/Client parses the URL to find the protocol, host, port etc.
- Browser/Client then forms an HTTP request.
- The host is translated to the IP address (DNS lookup).
- The socket is opened from the user computer to that IP address on the specified port (usually 80).
- A connection is made, and the HTTP request is sent to the host.
- Server inspects the request, does the necessary processing and sends the response back (usually an HTML page).
- Browser/Client receives the response and parses the HTML.
- The user sees the page on the screen.
The request that we are talking about is an HTTP request in most cases. HTTP request has a ‘header’, a ‘body’ and has one of these as the method – GET, POST, DELETE etc. GET and POST is the most common methods.
Without going deep into the understanding of these methods, let us simply remember that:
GET method is used to retrieve the information from the server.
And POST method is used to send data to the server.
Now, let us take an Example of amazon.com application and see how the HTTP request actually looks like.
In this Example, we are registering a user on the amazon.com application.
The corresponding HTTP requests for this user action can be seen in the developer tools (F12) page of the browser (we have used Internet Explorer here).
Shown below (marked in red) is the HTTP request for ‘Registering User’ action on amazon.com. As we see, among the other fields, the protocol is ‘HTTPS’ and the method is ‘POST’.
If we go to the Details, we can see the Request header and body (highlighted in red).
Now let’s go back to VuGen.
VuGen captures the HTTP traffic when we perform actions on an application and converts the same into a script (which when replayed emulates the real user actions on the application).
Here is how the script looks like (on the VuGen tool) for amazon.com user registration user action that we just discussed. As we see, the script is nothing but the HTTP request(s) which is put in the form of functions (two functions here include – web_add_cookie and web_custom_request). We will discuss functions in detail in our subsequent tutorials.
Here, it is important to note that VuGen scripts (when re-played) do not emulate the actual user actions on the browser, but emulate the requests (network traffic) that get generated as a result of the user actions.
So, VuGen doesn’t work at the GUI level (like the functional test tools do – like UFT/QTP) but works at the network level (HTTP requests).
Now let’s see how to actually record and create scripts in VuGen.
For this, we will use the sample ‘Web Tours’ application that comes with the Load Runner tool.
The url of this application is http://127.0.0.1:1080/WebTours/index.htm (this application will be hosted on our local machine) and we have to start the Web Tours Apache server (that also comes with the LoadRunner tool) to be able to use this application (we can also download the Web Tours application/server from Micro Focus website).
The below figure shows the file that is used to start the server and the corresponding command prompt window for the Apache server.
Let’s start recording the user actions on this application with VuGen.
Double-click on the VuGen shortcut
VuGen is getting initialized… (we are using Load Runner 12.55 here)
The main page in VuGen where we can see the recent scripts, useful links, and other options is opened.
In order to record a new application, open File => New Script, and Solution
Next, VuGen allows us to select the protocol (or protocols) that are used for client-server communication in our application (Web Tours in this example). We have to know the protocol or protocols (some applications use multiple protocols) in advance. We will discuss the ways of finding this out in our subsequent tutorials.
Let’s select Single Protocol (Web-http/HTML) and enter the Script name and path.
As we can see, the VuGen screen has ‘Solution Explorer’ pane on the left. This is where all the assets of our script ‘Web Tours’ will be listed (we can have multiple scripts under a solution but here we have only one).
We have three defaults Actions – vuser_init, Action, and vuser_end. The script is actually recorded/written into these actions (for now this is an empty script as we have not recorded/written anything into the actions yet).
VuGen opens with three defaults Actions – vuser_init, Action, and vuser_end. The script is actually recorded/written into these actions (for now this is an empty script as we have not recorded/written anything into the actions yet)
Let’s understand actions in detail:
Action: An action is a group of requests that perform a specific task. It is like a ‘function’ in a programming language.
Every Vuser script has three actions by default:
- vuser_init (records login to a server)
- Action (records user activity)
- vuser_end (records logoff procedure)
Apart from the default actions, we can create our own actions in the script.
For Example, for an e-commerce site, we can have the following actions:
- vuser_init (login into the application can be kept here)
- RegisterUser
- SearchProductAndOrder
- CancelOrder
- vuser_end (logout can be kept here)
When the script is run for multiple iterations, the vuser_init and the vuser_end actions are run only once and all the other actions are run multiple times (we will see this in detail when we discuss ‘Run-time Settings’).
Now let us start recording. Click on the Record button (red dot) or use the shortcut Ctrl+R.
VuGen allows us to select the following options:
#1) Record into action: Action into which the script is to be recorded. We can select one from the drop-down.
#2) Record: What to record is to be selected from the dropdown list.
3. Application: The Application used for recording is to be selected from the drop-down menu or is to be opened by selecting the path.
4. URL address: URL address if in case we are recording a Web Browser.
5. Start recording: Option to start recording immediately or after some delay.
6. Working directory: The working directory.
Also, on the left bottom corner, we have the most important option for script recording – ‘Recording Options’ (highlighted in red above). We will see this in detail in two parts – Part1 (in the next tutorial) and Part2 (in the subsequent tutorials when we will also see ‘Correlation’).
So let’s park the ‘Recording Options’ for now and continue with recording. When we click on Start Recording button, the Web Tours Application will be launched in internet explorer.
Also, we can see a floating window recording bar (highlighted in red) that gives information and allows various controls on a recording.
Here is the description of various options which the floating recording window bar offers.
A number of events are recorded to give the information on the events (HTTP traffic) that are currently recorded as we perform actions on the application/browser.
We will talk about Rendezvous, Comment and Text check in our subsequent tutorials. Other options are self-explanatory.
Let us continue with recording…
Enter the Username & Password and login (‘jojo’ user is registered by default with password ‘bean’, and we can register a new user if we want using the ‘sign up now’ link).
Click on the ‘Flights’ button.
Enter/select the details and continue.
Select flight and continue.
Enter the payment details and continue.
‘Sign Off’ now
Now, we have completed recording the user actions on the Web Tours application, click on the ‘Stop Recording’ option on the Floating Recording bar. Note that while we were recording the user actions, VuGen was only capturing the events (HTTP traffic) but was not creating the script yet.
So after we stop recording, VuGen generates the script.
It also performs some postscript generation operations which we will discuss later.
Finally, VuGen generates the script and presents a Recording Report as shown below.
And here is how that Script looks like.
Conclusion
Just to summarize, we discussed the following in this tutorial:
- Introduction to VuGen
- Basic understanding of Web Application, HTTP requests, and Protocols.
- Recording and creating a basic VuGen script (using http protocol) on Web Tours application.
In our upcoming tutorial, we will discuss more on Recording Options!!
=> Visit Here For Complete Series of LoadRunner Tutorials