Selenium基本使用测试报告生成

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Selenium基本使用测试报告生成相关的知识,希望对你有一定的参考价值。

报告目录结构

 

Reporter根目录

      |

      |-------------LOGS 

      |                                                |

      |                                         2017-09-21_12-34-39   每次按日期时间动态生成报告目录 

      |                                                |

      |                                             Image   用于存储每个功能点,验证截图,这个会显示在报告上    

      |

      |--- LOG.XSLT  #报告样式及格式

 

 

1、使用xslt,来设定样式

<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
 <html>
 <Head>
        <style type="text/css">

          body {
          background:#fff;
          margin:0;
          padding:40px 20px;
          font-family: "Arial", Arial, Sans-serif;
          font-size: 16px;
          color:#000;
          }

          table {
          margin:5px 5px 0;
          border:0px solid #222;
          font-size: 0.8em;
          }

          td {
          margin:5px 5px 0;
          padding:10px 10px 10px 10px;
          vertical-align:text-top;
          border:1px solid #222;
          border-width:1px 1px 1px 1px;
          }

          td.light {
          border:0px solid #222;
          }

          td.number {
          text-align:right;
          }

          td.status {
          text-align:right;
          vertical-align:text-bottom;
          }

        </style>


 </Head>
 <body>
   <!--OVER RESULT -->
   <xsl:variable name="OVER_STATUS" select="REPORT/OVER_STATUS"/>
   <xsl:variable name="STATUS" select="REPORT/LOG_ENTRY/STATUS"/>



   <h2>自动化测试执行报告</h2>
   <!--table -->
   <table border="1">
     <!--all result value-->
     <tr bgcolor="white" height = "35">
        <td>Overall Test Result</td>
        <td><xsl:value-of select="$OVER_STATUS"/></td>
        <td colspan="8"> </td>
     </tr>

     <tr bgcolor="#D8BFD9" height = "35">
       <th>Step</th>
       <th>Execute Time</th>
       <th>Step Result</th>
       <th>Description</th>
       <th>Step Description</th>
       <th>Action</th>
       <th>Index</th>
       <th>Element</th>
       <th>Value</th>
       <th>Expected Results </th>
     </tr>

       <!--select font color -->
       <xsl:variable name="fontColor">
           <xsl:choose>
               <xsl:when test="$STATUS = FAILED or $STATUS = PASSED">
                   <xsl:text>white</xsl:text>
               </xsl:when>
               <xsl:otherwise>black</xsl:otherwise>
           </xsl:choose>
       </xsl:variable>


          <!-- Compute the background color according to the overall test result -->
       <xsl:variable name="StatusBackgroundColor">
            <xsl:choose>
              <xsl:when test="$STATUS = \'FAILED\'">
                <!--<xsl:text>rgb(158, 48, 57)</xsl:text> -->
                <xsl:text>rgb(255, 40, 38)</xsl:text>
              </xsl:when>
              <xsl:when test="$STATUS = \'WARNING\'">
                <xsl:text>rgb(132, 76, 84)</xsl:text>
              </xsl:when>
              <xsl:when test="$STATUS = \'PASSED\'">
                <xsl:text>rgb(121, 180, 112)</xsl:text>
              </xsl:when>
              <xsl:when test="$STATUS = \'DONE\'">
                <xsl:text>white</xsl:text>
              </xsl:when>
              <xsl:when test="$STATUS = \'INFO\'">
                <xsl:text>white</xsl:text>
              </xsl:when>
              <xsl:otherwise>
                <xsl:text>white</xsl:text>
              </xsl:otherwise>
            </xsl:choose>
       </xsl:variable>


       <!--log entry-->
       <xsl:for-each select = "REPORT/LOG_ENTRY">

           <tr>
               <td><xsl:value-of select="STEP"/></td>
               <td><xsl:value-of select="EXECUTION_TIME"/></td>
               <td bgcolor="{$StatusBackgroundColor}"><xsl:value-of select="STEP_RESULT"/></td>
               <td><xsl:value-of select="DESCRIPTION"/></td>
               <td><xsl:value-of select="STEP_DESCRIPTION"/></td>
               <td><xsl:value-of select="ACTION"/></td>
               <td><xsl:value-of select="INDEX"/></td>
               <td><xsl:value-of select="ELEMENT"/></td>
               <td><xsl:value-of select="VALUE"/></td>
               <td><xsl:value-of select="EXPECTED_RESULTS"/></td>
           </tr>
           <!--    Store image path    -->
           <xsl:variable name="Image">
                <xsl:value-of select="IMAGE_PATH"/>
           </xsl:variable>
           <!--  If XML contains an image path then display it according to the following -->
           <xsl:choose>
               <xsl:when test="normalize-space($Image)!=\'\'">
                  <!-- Comment the Next line to Stop showing embedded image in log  and change the width number to make image size change-->
                  <tr>
                     <td colspan="10">
                       <a href="{$Image}" target="_blank" >
                         <img src="{$Image}" width="300"></img>
                       </a>
                     </td>
                  </tr>
               </xsl:when>
           </xsl:choose>
       </xsl:for-each>

       <tr bgcolor="white">
           <font color="{$fontColor}">
               <td colspan="10">Overall Test Result:  <xsl:value-of select="$OVER_STATUS"/></td>
           </font>
       </tr>
   </table>
 </body>
 </html>
</xsl:template>
</xsl:stylesheet>

 

2、生成xml报告(python代码会自动生成)

<?xml version="1.0" encoding="utf-8"?>
    <?xml-stylesheet href="../../LOG.XSLT" type="text/xsl"?>
    <REPORT>
        <OVER_STATUS>PASSED</OVER_STATUS>
        <LOG_ENTRY>
            <STATUS>PASSED</STATUS>
            <STEP>2</STEP>
            <EXECUTION_TIME>2017-09-21_12-34-47</EXECUTION_TIME>
            <STEP_RESULT>PASSED</STEP_RESULT>
            <DESCRIPTION>普惠家登录</DESCRIPTION>
            <STEP_DESCRIPTION>输入\'用户名\'</STEP_DESCRIPTION>
            <ACTION>input</ACTION>
            <INDEX>By.XPATH</INDEX>
            <ELEMENT>//Input[@id=\'userName\']</ELEMENT>
            <VALUE>msh195</VALUE>
            <EXPECTED_RESULTS></EXPECTED_RESULTS>
            <IMAGE_PATH></IMAGE_PATH>
        </LOG_ENTRY>
        <LOG_ENTRY>
            <STATUS>PASSED</STATUS>
            <STEP>3</STEP>
            <EXECUTION_TIME>2017-09-21_12-34-48</EXECUTION_TIME>
            <STEP_RESULT>PASSED</STEP_RESULT>
            <DESCRIPTION></DESCRIPTION>
            <STEP_DESCRIPTION>输入\'密码\'</STEP_DESCRIPTION>
            <ACTION>input</ACTION>
            <INDEX>By.XPATH</INDEX>
            <ELEMENT>//Input[@id=\'password\']</ELEMENT>
            <VALUE>112233</VALUE>
            <EXPECTED_RESULTS></EXPECTED_RESULTS>
            <IMAGE_PATH></IMAGE_PATH>
        </LOG_ENTRY>
        <LOG_ENTRY>
            <STATUS>PASSED</STATUS>
            <STEP>4</STEP>
            <EXECUTION_TIME>2017-09-21_12-34-56</EXECUTION_TIME>
            <STEP_RESULT>PASSED</STEP_RESULT>
            <DESCRIPTION></DESCRIPTION>
            <STEP_DESCRIPTION>单击\'立即登录\'</STEP_DESCRIPTION>
            <ACTION>click</ACTION>
            <INDEX>By.LINK_TEXT</INDEX>
            <ELEMENT>立即登录</ELEMENT>
            <VALUE></VALUE>
            <EXPECTED_RESULTS></EXPECTED_RESULTS>
            <IMAGE_PATH></IMAGE_PATH>
        </LOG_ENTRY>
        <LOG_ENTRY>
            <STATUS>PASSED</STATUS>
            <STEP>5</STEP>
            <EXECUTION_TIME>2017-09-21_12-34-56</EXECUTION_TIME>
            <STEP_RESULT>PASSED</STEP_RESULT>
            <DESCRIPTION></DESCRIPTION>
            <STEP_DESCRIPTION>‘我的帐户’是否存在</STEP_DESCRIPTION>
            <ACTION>verify</ACTION>
            <INDEX>By.LINK_TEXT</INDEX>
            <ELEMENT>我的账户</ELEMENT>
            <VALUE></VALUE>
            <EXPECTED_RESULTS>登录成功,显示登录后页面</EXPECTED_RESULTS>
            <IMAGE_PATH>D:\\PHJ\\Reporter\\LOGS\\2017-09-21_12-34-39\\Image\\image_2017-09-21_12-34-56.png</IMAGE_PATH>
        </LOG_ENTRY>
        <LOG_ENTRY>
            <STATUS>PASSED</STATUS>
            <STEP>6</STEP>
            <EXECUTION_TIME>2017-09-21_12-34-59</EXECUTION_TIME>
            <STEP_RESULT>PASSED</STEP_RESULT>
            <DESCRIPTION>正常充值</DESCRIPTION>
            <STEP_DESCRIPTION>单击\'充值\'</STEP_DESCRIPTION>
            <ACTION>click</ACTION>
            <INDEX>By.XPATH</INDEX>
            <ELEMENT>//div[@class=\'account_center_tips_div_4 fl\']/input</ELEMENT>
            <VALUE></VALUE>
            <EXPECTED_RESULTS></EXPECTED_RESULTS>
            <IMAGE_PATH></IMAGE_PATH>
        </LOG_ENTRY>
        <LOG_ENTRY>
            <STATUS>PASSED</STATUS>
            <STEP>7</STEP>
            <EXECUTION_TIME>2017-09-21_12-34-59</EXECUTION_TIME>
            <STEP_RESULT>PASSED</STEP_RESULT>
            <DESCRIPTION></DESCRIPTION>
            <STEP_DESCRIPTION>‘充值记录’是否存在</STEP_DESCRIPTION>
            <ACTION>verify</ACTIONSelenium HTMLTestRunner 无法生成测试报告的总结

记Selenium HTMLTestRunner 无法生成测试报告的总结

Python+Selenium笔记:生成测试报告

selenium+Python(生成html测试报告)

测试报告生成

Python+Selenium----使用HTMLTestRunner.py生成自动化测试报告2(使用PyCharm )