Search code examples
jqueryrobotframeworkjquery-templates

Understanding Robot Log (log.html) file construction


I am new to Robot framework and I want to customise the output of log.html generated upon the completion of test suites.

I have looked into the source code of log.html and found that the following line is responsible to add the test execution logs

addTestExecutionLog(topsuite);

The content of above function is follows,

function addTestExecutionLog(main) {
    $('body').append($('<h2>Test Execution Log</h2>'),
                     $.tmpl('suiteTemplate', main));
}

The log.html has jquery-template for suiteTemplate and testTemplate responsible for the addition of suite and testcases respectively.

Though testTemplate template is defined in the source code, I couldn't find where they are getting called. Because $.tmpl('suiteTemplate', main) , is calling only suiteTemplate.

Where the testTemplate for testcases are being used ?

testTemplate code inside log.html:

<script type="text/x-jquery-tmpl" id="testTemplate">


  <div id="${id}" class="test">
    <div class="element-header closed" onclick="toggleTest('${id}')">
      <div class="element-header-left" title="{{html fullName}}">
        <span class="elapsed" title="Elapsed time">${times.elapsedTime}</span>
        <span class="label ${status.toLowerCase()}">TEST</span>
        <span class="name">{{html name}}</span>
        {{if !isCritical}}(non-critical){{/if}}
      </div>
      <div class="element-header-right" onclick="stopPropagation(event)" title="">
        <a class="expand" title="Expand all" href="javascript:expandAll('${id}')"></a>
        <a class="collapse" title="Collapse all" href="javascript:collapseAll('${id}')"></a>
        <a class="link" title="Link to this test" href="#${id}" onclick="makeElementVisible('${id}')"></a>
      </div>
      <div class="element-header-toggle" title="Toggle visibility"></div>
    </div>
    <div class="children">
      <table class="metadata">
        <tr>
          <th>Full Name:</th>
          <td>{{html fullName}}</td>
        </tr>
        {{if doc()}}
        <tr>
          <th>Documentation:</th>
          <td class="doc">{{html doc()}}</td>
        </tr>
        {{/if}}
        {{if tags.length}}
        <tr>
          <th>Tags:</th>
          <td>{{html tags.join(', ')}}</td>
        </tr>
        {{/if}}
        {{if timeout}}
        <tr>
          <th>Timeout:</th>
          <td>{{html timeout}}</td>
        </tr>
        {{/if}}
        <tr>
          <th>Start / End / Elapsed:</th>
          <td>${times.startTime} / ${times.endTime} / ${times.elapsedTime}</td>
        </tr>
        <tr>
          <th>Status:</th>
          <td><span class="label ${status.toLowerCase()}">${status}</span> ({{if isCritical}}critical{{else}}non-critical{{/if}})</td>
        </tr>
        {{if message()}}
        <tr>
          <th>suri Message:</th>
          <td class="message">{{html message()}}</td>
        </tr>
        {{/if}}
      </table>
    </div>
  </div>

Solution

  • After debugging I have found that the following function is responsible for the same.

    function drawCallback(element, childElement, childrenNames) {
        return function () {
            util.map(childrenNames, function (childName) {                
                var children = element[childName + 's']();
                var template = childName + 'Template';
                util.map(children, function (child) {
                    $.tmpl(template, child).appendTo(childElement);
                });
            });
        }
    }
    

    The trace goes like this

    at drawCallback (log.html:571)
    at populateChildren (log.html:565)
    at expandElement (log.html:594)
    at expandRecursively (log.html:622)