cancel
Showing results for 
Search instead for 
Did you mean: 

UI object as an argument for a function

SOLVED
New Contributor

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Community Hero

Re: UI object as an argument for a function

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.

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

2 REPLIES 2
Community Hero

Re: UI object as an argument for a function

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.

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

New Contributor

Re: UI object as an argument for a function

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

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors