Most keyword test operations provide a number of customizable settings that control the operation's functionality. In the operation source code, these settings can be implemented as fields or parameters or their combination. The two major differences between fields and parameters are:
Parameters are accessible both by the operation code and by TestComplete and the users. Fields are “visible” only in the operation code. (However, user access to fields can be provided via custom forms displayed by the operation.)
Parameters can store Variant-compatible data types (numbers, strings, boolean values, and so on) as well as specific values, such as keyword test variables, last operation result, and others. Fields can only store Variant-compatible values.
In this tutorial, we will store the operation’s data in fields, because they are easier to implement and to manage in the operation code.
Our sample operation will contain the following fields:
||String. Holds the operation description to be displayed in the Description field of the Keyword Test editor.|
||Integer. Specifies the font color of a test log entry. Analog to the
||Integer. Specifies the background color of a test log entry. Analog to the
||Boolean. Specifies whether the text of a test log entry will be displayed in bold font. Analog to the
||Boolean. Specifies whether the text of a test log entry will be displayed in italic font. Analog to the
||Boolean. Specifies whether the text of a test log entry will be displayed underlined. Analog to the
||Boolean. Specifies whether the text of a test log entry will be displayed strikeout. Analog to the
||Boolean. Specifies whether the extended text of a test log message will be displayed in the HTML format or as plain text. Analog to the
To create operation fields, we need to add their definition to the description file:
Open the C:\My Extension Files\LogAttrExtension\description.xml file in your text or XML editor.
Add the following text to the file:
<?xml version = "1.0" encoding = "UTF-8"?>
<Category Name = "Keyword Test Operations">
<ScriptExtension Name = "Log Attributes Keyword Test Operation" Author = "SmartBear Software" Version = "1.0 test" HomePage = "smartbear.com">
<Description>Provides the Log Attributes keyword test operation.</Description>
<Script Name = "laCode.js">
<KDTOperation Name = "Log Attributes" Category = "Logging">
<!-- General properties -->
<Field Name = "Description" />
<!-- Log Attributes object properties -->
<Field Name = "FontColor" />
<Field Name = "BackColor" />
<Field Name = "Bold" />
<Field Name = "Italic" />
<Field Name = "Underline" />
<Field Name = "Strikeout" />
<Field Name = "PlainTextRemarks" />
Save the changes.
As you can see, to define methods of the object, we added the child
Data element to the
KDTOperation element and a number of child
Field elements to the
Data element. Let’s take a look at one of the
<Field Name = "Description" />
The Name attribute of this element specifies the field name. This name will be used to address the field in the operation’s code, so it must be a valid identifier in any scripting language supported by TestComplete. The easiest way to follow this rule is to use only letters (A..Z, a..z), digits (0..9) and underscores ( _ ) in the name and start it with a letter. The field name must also be unique among other fields of the operation.
The Field element may have the DefaultValue attribute holding the default value for the field. We will not use this attribute in this tutorial though. Instead, we will specify the default field values in the operation’s initialization routine, which we will create on the next step.
For details about elements and attributes that are used in the description files, see topics of the Script Extension Files section.