Introduction to Virtual User Generator – VuGen Tutorial

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:

  1. Introduction to VuGen Scripting process
  2. Getting started with VuGen
  3. Demo Application for Load Testing
  4. How to record your first test script in VuGen
  5. Exercise – Recording your test script
  6. How to add Transactions to your script
  7. How to insert Comments
  8. How to finalize your recording
  9. Recording options in LoadRunner
  10. How to playback a script

Introduction to VuGen Scripting process

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.loadrunner_vugen_tutorial_script_development_process

  1. 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.
  2. 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.
  3. 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.
  4. The setup of any runtime settings can include changing parameters such as the pacing of transactions or the think time of transactions.
  5. 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.

Getting started with VuGen

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.hp_loadrunner_virtual_user_generator_tutorial_vugen_icon

An intermediate Splash screen will be shown.loadrunner_vugen_tutorial_splash_screen

Below is the general interface you will be presented with, when you launch the Virtual User Generator.loadrunner_vugen_tutorial_interface

Demo Application for Load Testing

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.

  1. Ensure that Internet Explorer version 10 or higher is installed on the machine.
  2. Ensure that Java version 7 update 65 or Java 8 is installed on the machine.
  3. 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.loadrunner_vugen_tutorial_java_control_panel
  4. 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.hp_loadrunner_virtual_user_generator_tutorial_web_tours_server
  5. 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.hp_loadrunner_virtual_user_generator_tutorial_web_tours_client
  6. 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.hp_loadrunner_virtual_user_generator_tutorial_web_tours_flights
  7. Choose the Arrival City as Los Angeles and click on the Continue button.hp_loadrunner_virtual_user_generator_tutorial_web_tours_arrival
  8. The next screen will show the flights. Keep the first option as chosen and click on the Continue button.hp_loadrunner_virtual_user_generator_tutorial_web_tours_find_flight
  9. In the next screen which is the payment details screen, click on the Continue button.hp_loadrunner_virtual_user_generator_tutorial_web_tours_payment_detailsYou will finally be presented with your Invoice pagehp_loadrunner_virtual_user_generator_tutorial_web_tours_invoice

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.

How to record your first test script in VuGen

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.

  1. Choose the File menu option of “New Script and Solution”.hp_loadrunner_virtual_user_generator_tutorial_new_script
  2. In the next screen, you will be prompted to give more details on the script.load_runner_vugen_tutorial_new_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.load_runner_vugen_tutorial_multiple_protocols
      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.load_runner_vugen_tutorial_webtoursscript

  • Each script has 3 classes of actions.
    1. 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.
    2. Action – This method is used to hold all of the major code of the load testing script.
    3. 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.load_runner_vugen_tutorial_protocol_advisor

Step 2) Once the protocol advisor link is clicked, the following screen will be shown to the user.load_runner_vugen_tutorial_protocol_advisor_dialog

  1. Click on which type of application you want to record. For the demo purpose, we chose the Web browser option.
  2. For the program to analyze, we chose the option of Google Chrome.
  3. Enter the URL to analyze, in the above example we used but this should be your application URL.
  4. Click on the Start Analyzing button.

The Google Chrome browser will open and 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.load_runner_vugen_tutorial_protocol_advisor_analyze

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. load_runner_vugen_tutorial_protocol_advisor_results

Exercise – Recording your test script

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.

  1. In your VuGen IDE, click on the Record button.load_runner_vugen_tutorial_record
  2. In the next screen you will be required to provide the various recording options.load_runner_vugen_tutorial_start_recording
    1. First select which action (vuser_int, Action or vuser_end) the recorded code should be inserted into. In our exercise, we choose Action.
    2. Next choose the option that you want to record the actions via the web browser
    3. Choose the option of Google Chrome to create the recording via the Chrome browser.
    4. Enter the url of the sample Web Tours application.
    5. Choose the option to record immediately
    6. 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.load_runner_vugen_tutorial_script_recorder_dialog

How to add Transactions to your 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.load_runner_vugen_tutorial_script_recorder_login_transctions

  • 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.load_runner_vugen_tutorial_script_recorder_login_transctions_end

We will see Transactions in detail in upcoming topics.

How to insert Comments

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.

load_runner_vugen_tutorial_commentsTo 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

How to finalize your recording

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.load_runner_vugen_tutorial_script_recorder_stop_recording

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.loadrunner_vugen_tutorial_correlation-close

Some of the highlights in the code are quickly evident and shown below.

  • Each Web request will be recorded as a web URL.load_runner_vugen_tutorial_webrequest
  • 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.load_runner_vugen_tutorial_script
  • You can also see that the parameters of the user name and password for the Web tours application were recorded.load_runner_vugen_tutorial_parameters

Recording options in LoadRunner

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.load_runner_vugen_tutorial_recording_optionsType of Recording

You have an option of recording in 2 different ways, one is the HTML based and the other is the URL based.

loadrunner_vugen_tutorial_recording_options_recordingOne 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.

HTML-based script

"Url=", "Referer=", ENDITEM,

URL-based script



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.

Scripting Language

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.

loadrunner_vugen_tutorial_recording_options_scripting_languageThe 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. load_runner_vugen_tutorial_recording_options_protocols

This screen is only useful if you are using multiple protocols and you can select which protocols should be used in the recording session.

Code Generation

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.load_runner_vugen_tutorial_recording_options_correlation

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.load_runner_vugen_tutorial_recording_options_correlation_configuration

If you click on the Rules, you can actually see the details of the rules which are used in the correlation process.load_runner_vugen_tutorial_recording_options_correlation_rules

HTML Properties

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.load_runner_vugen_tutorial_recording_options_html_properties


All the options on this screen should be left as it is.load_runner_vugen_tutorial_recording_options_network

How to playback a script

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.load_runner_vugen_tutorial_playback_script_recording

  • 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.load_runner_vugen_tutorial_playback_actual

Once the entire script is run, you will be able to see the test results.loadrunner_vugen_tutorial_script_result

If you click on the The Test Results link in the above screen, you will get a drilled down report of the test.loadrunner_vugen_tutorial_detailed_results

In the next topic we will go through Advanced VuGen Topics like Transactions, Rendezvous points, Parameters etc.