4 Tips for Replaying Remote Desktop Protocol (RDP) scripts in LoadRunner

LoadRunner scripts that use the Remote Desktop Protocol (RDP) don’t always replay smoothly.  My colleague Kert (Yang Luo) from the LoadRunner R&D team has collected some tips that will save you time and effort, and help you ensure that your RDP scripts run correctly.

 

You can download HP LoadRunner here to experience it for yourself.

 

Tip #1: Sync for image before keyboard event

Sometimes the Virtual User (Vuser) script needs to send some keyboard event to the remote machine. One such example is sending the username and password during the login phase. However, during replay the script tends to run much faster than a manual interaction. So it's quite possible that the keyboard event is sent before the target control appears and is ready to accept input.

 

When a connection is established while recording a login scenario, the user types the username directly after the login screen appears. This means that during the replay, the rdp_type step is executed immediately after the rdp_connect is completed, which might be before the credentials screen has event appeared. So the “typing” will begin before its target control is visible, the username received at the server side will be incorrect (e.g. “strator” instead of “administrator”), the login process will fail and the client side will get a “Connection Reset” message.

 

The way to avoid the issue is by adding a sync_on_image step immediately before the rdp_type events. This way we can make sure the expected control appears before the typing begins. In fact, the generated script usually contains such a warning comment about it, but it is often ignored or overlooked:

 

/* This script contains keyboard steps without automatic synchronization.
    Consider adding a synchronization step before the relevant keyboard steps.*/

The sync_on_image step can be added manually by right-clicking on the snapshot. You can also perform a dummy mouse click on the target control before typing. That will add rdp_sync_image and rdp_mouse_click steps automatically:

 

rdp_SynchImage.png

 

 

Tip #2: Use rdp_sync_* functions to emulate think time 

In RDP scripts the think time is ignored by default:

rdp_RunTimeSettings.png

 

This means that the script doesn’t pause during the replay. Sometimes users need to wait for a very long time during some time-consuming initialization at the server side, so they'll enable think time and add an lr_think_time step with a sufficiently large value .  But this has potential problems. 

 

During the execution of the lr_think_time, the client side appears 'frozen' and will not communicate with the server in any way. So from the server's point of view, the client is non-responsive. If the lr_think_time is longer than the server's tolerance, the server will end the connection, causing the replay to fail.

 

The solution is to remove the lr_think_time, and use rdp_sync_* functions (such as rdp_sync_image, or rdp_sync_on_window) instead. The rdp_sync_* functions have a "timeout" parameter, and you just need to assign a large enough value to it:

 

rdp_synch_timeout.png

 

Tip #3: Use rdp_save_image for troubleshooting

An RDP script is difficult to debug because the protocol is image-based. When the script fails on some rdp_sync function, it's hard to understand what happened from the log alone.

 

The solution is to add an rdp_save_image step before or after the problematic step. This function will save the current screenshot to a file and show what happened at the server side.

 

Here's an example:

 

If ( LR_PASS!=rdp_sync_on_image(<parameters>,FailIfNotFound=No,RDP_LAST) )
                rdp_save_image(<parameters>);

 

Tip #4: Ensure licenses for Remote Desktop Service (aka Terminal Service) are available before replaying the script

Remote Desktop Service (formerly known as Terminal Service) is an enhanced version of RDP available in Windows Server Systems (Windows 2003, Windows 2008 etc.), which supports multiple concurrent sessions. However, it also requires an extra fee, as the client side must have a terminal service license in order to connect to a terminal server.

 

LoadRunner can retrieve Terminal Service license information from the client machine’s registry (assuming the license info is already there), and use that license to connect to the Terminal Service server. However, if the client side license is missing or expired, the RDP script replay will fail. In this case, launch the Microsoft RDP client (MSTSC.exe) and connect to the TS server manually first, so that the new/updated license is retrieved and stored in the registry.

 

Note: Terminal Service license support was added in LoadRunner 11.52.

 

-----

 

Many thanks to Kert (Yang Luo) from LoadRunner R&D for providing this article.

 

Click here to learn more about HP LoadRunner components

 

You can download HP LoadRunner for yourself here.

Comments
GoodNeil | ‎11-04-2013 12:43 AM

Useful article.

 

Many thanks.

| ‎11-04-2013 01:30 AM

Thanks for your feedback, GoodNeil!

Perfkk(anon) | ‎03-18-2014 06:42 AM

Hi,

 

That was really nice tips :). Do you have some more  ?

 

regards,

kk

Osuri(anon) | ‎09-07-2014 09:10 PM

Thanks a lot and which is very usful one ---Before start working on RDp protocol.

 

With out this might be will not have solution.

 

Thanks A lot once again..!

Leave a Comment

We encourage you to share your comments on this post. Comments are moderated and will be reviewed
and posted as promptly as possible during regular business hours

To ensure your comment is published, be sure to follow the Community Guidelines.

Be sure to enter a unique name. You can't reuse a name that's already in use.
Be sure to enter a unique email address. You can't reuse an email address that's already in use.
Type the characters you see in the picture above.Type the words you hear.
Search
Showing results for 
Search instead for 
Do you mean 
About the Author
Malcolm is a functional architect, focusing on best practices and methodologies across the software development lifecycle.
Featured


Follow Us
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.