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

  1. Take a backup of userdata/bin/testrunner.bat.
  2. 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.
  3. Copy config/reports/html/suites_list.xsl to userdata/config/reports/html/suites_list.xsl. (create folder if needed)
  4. Open userdata/config/reports/html/suites_list.xsl.
    1. 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>
    2. 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>
      customField and anotherCustomField were the names passed from testrunner.bat.
    3. 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-->
      info NOTE: Add as many entries as there are custom fields.
    4. 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 end
      and change it to
      // 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.
  5. Restart Sahi server and clear browser cache.
  6. Run testrunner.bat with your suite or script.
  7. Click on Logs from Dashboard. You should see the columns Custom Field and Another Custom Field appear with values.
  8. 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 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

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"]);