HTMLTestRunner 汉化版---来源一个大神的源码(加了失败截图,用例失败重新执行 功能)...

HTMLTestRunner 汉化版

  • 20170925
    • 测试报告完全汉化,包括错误日志的中文处理
    • 针对selenium UI测试增加失败自动截图功能
    • 增加失败自动重试功能
    • 增加饼图统计
    • 同时兼容python2.x 和3.x
  • 20180402
    • 表格样式优化
    • 修复部分bug
    • 增加截图组,可展示多张截图,首次打开自动播放
    • 增加仅展示最后一次运行结果,多次重试时,每个测试用例仅展示一次

报告汉化

selenium 截图

截图功能根据测试结果,当结果为fail或error时自动截图 截图方法在_TestResult 的测试结果收集中,可以根据自己使用的框架不同自行调整,selenium 使用的是get_screenshot_as_base64 获取页面截图的base64编码,避免了图片文件的问题 

因此要提取用例中的driver变量获取webdriver对象,所以要实现截图功能必须定义在用例中定义webdriver 为driver

def setUp(self):
    self.imgs=[]  # (可选)初始化截图列表 self.driver = webdriver.Chrome()

也可以在测试过程中某一步骤自定义添加截图,比如

  

生成报告后会统一进行展示 截图播放效果 

用例失败重试

根据unittest的运行机制,在stopTest 中判断测试结果,如果失败或出错status为1,判断是否需要重试;

 

在实例化HTMLTestRunner 对象时追加参数,retry,指定重试次数,如果save_last_try 为True ,一个用例仅显示最后一次测试的结果。

HTMLTestRunner(title="带截图的测试报告", description="小试牛刀", stream=open("sample_test_report.html", "wb"), verbosity=2, retry=2, save_last_try=True)

如果save_last_try 为False,则显示所有重试的结果。

HTMLTestRunner(title="带截图的测试报告", description="小试牛刀", stream=open("sample_test_report.html", "wb"), verbosity=2, retry=2, save_last_try=False)

运行中输出效果如下: 

 

 

url: https://github.com/GoverSky/HTMLTestRunner_cn/blob/master/README.md

源码url: https://github.com/GoverSky/HTMLTestRunner_cn/blob/master/HTMLTestRunner_cn.py 自己也在百度云收藏(百度云那个可能太老了,我自己github已收藏大神的库)

 

 

后记:

下载源码,和HTMLTestrunner.py文件用法一样

 

retry,用例执行失败后指定重试次数,

如果save_last_try 为True ,一个用例仅显示最后一次测试的结果。

                        为True,则展示全部测试结果。

verbosity=2 为信息输出控制台的展示方式

retry,指定重试次数

转载于:https://www.cnblogs.com/kaibindirver/p/9436649.html

导入HTMLTestRunnerPython,生成测试报告的工具类 """ A TestRunner for use with the Python unit testing framework. It generates a HTML report to show the result at a glance. The simplest way to use this is to invoke its main method. E.g. import unittest import HTMLTestRunner ... define your tests ... if __name__ == '__main__': HTMLTestRunner.main() For more customization options, instantiates a HTMLTestRunner object. HTMLTestRunner is a counterpart to unittest's TextTestRunner. E.g. # output to a file fp = file('my_report.html', 'wb') runner = HTMLTestRunner.HTMLTestRunner( stream=fp, title='My unit test', description='This demonstrates the report output by HTMLTestRunner.' ) # Use an external stylesheet. # See the Template_mixin class for more customizable options runner.STYLESHEET_TMPL = '<link rel="stylesheet" href="my_stylesheet.css" type="text/css">' # run the test runner.run(my_test_suite) ------------------------------------------------------------------------ Copyright (c) 2004-2007, Wai Yip Tung All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name Wai Yip Tung nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值