Forum Discussion

chicks's avatar
chicks
Regular Contributor
14 years ago

test complete recognizing unexpected windows





" he
OnUnexpectedWindow
event occurs during the test execution when TestComplete
encounters a window that was not active during the test recording. This topic explains how to create an event handler for this event."



So, if a script is written from scratch without test recording, how does TestComplete recognize an unexpected window?



Thanks!
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    The text in there is a bit misleading... you don't NEED to record something to get the Unexpected Window event.



    Basically, if there is a modal window that comes up that is not accounted for in the automation code (like an error window or notification message or something), TestComplete cannot proceed because that "unexpected window" is preventing interaction with any other windows.  If that happens, that's what first the OnUnexpectedWindow event.


  • chicks's avatar
    chicks
    Regular Contributor
    Thanks Robert!  That makes sense, as TC obviously is recognizing the windows for my non-recorded scripts.



    I do wonder how... but I suppose it's not terribly relevant.



    Regards, Curt
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Again, it has to do with a window being "in the way".  



    Say the scripts say Click on Button A on Form 1 then Enter Data in text field on Form 2 using the Keys method.  That is all that's in the code, no other forms or buttons or anything is referenced.  However, if after the scripts click on Button A, instead of Form 2 displaying, an error form (Form 3) is displayed.  If that form is modal or set to be "always on top" AND if that form actually gets in the way of the data field on Form 2, then Form 3 is classified as an "unexpected window" and triggers the event.



    Clear as mud?
  • chicks's avatar
    chicks
    Regular Contributor


    Yep,  clear as mud (grin) from a user perspective.  I was wondering about the internals.  Does TC recognize that another windows object has appeared in the object hierarchy by monitoring the number of windows objects and detecting that a new one has appeared after every window operation?  I could see that working for 'recorded' scripts but it seems like there's a lot more involved for non-recorded scripts.





    Regards, Curt
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Nope, not nearly that complicated.  You can't click on a button if the button is obscured by a modal window.  Pretty much that simple.  It goes to attempt the click, finds that it can't because of a window that's in the way, and blam.  It doesn't track what windows should be there or should not, it doesn't track window counts or anything... just simply "Hey!  There's something in my way! Better tell my user... either that or Tron will hit me with his data disc again..."






  • Hi Robert,



    I have a question about this ... I have a Form1 with a button OK and above of this other form2 with another OK button. I need to click on the button OK of the form2. I do a search of the button through the Sys.Process("XXXX"). FindAllChildren ("WndCaption", "OK", ...) and this return to me an array of all the buttons with the caption OK, I need to filter this to make sure to click on the OK button that is visible (Form2) . If I try to access another button to see if it is hidden or not, it automatically launches the Window Unexpected event. What do you recomend I do?



    Thanks,



    Ivette Onay
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Since you know you want the button for form 2, is there any reason why you can't just call



    Sys.Process("MyApp").Form2.OKButton.ClickButton
  • sshahin's avatar
    sshahin
    Occasional Contributor
    I am bumping this because I am having a hard time understanding how OnUnexpectedWindow works when script is written from scratch.
  • As I understand from the help article Handling Unexpected Windows the recognition of unexpected window is based just on the two facts: the foreground window overlaps the window against which next mouse action must be performed and this window is modal (requires user interaction). So I think you can start by setting up the TestComplete settings used to handle unexpected windows described in the help article mentioned above.