TestComplete supports Python 3.6.0. Below are some specifics of using this Python version in TestComplete. See also Specifics of Usage Common for All Languages.
Duplicate function names are not allowed within a TestComplete script unit.
In Python, code execution can start outside a function. In TestComplete, a test run must start from a function. You can start your tests from a function that does not have executable code. This function can contain an ellipsis and (optionally) comments:
Log.Message("Test execution will start from the top.") def Test(): # The ellipsis in the following line is not executed # However, the test will start ...
To import custom Python packages, put them in the <TestComplete>\Bin\Extensions\Python\Python36\Lib folder and use the
import command. If it is impossible, change the
sys_path variable explicitly and then import the module.
# Sets the new path sys.path.insert(0, "C:\\MyFolder\\MyPackage") # Imports the module import MyModule
Note: If you want to call TestComplete global scripting objects (for example,
NameMapping and others) in your custom Python package, you need to add your package file to the Script collection of your TestComplete project by using the Add > Existing Item command. See Adding and Removing Project Items and Their Child Elements.
In Python, you can import units to each other. At that, the Python units of your test project can import units that are not included in the project. TestComplete objects (like
Sys) are not available in these units. To use TestComplete objects in these units, include the units in your project, or import them as described in the Importing Tests topic.
Python supports circular references between script units.
Though the TestComplete Python library includes the threading module, TestComplete does not support multithreaded Python scripts. Code in the threads that you create will not work. Calls to TestComplete objects, methods and properties from these threads will cause an exception.
In Python applications, the
Log object. See Posting Messages to the Log.
Set Next Statement command is not supported for Python scripts.
|Note:||If the tuples and lists contain many items, the debugger panels and dialogs group them by 100 for convenient presentation.|
Python is a strongly typed language. COM objects can have properties that return a collection object. Most scripting languages allow accessing collection items directly, for example,
obj.Cells(i, j). TestComplete Python scripts do not support this to avoid ambiguity. To access items of a collection object, you should specify the appropriate property (
# Calling a property with parameters
value = obj.property[param1, param2]
obj.property[param1, param2] = "value"
# Calling a property with default parameters
value = obj.property # Syntax error!
value = obj.__getprop__("property") # Use this instead
obj.property = "value" # Syntax error!
obj.__setprop__("property", "value") # Use this instead
In TestComplete, the
__name__ variable always refers to the name of the unit where the function resides, for example, Unit1. TestComplete never assigns the value "__main__" to this variable. So, the condition
if __name__ == "__main__"
Using Tkinter to create GUI elements for your TestComplete tests may cause errors. Use TestComplete User Forms instead of Tkinter.
Asynchronous coroutines - TestComplete does not support asynchronous coroutines declared with the
Raw byte literals - literals with the
br prefixes, such as
rb"test". As a workaround, you can create raw bytes objects by converting strings:
a = str.encode(r'Test') # or a = bytes(r'Test', 'utf-8')