Forum Discussion

satya283's avatar
satya283
Occasional Contributor
15 years ago

How do I wait for a Window to gets closed?

I have a Window Object. After doing some operation on the window, I need to wait until the window gets closed. How to do this? I am using Testcomplete 6 with JScript

6 Replies

  • AlexKaras's avatar
    AlexKaras
    Icon for Champion Level 2 rankChampion Level 2
    Hi Satya,



    Something like this (pseudo-code):

    winObj.Close();

    while winObj.Exists

        Delay(500);
  • Hi,



    I'd recommend using the WaitWindow method to avoid errors in this case.

    Modified Alexei's pseudocode in this case would look like this:



    winObj.Close();

    while WaitWindow(class, caption, -1, 500).Exists

    do nothing

  • satya283's avatar
    satya283
    Occasional Contributor
    Thanks Jared. Actually I do not perform a 'close' operation on the window. After entering *some* details, I click on a 'Process' button. It does some operation, till which the window is open. Once the processing is done, the window closes automatically. Hence there is no  explicit close operation. Anyways, ur solution is useful in waiting the window to gets closed.
  • Mia's avatar
    Mia
    Contributor
    Hey guys,



    I tried to apply both pseudo-codes on my application and both are not working properly.



    - the case with objWnd.Exists always throws an error message, becuase when the window is actually closed, TestComplete can't find this object and the test fails.



    - the same issue applies on the second case with WaitWindow, with slight difference - it takes longer before the test fails, the cycle never ends...it continues even after the window is closed.



    I think this is pretty often test flow: e.g., Open some wizard > make some changes > Press Save > Wait for closing/saving > do another job



    So far I am alternating the "Wait for closing" with Delay() function, but it is soo unreliable. Is there any other way?



    Thanks

  • NisHera's avatar
    NisHera
    Valued Contributor
    Hi ,

    Did you try using  "WaitChild" method of parent window? 
  • Manfred_F's avatar
    Manfred_F
    Regular Contributor
    Hi there,

    this is my solution:



    (mcModul holds the Name of the module)




    Sub WaitUntilClosed(DialogAlias)


    ' waits until dialog disappears

    Const cRoutine = "WaitUntilClosed"

    Dim Ix

    Dim vorhanden

    Dim Timeout

    Dim Caption

      

       ' shorten delaytime to use .exists in script extension: set Options.Run.Timeout to 200

       Set Timeout = SetRuntimeoutObj(projectsuite.Variables.LoopMs)

      

       ' Dialog not available

       Caption = ""

       vorhanden = DialogAlias.Exists

       If vorhanden Then Caption = DialogAlias.wndCaption

     

       Ix = ProjectSuite.Variables.LoopStart  '10

       If vorhanden then 

          Do While Ix > 0 And DialogAlias.Exists = True

             If Not DialogAlias.visible Then Exit Do

             Ix = Ix - 1

             'Delays the test execution for the specified time period.

             Call Delay(ProjectSuite.Variables.LoopMs) '200

             ' Das Speichern kann etwas länger dauern, ggf. Cursor abwarten

       ' nice to have

     '        If Ix = ProjectSuite.Variables.LoopStart - 1 Then

     '           PVA_0.Cursor.WaitUntilReady

     '        End If  

          Loop

       End If

      

       ' reset delaytime to 10000

       Timeout.Restore



       ' Checkpoint

       If Caption = "" Then

          Caption = "Dialog"

       Else

          Caption = "Dialog " & PVA_0.Basis.NameWrap(Caption)

       End If

       If Ix <= 0 then

          log.Error Caption & " wurde nicht geschlossen", _

             (ProjectSuite.Variables.LoopStart - Ix) * ProjectSuite.Variables.LoopMs & "ms" & vbCr & mcModul & cRoutine

       Else

          Log.Event Caption & " wurde geschlossen", mcModul & cRoutine

       End If

    End Sub