cancel
Showing results for 
Search instead for 
Did you mean: 

CAll objects declared in another unit function

SOLVED
Highlighted
Regular Contributor

CAll objects declared in another unit function

Hello,

I know, In Test Complete there no need to create objectRepository we can use Name Mapping in place of object repository.

but i have to create ObjectRepository, How can i call my objects

Like:

Unit A

Function AllObjects()

 Set abc = ........Something here.......

 Set bcd = ........Something here.......

 Set cde = ........Something here.......

End Function

 

'USEUNIT A

Sub TestCase()

 'here what should i do so that I can get objects

as i am trying A.Allobjects.      

but after Allobjects proposals does'nt show objects in the function

how can i call the objects declared in another unit, function.

End Sub

1 ACCEPTED SOLUTION

Accepted Solutions
Community Manager

Re: CAll objects declared in another unit function

Thanks for the suggestions, AlexKaras, Wamboo!

 

@kaiiii, also, it's worth taking the following TestComplete basics course:

https://academy.smartbear.com/store/575377-testcomplete-basics-web-testing

Even if the course is oriented for Web Testing, it contains a lot of great descriptions of TestComplete Platform's features.

 

If nothing helped, let us know.

 
---------
Tanya Gorbunova
SmartBear Community Manager

Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today

View solution in original post

9 REPLIES 9
Highlighted
Community Leader

Re: CAll objects declared in another unit function

Hi,


There's no need to call it something like A.Allobjects.


If you use the NameMapping repository and (as we see in the code) you store references to NameMapping objects in variables.


You already have a reference, so you have to call AllObjects -> check the result and use the returned value in the code.

Highlighted
Regular Contributor

Re: CAll objects declared in another unit function

Hi @Wamboo ,

Thanks for reply

but I did'nt get your point. can you please eleborate.

 

Highlighted
Community Leader

Re: CAll objects declared in another unit function

I think You are using VB.


I am using JavaScript but the example will be simple and i think you can understand it.


example:

 

Unit A

Function AllObjects()

Set abc = ........Something here.......

Set bcd = ........Something here.......

Set cde = ........Something here.......

End Function

 

Here you try to save values (NameMapping repository values in variables). Return these values from the function and use it in the routine you want. In JS this is something like that.

 

function storeValues() {
  let variable = Aliases.obj.obj;
  return variable;
}

to be honest You can always store single NameMapping value inside variable without declaring function above it.

 

example:

 

var mainMenuButton = Aliases.obj.obj2;

 

or declare a function inside the variable:

 

var mainMenuButton = function() { 
  return alias.Find(propNames, propValues, depth, refresh);
}

 

ofc, instead of Alias.obj you can always use Sys.

 

Is that helpful? Is that what you meant?

Highlighted
Regular Contributor

Re: CAll objects declared in another unit function

Hi @Wamboo,

Thanks for your reply

somehow, I am getting your point.

function storeValues() {
  let variable = Aliases.obj.obj;
  return variable;
}

In the above the function we put the name mapped value and assign it into a variable and get return of that function.

but If i have a list of variable .. so I think there will need to create a lot of function and it will not make easy.

....I am trying but not getting your point properly as first I am facing problem that

1) How can i  create a Name Mapping repository.. It's good to create manually or by script.. I want to handle by script

2) How can I Store (objects or variables) in that repository.. and as you suggest that use NameMapped value and assign value in a variable and then return of that function. In that condition for lot of objests I have to create lot of functions. It's pathetic

3) The last one is if every thing is ready .. then how I will call that object from repository to in my test cases unit.

Highlighted
Community Leader

Re: CAll objects declared in another unit function

Starting from the beginning, I had the impression from the previous message that you deliberately do not want to use NameMapping.

 

ad 1) NameMapping is created by adding an appropriate item in the Project menu and then using the "object spy" option you add the indicated items to the repository.


The repository elements can be accessed in a script via Alias.obj etc.

 

 

Adding objects to the Name Mapping repository

Automatically - By default, TestComplete adds objects to the Name Mapping repository when you are recording and editing tests. See Mapping Objects Automatically.

 

Manually - You can add objects to the Name Mapping repository from screen or from the Object Browser. See Mapping Objects Manually.

 

Tip: The easiest way to map multiple objects quickly is to record user actions over these objects. TestComplete will map all the objects with which you have interacted automatically.


ad 2) You don't have to store it in variables. You can use it directly from the NameMapping repository via Alias.obj etc.

 

My example is completely different and results from not understanding your entry properly.

 

ad 3) Use the Aliases.obj

Highlighted
Regular Contributor

Re: CAll objects declared in another unit function

Hi @Wamboo ,

Thanks buddy

Now I got it and able to understand.

but now facing another problem... below is the code that I am using

Aliases.browser.pageLogin192.Login_Email_Address

but when i am trying to check proerties of this .. it's displaying everything disable

Please check the screenshot for same

 

Highlighted
Community Leader

Re: CAll objects declared in another unit function

Hmmm, it's weird... maybe someone else has an idea?


Simple questuins, but it's worth checking:


1) Do you have a WebTesting TestComplete license?

2) Do you have WebTesting plug-ins enabled?

3) Have you tried to enable all steps from this article?

https://support.smartbear.com/testcomplete/docs/app-testing/web/general/preparing-browsers/index.htm...

 

 

Highlighted
Community Hero

Re: CAll objects declared in another unit function

Hi,

 

Easiest stuff first:

> it's displaying everything disable

Object does not exist (.Exists property equals to False). Thus all other properties are not accessible because they do not exist either.

 

Now more complex things related to the terminology:

> How can i call my objects

No way. Point.

Objects can not be called. Object is a wrapping structure for the data and methods that process those data. Object must be defined first. I.e. it must be described what data will it contain and what code will process the data. Then the object instance must be instantiated. Instantiation allocates memory to keep data, assigns data to the allocated memory and sets pointers to the processing code. Then you may call the code that will process the data.

Summarizing: object cannot be called, but methods of object instance can be called.

 

Now your code:

Function AllObjects()
 Set abc = ........Something here.......
 Set bcd = ........Something here.......
 Set cde = ........Something here.......
End Function

 

The code assigns values (actually - references to some objects) to the abc, bcd and cde variables. As those variables are local to the AllObjects() function, they (variables) are dismissed of on function exit and cannot be used to access the objects that they referenced. (Existence and accessibility of the referenced objects is a separate question and you should read about objects disposal of and memory management in VBScript additionally.)

In order to keep variables and make them accessible outside of the AllObjects() function, those variables must be declared as public. I.e.:

Public abc
Public bcd
Public cde

Function AllObjects()
 Set abc = ........Something here.......
 Set bcd = ........Something here.......
 Set cde = ........Something here.......
End Function

After that in another unit you will be able to do something like this:

'USEUNIT A
Sub TestCase()
  Call AllObjects()
  Call abc.<SomeMethodProvidedByObjectReferencedBy_abc_Variable>()
End Sub

Note, however, that this approach should not be used in real life for the most of objects of your tested application.

Two primary cases:

a) Global variables are risky because they are accessible from everywhere and may be occasionally assigned some other value in an absolutely different part of your test code and you will have a hard debugging time to resolve this;

b) Objects of the tested application are usually created and destroyed while the application functions. So it is not possible to store the reference to some tested object until this object is created. And the stored reference will be invalidated when the tested object is destroyed in the tested application.

For example: it is not possible to store the reference to the Order Form to the abc variable until the form is opened in the tested application. And when the form is closed, abc variable will reference invalid object that cannot be used. (There are a couple of additional details here but they are out of scope at the moment.)

 

So, the best approach with TestComplete is to either use the provided NameMapping with Aliases, or to have a set of functions that will search for the required object and return a reference to it (if it exists), but not to try to search for all objects of the tested application on test start and keep references in public variables. This just will not work.

 

 

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
================================
Community Manager

Re: CAll objects declared in another unit function

Thanks for the suggestions, AlexKaras, Wamboo!

 

@kaiiii, also, it's worth taking the following TestComplete basics course:

https://academy.smartbear.com/store/575377-testcomplete-basics-web-testing

Even if the course is oriented for Web Testing, it contains a lot of great descriptions of TestComplete Platform's features.

 

If nothing helped, let us know.

 
---------
Tanya Gorbunova
SmartBear Community Manager

Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements
Join TechCorner Challenge!
Want a fun and easy way to learn TestComplete? Try solving weekly TechCorner challenges and get into the Leaderboard!

Challenge Status

How to execute remote test and obtain results via Test Runner REST API

Participate!

Comparing content of HTML table with Excel file data

Participate!

Compare HTML table with Excel file and correct data in the file

Participate!

Retrieve Data from a Web Page

Participate!
Top Kudoed Authors