Citrix Scripting Guidelines and Best Practices
Citrix Scripting Guidelines and Best Practices
2
© 2019 Cognizant Controlled Copy | Cognizant Confidential
Table of Contents
1. Introduction .................................................................................................................................................. 5
3
© 2019 Cognizant Controlled Copy | Cognizant Confidential
4.10.2. Window name under Recorder tab ..................................................................................................... 15
4.18.2. Increasing the wait time for connections and timeouts ...................................................................... 21
6.2. Error 2: Internet Explorer disappears during a Multi-protocol when ICA Client Launched ....................... 31
4
© 2019 Cognizant Controlled Copy | Cognizant Confidential
6.3. Error 2: Internet Explorer disappears during a Multi-protocol when IE Launch ....................................... 32
6.5. Error 5: Recording against a drop down menu does not work ................................................................. 36
Solution: .............................................................................................................................................................. 36
6.6. Error 6: replay Citrix script against a different window size ..................................................................... 36
Solution: .............................................................................................................................................................. 36
1. Introduction
Testing a citrix application with Loadrunner is a much more complicated and cumbersome than
a web application. The very fact that Loadrunner cannot understand the response sent by the
citrix servers makes scripting and executing a challenge.
Though not the ultimate compendium, this document has an exhaustive collection of guidelines
to be followed while scripting in the citrix protocol using Loadrunner.
Note: Citrix Access Gateway environment is not supported on Citrix Client 12.1. But with older
client version 9, and possibly 10.2, Citrix Access Gateway environment should work fine with
these versions.
2. Principle of Working
2.1. At Citrix Layer
Citrix Presentation Server hosts the applications to users via Independent Computing
Architecture (ICA), a communication protocol develop by Citrix
by which servers and client devices exchange data, and
Separates an application’s logic from its user interface.
This ICA protocol encrypts and transports application’s screens from the server it is running
onto the user’s client device, and returns the user’s input to the application on the server. As an
application runs on a server, Presentation Server intercepts the application’s display data and
uses the ICA protocol to send this data to the ICA client software running on the user’s device,
increasing application performance.
2.2. At LoadRunner
6
© 2019 Cognizant Controlled Copy | Cognizant Confidential
Citrix scripts also require synchronization between the client and application to ensure that the
user is not ahead of the actual request. Synchronization also helps when running multiple users
and the application under test is stressed, thereby yielding slow response. It ensures that the
client and the server are always in sync.
7
© 2019 Cognizant Controlled Copy | Cognizant Confidential
If you still need to use ctrx_sync_on_bitmap(), then firstly, check for the
consistencies between the recorded and replay machines: Window Size
(resolution), Window Colors, System Font and the other default options settings
for the Citrix client. These settings affect the hash value of bitmaps, and
inconsistencies may cause replay to fail. To view the Citrix Client settings, select
an item from the Citrix program group and choose Application Set Settings or
Custom Connection Settings from the right-click menu. Select the Default
Options tab or make necessary changes as per your recorded machine settings.
8
© 2019 Cognizant Controlled Copy | Cognizant Confidential
4. Best Practices
4.1. Citrix Agent to be used
There are many benefits in employing Citrix agent that comes with Load Runner VUGen as a
plug-in.
Ease of scripting by making the script more readable and intuitive. This is attained by adding
object names to the new function library developed for the Citrix protocol that is used with the
Citrix Agent, i.e. ctrx_obj_mouse_click()
Provides detailed information on all objects recorded by using object names along with X,Y
coordinates, therefore making it easier for Microfocus LoadRunner to find objects during replay
Allows the visual display of the object within the snapshot to see what was selected during the
recording, which is known as the “Active Object Recognition” functionality.
The following DEP settings should be considered for the Citrix protocol recording.
9
© 2019 Cognizant Controlled Copy | Cognizant Confidential
multi(0)disk(0)rdisk(0)partition(1)WINDOWS="Microsoft Windows XP Professional" /noexecute=optin
/fastdetect
C:CMDCONSBOOTSECT.DAT="Microsoft Windows Recovery Console" /cmdcons
======================
g. Change the setting noexecute=optin TO noexecute=AlwaysOff
h. Reboot your machine.
If the cache is not cleared, the following kind of error messages may occur:
Error: Connect cannot be established - Last Error=70, Last client error=1030
Error: Failed to create channel agent
Citrix Presentation Server must be configured to close the session when inactive or because of
an unexpected break in connectivity from the client. Terminating the session completely will
ensure that a new clean session is started each time the user fails or tries to reconnect to the
server.
If the setting to terminate the connection is not enabled, the user will connect to the last
session and be placed in the old workspace. This setting is critical to successful playback of the
10
© 2019 Cognizant Controlled Copy | Cognizant Confidential
script also, and the setting can be changed on the server by using the Citrix server console
illustrated below.
4.6. Synchronization
During the script execution it is important to synchronize the user steps with the application
response to ensure successful playback of the script. Synchronization allows the virtual user to
wait for a certain event to occur before moving onto the next step.
Synchronization in the script will make sure that a window or object is returned by the Citrix
server, and available for the user to execute the next step.
For example, it is necessary to ensure that the “Create Customer” form window appears on the
screen before you can enter customer information.
13
© 2019 Cognizant Controlled Copy | Cognizant Confidential
14
© 2019 Cognizant Controlled Copy | Cognizant Confidential
4.10.Recording Options
Few recording options listed below that were taken into consideration before recording the
script.
15
© 2019 Cognizant Controlled Copy | Cognizant Confidential
4.11.Keyboard vs Mouse
LoadRunner captures mouse clicks and key strokes as they are emulated at the time of playback
to simulate users performing an action. The mouse clicks are recorded based on the object
name and the X,Y coordinates of the screen and accordingly, during the play back, LoadRunner
sends instructions to the Citrix server to emulate these mouse clicks based on the object name
and the X,Y coordinate. The emulation of the virtual user based on the X,Y coordinates can be
unreliable and if the coordinates do not match accurately, the script will fail!
e.g.
ctrx_obj_mouse_click ("<class=Button text=Close>", 331, 308, LEFT_BUTTON, 0, CTRX_LAST);
Proposed Solution:
Use the keyboard instead of the mouse whenever possible during the recording. This avoids the
recording of X,Y screen coordinates in the script and sends the key strokes directly to the Citrix
server.
This is well depicted in the snapshot below where mouse clicks are avoided as much as possible
and keystrokes are used.
16
© 2019 Cognizant Controlled Copy | Cognizant Confidential
A list of usable keys:
SHIFT_KEY PAGE_DOWN_KEY
CTRL_KEY END_KEY
ALT_KEY HOME_KEY
BACKSPACE_KEY LEFT_ARROW_KEY
TAB_KEY UP_ARROW_KEY
ENTER_KEY RIGHT_ARROW_KEY
PAUSE_KE DOWN_ARROW_KEY
ESC_KEY NUM_LOCK_KEY
CAPS_LOCK_KEY PRINT_SCREEN_KEY
PAGE_UP_KEY PAGE_DOWN_KEY
SHIFT_KEY
4.12.Window resizing
It is recommended to not resize the window during recording although it is supported by
LoadRunner. The resizing changes the screen coordinates of the objects that are contained in
the window.
Instead, the window can be resized after the recording by going into Tree view, selecting the
appropriate step, right-clicking and selecting Properties. The Properties window will be
displayed with the width and height coordinates that can be changed as needed.
17
© 2019 Cognizant Controlled Copy | Cognizant Confidential
4.13.Display settings and color resolution
The display setting of the load generators and the screen resolution should be exactly the same
as when the script was recorded.
18
© 2019 Cognizant Controlled Copy | Cognizant Confidential
4.14.Recording a complete session
When recording a script, it should be ensured to perform the complete business process from
beginning to end. The end should include the session clean up by logging out of the
application. This will make sure that the session is cleaned up upon exit, and all windows are
closed.
The start and end conditions should always be the same so that the script can start where it
ended.
4.15.Timeout settings
Connect time allows the user to wait idle after establishing the connection for the period
specified. This setting should be default unless the Citrix authentication is slow in response.
The Waiting time setting applies globally to all synchronizations within the script and can be
changed programmatically by using the ctrx_set_waiting_time() function. Depending on the
server response, the wait time should be adjusted on an “as needed” basis.
4.17.GDI resources
Citrix virtual users use graphics device interface (GDI) resources on the load generators.
The GDI resources are limited on each machine, and are determined by the operating system.
GDI resources are also tied to the individual session running on the system.
The Microsoft Windows 2000 operating system has a maximum of 16,384 GDI resources
available. However, these resources are also used by other applications running on the
machine, so the numbers of users that can be executed are primarily determined by the
available GDI resources.
It is recommended to use 20-25 users max on a Load Generator.
Identified Tip:
In order to increase the number of citrix users on the load generator, a remote desktop
protocol (RDP) connection can be opened and connect to the individual RDP sessions as Load
Generator. This can be achieved by checking “Enabling Terminal Services” in Load Generator
Information from the LoadRunner Controller.
Each RDP session maintains its own GDI resources; if three RDP sessions are established on the
Load Generator, each can execute 25 users.
In LoadRunner Controller.
20
© 2019 Cognizant Controlled Copy | Cognizant Confidential
Note: Starting an RDP session on the Load Generator will consume memory and CPU on that
machine, thus limiting the number of users in other areas.
21
© 2019 Cognizant Controlled Copy | Cognizant Confidential
make sure that we capture the proper response times and not terminate the script pre-
maturely, use the following setting for Run-time setting -> Citrix -> Synchronization.
22
© 2019 Cognizant Controlled Copy | Cognizant Confidential
What makes the need for error handling even more pressing is that if a transaction fails in the
script and is not handled, the vuser assigned to the erring script might not be able to go ahead
the remaining iterations.
This ensures that the script does not traverse through the application too quickly and there by
reducing the chance of skipping a field or tab.
Another issue that might occur is typing too fast. This can be controlled by setting RTS -> Citrix -
> Synchronization
The value set is actually the delay (in milliseconds) between keystrokes
Type 1
23
© 2019 Cognizant Controlled Copy | Cognizant Confidential
Steps to follow
1. Create a parameter file called ‘timerVal’ with the following properties
24
© 2019 Cognizant Controlled Copy | Cognizant Confidential
3. Create another parameter called ‘stime’ which will contain the current time
4. Place an ‘if’ condition to check if stime = etime. If found equal, break and fail
the transaction, else break and continue
This can be done every time a response time has to be measured.
Type 2
Another way to capture accurate response time is by using ctrx_sync_on_bitmap_change.
For eg:
As seen in the above code snippet, after the ‘Enter Key’ is pressed, the script will wait for the
bitmap to change in the input coordinates before continuing forward. This is also another
effective way to measure response times.
25
© 2019 Cognizant Controlled Copy | Cognizant Confidential
26
© 2019 Cognizant Controlled Copy | Cognizant Confidential
4.18.6. Increasing readability for script
Since citrix works on mouse clicks and key strokes, there will be many occasions where the
script has to traverse through multiple fields to reach the target field by tabbing. Instead of
writing each and every ‘TAB’ command in a new line, group them in a for loop as shown below
Not only does this increase the readability of the script but also makes any script changes easier
and more importantly reduces the length of the script
Pre-execution validation
Ensure that the below in the Registry at the mentioned path or set the value accordingly
27
© 2019 Cognizant Controlled Copy | Cognizant Confidential
HKEY_LOCAL_MACHINE\SOFTWARE\Citrix\ICA Client\Engine\Lockdown Profiles\All
Regions\Lockdown\Virtual Channels\Third Party\CustomVC
"VirtualChannels"=""
Execution guidelines
During execution of multi user executions in loadrunner with Citrix, follow the below guide lines
1. Before running any test execution, debug critical scripts in the controller with the
following setting. This option may be set at Script (in controller) -> Details ->
More
In the command line, enter”-lr_citrix_vuser_view
2. Other run time settings should be enforced are “Generate snapshot on error”
3. To prevent overloading by multiple vusers while connecting, set an initialization
quota or use a ramp up schedule from the Controller’s scheduler
4. For best results, do not disable think time in the Run-Time settings. Think time is
especially relevant before the ctrx_sync_on_window and ctrx_sync_on_bitmap
functions, which require time to stabilize
5. Use the function ctrx_set_waiting_time before wait functions to set the desired
waiting time as shown in below snapshot. The parameters connect and waiting
timeout in runtime settings apply only for connection event and synchronization
functions, respectively and not for wait functions
28
© 2019 Cognizant Controlled Copy | Cognizant Confidential
4.18.9. Lost with Citrix Error
Following code is helpful when you are lost in a Citrix error where expected windows are not
appearing where they are supposed to, or they are not the right ones. Many times this will help
you expose just what the window and X/Y coordinates are that are causing a problem. At the
top of the script initialize the variables, and when you get to a portion of the code where a
problematic window has been stopping the script, place the ctrx_get_window_name and
ctrx_get_window_position right before it.
charwindow_name[100];
long xpos, ypos, width, height;
ctrx_get_window_name(window_name);
ctrx_get_window_position(window_name, &xpos, &ypos, &width, &height);
lr_output_message("Window = %s. x= %ld, y= %ld, width= %ld, height = %ld",
window_name, xpos, ypos, width, height);
Citrix Presentation Server must be configured to close the session when inactive or because of
an unexpected break in connectivity from the client. Terminating the session completely will
ensure that a new clean session is started each time the user fails or tries to reconnect to the
server. If the setting to terminate the connection is not enabled, the user will connect to the
last session and be placed in the old workspace. This setting is critical to successful playback of
the script, and the Citrix administrator can change the setting on the server by using the Citrix
server console illustrated below.
30
© 2019 Cognizant Controlled Copy | Cognizant Confidential
6. Common Errors encountered while CITRIX Scripting
6.1. Error 1: Failed to Create Agent Channel
Solution:
If you receive this error while recording or while replaying with Citrix Client 10.x, then we might
need to update the registry with the following patch. Please double click on this patch file and
then click OK to update the registry content.
Content:
The content of the above Citrix.reg file if we open it in notepad is as follows.
**********************
"VirtualChannels"=""
"VirtualChannels"=""
************************************
6.2. Error 2: Internet Explorer disappears during a Multi-protocol when ICA Client
Launched
Internet Explorer disappears during a Multi-protocol Nfuse recording as soon as the Citrix ICA
client is launched.
Solution:
Check to see if the machine has been set up to record against multiple processes. Go to the
registry editor to
31
© 2019 Cognizant Controlled Copy | Cognizant Confidential
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Windows\AppInit_DLLs
and check to see if it’s pointing to bbhook.dll. If it is then remove the entry and then reboot the
machine.
Internet Explorer disappears or crashes during a Multi protocol Nfuse recording as soon as the
browser is launched.
Solution:
Check to see if the machine has any Anti-Virus software running. Try shutting down the Anti-
Virus services. If you have McAfee Anti-Virus installed, shut down the following services:
AVSyncManager
McShield
If you have Norton Anti-Virus installed, shut down the Norton Antivirus service from the
services menu.
On facing any of the above 2 errors, Error 2 and Error 3; and if the given solution could not be
applied due to organizations security policies, the below mentioned steps can be followed to
create a multi protocol script:
1. Create a Web http/html script, and record the business process to the click on the icon of the
published Citrix application. Since this script does not include Citrix_ICA, the Citrix AUT will not
launch.
2. Stop the recording, and add these two variable declarations at the top of the Action() block:
32
© 2019 Cognizant Controlled Copy | Cognizant Confidential
Action()
{
int fp;
char * icafile;
3. In the recorded script, near the end, you should find a statement similar to this which is the
result of your click on the application icon (note: this script used URL-mode, yours may be
different):
web_url("launcher.aspx",
"URL=http://myCitrixServer.com/Citrix/AccessPlatform/site/launcher.aspx?NFuse_Application=
Citrix.MPS.App.PCFARM.Calc_Virtpc1&LaunchId=1259608978284",
"TargetFrame=",
"Resource=1",
"RecContentType=application/x-ica",
"Referer=http://myCitrixServer.com/Citrix/AccessPlatform/site/applist.aspx",
"Snapshot=t6.inf",
LAST);
4. Add this code above the web_url() in step 3 above, to capture the ICA file resulting from the
request:
5.Add this code below the web_url()in step 3 above , to save the ICA file to a local disk:
Action()
{
int fp;
char * icafile;
// …
// … Other recorded code removed to improve clarity of this KB
// …
33
© 2019 Cognizant Controlled Copy | Cognizant Confidential
web_reg_save_param("icadata", "LB=WFClient", "RB=", LAST); // Added: will save the returned
ICA file data in a parameter
// code below saves the parameter data onto the local C:\ drive, as an ICA file.
return 0;
}
7. Replay the modified script, which will save the ICA file to the local disk.
NOTE:
You will next use this ICA file to record the Citrix ICA portion of your script. Ensure any
errors are resolved before moving on.
8. Edit the saved ICA file with a text editor, removing the line "RemoveICAFile=yes" from the
ICA file, if it is present. Save the ICA file, exit the editor.
9. Ensure you can use this ICA file to launch your Citrix AUT (outside of VuGen). If your Citrix
Program Neighborhood ICA client is installed properly, you should be able to double-click on
this ICA file with Windows Explorer to launch this Citrix application.
10. Next, create a new, single-protocol Citrix ICA script. In the recording options, use this ICA
file saved earlier, and record the complete Citrix portion of your Business Process.
11. After recording the Citrix ICA portion, stop recording and examine the script. In the Action()
block, you will see reference to the ICA file in the ctrx_set_connect_opt() call:
34
© 2019 Cognizant Controlled Copy | Cognizant Confidential
ctrx_set_connect_opt(ICAFILE,"C:\\\icafile.ica"); // this is the ICA file you captured to disk.
ctrx_wait_for_event("LOGON", CTRX_LAST);
lr_think_time(5);
//The code below is just a simple example, an AUT being launched and exited.
//Your Citrix Business Process recording may produce more code.
12. Ensure this Citrix portion of your business process replays properly before proceeding.
13. Now, create a new Citrix ICA + Web http/html multi-protocol script.
14. Copy the Web HTTP/HTML script you replayed to capture the ICA file — into the top of the
Action block.
15. Copy the Citrix ICA script code you recorded in the Citrix part, appending it to the end of the
Action block (note : the full example not included here for simplicity).
16. Replay this script ensuring it replays successfully. Each time the script runs, it should
dynamically download the ICA file to disk.
NOTE: If the merged Web+Citrix ICA script fails during replay with the following error
immediately:
Solution:
Open the problematic Web+Citrix ICA script's default.cfg file (in the root of the Script directory)
in a text editor (like notepad).
35
© 2019 Cognizant Controlled Copy | Cognizant Confidential
Search in the default.cfg file for a section starting with "[Citrix]" similar to this:
[Citrix]
Latency=Use Server Default
Compression=1
Cache=0
Queue=0
Sound=Use Server Default
BitmapSyncLevel=Exact
NOTE: Notice above that the Citrix section is all lower case. The above section is incorrect.
Replace the entire citrix section with the following:
[CITRIX]
DesktopColors=16
Colors=High Color (16 bit) // can be modified based on the setting during recording
Enctyption=Use Server Default
Window=800 x 600 // can be modified based on the resolution settings used for recording
NOTE: Ensure there is not both a "[CITRIX]" and "[Citrix]" section! The only section that should
be present is the above "[CITRIX]" section!
Save the script. This should enable the script to replay without the error.
6.5. Error 5: Recording against a drop down menu does not work
During replay it fails on the ctrx_mouse_click when it is supposed to select an item from the
drop down.
Solution:
Use arrow keys or if the item is known you can type the text in the box of the drop-down
instead of mouse click to select an item from the drop down during recording.
Solution:
Go to the script directory in Windows Explorer. Open the default.cfg file located inside the
script directory and change the window= value under the [CITRIX] section to a valid value that
can be seen in the recording options (640 x 480, 800 x 600, 1024 x 768, 1280 x 1024 and 1600 x
1200). Please note that if you have any ctrx_sync_on_bitmap functions recorded it will not
replay in the new window setting because the hash value will be different.
36
© 2019 Cognizant Controlled Copy | Cognizant Confidential
Thank You
37
© 2019 Cognizant Controlled Copy | Cognizant Confidential