Scripting

Basics of LoadRunner Scripting

The simplicity, convenience of scripting, execution, and result analysis of LoadRunner are well known. You were given a high-level overview of all the fundamental procedures we take when performing performance testing with LoadRunner in the post titled “LoadRunner Basic Steps.” You must go through all of the subjects in the LoadRunner Tutorial to gain more information on each step. In this post, you will discover the crucial elements for producing a flawless LoadRunner script, starting with the fundamentals of LoadRunner scripting.

      Except for particular protocols, LoadRunner (VuGen) operates on the ‘Record and Replay’ principle.

If you’re just starting off, you should be familiar with the “Record and Replay” concept. ‘Record and Replay’ in this context only refers to scripting. The business flow (or user activities) can be recorded by merely browsing the web pages in the browser, and VuGen (the LoadRunner’s scripting component) records the communication between the browser and the server.

VuGen turns the recorded flow into a program named “Script” after recording. All of the user activities you took, while the recording was being made, are included in the recorded script. To confirm that the flow and business process is right, you can replay the script.

It is quite uncommon to succeed on the first try. This is due to the fact that certain websites contain security checks that can be handled with little extra coding. As a result, the recorded script needs to be modified, a process known as “script debugging.”

Let’s now get deeper into the specifics of scripting steps:

Basic LoadRunner Scripting Steps:

See the flowchart below (Figure 01). The LoadRunner scripting process consists of 5 basic steps:

  • Upload
  • Protocol
  • Identification
  • Recording
  • Debugging
LoadRunner Scripting Basics
  1. Protocol Identification:
      The first stage in script recording is protocol identification. You must be familiar with the technology and platform of the application on which the script will be written. Ask the application architect or developer for these details if you are unsure. Prior to Micro Focus’ discontinuation, VuGen included a tool named “Protocol Advisor” to help identify the supportive protocol. As a result, you must independently gather knowledge on protocols and select the appropriate one.
  2. Script Recording:
     As was already noted, the main benefit of LoadRunner is its recording feature, which saves performance testers time and effort by automating the writing of manual code for 80%–90% of protocols. In some circumstances, custom code must be written, although those instances require only basic logic.
    You can start script recording by simply surfing the websites in accordance with the business flow after choosing the appropriate protocol. Once the flow is over, the recording can be stopped. To scan the recording logs and produce the script, VuGen needs some time.
    Keep in mind that the online service (protocol) does not adhere to the recording practice, thus its script production procedures diverge.
  3. Script Debugging:
    Correlation: Although it includes an autocorrelation capability, LoadRunner generates a very basic script that cannot handle dynamic values arriving from the server. Undoubtedly, the question “What is the dynamic value?” pops into your head. For security reasons, the server generates various distinctive values, such as sessionIDs and permission tokens, which the script must manage. ‘Correlation’ is the LoadRunner term for the handling of dynamic values.

    If you play back a freshly recorded script without making any changes, the script might not work because of a correlation problem. because the server will reject it because it passes an outdated (recorded) dynamic value. As a result, you must locate the dynamic values in the script and use correlation when necessary. As was already noted, LoadRunner features an auto-correlation capability that can recognize dynamic values automatically, however, it is not always effective. The issue of correlation will be covered in more detail later.

    Flow logic: On occasion, you must create original code to manage user activities. A hotel booking website might include all the hotels and indicate whether they are booked or available. According to the business case, a user must only select hotels with an “Available” occupancy status. If you were to replay the script with the recorded hotel that had been reserved while recording, the script would attempt to do the same while the server would reject it and throw an error. Finally, a script failure notice will appear. You now need to create a custom logic that only books available hotels after first checking the hotel’s occupancy status.

    Content check: Examining the text or image that is displayed on a webpage aids in validating the response. This is a crucial check to see whether the target page has loaded or not. There are two types:
    • Verify the text in the response with a text check.
    • Image check: to make sure the image is present in the response.
  4. Script improvement:
    This stage, which comes after recording and debugging, gives the script an aesthetic appeal. Some crucial stages in script improvement are script factorization and parameterization. You can skip some steps as they are optional.

    Parameterization: Using parameters allows you to use the test data instead of the script’s hardcoded values. To replace a value with a parameter in VuGen, simply select the value, right-click on it, and choose “Replace with a parameter” or “Use existing parameter”.

    Add/Edit Transactions If not specified at the time of withdrawal, you can add or edit transactions. Transactions represent user actions. They help capture the delay and error of a specific request or user action. The transaction name can be specified both during posting and after posting. Additionally, you can quickly change the name of a transaction if you do not follow the business process or if you choose to change it.

    Meeting Points: At any point in the script, meeting points help to achieve user concurrency. A touchpoint significantly increases the user load on the server and allows LoadRunner to assess the capacity of the server for that particular operation. Click on the link for more information on the meeting point and policies.

    Add/Edit Think Time – An actual pause by a user while reading the content of a page is known as “think time”. Increases the realism of a scenario. Putting the think time (lr_think_time(n), where n is a delay in seconds) between two transactions is a good idea. In the script, there is a function for the think time included whose value can be changed.

    Update runtime configuration – The runtime configuration gives the Vuser script general control. You can make any necessary updates. Execution logic, think time, pacing, logging on/off, and other topics are typically covered.

    VuGen runtime configuration can be overridden via Performance Center/Controller.
  5. Upload the script to Controller or Performance Center:
    The entire script must be uploaded to Performance Center or Controller for execution. You must verify the following before submitting the script:
    • The script should work perfectly with different users and iterations.
    • The script must deliver the desired results and follow the correct business process.
    • If desired, disable or enable logging (minimum level).
    • The script must have the correct runtime configuration.
    • Unique logic should be separated from the business transaction.
    • The script must use the calculation of time and the rhythm of thought. Calculate time and pace with Think.

      These basics of LoadRunner programming will help you write fully automated, error-free scripts. Click on the links to learn more about a particular topic that was difficult to cover in the basics.
Scroll to Top