Forum Discussion

tziconsult's avatar
tziconsult
Occasional Contributor
7 years ago

Problems with the EXISTS method in TestComplete V9

I had some issues with the EXISTS method in terms of dealing with modal lists of an application (test object). Somehow the EXISTS method may not deliver the correct information, whether the object is available or not. In terms of misleading information the test process may run into an error.

 

I found a solution based on AliasObjects and direct accessing of the list.

 

---------------------------------------------------------------------------------------------------------------------------

 

Sub selectList (Caption, Action)

Dim Selection

' Define object
' If it is available, Selection contains the object otherwise an empty object
' WNCode is just a variable to cover several versions of the test object without
' the need of code adaptation

 

Set Selection = Sys.Process("za").WaitWindow("FNWNS"+WNCode,Caption,-1,1000)

 

' a mixture of AliasObjects |-> Aliases.za.wndSelect...| and
' direct coding |-> Sys.Process("za").WaitWindow("FNWNS"+WNCode...|
' of the GUI objects avoids / bypasses
' the weakness of the EXISTS method in the TestComplete V9
' the following lines work: it deals with no, one or multiple list(s), which
' may occur whilst user interaction

While (Aliases.za.wndSelect.Exists)
    ' Exists works solely fine with the AliasObjects!

     Aliases.za.wndSelect.SetFocus
     Aliases.za.wndSelect.Keys(Action)
     Set selection = Sys.Process("za").WaitWindow("FNWNS"+WNCode,Caption,-1,1000)

Wend

 

End Sub

--------------------------------------------------------------------------------------------------------------------

  • Your problem is in the following line

     

    While (Aliases.za.wndSelect.Exists)

     

    The Exists property MAY work fine for this in some situations... but it will generally fail.  The reason being is actually logically simple: you cannot check the "Exists" property of an object that doesn't exist... you must have an object to have the "Exists" property.  Usiing Aliases works best because some of that is taken care of within the NameMapping engine.

     

    The best way to check the existance of an object you've already demonstrated in your code: Use a "Wait" method of some sort.  So, I would actually change your line of code to something like this.

     

    While (Aliases.za.WaitAliasChild("wndSelect", 10000).Exists)

     

    Reference the following help topic.

    https://support.smartbear.com/testcomplete/docs/app-objects/common-tasks/checking-existence.html#checking-whether-an-object-exists-from-scripts

     

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Your problem is in the following line

     

    While (Aliases.za.wndSelect.Exists)

     

    The Exists property MAY work fine for this in some situations... but it will generally fail.  The reason being is actually logically simple: you cannot check the "Exists" property of an object that doesn't exist... you must have an object to have the "Exists" property.  Usiing Aliases works best because some of that is taken care of within the NameMapping engine.

     

    The best way to check the existance of an object you've already demonstrated in your code: Use a "Wait" method of some sort.  So, I would actually change your line of code to something like this.

     

    While (Aliases.za.WaitAliasChild("wndSelect", 10000).Exists)

     

    Reference the following help topic.

    https://support.smartbear.com/testcomplete/docs/app-objects/common-tasks/checking-existence.html#checking-whether-an-object-exists-from-scripts

     

    • tziconsult's avatar
      tziconsult
      Occasional Contributor

      Hello. 

       

      Yes, ist works! Thank you.

    • tziconsult's avatar
      tziconsult
      Occasional Contributor

      Hello.

       

      In fact, I thought the same concerning the EXISTS method whilst my trying with several code alternatives. I also used the WaitAliasChild. But I might be working almost correct. Thus I wil try your proposed solution.

       

      Thank you for your hint.

  • tziconsult's avatar
    tziconsult
    Occasional Contributor

    wndSelect has to be defined in the NameMapping section within the project.