On this step, we will create the code that will be executed by the operation during the test run. This procedure consists of two substeps:
Writing the routine that performs the desired tasks.
Subscribing to the operation’s
OnExecuteevent in the description file and specifying the routine as the event handler.
We will start with writing the routine code. As you may remember, our custom Log Attributes operation needs to create the
LogAttributes object that contains the font and color settings for test log entries, initialize object properties with values stored in the operation, and return this object as the operation result. Below is a function that performs these tasks. Open the laCode.js file in the Code Editor and append the following code to it:
var attr = Log.CreateNewAttributes();
attr.FontColor = Data.FontColor;
attr.BackColor = Data.BackColor;
attr.Bold = Data.Bold;
attr.Italic = Data.Italic;
attr.Underline = Data.Underline;
attr.StrikeOut = Data.Strikeout;
attr.PlainTextRemarks = Data.PlainTextRemarks;
Like the initialization routine, the
LogAttr_OnExecute function has the Data argument that provides access to the operation’s fields. This object contains properties that correspond to the operation’s fields and whose names coincide with the field names. Note, that the Data object is operation-specific, that is, it holds values specific for the operation instance being executed.
Now add information about the
LogAttr_OnExecute routine to the description file:
Open the C:\My Extension Files\LogAttrExtension\description.xml file in your test 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" />
<Event Name="OnCreate" Routine="LogAttr_OnCreate"/>
<Event Name="OnExecute" Routine="LogAttr_OnExecute"/>
Save the changes.
You may notice that we have added another Event element, which defines a handler for the operation’s
OnExecute event. This event is raised when the operation is executed during the test run; the event handler being the script routine to run. Thus, we specify the created
LogAttr_OnExecute routine as the
OnExecute event handler.