了解机器人日志 (log.html) 文件构造

Understanding Robot Log (log.html) file construction

我是 Robot 框架的新手,我想自定义 log.html 在完成测试套件时生成的输出。

我查看了log.html的源代码,发现下面一行负责添加测试执行日志

addTestExecutionLog(topsuite);

以上函数内容如下,

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

log.html 有 jquery 模板用于 suiteTemplatetestTemplate 分别负责添加套件和测试用例。

虽然在源代码中定义了testTemplate模板,但我找不到它们在哪里被调用。因为 $.tmpl('suiteTemplate', main) 只调用 suiteTemplate

测试用例的 testTemplate 在哪里使用?

里面的testTemplate代码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>

经过调试我发现下面的函数也是负责的。

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);
            });
        });
    }
}

轨迹是这样的

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