Forum Discussion

MadGrb's avatar
MadGrb
Contributor
5 years ago

OnUnexpectedWindow event sometimes not working for windows Appliction

Hi,
In my .Net Test Application, sometime I get error with our Messagebox. On this Case I have to run a procedure.

 

Sometimes TC gets this messagbox as unexpected window and sometimes ignore it as unexpected window. I have read the log, the messagebox is not registered as Error or unexpected window.

 

How can I solve this Problem, I want to get always this Messagebox as unexpected window.

  • MadGrb Since none of the suggested solutions worked, this issue definitely requires deeper investigation. Please contact our Support Team and describe it as minutely as possible.

     

    Our Support Team and Dev Team would need to reproduce it in their lab, so please send them a sample app and a sample TC project for this. 

     

    Please post the solution you get from them here, thank you🙂

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    OnUnexpectedWindow event is triggered in TestComplete when some modal window (application or system) prevents your test code to interact with UI elements out of this modal window. Examples of such interactions are clicks, setting focus and sending keys sequences. Exactly like it looks like for the human user.

    Note, that if your test code does not interact with UI but operates on tested application's methods/properties, then modal window will not block such interactions and thus the OnUnexpectedWindow event will not be triggered.

    For example, <inputField>.SetText('blah') will always succeed as it uses direct property assignment and does not interact with the <inputField> element via GUI. On the contrary, <inputField>.Keys('blah') will trigger the OnUnexpectedWindow event if the form with the field is blocked by some other modal message window.

    The good approach to get a reliable test code in the cases like this is to use .Activate for forms/windows and .Focus methods for controls before interaction with them to ensure that forms/controls are not blocked.

    E.g.:

    <form>.Activate;

    <form>.<inputField>.Keys('blah');

    <form>.<inputField2>.Keys('blah')

    ...

     

    • MadGrb's avatar
      MadGrb
      Contributor

      Yes,

       

       

      def EventSendToBugReport(Sender = None, Window= None, LogParams= None):
              if Objects_WAWi.BugAuftreten_Form.Exists:
                      Objects_WAWi.BugAuftreten_btnSend.Click()
                  
                      if Tools.WaitForAvailablity(Objects_WAWi.BugZusatzinformationSenden):
                  
                              Objects_WAWi.BugZusatzinformationSenden_AchtungSign.Click()
                              Objects_WAWi.BugZusatzinformationSenden_btnZusatzinformationenSenden.Click()
      
                              Tools.WaitForAvailablity(Objects_WAWi.AdditionalInformation_Form)
                              Objects_WAWi.AdditionalInformation_Txt.Keys("TestComplate Meldung!! Für mehr info rufe Mo an. Fehler Codes is unkown!")
                              Objects_WAWi.AdditionalInformation_btnOK.ClickButton()
      
                              Tools.WaitForAvailablity(Objects_WAWi.SendError_Progressbar)
                              
                              try:
                                      while Objects_WAWi.SendError_Progressbar.WaitProperty("Visible", True, mBase.cBase.GetTimes('SmallTime')):     
                                              Delay(mBase.cBase.GetTimes('SmallTime')) 
                              except Exception as exp:
                                      Log.Message('Oh lalala, I crashed')
      
                              finally:
                                      Tools.MessagboxManager()
                                               
                                      Tools.MessagboxManager()
                              
                                      Objects_WAWi.BugAuftreten_btnOK.ClickButton()
                                      
                                      mBase.cBase.TestResult('AQC of WAWi says: I crashed. BugInfo discoverd.',TypeOfResultObject = 'Bug')
                                      
                                      if Objects_WAWi.Absturz_btnSchlie_en.Exists:
                                              Objects_WAWi.Absturz_btnSchlie_en.ClickButton()
                                              Log.Message('WAWi Absturz')
                                              mBase.cBase.TestResult('AQC of WAWi says: Ich absturz. WAWi wird neuegestarten.',TypeOfResultObject = 'Bug')
                                      Delay(mBase.cBase.GetTimes('SmallTime'))   
      • BenoitB's avatar
        BenoitB
        Community Hero

        It happens to me sometimes also.

        I consider this is just a weakness of TC and try to always have a second level of detection (active detection instead of event).

         

        TC install hook on Windows message queue but we cannot be guaranteed that whenever it peek message on it, it successfully grab all.

         

        OS and software environment are becoming so complex so i don't blame TC for it.