Lesson 4: Preparing a Vuser Script for Load Testing

In the previous lessons, you verified that the replay of your Vuser script produced an accurate emulation of a real user. The next step is to prepare the script for load testing. How will the system work with many users working simultaneously? Will the system slow down to an unacceptable level?

In this lesson you will learn about different methods to enhance the script and to make it more effective for the load testing process.

In this lesson you will cover the following topics:

How do I measure the duration of a business process?

When preparing an application for deployment, you need to measure the duration of specific business processes—how long does it take to log on, book a flight, and so on. Each business process is normally made up of one or more steps or actions in your script. In a Vuser script, you designate a series of actions you want to measure by including these actions in a transaction.

When you run a Vuser script that includes a transaction, LoadRunner gathers information about the time it takes to perform the transaction, and displays the results in color-coded graphs and reports. You use this information to help determine if the application meets the performance requirements.

You can manually insert a transaction anywhere in a Vuser script. To mark a set of steps as a transaction, insert a start_transaction marker before the first step and an end_transaction marker after the last step.

In this section you will insert a transaction into your script to measure the amount of time it takes for the user to find and confirm a flight.

To insert a transaction into a Vuser script:

  1. In VuGen, open the Basic_Tutorial script which you created in Lesson 1: Building a Vuser Script. If it is still open, you can select the tab displaying its name. Otherwise you can open it from the File menu.
  2. Click the Step Navigator tab to display the Step Navigator.
  3. Insert a Start Transaction.
    1. In the Step Navigator, locate the step Image: Search Flights Button.
    2. Double-click the Image: Search Flights Button step to display the corresponding web_image step in the Editor.
    3. Click View > Steps Toolbox. The Steps Toolbox appears in the right pane.
    4. In the Steps Toolbox, under Common, select lr_start_transaction, drag it into the Editor, and release it before the web_image step. The Start Transaction dialog box opens.

    5. In the Transaction Name box, enter find_confirm_flight and click OK. VuGen inserts an lr_start_transaction step in the Step Navigator, and a corresponding lr_start_transaction function in the Editor.
  4. Insert an end transaction marker.
    1. In the Step Navigator, locate the step Submit Form: reservations.pl.
    2. Double-click the Submit Form: reservations.pl step to display the corresponding web_submit_form step in the VuGen editor.
    3. In the Steps Toolbox, under Common, select lr_end_transaction, drag it into the Editor, and release it after the web_submit_form step. The End Transaction dialog box opens.

    4. Make sure that find_confirm_flight appears in the Transaction Name box, and then click OK. VuGen inserts an lr_end_transaction step in the Step Navigator, and a corresponding lr_end_transaction function in the Editor.

      You have now defined the find_confirm_flight transaction.

Back to top

How do I emulate multiple users?

In your emulation, you tracked a user booking a flight and choosing an aisle seat. In a real-life setting, however, different users will have varying preferences. To improve your test, you need to check if the booking will work when users select different seating preferences (Aisle, Window, or None).

To accomplish this, you will parameterize the script. This means that you take the recorded value, Aisle, and replace it with a parameter. You will place values for the parameter in a parameter file. When you run the script, the Vuser will use values from the parameter file (Aisle, Window, or None) thereby emulating a true travel agency environment.

To parameterize your script:

  1. Find the section where you want to vary the data.
    1. Select View > Step Navigator to show the Step Navigator in the left pane.
    2. In the Step Navigator, locate the Submit Form: reservations.pl step.
    3. Right-click the Submit Form: reservations.pl step and select Show Arguments. The Submit Form Step Properties dialog box opens.

      The ABC icon to the right of each argument in the grid indicates that the argument has a fixed value.

  2. Change the fixed value to a varying value.
    1. In the Submit Form Step Properties dialog box, select seatPref in the seventh row of the grid.
    2. Click the ABC icon adjacent to the seatPref argument. The Select or Create Parameter dialog box opens.

  3. Create a parameter.
    1. In the Parameter name box, type seat.
    2. Click OK. In the Submit Form Step Properties dialog box, VuGen replaces the ABC icon with a Parameter icon .

    3. Click the Parameter icon adjacent to {seat} and select Parameter Properties. The Parameter Properties dialog box opens.

  4. Specify values for the parameter.
    1. Click Add Row. VuGen adds a row to the table.
    2. Replace the word Value with Window.
    3. Click Add Row. VuGen adds another row to the table.
    4. Replace the word Value with None.

      Note: The values are not case sensitive.

    5. Keep the default settings in the Select column and File format sections of the dialog box.
  5. Define how the test will vary the data.
    1. Keep the default setting that instructs VuGen to take a new value for each iteration: Update value on: Each iteration.
    2. Click Close to close the Parameter Properties dialog box.
    3. Click OK to close the Submit Form Step Properties dialog box.

      You have now created a parameter for the seating preference. When you run the load test, the Vusers will use the parameter values instead of the recorded value, Aisle.

      When you run the script, the Replay log will show the parameter substitution that occurs for each iteration. The Vuser will use Aisle for the first iteration, Window for the second iteration, and None for the third iteration.

Back to top

How do I verify Web page content?

When running a test, you often need to verify if certain content is found on a returned page. A content check verifies that expected information appears on a web page while the script is running. You can insert two types of content checks:

  • Text check. Checks that a text string appears on a web page.
  • Image check. Checks for an image on a web page.

In this section, you will insert a text check that checks if the phrase Find Flight appears on the Reservations page of HPE Web Tours.

Inserting a text check

  1. Click the Step Navigator tab to display the Step Navigator.
  2. In the Step Navigator, locate the Submit Form: reservations.pl step.
  3. On the VuGen toolbar, click the Show Snapshot pane button to display the Snapshot pane.
  4. In the Step Navigator, double-click the snapshot icon in the Submit Form: reservations.pl step. The corresponding snapshot appears in the Snapshot pane.
  5. From the VuGen menu, click View > Steps Toolbox. The Steps Toolbox pane appears.
  6. In the Steps Toolbox - Search box, type in web_reg, and then locate the web_reg_find step in the Filter Results.
  7. Drag the web_reg_find step from the toolbox into the Editor, before the web_submit_form function. The Find Text dialog box opens.
  8. In the Find Text dialog box, type Find Flight into the Search for specific Text box, and then click OK.
  9. VuGen inserts a web_reg_find step into the Step Navigator and a corresponding web_reg_find function into the Editor.

    When you replay the script, VuGen will look for the text Find Flight and indicate in the Replay log whether or not the text was found.

Back to top

How can I produce debugging information?

At certain points during a test run, you may want to generate and send messages that contain information relating to the script execution. These output messages will appear in both the Replay log in the Output pane, and in the Controller’s Output window. You can send a standard output message or a message that indicates that an error occurred.

The recommended way to work with error messages is to check for a Failed status. If the status is Failed, you instruct VuGen to issue an error message. For details, refer to the examples in the Function Reference.

In this section of the tutorial, you will instruct VuGen to insert an output message after the application completes a full booking.

To insert an output message:

  1. Click the Step Navigator tab to display the Step Navigator.
  2. In the Step Navigator, locate the last step, Image: SignOff Button.
  3. Double-click the Image: SignOff Button step. The Editor displays the corresponding web_image function.
  4. In the Steps Toolbox, under Common, locate the lr_output_message function.
  5. Select the lr_output_message function, drag it to the Editor, and release it after the web_image function. The Output Message dialog box opens.

  6. In the Message Text box, type The flight was booked.
  7. Click OK. VuGen adds an lr_output_message to the script, and a corresponding step in the Step Navigator.

  8. Click the Save button on the VuGen toolbar to save the script.

Note: To insert an error message, repeat the same process, except that in the Steps Toolbox, select an lr_error_message function instead of the lr_output_message function.

Back to top

Did the replay of my test succeed?

In this section, you will run the enhanced script and search the Replay log for text checks. You will view the results of the text checks, as well as details of the transactions and parameterization.

By default, image and text checks are disabled during playback since they require more memory. If you want to perform an image or text check, you need to enable checks in the runtime settings.

  1. Enable image and text checks.
    1. Double-click the Click Runtime Settings node in the left Solution Explorer pane to open the Runtime Settings view.
    2. Click Internet Protocol > Preferences.
    3. Select Enable image and text check.
    4. Click OK to close the Runtime Settings dialog box.
  2. Run the script.

    Click the Replay button on the VuGen toolbar. VuGen begins running the script, generating entries in the Replay log in the Output pane.

    Wait for the script to finish running.

  3. Locate the text check.
    1. Click the Output pane, and select Replay.
    2. Click in the Replay log, and then press Ctrl+F to open the Search dialog box.
    3. Search for web_reg_find.

      The first instance:

      web_reg_find started

      Click Find Next to display the next instance of web_reg_find.

      Registering web_reg_find was successful.

      This is not the actual text check—it only prepares VuGen to check for the text after the form submission.

      Click Find Next to display the next instance of web_reg_find.

      Registered web_reg_find successful for “Text=Find Flight” (count=1).

      This verifies that the text was found. If someone changes the Web page and removes the phrase Find Flight, then in subsequent runs, the output will indicate that the text was not found.

  4. Locate the beginning of a transaction.
    1. In the Replay log, press Ctrl+F to open the Search dialog box.
    2. Search for the word Transaction. This notification is shown in blue.
  5. View the parameter substitution.
    1. In the Replay log, press Ctrl+F to open the Search dialog box.
    2. Search for the word Parameter. The log contains a notification “seat” = “Aisle”.
    3. Search again (F3) for the next substitution. Note how VuGen takes a different value for each iteration.
  6. Select File > Save or click the Save button on the VuGen toolbar.

Back to top

Next steps: