• 试试:
    set timeout 120
    set password [lindex $argv 0]

    expect {
    "(yes/no)?" { send "yes\r"; exp_continue}
    "password:" { send "$password\r" }
    }

    expect eof

    建议debug,吐出稍微详细一些的stdout、stderr

  • Summary一下Allure Summary Email using Email-ext Jenkins Plugin,具体操作如下:
    Jenkins在发送邮件时,在设置E-mail触发里,有一个Content,在Content对应地方,填写如下内容:${SCRIPT, template="allure-report.groovy"}, 如下图所示:

    allure-report.groovy脚本放在哪儿呢? 放在$JENKINS_HOME/email-templates目录下,我当前Jenkins环境存放路径如下:

    jenkins@ubuntu-16:~/email-templates$ ls -l
    total 20
    -rw-rw-r-- 1 jenkins jenkins 5697 Mar 27 16:30 allure-report.groovy
    -rw-rw-r-- 1 jenkins jenkins 10764 Jun 17 2019 email-template.groovy
    jenkins@ubuntu-16:~/email-templates$ pwd
    /var/lib/jenkins/email-templates
    jenkins@ubuntu-16:~/email-templates$

    email-template.groovy应该是Robot Framework某个插件生成的(我猜测的,vi里面看到很多关于RF的,正好当前Jenkins里也有RF的project在跑)。

    allure-report.groovy脚本内容如下:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <style type="text/css">
    /*base css*/
    body
    {
    margin: 0px;
    padding: 15px;
    }

    body, td, th
    {
    font-family: "Lucida Grande", "Lucida Sans Unicode", Helvetica, Arial, Tahoma, sans-serif;
    font-size: 10pt;
    }

    th
    {
    text-align: left;
    }

    h1
    {
    margin-top: 0px;
    }
    a
    {
    color:#4a72af
    }
    /*div styles*/

    .status{background-color:<%=
    build.result.toString() == "SUCCESS" ? 'green' : 'red' %>;font-size:28px;font-weight:bold;color:white;width:720px;height:52px;margin-bottom:18px;text-align:center;vertical-align:middle;border-collapse:collapse;background-repeat:no-repeat}
    .status .info{color:white!important;text-shadow:0 -1px 0 rgba(0,0,0,0.3);font-size:32px;line-height:36px;padding:8px 0}
    </style>
    <body>
    <div class="content round_border">
    <div class="
    status">
    <p class="
    info">pytest automation build <%= build.result.toString().toLowerCase() %></p>
    </div>
    <!-- status -->
    <table>
    <tbody>
    <tr>
    <th>Project:</th>
    <td>${project.name}</td>
    </tr>
    <tr>
    <th>Build ${build.displayName}:</th>
    <td><a
    href="
    ${rooturl}${build.url}">${rooturl}${build.url}</a></td>
    </tr>
    <tr>
    <th>Product Version:</th>
    <td><%=build.environment['PRODUCT_VERSION']%></td>
    </tr>
    <tr>
    <th>Date of build:</th>
    <td>${it.timestampString}</td>
    </tr>
    <tr>
    <th>Build duration:</th>
    <td>${build.durationString}</td>
    </tr>
    <tr>
    <td colspan="
    2">&nbsp;</td>
    </tr>
    </tbody>

    </table>
    <!-- main -->
    <% def artifacts = build.artifacts
    if(artifacts != null && artifacts.size() > 0) { %>

    <b>Build Artifacts:</b>
    <ul>
    <% artifacts.each() { f -> %>
    <li><a href="
    ${rooturl}${build.url}artifact/${f}">${f}</a></li>
    <% } %>
    </ul>
    <% } %>
    <!-- artifacts -->

    <%
    lastAllureReportBuildAction = build.getAction(ru.yandex.qatools.allure.jenkins.AllureReportBuildAction.class)
    lastAllureBuildAction = build.getAction(ru.yandex.qatools.allure.jenkins.AllureBuildAction.class)

    if (lastAllureReportBuildAction) {
    allureResultsUrl = "
    ${rooturl}${build.url}allure"
    allureLastBuildSuccessRate = String.format("
    %.2f", lastAllureReportBuildAction.getPassedCount() * 100f / lastAllureReportBuildAction.getTotalCount())
    }
    %>
    <% if (lastAllureReportBuildAction) { %>
    <h2>Allure Results</h2>
    <table>
    <tbody>
    <tr>
    <th>Total Allure tests run:</th>
    <td><a href="
    ${allureResultsUrl}">${lastAllureReportBuildAction.getTotalCount()}</a></td>
    </tr>
    <tr>
    <th><span style="
    color: #000000; background-color: #ffff00;">Failed:</span></th>
    <td><span style="
    color: #000000; background-color: #ffff00;">${lastAllureReportBuildAction.getFailedCount()} </span></td>
    </tr>
    <tr>
    <th><span style="
    color: #000000; background-color: #008000;">Passed:</span></th>
    <td><span style="
    color: #000000; background-color: #008000;">${lastAllureReportBuildAction.getPassedCount()} </span></td>
    </tr>
    <tr>
    <th><span style="
    color: #000000; background-color: #3366ff;">Skipped:</span></th>
    <td><span style="
    color: #000000; background-color: #3366ff;">${lastAllureReportBuildAction.getSkipCount()} </span></td>
    </tr>
    <tr>
    <th><span style="
    color: #000000; background-color: #ff0000;">Broken:</span></th>
    <td><span style="
    color: #000000; background-color: #ff0000;">${lastAllureReportBuildAction.getBrokenCount()} </span></td>
    </tr>
    <tr>
    <th>Success rate: </th>
    <td>${allureLastBuildSuccessRate}% </td>
    </tr>

    </tbody>
    </table>
    <img lazymap="
    ${allureResultsUrl}/graphMap" src="${allureResultsUrl}/graph" alt="Allure results trend"/>
    <% } %>
    <!-- content -->
    <!-- bottom message -->
    </body>

    注意:
    脚本内容中有一个PRODUCT_VERSION变量,这个是我私有变量,可以通过‘Inject environment vairables’来定义:

    最终邮件效果图如下:

  • Jenkins发的Email是含有具体的测试结果的,展示了build环境信息以及total、pass、fail、broken等数据,但我更想在这些数据之下,把Jenkins对应build的Allure所展示的web界面信息,也体现在邮件里

  • 放弃这种思路,邮箱基于安全考虑(防止挂马),不支持mail中展示iframe

  • 我以为用iframe能解决,单独打开jenkins 里的email(拷贝内容后命名为show_allure_in_jenkins_mail.html)是OK的,但是从邮件(使用过Outlook和foxmail)打开,就不展示了,对应的iframe显示一片空白区域。。。

  • 问题已经,在pytest.ini文件中,增加了log_format && log_data_format
    log_format = %(asctime)s [%(filename)s:%(lineno)-4s] [%(levelname)5s] %(message)s
    log_date_format=%Y-%m-%d %H:%M:%S

  • 没有单独写一个log模块,使用的pytest.ini,在里面定义了log格式:

    [pytest]
    log_cli = true
    log_level = NOTSET
    log_file = ../report/xxx.log
    log_file_format = [%(filename)s:%(lineno)-4s] [%(levelname)5s] %(asctime)s %(message)s
    log_file_date_format=%Y-%m-%d %H:%M:%S
    log_cli_level = INFO
    log_cli_format = %(asctime)s [%(filename)s:%(lineno)-4s] [%(levelname)5s] %(message)s
    log_cli_date_format=%Y-%m-%d %H:%M:%S

    没有达到预期的效果。。。。

  • 估计更多的可能是使用上的问题,解释如下:
    allure使用了两种方式来渲染页面,分别是allure open 和 allure serve。前者用于在本地渲染和查看结果,后者用于在本地渲染后对外展示结果,所以要想查看有数据的html内容,需要使用allure open。运行命令 allure open allure-report即可自动打开浏览器(耐心等待一下)展示渲染好的结果,其中allure-report为allure generate生成的结果所在目录。

  • 使用Fiddler吧

  • 我的测试报告,python的,应该美观点


蹉跎错,消磨过,最是光阴化浮沫