Converting Keyword Tests to Scripts

Applies to TestComplete 15.69, last modified on November 13, 2024

You may convert keyword tests to test scripts. This may be useful, for instance, when you are learning scripting. Or, if you need to perform some specific actions which are easier to do with script code than with keyword test operations.

Export keyword test to script

To export a keyword test to a script:

  1. Open the project.

  2. Right-click the name of the desired keyword test in the Project Explorer panel.

  3. Select Convert to Script from the ensuing context menu.

    Converting keyword tests to scripts

Conversion notes

  • If you select an existing routine in the Specify Routine Name dialog, the generated script statements will replace the code of this routine. Be aware.

  • Keyword-test parameters become parameters of the generated script routine.

  • Keyword-test variables are converted to local variables of the script routine. The only exception from this rule is keyword-test variables of the Table type. TestComplete converts them to project variables of the Table type.

  • The generated script commands use full object names starting from the root of the object hierarchy, for instance:

    Aliases.notepad.wndNotepad.Click("File|Open...");
    Aliases.notepad.dlgOpen.OpenFile("C:\MyFile.txt", "Text Documents (*.txt)");
    Aliases.notepad.wndNotepad.Close();

  • Each keyword test operation may be represented by one or more scripting commands. That is, a keyword test operation may be converted to several script statements.

  • The text the operation description fields contain can be converted to script comments. If at least one operation in the keyword test has a description, TestComplete shows a message prompting you to convert the description to comments.

  • TestComplete converts Visualizer images along with keyword test operations. That is, if a keyword test operation has a Visualizer image associated with it, TestComplete creates an appropriate association for the generated script statement.

  • If TestComplete is unable to convert a keyword test operation to script, it inserts a commented text about this.

  • The following operations are not converted:

    • Try, Catch, Finally
    • Label, Go to Label
    • Run Test

    When TestComplete meets these operations in a keyword test, it inserts the appropriate comments into the generated script code.

  • The Data-Driven Loop operation is converted to a block of script statements emulating the operation's functioning. These statements work with the DB Table variable that is used by the operation. The first statement is a call to the Reset method (it initializes the variable’s data iterator). The following statements is a loop that iterates through data rows:

    JavaScript, JScript

    Project.Variables.DBTableVar1.Reset();
    while(! Project.Variables.DBTableVar1.IsEOF() )
    {
      ...
      Project.Variables.DBTableVar1.Next();
    }

    Python

    Project.Variables.DBTableVar1.Reset()
    while not Project.Variables.DBTableVar1.IsEOF():
      ...
      Project.Variables.DBTableVar1.Next()
    ...

    VBScript

    Call Project.Variables.DBTableVar1.Reset
    While Not Project.Variables.DBTableVar1.IsEOF
        ...
        Call Project.Variables.DBTableVar1.Next
    WEnd

    DelphiScript

    Project.Variables.DBTableVar1.Reset();
    while not Project.Variables.DBTableVar1.IsEOF() do
    begin
      ...
      Project.Variables.DBTableVar1.Next();
    end;

    C++Script, C#Script

    Project["Variables"]["DBTableVar1"]["Reset"]();
    while(! Project["Variables"]["DBTableVar1"]["IsEOF"]() )
    {
      ...
      Project["Variables"]["DBTableVar1"]["Next"]();
    }

  • TestComplete uses different scripting properties and objects to provide a scripting interface to context menus and main menus of different vendors. For instance, if your tested application uses Developer Express menus, TestComplete uses the XtraMainMenu and XtraPopupMenu properties, if the tested application uses standard Win32 main and context menus, TestComplete uses the MainMenu and PopupMenu properties and so on.

    TestComplete determines the menu types automatically when creating a keyword test and uses these types to generate script code.

    If TestComplete fails to determine the menu types, it displays the Select Menu Type dialog asking you to specify the menu type that will be used to generate the script code for all undetermined menu type operations. If your test works with undetermined menus of different vendors, you may need to modify the generated script code manually or to use the Select Preferred Menu dialog to set the menu type for each undetermined operation manually.

    To call the Select Preferred Menu dialog, right-click the menu operation in the keyword test exposed in the Keyword Test editor and select the Select Preferred Type item from the ensuing context menu.

  • The Group operation is converted to a script comment.

  • If you export a keyword test to DelphiScript code, the While and For Loop operations are converted to the while scripting statements.

    If you export a keyword test to VBScript, JScript, Python, C++Script or C#Script code, the While Loop operation is converted to the while statement, and the For Loop operation is converted to the for statement.

See Also

Keyword Tests
Keyword Tests

Highlight search results