What is the correct way to identify the unexpected window?
In my application where I build my automated tests, several unexpected windows appear (error window, window to confirm by clicking OK, window to decide to click yes or no), I would like to gradually map these unexpected windows and deal with the function assigned there in GeneralEvents> OnUnexpectedWindow.
Following the example of the documentation I have this role assigned to OnUnexpectedWindow:
function GeneralEvents_OnUnexpectedWindow (Sender, Window, LogParams) {
inside this function I would like to place the filters:
(pseudo)
if (windowAppeared == Confirmation)
{
>click OK<
}
if (windowAppeared == error)
{
>print log<
>halt execution<
}
}
In my case it is a very complex application. Is a good approach?
I'm having trouble to identifying the windows, because some are external applications (window to print a pdf, timeout error connection to server). Windows don't always have the same properties, so what is the correct way to identify the unexpected window? in some I use Caption, in others I can't use Caption property and I'm using ObjectIdentifier
Samples of windows:
Thanks
Hi,
To make it second to what was said by tphillips :
By definition, the unexpected window in TestComplete is the window that blocks user input and that is not referenced in test code.
If the window fits the above criteria, the OnUnexpectedWindow event will be triggered.
Note, that in order to be treated as unexpected, the window must block user input, i.e. to be system- or application modal and prevent activation of the window/control that test code tries to interact with.
So, in most cases, the OnUnexpectedWindow event is triggered by the .Activate, .Focus, .Click and .Keys methods and the most reliable way to detect unexpected window is to call .Activate or .Focus methods before trying to .Click or .Keys the window or control respectively for desktop applications.
Note, that if your test code does not interact with the application via GUI but uses direct assignments (e.g. via the .SetText method) the OnUnexpectedWindow will not be triggered because nothing prevents the target control to be interacted with.
If your test code explicitly waits if the modal window exists and processes it if it does, then, as it was said by tphillips, this window will not be considered to be unexpected and the OnUnexpectedWindow event will not be triggered.