Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to handle errors in a Citrix environment

Dynatrace Participant
Dynatrace Participant


I am currently working in creating scripts for a Citrix environment.

Some of the scripts open a Virtual Desktop (through Citrix Receiver) and then SAP is open (also through a Citrix Receiver inside that VD)

I'm trying to get information on how to handle errors, mostly to be able to do a clean exit of SAP and Citrix for it not to ruin the tests that run after.

I have found two things but I'm not quite sure how to use them.

UserCleanDesktop: I don't know if I'm right but my idea was this just as another Sub that I would write after the ErrorHandler Sub

UserCloseCitrix: This is the one that I don't know how to use or what it does. Until know I have been logging off Citrix through SelfService.exe with the logoff flag, but I don't know if UserCloseCitrix will be a better option.

About closing SAP I don't know how to make a clean close without having to search for the "X" and trying clicking it. That solution has given me a lot of problems, any alternative?



Dynatrace Helper
Dynatrace Helper

Hi Pol,

Great question! At a previous client I created a shared module that contained my closing/cleanup subs, and then in CVFW_User_Modifiable_Functions I added to UserCleanUpDesktop a call that would trigger my cleanup subs within the shared module. These cleanup subs would look for images that would occur throughout my script runs, and I would use alt+F4 to close the window if it appeared. Let's see if I can provide an example:

In my created shared module I would have something like:

Sub CloseAllApps()
Call CloseSAP
Call CloseCitrixVD
End Sub
Sub CloseSAP()
If IsImage("CitrixVD_Window", "CVD_SAP_MainWindow_Image") = True Then
Window.Type "{Alt{F4}}" //(This blindly closes the window in the forefront)
WaitForImage "CitrixVD_Window", "CVD_DesktopIcon_Image", True //(CVD_DesktopIcon_Image is visible when all SAP windows are closed. If there is more than one SAP window, look for images to identify those windows and close them above this If statement.)
End If
End Sub
Sub CloseCitrixVD()
If IsWindow("CitrixVD_Window", "Exists") = True Then //(After this do whatever is needed to close the Citrix VD down cleanly. Below is an example that worked to log off Windows within a Citrix VD.)
Window.Type "{Ctrl {Esc}}"
Window.Type "{ExtRight}{Return}"
WaitForImage "WindowsDesktop_Window", "Win_TrashIcon_Image", True
End If
End Sub

In UserCleanUpDesktop in CVFW_User_Modifiable_Functions I would then add:

Call CloseAllApps

UserCleanUpDesktop is called on failures, so on failures my CloseAllApps is called as well, cleaning what ever windows may have been left open. Make sense? Long winded, but let me know if you have questions.



Dynatrace Participant
Dynatrace Participant

Thanks Pablo,

That is what I'm doing right now.

I'll see if I can manage to make Image recognition, until now it has work horribly (probably because it is a Citrix inside a Citrix) but I'll keep trying.

Thanks for your answer!