question

Pol R. avatar image
Pol R. asked ·

How to handle errors in a Citrix environment

Hi,

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?

Thanks!

esmscriptingcitrixsap
10 |2000000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 50.0 MiB each and 250.0 MiB total.

1 Answer

Pablo G. avatar image
Pablo G. answered ·

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("CitrixVD_Window").Attach
         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("CitrixVD_Window").Attach
         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.

Thanks,

Pablo

1 comment Share
10 |2000000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 50.0 MiB each and 250.0 MiB total.

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!

1 Like 1 · ·