├── .github └── dependabot.yml ├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── assets └── report.gif ├── lib ├── HTMLTestReportCN.py └── __init__.py ├── requirements.txt └── samples ├── RunAllTests.py ├── __init__.py └── testcases ├── __init__.py ├── test1.py └── test2.py /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "pip" # See documentation for possible values 9 | directory: "/" # Location of package manifests 10 | schedule: 11 | interval: "weekly" 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | venv 3 | *.iml 4 | report 5 | src/report 6 | __pycache__ 7 | */__pycache__ 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Gelomen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: install freeze 2 | 3 | # 安装依赖 4 | install: 5 | pip3 install -r requirements.txt --break-system-packages 6 | 7 | # 锁定依赖 8 | freeze: 9 | pip3 list --format=freeze > requirements.txt 10 | 11 | # 启动测试 12 | run: 13 | python3 src/RunAllTests.py 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HTMLTestReportCN-ScreenShot 2 | 3 | 带有截图功能的 `HTMLTestReportCN`, 基于 [findyou](https://github.com/findyou) 和 [boafantasy](https://github.com/boafantasy) 两位的版本修改的, 添加功能并修复bug和优化细节 4 | 5 | - 目前同时拥有无截图和有截图报告功能, 通过参数 `need_screenshot` 开启截图功能 6 | - 生成的报告有饼图显示, 测试结果比较直观 7 | - [findyou](https://github.com/findyou) 版本: https://github.com/findyou/HTMLTestRunnerCN 8 | - [boafantasy](https://github.com/boafantasy) 版本: https://github.com/boafantasy/HTMLTestRunnerCN 9 | 10 | ## 步骤 11 | 12 | 查看例子: [Samples](./samples) 13 | 14 | ### 1. 初始化修饰器 15 | 16 | 新建 `RunAllTests.py`, 如何封装可以自行决定 17 | 18 | - `run()` 添加 `@HTMLTestReportCN.init()` 修饰器, 并把报告目录和报告标题传入 19 | - 调用 `HTMLTestReportCN.get_report_path()` 获取 `HTML` 报告路径, 用于测试结果写入 20 | 21 | ```python 22 | import unittest 23 | from lib import HTMLTestReportCN 24 | 25 | report_dir = "./report" 26 | title = "自动化测试报告" 27 | description = "测试报告" 28 | test_case_path = "./testcases" 29 | 30 | 31 | @HTMLTestReportCN.init(report_dir=report_dir, title=title) 32 | def run(): 33 | test_suite = unittest.TestLoader().discover(test_case_path) 34 | 35 | fp = open(HTMLTestReportCN.get_report_path(), "wb") 36 | runner = HTMLTestReportCN.HTMLTestRunner( 37 | stream=fp, title=title, description=description, tester=input("请输入你的名字: ") 38 | ) 39 | runner.run(test_suite) 40 | fp.close() 41 | 42 | 43 | if __name__ == "__main__": 44 | run() 45 | 46 | ``` 47 | 48 | ### 2. 截图修饰器 49 | 50 | 在需要截图的测试用例添加 `@HTMLTestReportCN.screenshot` 修饰器, 失败时会自动截图 51 | 52 | ```python 53 | from lib import HTMLTestReportCN 54 | 55 | ... 56 | 57 | @HTMLTestReportCN.screenshot 58 | def test1_find_input(self): 59 | ... 60 | 61 | ``` 62 | 63 | ----- 64 | 65 | ## 效果预览 66 | 67 |  68 | -------------------------------------------------------------------------------- /assets/report.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gelomen/HTMLTestReportCN-ScreenShot/4a6f5b314c528082b03162d685d0bf3dbfc9aed2/assets/report.gif -------------------------------------------------------------------------------- /lib/HTMLTestReportCN.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | """ 3 | A TestRunner for use with the Python unit testing framework. It 4 | generates a HTML report to show the result at a glance. 5 | 6 | The simplest way to use this is to invoke its main method. E.g. 7 | 8 | import unittest 9 | import HTMLTestRunner 10 | 11 | ... define your tests ... 12 | 13 | if __name__ == '__main__': 14 | HTMLTestRunner.main() 15 | 16 | 17 | For more customization options, instantiates a HTMLTestRunner object. 18 | HTMLTestRunner is a counterpart to unittest's TextTestRunner. E.g. 19 | 20 | # output to a file 21 | fp = file('my_report.html', 'wb') 22 | runner = HTMLTestRunner.HTMLTestRunner( 23 | stream=fp, 24 | title='My unit test', 25 | description='This demonstrates the report output by HTMLTestRunner.' 26 | ) 27 | 28 | # Use an external stylesheet. 29 | # See the Template_mixin class for more customizable options 30 | runner.STYLESHEET_TMPL = '' 31 | 32 | # run the test 33 | runner.run(my_test_suite) 34 | 35 | 36 | ------------------------------------------------------------------------ 37 | Copyright (c) 2004-2007, Wai Yip Tung 38 | All rights reserved. 39 | 40 | Redistribution and use in source and binary forms, with or without 41 | modification, are permitted provided that the following conditions are 42 | met: 43 | 44 | * Redistributions of source code must retain the above copyright notice, 45 | this list of conditions and the following disclaimer. 46 | * Redistributions in binary form must reproduce the above copyright 47 | notice, this list of conditions and the following disclaimer in the 48 | documentation and/or other materials provided with the distribution. 49 | * Neither the name Wai Yip Tung nor the names of its contributors may be 50 | used to endorse or promote products derived from this software without 51 | specific prior written permission. 52 | 53 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 54 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 55 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 56 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 57 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 58 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 59 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 60 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 61 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 62 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 63 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 64 | """ 65 | 66 | # URL: http://tungwaiyip.info/software/HTMLTestRunner.html 67 | # URL: https://github.com/Gelomen/HTMLTestReportCN-ScreenShot 68 | 69 | __author__ = "Wai Yip Tung, Findyou, boafantasy, Gelomen" 70 | __version__ = "1.2.0" 71 | 72 | """ 73 | Version 0.8.2.1 -Findyou 74 | * 改为支持python3 75 | 76 | Version 0.8.2.1 -Findyou 77 | * 支持中文,汉化 78 | * 调整样式,美化(需要连入网络,使用的百度的Bootstrap.js) 79 | * 增加 通过分类显示、测试人员、通过率的展示 80 | * 优化“详细”与“收起”状态的变换 81 | * 增加返回顶部的锚点 82 | 83 | Version 0.8.2 84 | * Show output inline instead of popup window (Viorel Lupu). 85 | 86 | Version in 0.8.1 87 | * Validated XHTML (Wolfgang Borgert). 88 | * Added description of test classes and test cases. 89 | 90 | Version in 0.8.0 91 | * Define Template_mixin class for customization. 92 | * Workaround a IE 6 bug that it does not treat 246 | 247 | 248 | 249 | %(stylesheet)s 250 | 251 |
252 | 518 | %(heading)s 519 | %(report)s 520 | %(ending)s 521 | 522 | 523 |