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);

     

3 comments:

  1. Hi Suma,
    Would you mind if we repost this on the HP Performance Testing blog (mentioning your name, of course)?
    This way it could reach a wider audience.

    Gal Shadeck, LoadRunner R&D

    ReplyDelete
  2. Sure Gal.
    Intact I am always happy.
    If it is reaching wider audience.

    Thank you,
    Suma

    ReplyDelete