Forum Discussion
As with any coding environment, if you want a variable to be accessible to all code, you need to declare it at a higher scope than where you are calling it and then make sure that you reference that scope.
Probably the EASIEST way to do this in TestComplete is to use Project Variables. Define a project variable for the components you want and then reference Project.Variables.<variable name>.
For Python, you can declare all your variables globally in one unit of code and then reference that unit in all your other units. See https://support.smartbear.com/testcomplete/docs/scripting/calling-routines/declared-in-another-unit/python.html
A third alternative: Learn to use NameMapping and Aliases. With Aliases, you could easily just build an alias for that login that would be referenced as Aliases.user_name_box and you can then use that EVERYWHERE. See https://support.smartbear.com/testcomplete/docs/testing-with/object-identification/name-mapping/overview.html#about-the-mapped-objects-and-aliases-trees and related topics.
- tc_20187 years agoContributor
I try to declare variable in class and call it from a script file as shown below:
In class_objects.py file:
Class MyObjects:
user_name_box = Sys.Process("myapp").VBObject("login").VBObject("txtUserName")
In my script file:
import class_objects
def test():
mo = class_objects.MyObjects()
mo.user_name_box.SetText("test")
And it works.
Do you have any input for doing this way? Thanks.
- tristaanogre7 years agoEsteemed Contributor
See the second option I mentioned above.
Related Content
- 5 years ago
- 13 years ago
Recent Discussions
- 8 hours ago