LoadRunner Scripting Basics

LoadRunner is well-known for its simplicity, ease of doing scripting, execution and result analysis. In the LoadRunner Basic Steps post, you got a high-level idea about all the basic steps which we follow in the performance testing using LoadRunner. To get more details on each step you have to go through all the topics of LoadRunner Tutorial. Starting with LoadRunner scripting basics, in this post, you will learn the important steps for a perfect LoadRunner script creation.

LoadRunner (VuGen) works on the ‘Record and Replay’ concept, except for some protocols.

If you are a beginner then you must know what is ‘Record and Replay’ concept. Here, the ‘Record and Replay’ term is related to scripting only. It means that you can record the business flow (or user actions) by simply navigating the web pages in the browser and VuGen (the scripting component of the LoadRunner) captures the communication between the browser and the server. This is the recording part (Record). Refer to the post to know how does LoadRunner work?

After recording, VuGen converts the recorded flow in a program called ‘Script’. The recorded script has all the user actions which you performed during the recording. The script can be replayed to verify the correctness of the flow and business process. This is the ‘Replay’ part.

It is very rare to get success in the first replay. This is because some websites have security checks which can be handled through some additional coding. Hence the recorded script requires modification which is called ‘Script Debugging’.

Now, let’s get into more details about scripting steps:

Basic Steps of LoadRunner Scripting:

Refer to the below flow chart (Figure 01). There are 5 main steps of LoadRunner scripting:

  • Protocol Identification
  • Recording
  • Debugging
  • Enhancement
  • Upload
LoadRunner Scripting Basics
Figure 01: Basic Steps of LoadRunner Scripting

1. Protocol Identification:

Protocol Identification is the first step for script recording. For creating a script you should know the technology/platform of the application on which it is built. If you do not know then get these details from the application architecture or developer. Previously, VuGen had a feature called ‘Protocol Advisor’ to identify the supportive protocol but Micro Focus had discontinued it. Therefore you need to gather protocol-related information by yourself and choose the correct one.

Sometimes you need to select multiple protocols to record the application which depends on the nature of the application. The list of protocols is available here.

2. Script Recording:

As mentioned above, the biggest advantage of LoadRunner is that it has a recording feature which covers 80%-90% of protocols and saves the time and effort of a performance tester to write manual code. In some cases, you have to write the custom code but those are some simple logic.

After the selection of the correct protocol, you can start script recording by simply navigating the web pages as per business flow. You can stop the recording once the flow is completed. VuGen takes some time to scan the recording logs and generate the script.

Remember that web service (protocol) does not follow the recording practice hence the script generation steps are different for it.

3. Script Debugging:

Correlation: LoadRunner generates a very basic script which lacks the handling of dynamic values coming from the server; although it has an autocorrelation feature. Definitely, a question comes to your mind what is the dynamic value? The server generates some unique value like sessionID, authorization token etc. for security purpose that needs to be handled in the script. The handling of dynamic values in LoadRunner is called ‘Correlation’.

If you replay the freshly recorded script without any change, the script may fail due to the correlation issue. Because it passes the old (recorded) dynamic value which will be refused by the server. Hence you need to identify the dynamic values in the script and apply the correlation wherever required. As mentioned above, LoadRunner has an auto-correlation feature that automatically identifies the dynamic values but it does not work every time. We will discuss the correlation topic later in detail. Refer to the link for more details.

Flow Logic: Sometimes, you need to write custom code to handle user activities. For example, a hotel booking site displays a list of the hotel along with their occupancy status (Booked/Available). As per the business case, a user has to pick only that hotel which has occupancy status as ‘Available’. Let’s consider you replay the script with the recorded hotel which has already been booked while recording then the script will try to book the same booked hotel and the server will refuse it and throw an error. At last, you will get the script failure message. Now, you need to write a custom logic which checks the occupancy status of the hotel first and then book the available hotel only. In this scenario, you will perform flow debugging. Refer to the link for more information.

Content Check: It helps to validate the response by checking the content or image present on a webpage. This is an important check to verify whether the desired page has been loaded or not. It is of two types:

  • Text check: To validate the text in the response.
  • Image check: To verify the availability of the image in the response.

Refer to the link to get more detail.

4. Script Enhancement:

After recording and debugging, the script enhancement step gives beauty to the script. Script enhancement has some important steps like parametrization, script factorization, etc. Some of the steps are optional which you can skip:

Parameterization: The parameter helps to replace hard-coded values from the script with the test data. In VuGen, you just need to select the value, right-click on it (the value you want to replace with a parameter) and select the option ‘Replace with a Parameter’ or ‘Use Existing Parameter’ option. For more detail, you can refer to the Link.  

Add / Edit Transactions (If not given at the time of recording): Transactions are the user steps. They help to capture the response time and error for a particular request or user step. You can provide the name of the transaction either during recording or post-recording. Also, if a transaction name does not match the business flow or want to change then you can easily modify it.

Rendezvous Points: Rendezvous Point helps to achieve user concurrency at any step in the script. A rendezvous point creates an intense user load on the server and enables LoadRunner to measure server performance under load for that particular functionality. Refer to the link to get more details on Rendezvous Point and policy.

Add / Edit Think Time: Think time is a pause time that a real user takes to read the content of the page. It makes a scenario more realistic. It is a good practice to insert think time (lr_think_time(n) where n is a delay in seconds) between two transactions. You can also find the recorded think time function in the script whose value can be edited. Refer to the link to get more details on think time.

Update Runtime Setting: Run time settings provides overall control on the Vuser script. You can update it as per the requirement. It generally covers run-logic, think time, pacing, enable/disable logs etc. Refer to the link for detailed information on Runtime Setting.

Note: Performance Center/Controller can override the run time settings of VuGen.

Insert Comment: Add the comment in the script wherever required. Refer to the link for more information.

5. Upload the script in Performance Center / Controller: 

The last step is to upload the final script in Performance Center or Controller for the execution purpose. Before uploading the script, you must ensure that:

  • The script should run for multiple users as well as multiple iterations without any failure.
  • The script should follow the correct business flow and give the expected output.
  • Disable/Enable (minimum level) log as per requirement.
  • The script should have an appropriate runtime setting.
  • The custom logic should be outside the business transaction.
  • The script should have calculative think time and pacing. Use Think Time and Pacing calculator.

These are the basics of LoadRunner scripting which will help you to create a perfect and fully automated script. You can refer to the given links to get detailed information on the particular topic which was difficult to cover in the basics.

You may be interested:

Leave a Comment