The VuGen or Virtual User Generator component of HP LoadRunner is used to generate load testing script in LoadRunner. This is done by recording the actual business scenarios. The VuGen tool will generate scripts based on these scenarios which can then be played back.
In this tutorial, you will learn:
- Introduction to VuGen Scripting process
- Getting started with VuGen
- Demo Application for Load Testing
- How to record your first test script in VuGen
- Exercise – Recording your test script
- How to add Transactions to your script
- How to insert Comments
- How to finalize your recording
- Recording options in LoadRunner
- How to playback a script
As a test team member, it is important to know the entire process involved when working with Load Runner scripts. Below is the normal process followed when developing any load testing script.
- The first step is to record your business scenario. The key point in the recording process is to ensure the business scenario is properly documented. The next key point is to use the right protocol for recording purposes. For example, if you are load testing a web application, you need to use the HTTP protocol.
- The next step is to modify your script to ensure that when it is run, it works as expected. There are times when you would need to make your script pick up test data from an excel sheet or database as input parameters.
Your business scenario may need you to to make your test script more generic to work under different circumstances. In such cases you would need to make the necessary changes to your script. If your scenario includes transactions, then you can setup transactions at this stage.
- The most important step is to playback your script to ensure it works as expected. If you have made changes to your script as per Step 2, then the script verification process is an important step.
- The setup of any runtime settings can include changing parameters such as the pacing of transactions or the think time of transactions.
- Finally, since all your load test scripts will be run as a suite, ensure the scripts are placed in a proper order so that they are executed accordingly.
The first is to launch the VuGen IDE. This can be done by double clicking the Virtual user Generator icon which is present on your desktop. This icon would be there after the installation of all the LoadRunner components.
An intermediate Splash screen will be shown.
Below is the general interface you will be presented with, when you launch the Virtual User Generator.
The HP Loadrunner installation provides a sample web application called HP Web Tours application that gets installed when Loadrunner is installed. This application can be used for demo purposes. To ensure that the demo application can be run, please perform the below mentioned steps.
- Ensure that Internet Explorer version 10 or higher is installed on the machine.
- Ensure that Java version 7 update 65 or Java 8 is installed on the machine.
- Add the following urls to the Security Exception list in Java Control Panel.
http://localhost:1080The below screenshot is of the Java Control Panel with the above mentioned URL’s added to the Exception List.
- Launch the server component of the Web Tours application. You can do this by selecting Start > All Programs > HP Software > HP LoadRunner > Samples > Web > Start HP Web Tours Server. You will see the below server window pop up which will show the server services running.
- Launch the web tour client application. You can do this by selecting Start > All Programs > HP Software > HP LoadRunner > Samples > Web > HP Web Tours Application. You will be shown the below screen.
- Login in your application using the following credentialsUser name – jojoPassword – beanYou will then be logged on to the application and be presented with the below screen. Click on the Flights option.
- Choose the Arrival City as Los Angeles and click on the Continue button.
- The next screen will show the flights. Keep the first option as chosen and click on the Continue button.
- In the next screen which is the payment details screen, click on the Continue button.You will finally be presented with your Invoice page
This is your full business transaction and the functionality that you will load test. Now let’s see how we script this in the VuGen component.
Now it is time to generate your first test script in VuGen based on the above functionality.
Note: In a real world scenario, always test the business scenarios to make sure they are working as they should, before you start the scripting process. Normally the load testing team is not responsible for the application under test. There are times when either the wrong application link or a buggy application can be given to the load testing team. In such situations it’s absolutely important to ensure that as a tester the application works as it should.
Let’s look at the steps required to create your first test script.
- Choose the File menu option of “New Script and Solution”.
- In the next screen, you will be prompted to give more details on the script.
- You will need to first select the option Single Protocol. This is because you are working with the web application which is based on a web protocol, hence we just have the http protocol which is required.
- Next choose the Web – HTTP/HTML protocol option.
Note: If your application works with multiple protocols , then you can choose the Multiple protocols option as shown below.
When you choose the Multiple protocols option, you can then select the required combination of protocols.
- Enter the name of the script. Always give a meaningful name to the script, for maintenance purposes.
- Provide a location for the script.
- Finally use the Create button to create the script.
The script will look like the screenshot shown below. Let’s look at some of the key aspects of the file.
- Each script has 3 classes of actions.
- vuser_init – This method is used to perform any sort of initialization in the script. An example would be, if any additional files or database connections need to be opened during this phase.
- Action – This method is used to hold all of the major code of the load testing script.
- vuser_end – This method is used to perform any sort of clean-up in the script. An example would be, if any additional files or database connections need to be closed during this phase.
- This tab provides all the main code. If you click on either of the action classes mentioned above, the associated code window will be opened.
Note: If you don’t know which protocols to choose , then we you use the Protocol Advisor option. This is an option available in LoadRunner to give an indication on what is the underlying protocol used by the application. Follow the below steps to learn how to use the Protocol Advisor.
Step 1) In the dialog window to create a new script, click on the Protocol Advisor link.
Step 2) Once the protocol advisor link is clicked, the following screen will be shown to the user.
- Click on which type of application you want to record. For the demo purpose, we chose the Web browser option.
- For the program to analyze, we chose the option of Google Chrome.
- Enter the URL to analyze, in the above example we used google.com but this should be your application URL.
- Click on the Start Analyzing button.
The Google Chrome browser will open and google.com will be loaded in the URL. You will also see a small dialog box which indicating the progress of the analysis in the background. Finally click on the Finish Analyzing button.
The Results of the Protocol Analyzer will be displayed in the next screen. The protocol advisor may not always be accurate so its best to use verify the protocol to be used from the application development team or other experts.
Now that you are well versed with creation of your first test script, it’s now time to record your script. Let’s look at how we can achieve this.
- In your VuGen IDE, click on the Record button.
- In the next screen you will be required to provide the various recording options.
- First select which action (vuser_int, Action or vuser_end) the recorded code should be inserted into. In our exercise, we choose Action.
- Next choose the option that you want to record the actions via the web browser
- Choose the option of Google Chrome to create the recording via the Chrome browser.
- Enter the url of the sample Web Tours application.
- Choose the option to record immediately
- Finally click the Start Recording button to start the recording process.
Google Chrome will then open and the Web Tours application will be loaded in the browser. A small dialog window will also open which will provide various options to the tester while recording of the script.
Transactions are used in test script to logically separate a set of actions within a business scenario. This is very useful and highly recommended for test scripts. For example, we can create a transaction checkpoint just for the login part of the application. This is helps us to know the commands executed in the test scripts which are just associated with the login functionality of the application. To add a transaction, follow the below steps.
Step 1) While recording the business scenario use the recording options to create a transaction.
- Click on the Record Transaction icon.
- Enter a logical name for the transaction checkpoint such as chk_Login
- Click on the OK button to create the checkpoint.
Step 2) End the checkpoint after the login process. Once you have logged into the application, it’s now to end the checkpoint. Click on the Close Transaction button and choose the chk_Login checkpoint option.
We will see Transactions in detail in upcoming topics.
Comments can be inserted at any point during the recording session. Comments can be used to store documentation or notes so that the script can be understood any someone else or even by you, if you review the script after 6 months or a year.
Whenever the script is opened by another tester, the comments can help the tester understand better what the code is doing.
To add comments in your code, perform the below steps when recording:
- Click the Insert comments option
- Add the required comment in the textbox for the comment
- Click the OK button to insert the comment
Once you have executed the entire business scenario for the Web Tours application you can stop the recording process. Click on the Stop recording to stop the recording process.
Once you stop the recording process, the script will be shown in the IDE as shown below.
You will initially be prompted with the Correlation screen. For now, you can choose the Close button. We will discuss correlation in a subsequent chapter.
Some of the highlights in the code are quickly evident and shown below.
- Each Web request will be recorded as a web URL.
- If you added any transactions, you can find them in the script. Note the line which was used for inserting the transaction for the login functionality of the application.
- You can also see that the parameters of the user name and password for the Web tours application were recorded.
While recording, there are a variety of options available to the tester. Let’s go through the recording options one by one. You can access the recording options by clicking on the menu option of Record > Recording Options.Type of Recording
You have an option of recording in 2 different ways, one is the HTML based and the other is the URL based.
One of the core differences is that, for the URL based recording, every URL request for any resource is recorded. This is not the case for HTML recording. So for example if you have a sub request for an image, the URL recording for the image would be recorded in the URL based script.
Examples of code snippets are shown below for both.
web_url("seed", "URL=https://clients4.google.com/chrome-variations/seed?osname=win", "Resource=0", "Referer=", "Snapshot=t39.inf", "Mode=HTML", EXTRARES, "Url=https://translate.googleapis.com/translate_a/l?client=chrome&hl=en&key=AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw&alpha=1", "Referer=", ENDITEM, LAST);
web_url("hp_logo.png", "URL=http://127.0.0.1:1080/WebTours/images/hp_logo.png", "Resource=1", "RecContentType=image/png", "Referer=http://127.0.0.1:1080/WebTours/header.html", "Snapshot=t6.inf", LAST); web_url("webtours.png", "URL=http://127.0.0.1:1080/WebTours/images/webtours.png", "Resource=1", "RecContentType=image/png", "Referer=http://127.0.0.1:1080/WebTours/header.html", "Snapshot=t8.inf", LAST);
Advantages of HTML Recording
- You don’t need to manually record or capture dynamic based values.
- The scripts are generally less in size, which makes them more readable and easier to maintain.
Disadvantages of HTML Recording
- Scripts are less scalable
- The scripts require more CPU and power , because most of the dynamic based values are cached in memory
Advantages of URL Recording
- There is an in-built support for Java Applets and ActiveX objects.
- You can replay the scripts on a UNIX machine
Disadvantages of URL Recording
- Scripts require more correlation since nothing is stored in memory cache
- Context-sensitive checks won’t work
- Scripts are large since each sub request is recorded.
By default the scripting language used by LoadRunner is C. If there are any Java based applications recorded, then the underlying script will be created by Java.
The language to be used for the scripting is decided by the tool itself.
There are other options such as the maximum lines of code that can be used in the Action File. The maximum limit is 65,000 lines. After this, LoadRunner will create second Action script file.
The active protocols being used in the script will be displayed here.
This screen is only useful if you are using multiple protocols and you can select which protocols should be used in the recording session.
In this screen you can enable or disable correlation during the code generation process. Correlation can be used to correlate objects after the recording session is completed. The below screenshot shows the options available.
You can also enable asynchronous scanning using the Async Scan option. Its recommended to leave both boxes checked so that the scan is asynchronous and dynamics values are correlated during automatically during code generation.
Correlation – Configuration
This is the general configuration used by the rules once the recording is complete. The important point to note is that the Rules scan is enabled and that the Heuristic level is set to medium.
If you click on the Rules, you can actually see the details of the rules which are used in the correlation process.
Most of the HTML properties should be left as it is. The most important is the context reset for each URL action. So for each request to the web server, the context of the web request will be reset.
All the options on this screen should be left as it is.
Now that the script has been recorded, the next important step is to playback the script to see that it works properly. To playback a particular script, just click on the playback button.
- During the playback process, you will see all the actions being executed in the left hand side of the screen
- You will also be able to see a yellow cursor which will indicate which is the current request being serviced.
Once the entire script is run, you will be able to see the test results.
If you click on the The Test Results link in the above screen, you will get a drilled down report of the test.
In the next topic we will go through Advanced VuGen Topics like Transactions, Rendezvous points, Parameters etc.