May 19, 2016

LoadRunner Part # 8 - Understanding VUGen in LoadRunner

Understanding VUGen in LoadRunner

VUGen is one of the four core components of LoadRunner. It is the first component you interact with when getting started with Performance Testing using HP LoadRunner.
Let’s understand a few salient features related to VUGen
VUScripts: As already described, the purpose of VUGen is to create VUScripts that are used to simulate a real-like virtual-user.
Actions: An action is set of user transactions performed in the System Under Load to achieve a defined task. An action can be compared to a function in other programming languages. Each Vuser script has 3 default functions
Vuser_init(used to login into the application)
Action (used to record the business process)
Vuser_end (used to logout of the application)
VUGen not only records scripts but also replays them (for only 1 VUser) to ensure script is recorded correctly. Once you ensure the script is recorded correctly you incorporate it in a LoadRunner scenario
In this tutorial we are going to study

The script development process in VUGen

1. Record the Script: Usually this is the first step of scripting where every user action is recorded into a script.
2. Replay and Verify: Once the script is recorded, reply the script to ensure its working right. Verify any impact through application frontend or database.
3. Enhance the Script: Once recording has been verified, enhance script by adding checkpoints, validating data, adding transactions and rendezvous points.
4. Replay and Verify: As earlier, re-play your script and verify that everything is working as intended.
5. Configure Runtime Settings: Configure and control pacing duration, think time variation, proxy settings and whether you wish to ignore any external resources.
6. Use for Load Scenarios: Formulate load scenarios based on test objectives. Use load distribution and geo-wide agents to make real like scenarios.

Compare recording between QTP and LoadRunner

VUGen disregards UI Objects:
Unlike QTP scripts, LoadRunner scripts are independent of GUI. This is because the code generated does not work based on UI objects, rather, it works on the principal of client’s request to the server and expecting server response back to the client. This is why replaying LoadRunner scripts are always browser independent. The VUser can communicate directly with a server by executing calls to the server API-without relying on client software (SUL) this means there will no impact on scripts if the changes are made to the UI of the System Under Load. This tells; the performance testing is completely based on client/server communication (request and response) and not the GUI objects.
Please refer to below link for more details: http://youtu.be/FDORUeqpNJs?t=3m41s
We will see in more details how VUGen works below.

Introduction to Web Tours Application

For all hands-on purpose, we will be using the Web Tours Application that comes bundled with LoadRunner.
The HP Web Tours requires a dependent “Web tours apache server” to be running before it can operate. To run the Web Tours Apache Server, go to Start Menu => HP Software => Samples => Web and then click on Start HP Web Tour Server.
Once the “server” has been activated, it will open a shell and output on the console.
The console should look like snapshot below, look for your IP address in the shell:
NOTE: if you close this window, the server will stop.
Now you can access the Web Tours Application –
Once launched, it will look like –

Understanding the VUGen Environment

To run the VUGen, double click on the VUGen shortcut from the desktop, or go to Start Menu => HP Software => and then click on Virtual User Generator.
VUGen splash screen will appearas follows
The splash screen will subsequently open HP VUGen Home page, as shown below:
From the File menu, you can observe various command controls. The purpose of these controls are mentioned below:
New Script and Solution: is used to start creating a new script. Alternatively, you can create a new script from the toolbar button.
Open >> Script Solution: is used to open an existing, previously created script or solution from a directory.
Add >> New Script: is used to add a previously created script into current solution
We will get acquainted with other controls as we start creating our first script. Let’s continue learning.

Please be patient. The Video will load in some time. If you still face issue viewing video click here

Creating Your First VUGen Script

Before you record, make sure the Web Tours App serveris running. Remember, you need to keep the server running so do not close it. If the window bothers you, you can minimize it.
Tip:In a real world problem, one needs to get acquainted with the subject application (SUL) especially if it involves complex business workflows and data stages. You can also interact with HP Web Tours to ensure you can repeat the exact steps when recording.
Before one can start with scripting of any application (SUL), one needs to get acquainted with the application flow. With this tutorial, let’s get acquainted with HP Web Tours which is shipped and automatically installed with HP LoadRunner.
Step 1)Click on File =>New Script and Solution as shown in the snapshot below:
You can use the shortcut (Ctrl + N) to do the same.
Step 2) A window to select the protocol is shown.  The list looks slightly different from previous versions
1. Select Single Protocol
2. Web
3. Enter Script Name
4. Click Create
Note: You can use Protocol Advisor to determine right protocol your application uses for communication. For HP Web Tours, we already know that it requires “Web – HTTP/HTML” protocol. We will learn at a later stage how to determine the right protocol for your SUL.
Tip: An application may require more than 1 Protocols sometimes to communicate with its server. For such a case, navigate to Multiple Protocols list on the left side of window.
HP Web Tours, however, requires only one protocol when scripting with VUGen.
Tip: You cannot rename your scripts easily, so be creative when giving your scripts a name. If you’ve to rename a script, use Save As feature and give a new name. A good nomenclature could be something like, WT01_Signup where WT is short form of the application name, 01 is a business process sequence, and Sign up refers to the business processes being scripted. Also note that you cannot use spaces in a script name.
Step 3) once you click Create, HP VUGen will open the IDE (Integrated Development Environment) or code editor. You can notice the script files are blank, except basic signature of Function Action. Below snapshot should help understand it more:
Step 4) Click the Recording  button which you can find in the toolbar. Refer to the snapshot below:
Step 5) a new window opens
1. If we study the above window, the name of the script is mentioned in the title bar of this popup. This will help you make changes to the right script when you are dealing with multiple scripts opened at a time.
2. If you do not see the rest of controls, click on the Fewer Options button to ensure you are not viewing fewer options.
3. Record into the action field determines where the code is generated after recording. VUGen facilitates switching to other actions or create new actions during and after recording.
4. Record: field tells VUGen that the subject application (SUL) is a web application or a desktop client. This option cannot be overridden once recording begins.
5. Application: field tells VUGen, which browser to use for recording. If you are not working with Web – HTTP/HTML protocol, you will select the desktop client with this field.
Tip: Unlike QTP scripts, LoadRunner scripts are independent of GUI. This is because the code generated does not work based on UI objects, rather, it works on the principle of client’s request to the server and expecting server response back to the client – usually, in the form of HTML (hence the name of protocol)
6. URL Address: The URL of the SUL is input here. VUGen will invoke this URL when “Start Recording” is clicked. The browser used will be the one mentioned under “Record:” field if it is different from your default browser.
7. Start Recording: Immediate vs. Delayed: If you’ve selected Immediate recording mode, you will notice that VUGen starts recording events as soon as you hit “Start Recording” button. However, if you select Delayed recording mode, the VUGen will invoke the system (SUL) but will not commence capturing events unless you click on the Recording button from the floating bar.
8. Working Directory: This is a temporary directory which VUGen will use while capturing events. A copy of your script will be available at this location as well, just in case if you lose your folder :)
9.Recording Options: These settings tell VUGen what type of URLs to capture and what recording mode to use.
10.Start Recording: Will start recording. Click on it
Step 6) Once recording starts, VUGen will invoke the HP Web Tours application using the browser selected.
Let’s Sign up a user at Web Tours application and record a basic script.
A floating recording bar will appear which will offer various controls over recording.  This tells the time elapsed and number of events automatically captured. Let’s look at the floating bar closely.
In the snapshot shown above, the SUL has fired 56 events and a total of 0 minutes, and 25 seconds of time duration have elapsed since recording begun.
You’ll also observe that no events are fired as you type. Ask yourself why. Can you answer?
This is because no client to server communication takes place as you type. Hence, no events are fired and no script is generated regarding typing. Code will be generated only once you submit the form (click Continue)
Recording can be pause  using the pause button. Please note, as long as the recording remains paused, all events being fired by the application will be disregarded. This also means that even if your application is sending requests and/or receiving response form SUL, the script will not be generated as long as you’ve paused the recording.
If you’ve paused recording, you will need to click recording button from the floating bar to resume recording.
While you are recording in vuser_init section, you’d notice that rendezvous button is not enabled. Switch to Action (or create a new Action) and continue recording. Refer to below snapshot to learn how to switch Action.
You’ll notice that after switching to an Action, the rendezvous  button will be enabled automatically. This is because VUGen does not allow insertion of rendezvous points in vuser_init.

Using Transactions at Record Time

Let’s assume you wish to gauge response time when X number of users simultaneously Sign up. To address this objective, let’s read further. 
By now you’ve recorded opening of the application in vuser_init action. After you’ve switched to Action, enter the user information required by SUL. Now before you hit “Continue” button, follow below steps:
Start a transaction by clicking  button in floating bar. Enter the name of the transaction, for example, 01_Signup.
Tip: It is a good practice to name your transaction with a prefix like 01_ to help keep them unique.
The floating bar will look like this:
Click OK to close the transaction label.
Click the Continue button of the application.
End transaction by clicking  button. Select the name of the transaction you wish to close, for example, 01_Signup in this case. Refer to below snapshot for illustration.
If you do not have multiple transactions opened, you’ll see only one name. If you’ve multiple, however, you’ll 0be able to select from the list.  

Insert Comments at Record Time:

Now that you’ve successfully closed the transaction, you can put a comment at record time to give yourself a reminder when you study the code later. From the floating bar, click on the button to insert a comment. A text box will appear adjacent to the floating bar where you can enter any text.
This comment will be inserted into the code after the steps (code) you’ve just finished before clicking OK button.
From the application, you can click continue. You’ll observe a welcome note by application.
Now select vuser_end action and click Sign off from the application. Close the application and click stop button from the floating bar.

Code Generation:

Once recording has been stopped, you’ll notice VUGen post generation activity. This includes generating code, transactions and comments based on your recording. Refer to snapshot below.

Immediately after VUGen finished “Performing post generation operations” it will start “Performing scan for correlation post generation operation” We will see in more detail what correlation means.  
Once post generation operation is finished, you will see Design Studio window. If any candidates for correlation are found, you’ll be able to review them in this window.  
You can safely click on the Close button, and VUGen will take you to the code that has been generated.
The window will look like this:
As highlighted in the above figure, the editor contains easy to understand, readable code. You can have a look on the parameters used while recording.
The left side of VUGen is called Step Navigator that lets you understand the “script” without looking at the granularities of the code. For example, you can read steps as, opening a URL, spend Think Time and submit the form. This encapsulates all the parameters associated with each request.
Your script has been generated, click on the File menu and then click on Save Script As to browser the location where you wish to save your script. VUGen will automatically suggest the last directory used if you’ve already saved a script earlier. The name suggested will be the name you mentioned when you started recording.
All done.
Now, congratulate yourself for having your first script successfully generated and saved.

No comments:

Post a Comment