How to verify download of a file in Web scripts

How can the user verify the download of a file in Web scripts? For example, how can the user verify if a .zip file or .pdf file is downloaded correctly?

Solution

1. Text check with web_reg_find.
For example, if you have a .pdf file, you can verify the information by using the regular text check function web_reg_find. Replay the script with extended log option "Data returned by server" to help to identify the piece of information to verify. If you decide to check on the text, the information could be in binary format, not as displayed in the Acrobat reader. If this is the case, then you can use the "/BIN" optioin to specify binary data.

2. Check the size of the download.
You can use the web_get_int_property() function with HTTP_INFO_DOWNLOAD_SIZE to check the size of the download is correct.

Example:
long i;

//Start a transaction to download the file.
lr_start_transaction("file_download");

//HTTP call to the .pdf file
web_url("<HTTP call to the pdf file>");

//Get the download size.
i = web_get_int_property( HTTP_INFO_DOWNLOAD_SIZE );

//Check if the size if empty. If so, fail the transaction. You can set it to a specific number if you know the expected size.
if ( i == 0 ){
//End the transaction
lr_end_transaction("file_download", LR_FAIL);
}

else{
//End the transaction with passed status.
lr_end_transaction("file_download", LR_PASS);
}

3. Output the data to a file.
You can also output the data into a file (i.e., download the file, write it to the hard drive), then open it.

Example: (This is for a .pdf file.)

int fp;
long i;

//Truncate to zero length or create file for writing.
fp = fopen("c://my_file.pdf","wb");

//Start a transaction to time the download time.
lr_start_transaction("file_download");

//Set the parameter size large enough to save the data.
web_set_max_html_param_len("100000");

//Use web_reg_save_param with the correct boundary to capture the data returned by the server.
web_reg_save_param("FILED","LB=","RB=","Search=Body",LAST);

//HTTP call to the .pdf file
web_url("<HTTP call to the pdf file>");

//Get the download size.
i = web_get_int_property( HTTP_INFO_DOWNLOAD_SIZE );

//Write the data saved to an output file.
fwrite(lr_eval_string("{FILED}"),i,1,fp);

//End the transaction
lr_end_transaction("file_download", LR_AUTO);

//Close the file pointer.
fclose(fp);

Advertisements

3 thoughts on “How to verify download of a file in Web scripts

  1. Rishi

    Hello, I am having an issue downloading a large zipped file of size 521MB. It looks like the script does not even begin to download when trying with a large file however it completes the action succesfuly when I try with a small file (43kb). I have tried increasing step download time to its max value (1000). The time it takes to manually download the file is less than 2 mins. The app registers and displays the download of the file as soon as the download begins. When I run the script for small file, it shows the download on the app but when I do so for the large file via script, the app does not show the file was downloaded. The replay log shows the following message:

    Action.c(134): Downloading resource “http://loanperformancedata-devl.fanniemae.com/lppub-docs/publish/Acquisition_2000Q1.txt.gz” (specified by argument number 12) [MsgId: MMSG-26577]
    Action.c(134): Warning -26663: Content-Length value is missing or invalid [MsgId: MWAR-26663]
    Action.c(134): Warning -27727: Step download timeout (240 seconds) has expired when downloading resource(s). Set the “Step Timeout caused by resources is a warning” Run-Time Setting to Yes/No to have this message as a warning/error, respectively [MsgId: MWAR-27727]
    Action.c(134): Aborting pending download of URL=”http://loanperformancedata-devl.fanniemae.com/lppub-docs/publish/Acquisition_2000Q1.txt.gz” [MsgId: MMSG-27656]
    Action.c(134): Downloading resource “http://dlstruct-ap51a:7305/lppub/getMonthlyDownloadJson.json?_=1366729609942&_search=false&nd=1366729609942&rows=20&page=1&sidx=&sord=asc” (specified by argument number 9) [MsgId: MMSG-26577]
    Action.c(134): Downloading resource “http://dlstruct-ap51a:7305/lppub/filedownload.json?file=http://loanperformancedata-devl.fanniemae.com/lppub-docs/publish/Acquisition_2000Q1.txt.gz&_=1366729613005” (specified by argument number 15) [MsgId: MMSG-26577]
    Action.c(134): Downloading resource “http://dlstruct-ap51a:7305/lppub/getMonthlyDownloadJson.json?_=1366729613005&_search=false&nd=1366729613005&rows=20&page=1&sidx=&sord=asc” (specified by argument number 18) [MsgId: MMSG-26577]
    Action.c(134): Downloading resource “http://dlstruct-ap51a:7305/lppub/getMonthlyDownloadJson.json?_=1366729667516&_search=false&nd=1366729667516&rows=20&page=1&sidx=&sord=asc” (specified by argument number 21) [MsgId: MMSG-26577]
    Action.c(134): Warning -27727: Step download timeout (240 seconds) has expired when downloading resource(s). Set the “Step Timeout caused by resources is a warning” Run-Time Setting to Yes/No to have this message as a warning/error, respectively [MsgId: MWAR-27727]
    Action.c(134): Aborting pending download of URL=”http://dlstruct-ap51a:7305/lppub/getMonthlyDownloadJson.json?_=1366729609942&_search=false&nd=1366729609942&rows=20&page=1&sidx=&sord=asc” [MsgId: MMSG-27656]
    Action.c(134): Aborting pending download of URL=”http://dlstruct-ap51a:7305/lppub/filedownload.json?file=http://loanperformancedata-devl.fanniemae.com/lppub-docs/publish/Acquisition_2000Q1.txt.gz&_=1366729613005″ [MsgId: MMSG-27656]
    Action.c(134): Aborting pending download of URL=”http://dlstruct-ap51a:7305/lppub/getMonthlyDownloadJson.json?_=1366729613005&_search=false&nd=1366729613005&rows=20&page=1&sidx=&sord=asc” [MsgId: MMSG-27656]
    Action.c(134): Aborting pending download of URL=”http://dlstruct-ap51a:7305/lppub/getMonthlyDownloadJson.json?_=1366729667516&_search=false&nd=1366729667516&rows=20&page=1&sidx=&sord=asc” [MsgId: MMSG-27656]
    Action.c(134): web_url(“downloadMonthly.html”) highest severity level was “warning”, 98372068 body bytes, 587 header bytes [MsgId: MMSG-26388]
    Action.c(149): web_get_int_property was successful [MsgId: MMSG-26392]
    Action.c(159): Total bytes read 98372655
    Action.c(160): Notify: Transaction “Acquisition_2000Q1.txt.gz” ended with “Pass” status (Duration: 247.3958 Wasted Time: 235.9502).
    Ending action Action.

    Reply
  2. Mahantesh

    Hi There,

    I am trying to use the code that is posted here for one of my requirement. I am using below code:
    lr_start_transaction(“1_transaction”);

    web_reg_save_param(“FILED”,”LB=”,”RB=”,”Search=Body”,LAST);

    web_url(“MY Requirement URL”,
    “URL=MY Requirement URL”,
    “Resource=1”,
    “RecContentType=application/x-mpegurl”,
    “Referer=”,
    “Snapshot=t1.inf”,
    LAST);
    i=web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE);
    fwrite(lr_eval_string(“{FILED}”),i,1,fp);
    lr_end_transaction(“1_transaction”,LR_PASS);
    fclose(fp);

    the above code is working fine for me, I am able to check if the file is downloaded correctly or not?.

    I also see that in the response body of vugen script, it is storing values as shown here

    Action.c(60): Notify: Parameter Substitution: parameter “FILED” = “#text\n
    #text:TYPE=AUDIO,GROUP-ID=”master_broadcast”,LANGUAGE=”eng”,NAME=”Master Audio”,AUTOSELECT=YES,DEFAULT=YES\n
    #text:BANDWIDTH=0000000,RESOLUTION=111×111,CODECS=”mp**.*.*, text.text”,AUDIO=”text”\n
    http://URL-1n
    #text:BANDWIDTH=0000000,RESOLUTION=111×111,CODECS=”mp**.*.*, text.txt”,AUDIO=”text”\n
    http://URL-2n

    from this above response I need to pass URL-1 and URL-2 for next iteration in vugen scripting. could you please tell me how this can be done?

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s