前言

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

环境必备:

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

BeautifulReport

1.BeautifulReport下载地址:BeautifulReport

2.下载方法:

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

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

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

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

使用方法

1.项目结构:

case test开头的.py用例脚本

report 放生成的html报告

run_all.py 用于执行全部脚本

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

# coding:utf-8

import unittest
from selenium import webdriver
import time class 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-8
import unittest
from BeautifulReport import BeautifulReport
import os
from 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.报告效果图

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

最新文章

  1. session的使用方法详解
  2. Hive 按某列的部分排序 以及 删列操作
  3. 【bootstrapValidator 不验证】使用bootstrapValidator 验证效果不起作用
  4. 360浏览器下jquery.validate.unobtrusive的日期验证问题
  5. material design——设计文档
  6. webrtc学习(一): webrtc开始
  7. ListVIew中插入view
  8. PHPCMS标签:get标签
  9. viewpager+fragment学习笔记
  10. java计算一个月有多少天和多少周
  11. css position 相对定位
  12. Angular实现购物车计算
  13. java中的ConcurrentModificationException异常
  14. JVM方法调用
  15. golang struct 和 byte互转
  16. linux查看和修改PATH环境变量的方法
  17. html基础知识梳理
  18. docker 构建 https 私有仓库 Registry
  19. 学习笔记:fhq-treap
  20. GitHub学习总结

热门文章

  1. 20155117王震宇 2016-2017-2 《Java程序设计》第七周学习总结
  2. .NET 中小心嵌套等待的 Task,它可能会耗尽你线程池的现有资源,出现类似死锁的情况
  3. kafka日志同步至elasticsearch和kibana展示
  4. The Alphabet Sticker
  5. Linux的getrlimit与setrlimit系统调用
  6. wpf 客户端【JDAgent桌面助手】开发详解(三) 瀑布流效果实现与UI虚拟化优化大数据显示
  7. 调用飞信HTTP接口给自己发短信
  8. jquery选择器之属性过滤选择器详解
  9. Bloom Filter(布隆过滤器)的概念和原理
  10. php实现Facebook风格的 time ago函数