博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
selenium+python自动化91-unittest多线程生成报告(BeautifulReport)
阅读量:6905 次
发布时间:2019-06-27

本文共 2399 字,大约阅读时间需要 7 分钟。

前言

selenium多线程跑用例,这个前面一篇已经解决了,如何生成一个测试报告这个是难点,刚好在github上有个大神分享了BeautifulReport,完美的结合起来,就能生成报告了。

环境必备:

  • python3.6 : BeautifulReport不支持2.7
  • tomorrow : pip install tomorrow安装
  • BeautifulReport : github下载后放到/Lib/site-packages/目录下

BeautifulReport

1.BeautifulReport下载地址:

2.下载方法:

  • 方法一 会使用git的直接用git下载到本地

git clone https://github.com/TesterlifeRaymond/BeautifulReport

1070438-20180202111131406-1274688803.png

  • 方法二 点Clone or Download按钮,Download ZIP就能下载到本地了

1070438-20180202111140062-1590110692.png

3.下载完之后,把BeautifulReport整个包放到python的/Lib/site-packages/目录下

1070438-20180202111149328-779765671.png

使用方法

1.项目结构:

case test开头的.py用例脚本
report 放生成的html报告
run_all.py 用于执行全部脚本

1070438-20180202111157921-1147140098.png

2.单个测试脚本test_a.py参考

# coding:utf-8import unittestfrom selenium import webdriverimport timeclass Testaa(unittest.TestCase):    u'''测试用例a的集合'''    @classmethod    def setUpClass(cls):        cls.driver = webdriver.Firefox()    def setUp(self):        self.driver.get("https://www.cnblogs.com/yoyoketang/")    def test_01(self):        u'''用例1:用例1的操作步骤'''        t = self.driver.title        print(t)        self.assertIn("悠悠", t)    def test_02(self):        u'''用例2:用例2的操作步骤'''        t = self.driver.title        print(t)        self.assertIn("悠悠", t)    def test_03(self):        u'''用例3:用例3的操作步骤'''        t = self.driver.title        print(t)        self.assertIn("悠悠", t)    @classmethod    def tearDownClass(cls):        cls.driver.quit()if __name__ == "__main__":    unittest.main()

3.run_all代码

# coding=utf-8import unittestfrom BeautifulReport import BeautifulReportimport osfrom tomorrow import threads# 获取路径curpath = os.path.dirname(os.path.realpath(__file__))casepath = os.path.join(curpath, "case")if not os.path.exists(casepath):    print("测试用例需放到‘case’文件目录下")    os.mkdir(casepath)reportpath = os.path.join(curpath, "report")if not os.path.exists(reportpath): os.mkdir(reportpath)def add_case(case_path=casepath, rule="test*.py"):    '''加载所有的测试用例'''    discover = unittest.defaultTestLoader.discover(case_path,                                                  pattern=rule,                                                  top_level_dir=None)    return discover@threads(3)def run(test_suit):    result = BeautifulReport(test_suit)    result.report(filename='report.html', description='测试deafult报告', log_path='report')if __name__ == "__main__":    # 用例集合    cases = add_case()    print(cases)    for i in cases:        print(i)        run(i)

4.报告效果图

1070438-20180202111211500-473973757.png

备注:BeautifulReport是某大神在github分享的框架,这里借花献佛了,更多使用方法参考地址:https://github.com/TesterlifeRaymond/BeautifulReport

你可能感兴趣的文章
ie启动不了的解决办法,win7,win8都可以
查看>>
ECshop 快捷登录插件 支持QQ 支付宝 微博
查看>>
HTML转义字符大全
查看>>
高级进程间通信之UNIX域套接字
查看>>
HTML5打造的炫酷本地音乐播放器-喵喵Player
查看>>
WPF命中测试示例(二)——几何区域命中测试
查看>>
ArrayList、linklist、list的区别
查看>>
Linux下的lds链接脚本基础
查看>>
【ASP.NET】关于iframe的两个技巧
查看>>
Django 数据库查询
查看>>
Excel将秒转换成标准的时间格式HH:MM:SS
查看>>
迁移已有的虚拟机
查看>>
sql server 2008有关SQL的模糊查询
查看>>
ECMall中Widgets模式的布局引擎
查看>>
细说UI线程和Windows消息队列
查看>>
Centos6.4 xen编译部署
查看>>
开源免费的C/C++网络库(c/c++ sockets library)
查看>>
win7下jdk安装环境变量配置
查看>>
UVA 1484 - Alice and Bob's Trip(树形DP)
查看>>
C语言求最大公约数和最小公倍数
查看>>