Come let us explore together…

Posts tagged ‘Code Template’

Extending Code Template feature in TestComplete


We have a feature in TestComplete to store code templates and use it whenever we need while coding with a keyboard short-cut CTRL+ J.

Advantages:

  • Supports all TestComplete script languages
  • Has templates of different statements, declarations from the language
  • Can be accessed with a keyboard short cut
  • Can avoid typing and declaration errors
  • Can speed up the coding
  • Templates can be exported and imported

Apart from these advantages we can add our generic reusable code in to the templates…

Now this is where we can play with TestComplete

Based on the project implementation we may need to repeat same set of code across different script units and modules.

Best example is exception handling,
We need to handle the exception +
We may log the error details in the log file +
We may take the screen shot of the exception/error

The simplest way to handle this scenario is write once in any of the function and copy + paste wherever is needed.

Alternatively when you use Code Template of TestComplete, you can be more innovative and productive.

Steps to follow :

  1. Open the Code Template by selecting Tools -> Option -> Panels folder -> Code Templates
  2. In the right panel, select the language from the drop down you want to add the templates
  3. Now you can see the default templates in the listview for the selected languages
  4. Click Add which will add new entry in listview
  5. Give “Name” and “Description” for the template for the new entry in the listview
  6. In the text area below the listview enter your code
  7. Click “ok” to save the template

Finished !!! You have just now added your own template…

While coding, just enter CTRL + J to get the list of templates available and select your template to be populated inside the code editor.

Points to be noted :

  • The pop-up list of templates on pressing CTRL+J will be based on your language selection in the project. So be careful under which language you are adding the template.
  • Make sure the template is generic so that you can use it globally.
  • Make sure the template is error free though you can modify or delete at later point of time.

Hope there is 101 ways to automate…

Thanks & Regards,
Giri Prasad