About Scripts
There are two basic ways to create a script:
-
Record a script using the TestComplete script recorder (see Recording in TestComplete).
-- or --
-
Write a script in the TestComplete Code Editor.
The easiest way to begin scripting is to use the recorder. The script can be edited further through the Code Editor.
All scripts existing in the current project are shown in the Project Explorer panel under the Script node:
A script is a procedure or function in one of the supported scripting languages (see the Scripting Languages section below). Scripts are grouped into unit files, and each project may use as many units as needed. In the hierarchy of project elements, 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.
A typical script that simulates user actions contains the following statements:
-
Sys.Process(…)
- This method returns an object that provides a scripting interface to the process of the tested application. -
processObj.Window(…)
,windowObj.Window(…)
- These methods return windows of objects or child windows of a parent window (controls on an application form). -
windowObj.Click
,windowObj.DblClick
, and so on - These statements simulate user actions over a window.
For more information on these instructions, see Naming Objects and Simulating User Actions.
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. See Calling Routines and Variables Declared in Another Unit from GUI to learn more. You can also import units of other projects. See Calling Routines Declared in Another Project.
Note: | Since the unit name can be used in script code, the unit name should be a valid script identifier and it should not coincide with the name of an existing programming object. If the unit name is invalid, you have to rename the unit. You can do this in the same way you rename any other project items. See Renaming Projects, Project Suites and Project Items. |
Whenever you run a command execution of any script, TestComplete checks all script units for syntax errors. The script will not be run if syntax errors are found. You can check syntax by right-clicking the desired unit in the Project Explorer and selecting Check Syntax from the context menu.
Note that 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.
Scripting Languages
When you create a project, you select a scripting language for this project. You can choose from JavaScript, JScript, Python, VBScript, 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 includes its own script debugger. So, debugging script routines does not require any additional software.
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. Read the Selecting the Scripting Language topic to decide what language you should choose.
For complete information on the supported scripting languages, use the links below:
JavaScript | https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference |
JScript | http://msdn.microsoft.com/en-us/library/hbxc2t98.aspx |
Python | https://docs.python.org/3.6/ |
VBScript | http://msdn.microsoft.com/en-us/library/t0aew7h6.aspx |
DelphiScript | DelphiScript Reference |
C#Script | Writing C# Scripts |
C++Script | Writing C++ Scripts |
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.