TestComplete supports Python 3.10.10. 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:
We do not guarantee stable work of your script tests that use third-party Python packages. When you run such tests, you may experience unexpected errors or TestComplete can stop responding.
To import a custom Python package:
Place the package file (.py) to the following folder:
If you use a 64-bit version of TestComplete:
If you use a 32-bit version of TestComplete:
You can do it by using any file manager, for example, Windows Explorer.
In your script test, use the
If copying the package directly is not possible, set the
sys_path variable explicitly and then import the package:
# Set the new path to search for modules import sys sys.path.insert(0, "C:\\MyFolder\\MyPackage") # Import the module import MyModule
- If you want to call TestComplete global scripting objects (for example,
NameMappingand 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.
If your custom Python packages have tags assigned to routines, the tags will not be available in TestComplete, and you will not be able to use them to run routines.
References between scripts
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.
Accessing collection items
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 (
Using parameterized properties
# 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
Using Tkinter to create GUI elements for your TestComplete tests may cause errors. Use TestComplete User Forms instead of Tkinter.
If you have TestComplete version 14.73 or later, you can use the assignment expressions in your tests. The
:= operator allows assigning values as part of a larger expression. For example:
Functions with a variable number of arguments
In Python scripts, you can declare and use functions with a variable number of arguments. See Python Reference - Arbitrary Argument Lists.
Unsupported language features
Asynchronous coroutines - TestComplete does not support asynchronous coroutines declared with the
Raw byte literals - literals with the
brprefixes, such as
rb"test". As a workaround, you can create raw bytes objects by converting strings: