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:
Open the project.
Right-click the name of the desired keyword test in the Project Explorer panel.
Select Convert to Script from the ensuing context menu.
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.dlgOpen.OpenFile("C:\MyFile.txt", "Text Documents (*.txt)");
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
Resetmethod (it initializes the variable’s data iterator). The following statements is a loop that iterates through data rows:
while(! Project.Variables.DBTableVar1.IsEOF() )
while not Project.Variables.DBTableVar1.IsEOF():
While Not Project.Variables.DBTableVar1.IsEOF
while not Project.Variables.DBTableVar1.IsEOF() do
while(! Project["Variables"]["DBTableVar1"]["IsEOF"]() )
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
XtraPopupMenuproperties, if the tested application uses standard Win32 main and context menus, TestComplete uses the
PopupMenuproperties 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
If you export a keyword test to VBScript, JScript, Python, C++Script or C#Script code, the While Loop operation is converted to the
whilestatement, and the For Loop operation is converted to the