Monday 25 May 2015

Upload external files in load runner scripting


How to upload files in Scripting Load Runner(Vugen)

How to upload any file from local location or from a sharepoint path in virtual user generator:

 There are several options that do the same work:
 
Running test locally :
If you are running script on your machine then. I suggest placing file in “C:\temp” before recording.
Run the test using same local machines. Test will pass since script and upload file both located in the same machine during recording and test execution.
Keep in mind to replace "\" symbol with "\\" as this is c character .To avoid confusion go to load runner there is option to convert code into c language. For example "“C:\temp” in c language will be “C:\\temp”  single backslash with double backslashes in the script. Here is the sample script:
web_submit_data("AddAttachment.aspx",
 "Action=https://learningshared.com/AddAttachment.aspx",
 "Method=POST",
 "EncType=multipart/form-data",
 "RecContentType=text/html",
 "Snapshot=t7.inf",
 "Mode=HTML",
 ITEMDATA,
     "Name=__VIEWSTATE", "Value={ViewState_Value_1}", ENDITEM,
     "Name=__EVENTVALIDATION", "Value={EVENTVALIDATION_1}", ENDITEM,
     "Name=FileUpload1", "Value=C:\\Temp\\uploaded_file.pdf", "File=yes", ENDITEM,
     "Name=Button1", "Value=Upload", ENDITEM,
 LAST);

Running test with any network load generator: This method is similar to the first method. Provide address of share location from where you want performance center to pick up your files and execute a network share location with read & write access. Place files those need to be uploaded.
Make sure to replace single backslash with double backslashes in the script. Here is the sample script:
 

web_submit_data("AddAttachment.aspx",
 "Action=https://learningshared.com/AddAttachment.aspx",
 "Method=POST",
 "EncType=multipart/form-data",
 "RecContentType=text/html",
 "Snapshot=t7.inf",
 "Mode=HTML",
 ITEMDATA,
     "Name=__VIEWSTATE", "Value={ViewState_Value_1}", ENDITEM,
     "Name=__EVENTVALIDATION", "Value={EVENTVALIDATION_1}", ENDITEM,
     "Name=FileUpload1", "Value=\\\\Global_shared_network_location\\projectspace\\uploaded_file.pdf", "File=yes", ENDITEM,
     "Name=Button1", "Value=Upload", ENDITEM,
 LAST);

 Attach upload file with scripts:
  • This method is similar to the first method. Record the script with a local file.
  • Add all the files (to be uploaded) to scripts by clicking “Add Files to Scripts…” menu from “Files -> Add Files to Scripts…”
  • Now clear file location and just leave the file name. These scripts should run from any load generators in the network or can be run from Performance center ALM too.
web_submit_data("AddAttachment.aspx",
 "Action=https://learningshared.com/AddAttachment.aspx",
 "Method=POST",
 "EncType=multipart/form-data",
 "RecContentType=text/html",
 "Snapshot=t7.inf",
 "Mode=HTML",

ITEMDATA, "Name=__VIEWSTATE", "Value={ViewState_Value_1}", ENDITEM, "Name=__EVENTVALIDATION", "Value={EVENTVALIDATION_1}", ENDITEM, "Name=FileUpload1", "Value=uploaded_file.pdf", "File=yes", ENDITEM, "Name=Button1", "Value=Upload", ENDITEM, LAST);

4 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. It would be great if you can suggest how to upload multiple files in single request. I'm facing challenge to mention path to the files while uploading multiple files.
    Pasting my request below - The field "hotelImageSaveResources" has two json to upload two images. BUT I need a way to mention the path for two files in "files" field.

    web_submit_data("FileUpload",
    "Action=https://testeunupaslbyapm01.azure-api.net/hotelfileuploader",
    "Method=POST",
    "EncType=multipart/form-data",
    "TargetFrame=",
    //"RecContentType=text/html",
    "RecContentType=application/json",
    "Mode=HTML",
    ITEMDATA,

    "Name=files", "Value=HotelDetailsIMG.jpg", "File=yes", ENDITEM,
    "Name=hotelImageSaveResources", "Value=[{\"HotelId\":\"3794\",\"ImageName\":\"HotelDetailsIMG.jpg\"},{\"HotelId\":\"118\",\"ImageName\":\"Alvear.jpg\"}]", ENDITEM,


    LAST);

    ReplyDelete
  3. Hi - For file Upload I have PUT request which accepts only Binary Body. It is a AWS S3 Bucket URL. With Vugen I was able to capture only 11 KB file - Binary Body. But I would like to test large file Uploads. Vugen is unable to capture these recordings. Can you please suggest me how to capture file and covert it to Binary Body.

    ReplyDelete