WaitWindow with Python
- 4 years ago
Hi,
> This appears random, in 1-2 sec after the workspace is set.
Probably the main problem with windows like this is that they appear at non-predictable moment of time and it may take unpredictable time to close. I.e., depending on a bunch of different factors like network, memory and CPU performance, volume of work to be done, etc. the window may open, say, within 1-10 seconds time frame from the moment of initial workspace initialization. Depending on the volume of work to be done the window may close almost immediately or remain visible on the desktop for some time. Additionally, the window may not appear at all if the volume of work is too small or is absent.
On the other hand, it takes some noticeable time for TestComplete to detect the new window and to process it.
All the above leads to a problem that if the window was not detected within, for example 1 second, you can not be sure whether this is because all the work was done and the window will not be displayed or you need to wait more because of, say, congested network or overloaded CPU.
The best strategy for the situation like this depends on your goal: whether you need to interact with such window or need just to postpone test execution until the window is closed.
Probably the best option is if you can talk to developers and they add some property to the main application window that is set to false initially and to true after the window was closed. In this case you will be able reliably wait until the window is closed without spending extra time by just waiting in a loop until this property becomes true.
Check https://support.smartbear.com/testcomplete/docs/app-testing/open-apps/unavailable-members.html help topic if the above is an option.
If you need to interact with the window then you should use one of the WaitXXX methods. WaitWindow() or WaitAliasChild(). Use of Aliases is a good practice in TestComplete world but be aware and remember about caching: https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/refreshmappinginfo-method.html. Regardless of whether you are using .WaitWindow() or .WaitAliasChild(), you need to work with the window itself, but not with some of its child UI elements. Considering the code that you provided, this is the window with class name '#32770' and 'Task Manager' caption. But you may ask developers to be on the safe side.
In any case, remember, that if window may not appear or appears for too short period of time (consult with developers as for this) then you must consider some timeout in order to prevent endless wait. Selection of timeout is the major tradeoff here - you must wait long enough to let window appear and be detected by TestComplete, but not too long in order not to waste time on wait when it becomes evident that the window (most probably) will not appear.
If the window we are talking about is of modal type you may consider to use the OnUnexpectedWindow event provided by TestComplete (https://support.smartbear.com/testcomplete/docs/reference/events/onunexpectedwindow.html). In the case of using events, you should not wait for the window but just proceed with test flow. If the event is triggered, then you should check if the event was triggered by the window you are interested in (Task Manager) and either wait until it closes or interact with it if needed.
P.S. I understand that all the above might look too abstract for the one who just started to use TestComplete. Feel free to ask here if something is not clear enough.
P.P.S. May 26 SmartBear holds TestComplete Introductory Training (https://smartbear.zoom.us/webinar/register/8616153693294/WN_gwJbYsBcQU2HNC_8_iWQjw) which might appear to be useful.