Selenium + Java (12): + Jenkins automated Selenium test report messages sent

The last chapter: the Selenium + the Java (11): the Selenium + Jenkins automated continuous integration
in the last chapter where we finished how Jenkins association by run.bat batch script will Selenium +, achieve sustainable integrated automation testing.
In this chapter we continue to talk about "Auto Test Report e-mail" , and "time triggered build a" configuration.
Come On!

We were divided into two points:
First, automated testing report shows Jenkins in the
Second, automated testing and automated build mailing report


First, the report shows automated testing in Jenkins in

  1. Installation depends plugin
    we need to download htmlpublisher.hpi and testng-plugin.hpi Both Jenkins plugins.
    You can be downloaded at this site in: Jenkins plugin download .
    After the download is complete, our system of management jenkins, open the Plugin Manager:
    Here Insert Picture Description
    entering point "Advanced - upload plugin - select a file to upload" and then just downloaded both plug-ins upload up on the line. You can then restart it Jenkins.
    Restart: Use an administrator open a command line, in which typing NET STOP Jenkins , Enter, and then typing NET Start Jenkins , displayed on the screen until you can start the service is completed.

  2. After configuring the build operation
    to open our Jenkins project, click on the left side of the "Configure"
    Here Insert Picture Description
    click "to build after the operation", then select "Add to build after the operation", the lower figure is my take on a spiked red box turns up:
    Here Insert Picture Description
    we turn to talk about how to configure:
    Publish HTML Reports :
    Here Insert Picture Description
    As long as we fill in html files in their path to the directory where Selenium project in the first line, I look at the figures to fill in, I believe you can understand ~

    Publish TestNG Results
    Here Insert Picture Description
    and above almost fill testng-results.xml file storage path. Note slash direction, is "/" this.

Click Save. Then all of a sudden wish to restart.
At this point we return to Jenkins project home page, click on the left side of the building immediately, then we can complete the construction of the left, click "HTML Reports" to view test reports: the
Here Insert Picture Description
appearance of the report on the same and we set in the Selenium project in:
Here Insert Picture Description
at the same time we can also see "TestNG results" button on the left side of the Jenkins project page, on the right we can see the trend of the results of the sub-constructed trend:
Here Insert Picture Description
after completing the above steps, we have been able to get into the automated test report .
Next is our "test report and send messages automatically build" configuration to Keguan go down:


Second, automated testing and automated build mailing report

  1. Jenkins mail transmission function configured
    Jenkins mailing functional configuration, I can refer to this blog: Jenkins (03): Jenkins configured to automatically send messages and write very detailed.

    Here only code I personally think a little more simple and beautiful template, you can copy and paste into Editable Email Notification of Default Content column, you can do some optimization to modify their own code is as follows:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>${ENV, var="JOB_NAME"}-第${BUILD_NUMBER}次构建日志</title>
</head>
<style>
  * {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
  }

  html,
  body {
    height: 100%;
  }

  body {
    width: 800px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", SimSun, sans-serif;
    font-size: 14px;
    color: #1F2D3D;
    padding: 10px;
  }

  h1,
  h2 {
    padding: 10px 0;
  }
 h1 {
    color: #0000E3;
  }
  h2 {
    margin-top: 20px;
  }

  table {
    background: #f5f5f5;
    border-collapse: collapse;
    box-shadow: inset 0 1px 0 #fff;
    font-size: 12px;
    line-height: 24px;
    text-align: left;
  }

  th {
    background: linear-gradient(#777, #444);
    border-left: 1px solid #555;
    border-right: 1px solid #777;
    border-top: 1px solid #555;
    border-bottom: 1px solid #333;
    box-shadow: inset 0 1px 0 #999;
    color: #fff;
    font-weight: bold;
    padding: 10px 15px;
    position: relative;
    text-shadow: 0 1px 0 #000;
  }

  th:after {
    background: linear-gradient(rgba(255, 255, 255, 0), rgba(255, 255, 255, .08));
    content: '';
    display: block;
    height: 25%;
    left: 0;
    margin: 1px 0 0 0;
    position: absolute;
    top: 25%;
    width: 100%;
  }

  th:first-child {
    border-left: 1px solid #777;
    box-shadow: inset 1px 1px 0 #999;
  }

  th:last-child {
    box-shadow: inset -1px 1px 0 #999;
  }

  td {
    border-right: 1px solid #fff;
    border-left: 1px solid #e8e8e8;
    border-top: 1px solid #fff;
    border-bottom: 1px solid #e8e8e8;
    padding: 10px 15px;
    position: relative;
    transition: all 300ms;
  }

  td:first-child {
    box-shadow: inset 1px 0 0 #fff;
  }

  td:last-child {
    border-right: 1px solid #e8e8e8;
    box-shadow: inset -1px 0 0 #fff;
  }


  tr:last-of-type td {
    box-shadow: inset 0 -1px 0 #fff;
  }

  tr:last-of-type td:first-child {
    box-shadow: inset 1px -1px 0 #fff;
  }

  tr:last-of-type td:last-child {
    box-shadow: inset -1px -1px 0 #fff;
  }


  li {
    list-style: none;
    padding: 6px 0;
  }

  li > span {
    margin-right: 6px;
  }

  li > a {
    color: #58B7FF;
  }

  .tip {
    color: #bbb;
    padding: 10px 0;
  }
  .failed {
    color: #FF4949;
  }
  .passed {
    color: #13CE66;
  }
</style>


<body>
  <h1>测试结果 - ${BUILD_STATUS}</h1>
  <span class="tip">(本邮件是程序自动下发的,请勿回复,谢谢!!)</span>
  <h2>Test Summary</h2>
  <table>
    <thead>
      <tr>
        <th></th>
        <th>Total</th>
        <th>Failed</th>
        <th>Passed</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>数目</td>
        <td>${TEST_COUNTS}</td>
        <td class="failed">${TEST_COUNTS,var="fail"}</td>
        <td class="passed">${TEST_COUNTS,var="pass"}</td>
      </tr>
    </tbody>
  </table>

  <br>
  <h2>Failed Cases:</h2>
  <p class="failed">${FAILED_TESTS}</p>

</body>

</html>

(以上代码来自网络,有删改)

After completion of the configuration like this, we'll click on the building immediately, it gives the specified user receives an e-mail the test report, and I'm here to do a little modification, not yet optimized for good, for now, we can own optimize color and display items:
Here Insert Picture Description
2. Jenkins automatic timing build configuration
this function is very simple, fill in cron format directly in the "building triggers" section where you can let time regular build, or we can also "build trigger" module under some customized settings that you can look at yourself, well understood, I do not write it.
Here Insert Picture Description

Over


软件测试工程师一只,也在不断的学习阶段,平时的小经验不定期分享。
博主经验有限,若有不足,欢迎交流,共同改进~
愿与同在CSDN的你共同进步。

Guess you like

Origin blog.csdn.net/qq_36396763/article/details/94734754