Wednesday, 13 January 2016

How to verify the file download in Load runner RDP scripts

Validating File download or File export in Load runner RDP scripts:

Load runner RDP protocol is basically image based. Request and response is getting processed with bitmaps.
When you are downloading a file from an application, or exporting the data from application to external file, it is difficult to validate ,whether the file is successfully created and uploaded all the data.
In web http/html protocol, we can achieve this through web_get_int_property().
Where as in RDP scripts are image based,directly we can't give a checkpoint to validate the file download.

We can handle this issue, by using file streams. Here is the sample code.

Action()
{
     int count, total = 0;

    char buffer[1000];

    long file_stream;
  
    char * filename;
 
   lr_start_transaction("Export_data_to_a_file");

  rdp_sync_object_mouse_click("StepDescription=Mouse Click on Synchronized Object 28",
        "Snapshot=snapshot_95.inf",
        "WindowTitle=Confirmation",
        "Attribute=TEXT",
        "Value=Confirmation",
        "MouseX=412",
        "MouseY=112",
        "MouseButton=LEFT_BUTTON",
        RDP_LAST);
     

    rdp_type("StepDescription=Typed Text 6",
        "Snapshot=snapshot_93.inf",
        "TypedKeys={ExportFile}",
        RDP_LAST);


    rdp_key("StepDescription=Key Press 19",
        "Snapshot=snapshot_94.inf",
        "KeyValue=VK_RETURN",
        RDP_LAST);

   filename = lr_eval_string("{ExportFile}");
         
 
    if ((file_stream = fopen(filename, "r")) == NULL ) {

        lr_error_message ("Cannot open %s", filename);

        return -1;

    }

    // Read until end of file 

    while (!feof(file_stream)) {

        // Read 1000 bytes while maintaining a running count

        count = fread(buffer, sizeof(char), 1000, file_stream);

        lr_output_message ("%3d bytes read", count);

        if (ferror(file_stream)) { /* Check for file I/O errors */

            lr_output_message ("Error reading file %s", filename);

            break;

        }

        total += count; // Add up actual bytes read 

    }

    // Display final total 

    lr_output_message ("Total number of bytes read = %d", total );
 
    //check the file of the size is approximately matching the expected size or not 
 
    if(total>14000000)
    {
        lr_output_message("All records are exported and mark the transaction as passed");
     
        lr_set_transaction_status(LR_PASS);
     
        lr_end_transaction("Export_data_to_a_file"LR_AUTO);

    }
 
    else
    {
        lr_output_message("All records are not exported and mark the transaction as falied");
     
        lr_set_transaction_status(LR_FAIL);
     
        lr_end_transaction("Export_data_to_a_file"LR_AUTO);
 
    }

    // Close the file stream 

    if (fclose(file_stream))

        lr_error_message ("Error closing file %s", filename);
    return 0;

    }





No comments:

Post a Comment