Thursday, 14 January 2016

Difference Between WinInet Level Replay and Socket Level Replay in Loadrunner

Here are the differences between WinInet Level Replay and Socket Level Replay.

WinInet Level Replay

  1. The requests are executed over wininet.dll API used by certain applications. Port mapping is irrelevant here
  2. Port mapping is used in only recording and it is irrelevant for the replay
  3. Recommended for web applications which uses SSO/Certificates as a workaround
  4. Exhibits additional overhead in memory consumption while running as Virtual Users in a scenario
  5. Step download timeout doesn’t work. Hence web_set_max_retries() has to be used instead
  6. LR analysis doesn’t show Web page diagnostics when the scripts are replayed using Wininet mode replay + enable Kerberos/Integrated NTLM authentication in run time settings


Socket Level Replay
  1. Recommended for all web applications
  2. Normal memory consumption per virtual user in a scenario
  3. Step download time out works as expected
  4. Web page diagnostics are displayed for the scripts run in socket mode

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;

    }





Monday, 4 January 2016

How to handle dynamic popup windows in RDP scripts

While creating RDP scripts, we might get multiple window popups and the position of these windows will change every time.

As RDP protocol is image based,it always communicates through x and y co-ordinates.
If popup windows position is changing during replay, then mouse clicks and image checks will fail.

To handle this situation, we have many useful functions in RDP protocol.

Below is the sample code for handling dynamic popup windows.

int x,y;
  
    //To make sure we are on the right page, add a sync_on_image,where we need to create a mouse click.
  
    rdp_sync_on_image("StepDescription=Image Synchronization",
        "WaitFor=Appear",
        "AddOffsetToInput=Default",
        IMAGEDATA,
        "ImageLeft=922""ImageTop=127""ImageWidth=112""ImageHeight=47""ImageName=snapshot_83.png"ENDIMAGE,
        RDP_LAST);

//This muse click will invoke a new popup window

    rdp_mouse_click("StepDescription=Mouse Click",
        "Snapshot=snapshot_1.inf",
        "MouseX=1025",
        "MouseY=84",
        "MouseButton=LEFT_BUTTON",
        "Origin=Default",
        RDP_LAST);

          
//Get the title and ordinal of the new popup window

    rdp_get_active_window_title("StepDescription=Get Active Window Title",
        "Snapshot=snapshot_96.inf",
        "WindowTitle=ParamWindowTitle",
        "WindowOrdinal=ParamWindowOrdinal",
        RDP_LAST);


    lr_output_message("window title is %s",lr_eval_string("{ParamWindowTitle}"));

  
    //Get the co ordinates of the popup window
  
    rdp_get_window_position("StepDescription=Get Window Position",
        "Snapshot=snapshot_97.inf",
        "WindowTitle={ParamWindowTitle}",
        "WindowOrdinal={ParamWindowOrdinal}",
        "WindowLeft=ParamLeft",
        "WindowTop=ParamTop",
        "WindowWidth=ParamWidth",
        "WindowHeight=ParamHeight",
        RDP_LAST);
  

    lr_output_message("String value of prmLeft: %d"atoi(lr_eval_string("{ParamLeft}")));
  
    lr_output_message("String value of prmTop: %d"atoi(lr_eval_string("{ParamWidth}")));
  
    x= atoi(lr_eval_string("{ParamWidth}"));
    y= atoi(lr_eval_string("{ParamLeft}"));


    //Modify x and y co-ordinates based ont he mouse clicks we need to create
    x=x+25;
    y=y+76;
  
  
    //Save x and y to loadrunner Parameters
    lr_save_int(x, "prmx");
  
    lr_save_int(y, "prmy");
  
  
    //Create a customized mouse click.Similarly we can create customized sync_on_images
  
    rdp_mouse_click("StepDescription=Mouse Click",
        "Snapshot=snapshot_99.inf",
        "MouseX={prmx}",
        "MouseY={prmy}",
        "MouseButton=LEFT_BUTTON",
        "Origin=Default",
        RDP_LAST);

     

Error handling in load runner RDP scripts

We may face many intermittent issues,while validating rdp scripts.
We usually add rdp_sync_on_image on each and every page.But sometimes mouse clicks or synchronized mouse clicks may not work properly and hence the image check might fail.

Here is the simple logic for error handling

int imgchk,i;
    char buffer[50];

    i=0;do{
    
        sprintf(buffer, "01_Transaction_%d",i);
 
    lr_start_transaction(buffer);

    //Perform a mouse click

    rdp_mouse_click("StepDescription=Mouse Click",
        "Snapshot=snapshot_87.inf",
        "MouseX=50",
        "MouseY=463",
        "MouseButton=LEFT_BUTTON",
        "Origin=Default",
        RDP_LAST);

    //imgchk returns "0" on success

 imgchk = rdp_sync_on_image("StepDescription=Image Synchronization",
                "WaitFor=Appear",
                "AddOffsetToInput=Default",
                IMAGEDATA,
                "ImageLeft=215""ImageTop=71""ImageWidth=107""ImageHeight=23""ImageName=snapshot_88.png"ENDIMAGE,
                RDP_LAST);

 if (imgchk == 0)

    {

         lr_output_message("image check successful");
     
         lr_set_transaction_status(LR_PASS);

        lr_end_transaction(buffer,LR_AUTO);
    }

 //If image check fails, do one more click

    else
    {

        i++;
        lr_output_message("execute mouse click one more time and increment i val");
    }

    //Trying for a maximum of 3 times and then exiting the current iteration

    if(i >= 2)
    
    {
        lr_output_message("Mouse click tried for 3 times and didn't work");
        lr_exit(LR_EXIT_ITERATION_AND_CONTINUE,LR_FAIL);
    }


    }while(imgchk != 0 && i<=2);

Loadrunner RDP scripts Best Practices

Load runner RDP Protocol:

Loadrunner RDP scripts will not always replay smoothly.In my experience, I have collected some tips, which might save your time and effort.
I have created rdp scripts  for WPF(Windows Presentation Framework) applications. We couldn't find any other Load testing tool,which supports WPF applications.

Here are few tips I would like to share.

  1. Make sure we have installed LR RDP agent on the machine , for which we are connecting through RDP.
  2. Use RDP agent, while recording the application in RDP Protocol,so that we can use all synchronization functions in RDP Protocol
  3. Minimize your scripting with keyboard short cuts, instead of using mouse clicks.
  4. Minimize the number of times you login and logout of RDP.
  5. Make sure you have sufficient licencing to cover the number of RDP sessions
  6. While navigating to the application use tabs instead of using mouse clicks
  7. Make sure to add a sync_on_image  function before sync_on_agent function.
  8. Don't add many sync_on_window functions, which will consume more time while executing