0

html-testRunner 在所有测试完成后创建测试报告。文本打印在报告中,但没有控制台中的新行。

如何在每个打印文本后换行?可以在 report_template.html 文件中完成,还是应该在代码中完成?在我的 Python 代码中进行了尝试\n\r\n但仍然没有任何变化。

这是 html-testRunner 报告的结果 在此处输入图像描述

这是来自生成的报告 .html 文件

                        <tr style="display:none;">
                            <td class="col-xs-9" colspan="3"><p>Login successfull & home page successfully loaded
Element ( course-form-form:add-partner-course-partnerTrainings-edit ) is visible, moving further
Element ( ui-dialog ) disappeared, moving further
Element ( courseEditForm:delete ) is visible, moving further
Element ( j_idt47 ) is visible, moving further
Element ( courseEditForm:return ) is visible, moving further
Element ( course-form-form:add-partner-course-partnerTrainings-edit ) is visible, moving further
</p>
                            </td>
                        </tr>

这就是report_template.html

<!DOCTYPE html>
<html>
<head>
    <title>{{ title }}</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
</head>
<body>
    <div class="container">
        <div class="row">
            <div class="col-xs-12">
                <h2 class="text-capitalize">{{ title }}</h2>
                <p class='attribute'><strong>Start Time: </strong>{{ header_info.start_time.strftime("%Y-%m-%d %H:%M:%S") }}</p>
                <p class='attribute'><strong>Duration: </strong>{{ header_info.status.duration }}</p>
                <p class='attribute'><strong>Summary: </strong>Total: {{ header_info.status.total }}, Pass: {{ header_info.status.success }}{% if header_info.status.failure %}, Fail: {{ header_info.status.failure }}{% endif %}{% if header_info.status.error %}, Error: {{ header_info.status.error }}{% endif %}{% if header_info.status.skip %}, Skip: {{ header_info.status.skip }}{% endif %}</p>
            </div>
        </div>
        {%- for test_case_name, tests_results in all_results.items() %}
        {%- if tests_results %}
        <div class="row">
            <div class="col-xs-12 col-sm-10 col-md-10">
                <table class='table table-hover table-responsive'>
                    <thead>
                        <tr>
                            <th>{{ test_case_name }}</th>
                            <th>Status</th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
                        {%- for test_case in tests_results %}
                        {%- if not test_case.subtests is defined %}
                        <tr class='{{ status_tags[test_case.outcome] }}'>
                            <td class="col-xs-10">{{ test_case.test_id.split(".")[-1] }}</td>
                            <td class="col-xs-1">
                                <span class="label label-{{ status_tags[test_case.outcome] }}" style="display:block;width:40px;">
                                    {%- if test_case.outcome == test_case.SUCCESS -%}
                                        Pass
                                    {%- elif test_case.outcome == test_case.SKIP -%}
                                        Skip
                                    {%- elif test_case.outcome == test_case.FAILURE -%}
                                        Fail
                                    {%- else -%}
                                        Error
                                    {%- endif -%}
                                </span>
                            </td>
                            <td class="col-xs-1">
                                {%- if (test_case.stdout or test_case.err) %}
                                <button class="btn btn-default btn-xs">View</button>
                                {%- endif %}
                            </td>
                        </tr>
                        {%- if (test_case.stdout or test_case.err or test_case.err) and test_case.outcome != test_case.SKIP %}
                        <tr style="display:none;">
                            <td class="col-xs-9" colspan="3">
                                {%- if test_case.stdout %}<p>{{ test_case.stdout }}</p>{% endif %}
                                {%- if test_case.err %}<p style="color:maroon;">{{ test_case.err[0].__name__ }}: {{ test_case.err[1] }}</p>{% endif %}
                                {%- if test_case.err %}<p style="color:maroon;">{{ test_case.test_exception_info }}</p>{% endif %}
                            </td>
                        </tr>
                        {%- endif %}
                        {%- if (test_case.stdout or test_case.err or test_case.err) and test_case.outcome == test_case.SKIP %}
                        <tr style="display:none;">
                            <td class="col-xs-9" colspan="3">
                                {%- if test_case.stdout %}<p>{{ test_case.stdout }}</p>{% endif %}
                                {%- if test_case.err %}<p style="color:maroon;">{{ test_case.err }}</p>{% endif %}
                            </td>
                        </tr>
                        {%- endif %}
                        {%- else %}
                        <tr class='{{ status_tags[test_case.outcome] }}'>
                            <td class="col-xs-10">{{ test_case.test_id.split(".")[-1] }}</td>
                            <td class="col-xs-1">
                                <span class="label label-{{ status_tags[test_case.outcome] }}" style="display:block;width:40px;">
                                    {%- if test_case.outcome == test_case.SUCCESS -%}
                                        Pass
                                    {%- else -%}
                                        Fail
                                    {%- endif -%}
                                </span>
                            </td>
                            <td class="col-xs-1">
                                {%- if test_case.subtests %}
                                <button class="btn btn-default btn-xs">View</button>
                                {%- endif %}
                            </td>
                        </tr>
                        {%- if test_case.subtests %}
                        <tr style="display:none;">
                            <td colspan="3">

                                <table class='table table-hover table-responsive'>
                                    <tbody>
                                        {%- for subtest in test_case.subtests %}
                                        <tr class='{{ status_tags[subtest.outcome] }}'>
                                            <td class="col-xs-10">{{ subtest.test_id.split(".")[-1] }}</td>
                                            <td class="col-xs-1">
                                                <span class="label label-{{ status_tags[subtest.outcome] }}" style="display:block;width:40px;">
                                                {%- if subtest.outcome == subtest.SUCCESS -%}
                                                    Pass
                                                {%- else -%}
                                                    Fail
                                                {%- endif -%}
                                                </span>
                                            </td>
                                            <td class="col-xs-1">
                                                {%- if subtest.err %}
                                                <button class="btn btn-default btn-xs">View</button>
                                                {%- endif %}
                                            </td>
                                        </tr>
                                        {%- if subtest.err or subtest.err %}
                                        <tr style="display:none;">
                                            <td class="col-xs-9" colspan="3">
                                                {%- if subtest.err %}<p style="color:maroon;">{{ subtest.err[0].__name__ }}: {{ subtest.err[1] }}</p>{% endif %}
                                                {%- if subtest.err %}<p style="color:maroon;">{{ subtest.test_exception_info }}</p>{% endif %}
                                            </td>
                                        </tr>
                                        {%- endif %}
                                        {% endfor %}
                                    </tbody>
                                </table>
                            </td>
                        </tr>
                        {%- endif %}
                        {%- endif %}
                        {%- endfor %}
                        <tr>
                            <td colspan="3">
                                Total: {{ summaries[test_case_name].total }}, Pass: {{ summaries[test_case_name].success }}{% if summaries[test_case_name].failure %}, Fail: {{ summaries[test_case_name].failure }}{% endif %}{% if summaries[test_case_name].error %}, Error: {{ summaries[test_case_name].error }}{% endif %}{% if summaries[test_case_name].skip %}, Skip: {{ summaries[test_case_name].skip }}{% endif %} -- Duration: {{ summaries[test_case_name].duration }}
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
        {%- endif %}
        {%- endfor %}
    </div>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $('td').on('click', '.btn', function(e){
                e.preventDefault();
                e.stopImmediatePropagation();
                var $this = $(this);
                var $nextRow = $this.closest('tr').next('tr');
                $nextRow.slideToggle("fast");
                $this.text(function(i, text){
                    if (text === 'View') {
                        return 'Hide';
                    } else {
                        return 'View';
                    };
                });
            });
        });
    </script>
</body>
</html
4

2 回答 2

1

尝试在您的<head>标签中添加以下代码:

<style> 
    p {  
        white-space: pre-line; 
    }
</style> 

当你的<p>标签被x斧头溢出时,它会在下面的一行或多行上打印他的其余内容。

于 2020-08-31T13:15:38.113 回答
0

我试图通过输入 HTML 标签而不是 pythonish '\n' 来操作打印命令。如果将 HTML 段落标记 <p> 和 </p> 之间的字符串作为字符串括起来,则会在新行中获得封闭的数据。在测试用例的某处输入这样的数据对我有用:

print('<p>' + string1_for_documenting + '</p>')
print('<p>' + string2_for_documenting + '</p>')

但我无法管理较短的 <BR> 之类的东西

print(string1_for_documenting + '<BR>')
于 2021-03-18T10:27:29.503 回答