Our application has quite a few pop ups (modal windows) at various points.
The "unexpected window" event doesn't really apply because they are expected. What I'm findind is that my code is becoming litered with logic and wait situations that only work if they are in the specific part of the test (scripted) where that pop up will occur.
Is there a better, more general way to handle pop ups?
Is there a way to monitor for any popup, and if it's of type x or has property y. Hanldle it accordingly?
You did not mention it, but considering the fact that you are posting to the Desktop Testing section, I assume that you are working with the native Windows application.
As it was already adviced by @karkadil, OnUnexpectedWindow event is your way to go. This event is triggered when the target window or control cannot be activated because it is blocked by some other modal or system modal window. The above means that the event will be triggered only if test code attempts to activate some window or put focus to some control. The event will not be triggered if test code gets or sets value of some control's property or calls some control's method.
Thus, the generic solution for your case might be like this:
-- Try to activate control's parent window by calling <window>.Activate() method before interacting with the window's control;
-- If the window is blocked by some modal window, then the OnUnexpectedWindow() event will be triggered and your test code will be able to handle this window;
-- Call <control>.Click() or <control>.Focus() method to put the inlut focus to the required control and proceed as required.
P.S. If you are testing web application, then another approach is required because HTML cannot display modal HTML window. (alert() function displays not HTML, but native modal window that canbe handled as described previously.) In case of web application, you need to create a while loop and within this loop search for either the target control or the HTML-emulated popup. If control is found, then this means that the popup was not displayed and the code may exit the loop and proceed. If popup is found, then test code can handle it and continue in a loop until all popups are processed and the sought for control is found.
@sanc74: This is TestComplete's forum (and section about native desktop applications testing) and TestComplete has very little in common with Selenium and does not use WebDriver at all.
Hi you have some popups that may occur or not, and if you know the apparition order, you could wait each of them a few seconds for clicking on their close button :
if (AliasObject.WaitAliasChild(ChildName, time).Exists) then
If the popup don't arrives at all, you only had lost a few seconds per popup.
If the popup shows itself after the delay, you test will fail.
If the popup shows in time, you won't have to wait all you delay : it will execute the click as soon as possible.