How to show custom fields in reports
Here are the steps to get custom fields to show up in Reports. Note that these steps require you to usetestrunner.bat
.
These steps just illustrate the addition of two indicative custom fields. You can add/modify/delete the custom fields as you see fit.
Suppose you need two custom fields:
customField
and anotherCustomField
-
Take a backup of
userdata/bin/testrunner.bat
. -
Open
testrunner.bat
.
You will see a line like:
Change it toREM SET CUSTOM_FIELDS=-customField customValue -anotherCustomField "another value"
SET CUSTOM_FIELDS=-customField customValue -anotherCustomField "another value"
"another value"
is in double quotes since there is a space in the string. -
Copy
config/reports/html/suites_list.xsl
touserdata/config/reports/html/suites_list.xsl
. (create folder if needed) -
Open userdata/config/reports/html/suites_list.xsl.
-
Custom field headers
Search for
and change it to<!-- Custom Field header--> <!--<td id="RowNo">Custom Field</td>-->
<!-- Custom Field headers--> <td id="CustField1">Custom Field</td> <td id="CustField2">Another Custom Field</td>
-
Custom field values
Search for
and change it to<!--Retrieve custom field value--> <!--<td> <xsl:if test="SUITEINFO != 'null'"> <xsl:value-of select="util:fetchInfo(SUITEINFO, 'customField')" /> </xsl:if> </td>-->
<!--Retrieve custom field values--> <td> <xsl:if test="SUITEINFO != 'null'"> <xsl:value-of select="util:fetchInfo(SUITEINFO, 'customField')" /> </xsl:if> </td> <td> <xsl:if test="SUITEINFO != 'null'"> <xsl:value-of select="util:fetchInfo(SUITEINFO, 'anotherCustomField')" /> </xsl:if> </td>
customField
andanotherCustomField
were the names passed fromtestrunner.bat
. -
Custom field filter headers
Search for
and change it to<!-- custom field filtering part start--> <!--<td> <span style="display:inline-block;height:11px;width:1px;"></span> <input type="text" class="flt" name ="custom_field_flt" id="custom_field_flt" onkeydown="pressEnter(event)"></input> </td>--> <!-- custom field filtering part end-->
<!-- custom field filtering part start--> <td> <span style="display:inline-block;height:11px;width:1px;"></span> <input type="text" class="flt" name ="custom_field_flt" id="custom_field_flt" onkeydown="pressEnter(event)"></input> </td> <td> <span style="display:inline-block;height:11px;width:1px;"></span> <input type="text" class="flt" name ="another_custom_field_flt" id="another_custom_field_flt" onkeydown="pressEnter(event)"></input> </td> <!-- custom field filtering part end-->
info NOTE: Add as many entries as there are custom fields. -
Custom field filtering code
Search for
and change it to// custom field filtering enable starts /* case "custom_field_flt": return (" SUITEREPORTS.SUITEINFO LIKE '%customField=%" + ele.value + "%'") */ // custom field filtering enable end
// custom field filtering enable starts case "custom_field_flt": return (" SUITEREPORTS.SUITEINFO LIKE '%customField=%" + ele.value + "%'") case "another_custom_field_flt": return (" SUITEREPORTS.SUITEINFO LIKE '%anotherCustomField=%" + ele.value + "%'") // custom field filtering enable end
info NOTE: The constants "custom_field_flt", "another_custom_field_flt" should match what was defined above in Custom field filter headers.
-
Custom field headers
Search for
- Restart Sahi server and clear browser cache.
- Run testrunner.bat with your suite or script.
-
Click on Logs from Dashboard. You should see the columns
Custom Field
andAnother Custom Field
appear with values.
As mentioned earlier, change/add/remove the custom field names and values as you see fit.
How to show custom fields in Excel reports
To view the custom fields in the index file of the excel report, repeat all the steps mentioned previously foruserdata/config/reports/html/suites_list.xsl
in userdata/config/reports/excel/suites_list.xsl
.
You should see the custom fields and values in the generated
index.xls
How to access custom fields in a test script
The custom attributes that are passed asCUSTOM_FIELDS
through testrunner.bat
can be accessed in the scripts using _suiteInfo()
.
Access these variables in script as:
var $suiteInfo = _suiteInfo();
_log($suiteInfo["customField"]);
_log($suiteInfo["anotherCustomField"]);
Another example:
Let us say
CUSTOM_FIELDS
are specified as
SET CUSTOM_FIELDS=-company "Tyto" -user "john" -javah "%JAVA_HOME%"
Note that these custom fields are indicative. You can pass any variable according to your need. Here JAVA_HOME is a system variable.
Access these variables in script as:
var $suiteInfo = _suiteInfo();
_log($suiteInfo["company"]);
_log($suiteInfo["user"]);
_log($suiteInfo["javah"]);