About Script Tests

Applies to TestComplete 14.30, last modified on November 21, 2019

About Scripts

A script is a procedure or function in one of the supported scripting languages.

A script test in TestComplete

Click the image to enlarge it.

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: Since 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.
Scripts in Project Explorer

A typical script usually contains:

  • Objects that provide scripting interface to the process of your tested application and its UI elements.

  • Methods of those objects that simulate user actions over the tested applications and its UI elements.

For more information on these instructions, see Object Identification and Simulating User Actions.

Creating and Editing Script Tests

There are two ways to create a script:

  • The easiest way is to record a script test.

  • You can also write a script test manually in the Code Editor in TestComplete.

To modify scripts, open them in the Code Editor. To do this, right-click a unit that contains a script in the Project Explorer and choose Edit from the context menu. TestComplete will open the Code Editor with the unit code.

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.

Scripting Languages

When you create a project, you select a scripting language for this project:

  • 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 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:

Selecting the Scripting Language

For complete information on the supported scripting languages, use the links below:

 JavaScript developer.mozilla.org/en-US/docs/Web/JavaScript/Reference
 JScript docs.microsoft.com/en-us/previous-versions//hbxc2t98(v=vs.85)
 Python docs.python.org/3.6/
 VBScript docs.microsoft.com/en-us/previous-versions//t0aew7h6(v=vs.85)
 DelphiScript DelphiScript Reference
 C#Script Writing C# Scripts
 C++Script Writing C++ Scripts

Debugging Scripts

TestComplete includes its own script debugger. So, debugging script routines does not require any additional software. See Debugging Tests.

Running 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.

See Also

Script Tests
Working With Application Objects and Controls

Highlight search results