Forum Discussion

avl123's avatar
avl123
New Contributor
4 years ago

UI object as an argument for a function

Hi,

I have a JavaScript function performing operations on the UI object which is its argument. The functioned is called like this: myFunction(Aliases.Parent.Object).

 

Recently I started getting an error during test run from time to time: The tested window (or control) has been deleted. Details: This error occurred when the tested window (or control) or its parent object was deleted or recreated right before the method call. For example, you stored a window reference to a variable and then called a method through this variable. If the object has been recreated, then to avoid the error, get the new object before the method call.

So now I have an additional function: function getObject(){return Aliases.Parent.Object} and the initial function is called like this: myFunction(getObject()).

 

I guess it should solve the problem, but I wonder if it is the best/correct way of doing it? Should Aliases generally be avoided as arguments?

  • Hi,

     

    Should Aliases generally be avoided as arguments?

    It is perfectly fine to use Aliases as a function's argument.

    But one must always remember (as it is stated in the quoted log message and which is true for the non-Aliased argument as well) that if the object referenced by the current Alias is destroyed (and, optionally, recreated), this does not update the reference in the Alias but invalidates it. As the result, Alias will reference empty stub object and one must use the .RefreshMappingInfo() method call to search for the new object and refresh the object's reference stored in the Alias.

     

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    Should Aliases generally be avoided as arguments?

    It is perfectly fine to use Aliases as a function's argument.

    But one must always remember (as it is stated in the quoted log message and which is true for the non-Aliased argument as well) that if the object referenced by the current Alias is destroyed (and, optionally, recreated), this does not update the reference in the Alias but invalidates it. As the result, Alias will reference empty stub object and one must use the .RefreshMappingInfo() method call to search for the new object and refresh the object's reference stored in the Alias.

     

    • avl123's avatar
      avl123
      New Contributor

      AlexKarasthank you! I expected that there should be a way to solve the problem using TestComplete functionality