Forum Discussion

dhundley's avatar
dhundley
Regular Contributor
23 days ago

Unexpected Window Event Handler

I’m trying to set up my OnUnexpectedWindow event handler. I am following the exact steps that are shown in the following smartbear video:

https://support.smartbear.com/testcomplete/videos/dealing-with-unexpected-pop-ups/

my handler is doing what it is supposed to do (clicking a Yes button on the unexpected window which closes the window) but the test is not continuing from that point like it does in the video. It still fails with an unexpected window error even though the unexpected window no longer exists.

I have this theory as to why it might be failing but don't know what i can do to resolve it (if it is in fact the case).

Here is a screenshot of how my application looks with the unexpected window centered on the screen. The larger window in the background is my application

The event handler has three parameters: Sender, Window and LogParams

If I put a Log.Message(Window.Name) statement in the event handler, it logs the name of the application in the background into the results log

rather than the little window in the middle (as can be seen in the object browser image below).

Why isn’t the the correct window name being passed into the Handler's Window parameter?

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Verify your Project Settings for Playback is correctly setup - there's options for Error Handling and On Unexpected Window.

    Also, since you are closing the tab, is it really considered to be an unexpected window, as you are being prompted "Are you sure you want close the Teller?" ?

    • dhundley's avatar
      dhundley
      Regular Contributor

      these are the playback settings. while the On Error is set to Stop Current Item, the On unexpected window's Stop Execution is not checked so i would think that means that if the unexpected window is handled that it should not be considered an error and continue running. 

      as for the example being an expected window, you are correct, i know that this particular message box named Window("#32770", "CSI NuPoint", 1)  will always appear when the Teller tab is closed and i will be automating the click of its Yes button but there are other types of these messages that will occasionally appear that have other messages such as "object reference not set to the instance of an object" or the extremely vague "Unhandled error". Quite often, if i click their OK or Yes buttons the test case will proceed and finish successfully. but i can't know when those message boxes are going to pop up so i'm trying to develop my event handler using the same type of box that i can control. inside the handler i will intercept the unexpected pop ups, issue a warning message in the log and, perhaps, even send an email to a developer with a picture of the pop up, the time, test case and location where it occurred and even attached a zip file containing the trace logs, but it will then click the appropriate button to allow it to continue running if the error is not fatal. 

      so, the question remains, why doesn't the Window parameter contain the name of the actual unexpected window in my scenario? The smartbear website 


      https://support.smartbear.com/testcomplete/docs/testing-with/running/handling-errors/unexpected-windows.html#Remarks

      shows the following information. By my having disabled the statements in my keyword test that click the Yes button, the next sequential automated step is to "Click" on the File|Exit menu selection (which can be seen in the upper left of the first image i posted yesterday). Since the unexpected window is modal it is what is "impeding" the Click action from occurring and, thereby, triggering the OnUnexpectedWindow event. But, as i said, my event handler is successfully closing the unexpected window by clicking the Yes button which, in turn, closes the Teller tab. IOW, it has satisfied step #3 at the bottom of the image below. So why isn't the automation resuming at that point to click File|Exit?

       

       

      • dhundley's avatar
        dhundley
        Regular Contributor

        after much trial and error I think i may have stumbled upon a solution. Here is my event handler

        i put some Log.Message statements in to show what's happening. When the Click action on the File | Exit  menu is impeded because of the modal window the event hander is triggered. The If statement on line 17 checks to see if the unexpected window is a message popup box. If it is not, then it will assign the message popup box to the Window parameter and then click right in the middle of it to make it the active control on the screen. at that point i think it is going back and trying to Click File | Exit again. it is still impeding but the second time the event handler gets triggered the Window parameter is now equal to model window object and the Yes button is clicked. Here's the results log showing how this event handler was executed. The first window click was closing the Teller tab. The second window click in the red box is in the middle of the pop up during the first traversal of the event handler and then the button click is on the Yes button of the pop up and finally the File | Exit is clicked and the test case was successful. It's a bit of a roundabout way of doing it but it does seem to work. 

        still seems like the modal window should be sent to the event handler the first time but apparently it's not. I will hold off on marking this as the solution in case someone has a better suggestion for me. thanks!