Creating Script Extensions That Process Test Results

Applies to TestComplete 15.44, last modified on November 10, 2022

You can create script extensions that process test results and submit work items and test logs into various issue-tracking systems, for example, Atlassian JIRA or Mozilla Bugzilla. When you install such an extension to TestComplete, the latter creates a toolbar item for it on the test log toolbar.

When you click this button on the toolbar, TestComplete calls the script extension code which will post test results to an issue-tracking system. To let TestComplete know which actions the extension provides and which script routines they execute, log processing actions are defined in the description file of the extension’s package. The definition includes the action name and the name of the underlying script routine (see Structure of the Description File for details).

This topic provides more information about creating log processing script extensions. It contains the following sections:

Creating Script Extension - Basic Concepts

The process of creating an extension that processes test results includes the following steps:

  1. Writing the extension code

    The main step in creating a log processing extension is writing a script routine that implements the needed functionality. Such a routine must have one parameter that specifies the fully-qualified name of the temporary .MHT file the test log was exported to. So, a sample routine declaration looks like this:

    JScript

    function ShowForm(LogFile)
    {
      // Create a work item
    }

    VBScript

    Sub ShowForm(LogFile)
      ' Create a work item
    End Sub

    Notes:

    • The script routine may display a form to allow a user to specify additional information like the server address, or the subject and description of the created bug report, or the identifier of the project to which the item will be added. To learn how to create and use forms in script extensions, see Using Forms in Script Extensions.

    • To create a work item in an issue-tracking database, the extension should use the issue-tracking system’s API. The API needs to be scriptable (e.g. a COM interface, a web service, and so on). For instance, the script routine can connect to the issue-tracking system via COM and perform the needed actions by using COM interfaces.

    • To store TestComplete results to the issue-tracking system, attach the .MHT file to the created work item.

    It is convenient to create the needed script code in TestComplete and then export it to a .vbs or .js file and include this file in the script extensions collection. For more information, see Creating Script Extensions - Basic Concepts.

  2. Creating the action icon (optional)

    It is possible to associate a meaningful icon with an action. This icon will be displayed on the test log’s toolbar. The icon must be a 16×16 BMP or PNG file with the 24-bit or lower color depth; the color of its leftmost bottom pixel is treated as transparent.

    If the action does not have an icon, the corresponding toolbar item will display the action name.

  3. Adding information about the extension action to the description file

    Finally, the action needs to be defined in the description.xml file of the script extension package. You can do this using special LogAction elements of the file’s XML markup. The action definition includes the following attributes: the action name, the action’s icon file and the name of the routine the action calls, all specified in the appropriate attributes of the mentioned XML elements. For more information about writing description files, see Structure of the Description File.

    Below, is a sample description.xml file:

    XML

    [description.xml]

    <?xml version="1.0" encoding="UTF-8"?>
    <ScriptExtensionGroup>

      <Category Name="Log Actions">

        <ScriptExtension Name="FogBugz Integration" Author="John Smith" Version="1.0" HomePage="www.example.com">
          <Description>Adds a command to submit test logs to FogBugz.</Description>
          <Script Name="myscript.js">
            <LogAction Name="Submit to FogBugz" Icon="icon.bmp" Routine="ShowForm"/>
          </Script>
        </ScriptExtension>

      </Category>

    </ScriptExtensionGroup>

    In this example, the toolbar item’s name is Submit to FogBugz, and the routine’s name is ShowForm. Note that we do not specify routine parameters here.

How the Extension Works

When a user selects the log processing command on the test log’s toolbar, TestComplete exports the currently opened test log to a temporary .MHT file on the hard disk. After that, TestComplete calls the script routine specified by the extension attributes and passes the .MHT file name to this routine as a parameter. The routine accepts the file name and performs the needed operations. For instance, it could display a form asking a user to input some critical data like the path to an issue-tracking database or project identifier. After the user specifies the needed data and closes the form, the routine can create a new work item in the issue-tracking system and adds the log file as an attachment. After the routine execution is over, TestComplete automatically removes the temporary .MHT file.

Example

TestComplete includes a number of script extensions that post test results from the test log to a database. You can find the source code of these extensions in the <TestComplete>\Bin\Extensions\ScriptExtensions folder. The .tcx extension files are ZIP archives. So, you can use any zip archiver to unpack files from them. For more information on the extension files, see Pre-Installed Script Extensions.

See Also

Script Extensions
Creating Script Extensions
Debugging Script Extensions
Deploying Script Extensions

Highlight search results