How to Upload File in LoadRunner Script: LoadRunner is the most used commercial tool in the performance testing industry, It is created by Mercury Interactive and later acquired by HP.

In recent days it was acquired by Microfocus, Microfocus will be releasing the next latest versions. LoadRunner is used for doing performance testing and its supports almost all types of communications that happen between server and client to pass data to and fro, In LR most used protocol is WEB/Html, This protocol is used to replicate or create the actions which are done by real users on browsers or mobile apps with HTTP protocols by passing data to the tool.

How to Upload File in LoadRunner Script

In this post we will see how the LoadRunner web/HTML protocol is used in cases like uploading a file or images to the server, If we see in recent days all web applications have the functionality of uploading files let’s take an example like eCommerce application which we need to upload images for shopping or for your profile picture so on.

Sometimes we need to add this kind of scenario as a part of your performance test suites because reading file content and writing file content on a server hard disk or to the cloud will consume a lot of IO operations which also impact performance

Just to show the upload scenario in load runner I have created a simple java web application that will allow us to upload files and saves on to hard disk

Below is the URL which is to launch the home page

http://localhost:8080/spring4upload/

Screen  looks like

File Uploading in LoadRunner Script

  • After choosing the file and clicking submit we will be seeing below the screen a response

How to Upload File in LoadRunner Script

we can achieve this with help of the web_submit_data function in the LR web protocol

The syntax of web_submit_data is shown below


web_submit_data("requestname",
"Action=URL of the request",
"Method=POST/PUT",
"EncType=Contenttype headers as per your request",
"TargetFrame=",
"RecContentType=Response content type",
"Snapshot=t5.inf",
"Mode=HTML",
ITEMDATA,
"Name=Post parameter name",
"Value=this is the file name saved in server",
"File=yes",
"FilePath=complete file path of file including extension",
ENDITEM,
LAST );

  • From the above method, we can include normal fields which have string or integer values in the post body along with file parameters
  • for every post parameter, we need to pass one ITEMDATA and ENDITEM to specify for each field
  • Below is the 2 different fields which are having file and normal field in post parameters

ITEMDATA,
"Name=Post parameter name", "Value=this is the file name saved in server", "File=yes","FilePath=complete file path of file including extension",
ENDITEM,

ITEMDATA,
"Name=Post parameter name", "Value=this is the file name saved in server",
ENDITEM,

  • The difference between a normal field and a field with file content is, For the File content field we need to mention
     "File = yes"

    and

    "FilePath=complete file path"

    Attributes in ITEMDATA for normal fields which carry String or Integer or Boolean no need to mention these attributes

  • Another point is to mention request that you are sending the file is need to add EncType or add the header “content-type =multipart/form-data” by this, we tell the server that we are sending file content in our request.

The actual request which looks like below


web_submit_data("Attachments",
"Action=http://localhost:8080/spring4upload/upload",
"Method=POST",
"EncType=multipart/form-data",
"TargetFrame=",
"RecContentType=text/html",
"Snapshot=t5.inf",
"Mode=HTML",
ITEMDATA,
"Name=file",
"Value=File uploading web application1.PNG",
"File=yes",
"FilePath=C:\\Users\\user\\Pictures\\jmeter\\File uploading in jmeter\\uploading successful message.PNG",
ENDITEM,
LAST );

when I run this script below is the output received from the server

File Uploading in LoadRunner Script

How to Upload File in LoadRunner Script


Hope this will help you, Happy learning.

For a better understanding, watch LoadRunner Tutorial videos on our YouTube Channel.

Subscribe to my YouTube Channel Here

 

How to Upload File in LoadRunner Script

Leave a Reply

Your email address will not be published. Required fields are marked *