Forum Discussion

pashooo's avatar
pashooo
Contributor
14 years ago
Solved

definition variables when them are not exist yet

In my TC project I have created file "definition". it contain such definitions of variables: main_menu = Sys.Process("OptionsWorkshop").WPFObject("HwndSource: MainForm").WPFObject("MainForm...
  • tristaanogre's avatar
    14 years ago
    You cannot assign objects to a variable if the object does not exist in memory.  So, you'll need to make sure that these assignments are wrapped in a script routine like



    function AssignVariables()

    {

        main_menu = ...

        main_form = ...



    }




    However, this may still cause problems if the objects are not created all up front.  For example, say you have a form defined in AssignVariables the does not exist until you click a button.  You'll still end up with your error in that case.



    It sounds like you're trying to build an object repository on the fly.  It is possible to do so but you need to do a lot more than just assigning variables.  You need to make sure you relate things to other things and make sure that you refresh the variables on occasion in case the handles and such have shifted.



    A better, solution, is to use the NameMapping feature of TestComplete as this will allow you to pre-defined all your objects and map them to Aliases ahead of time.  Then you can just simply call things like



    Aliases.main_menu

    Aliases.main_form




    You can check out this video:



    http://smartbear.com/support/screencasts/testcomplete/reliable-tests-for-dynamic-objects/



    I'd also recommend reading the articles starting with



    http://smartbear.com/support/viewarticle/11508/http://smartbear.com/support/viewarticle/11508/