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 use testrunner.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:
REM SET CUSTOM_FIELDS=-customField customValue -anotherCustomField "another value"Change it to
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.xsltouserdata/config/reports/html/suites_list.xsl. (create folder if needed) -
Open userdata/config/reports/html/suites_list.xsl.
-
Custom field headers Search for
<!-- Custom Field header--><!--<td id="RowNo">Custom Field</td>-->and change it to
<!-- Custom Field headers--><td id="CustField1">Custom Field</td><td id="CustField2">Another Custom Field</td> -
Custom field values Search for
<!--Retrieve custom field value--><!--<td><xsl:if test="SUITEINFO != 'null'"><xsl:value-of select="util:fetchInfo(SUITEINFO, 'customField')" /></xsl:if></td>-->and change it to
<!--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>customFieldandanotherCustomFieldwere the names passed fromtestrunner.bat. -
Custom field filter headers Search for
<!-- 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-->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><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--> -
Custom field filtering code Search for
// custom field filtering enable starts/*case "custom_field_flt":return (" SUITEREPORTS.SUITEINFO LIKE '%customField=%" + ele.value + "%'")*/// custom field filtering enable endand change it to
// custom field filtering enable startscase "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
-
-
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 FieldandAnother Custom Fieldappear 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
Section titled “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 for userdata/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
Section titled “How to access custom fields in a test script”The custom attributes that are passed as CUSTOM_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"]);
