A script is a procedure or function in one of the supported scripting languages.
Scripts are grouped into unit files, and each project may use as many units as needed. In a TestComplete project, all the units belong to the Script project item. When you create a new project, TestComplete automatically creates the Script project item with one unit in it.
Note: A unit name can be used in scripts, it should be a valid script identifier, and it should not coincide with the names of existing program objects.
Creating and Editing Script Tests
Use the following ways to create a script:
The easiest way is to record a script test.
You can write a script test manually.
You create and edit script tests in the Code Editor of TestComplete. To open your script test in the editor, right-click the unit that contains the script, and then click Edit.
When you edit a script unit, TestComplete automatically creates a backup copy of the unit file. The copy resides in the same folder as the unit file resides. The copy has the original unit file name and the .bak extension. Using this copy you can restore the unit code as it was before editing.
Calling Scripts Declared in Another Unit
You can call scripts from other scripts by their name. If you want to call a script from another unit, you must import it first. You can also import units of other projects. See Calling Routines.
When you create a project, you select a scripting language for this project:
- DelphiScript (a subset of Object Pascal)
- C#Script or C++Script (both based on the JScript engine)
Support for these languages is built into TestComplete, and does not require additional modules or configuration. All languages are restricted to variables of the OleVariant-compatible type, and cannot use pointers. Types specified in variable or function declarations are ignored.
TestComplete is equally oriented on each of the supported scripting languages. However, each of the languages has its pros and cons that may or may not match your specific requirements. To decide which language to choose, read the following:
For complete information on the supported scripting languages, use the links below:
|C#Script||Writing C# Scripts|
|C++Script||Writing C++ Scripts|
You can run scripts:
As your project’s test item specified either by the script name and unit or by tags.
From the Project Explorer.
From the Code Editor.
From other tests.
From the command line.
To learn more, see Run Scripts.
Before running any script, TestComplete checks all script units for syntax errors. The script will not be run if syntax errors are found.
Script File Format and Source Control Systems
TestComplete script files can have either ANSI, UTF-8 or Unicode (UTF-16) format. Some source control systems treat Unicode files as binary and thus do not let you perform some operations over such files, for example, compare or merge. Please refer to the documentation on your source control system to learn how you can work with Unicode files.
To solve the problem, you can also change the character encoding format used in your project for script files. For more information on this, see Units Encoding.