Use code snippets and templates
Relevant for: GUI actions, scripted GUI components, and function libraries
This task describes how to insert predesigned code snippets or blocks of text into your document, as well as how to manage templates for such snippets in the Code Templates Pane.
Insert code snippets into your document in the Editor
Create or open an action, scripted GUI component,or function library.
(If you are editing a GUI action or scripted GUI component, open it in the Editor.)
Place your cursor at the point in the document that you want to insert the code snippet and then enter text as described in the following table.
If you enter:
UFT does the following:
The keyword for a code snippet listed in the Edit > Code Snippet menu
Inserts the first VBScript snippet defined for the keyword you entered, as listed in the Edit > Code Snippet menu.
The keyword for a code template defined in the Options dialog box
Inserts the code snippet defined in the relevant template in the Code Templates Pane.
If multiple templates are defined for the keyword you entered, the first template in the list is inserted.
Part of a code template keyword
Displays a list of the code snippets and templates whose keywords match the characters you entered.
The list includes the static VBScript snippets listed in the Edit > Code Snippet menu, as well as the code templates defined for the relevant file type in the Code Templates Pane.
In the drop-down list, browse to the keyword for the template you want to insert, and press Tab to insert its snippet into your document.
Modify an existing list of code templates
Open the Code Templates Pane.
From the File Types drop-down list, select the item associated with the list of templates you want to modify. The table lists all code templates defined for the selected file type or types.
To edit the file types associated with the selected list, click Edit List. In the Edit List dialog box, enter the file type or types that should be supported by the selected list, separated by semicolons (;).
To edit the list of code templates, select the table row for the code template you want to modify and do one of the following:
Add a new template in the list: Click the empty space below the last row in the table, above the syntax area.
Edit the template name: Double-click the cell in the Template column, and update the name.
Edit the keyword: Double-click the cell in the Keyword column, and update the keyword. The keyword is the text that you enter in the Editor to insert the template.
Edit the code template description: Double-click the cell in the Description column and update the description text.
Edit the code syntax inserted into your code: Click inside the code syntax area below the table and update the code.
Note: Note that changes made here do not affect the code snippets available from the Edit > Code Snippet menu, which are static and cannot be modified.