https://www.jianshu.com/p/3d2c0e092ffb

自动化测试,最重要的还是测试报告,下面就教大家使用BeautifulReport生成自动化测试报告
GitHub:https://github.com/TesterlifeRaymond/BeautifulReport

第一步:安装git

1、下载地址:https://git-scm.com/downloads
2、安装:按照默认安装就完事了
3、环境配置:配置(Git安装目录)/Git/cmd完整路径到环境变量path下

 
配置环境变量
 
安装成功
第二步:安装BeautifulReport

1、cmd下进入到指定目录:(python3安装目录)\Lib\site-packages

 
指定目录
 
进入指定目录

2、复制BeautifulReport到指定目录

>>>git clone https://github.com/TesterlifeRaymond/BeautifulReport
 
复制BeautifulReport
 
复制完成
第三步:使用BeautifulReport生成报告
 
大概的一个目录

1、测试用例py:

# -*- coding: utf-8 -*-
import os
import time
import unittest
from selenium import webdriver
from dateutil.parser import parse
from BeautifulReport import BeautifulReport class Test(unittest.TestCase):
# 定义一个保存截图函数
def save_img(self, img_name):
self.browser.get_screenshot_as_file('{}/{}.png'.format(os.path.abspath("E:/test/auto_test_local/Auto_Test/img"), img_name))
# 启动函数,每个用例测试前,都会执行该函数
def setUp(self):
self.browser = webdriver.Chrome()
self.browser.set_window_size(1920, 1080)
self.starttime = parse(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
print("开始测试时间:", self.starttime)
self.browser.get("https://www.baidu.com/")
time.sleep(3) # 结束函数,每个用例测试结束后,都会执行该函数
def tearDown(self):
time.sleep(3)
self.browser.quit()
self.endtime = parse(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
print("测试结束时间:", self.endtime)
totaltime = (self.endtime - self.starttime).total_seconds()
print("总时长:", totaltime, "秒") # 测试用例1:必须以test_开头
@BeautifulReport.add_test_img('打开登录页面', '输入账号密码', '登录')
def test_01(self):
u"""登录"""
self.browser.find_element_by_xpath("//*[@id=\"u1\"]/a[7]").click()
# 需要进行截图的时候,直接调用截图函数就ok,下同
self.save_img('打开登录页面')
self.browser.find_element_by_xpath("//*[@id=\"TANGRAM__PSP_10__footerULoginBtn\"]").click()
# self.browser.find_element_by_id("TANGRAM__PSP_10__footerULoginBtn").click()
self.browser.find_element_by_id("TANGRAM__PSP_10__userName").send_keys("userName")
time.sleep(1)
self.browser.find_element_by_id("TANGRAM__PSP_10__password").send_keys("password")
time.sleep(1)
self.save_img('输入账号密码')
self.browser.find_element_by_id("TANGRAM__PSP_10__submit").click()
time.sleep(1)
self.save_img('登录') # 测试用例2:也是必须以test_开头
@BeautifulReport.add_test_img('测试用例2')
def test_02(self):
u"""测试用例2"""
self.save_img('测试用例2')
time.sleep(1) if __name__ == '__main__':
unittest.main()

2、整合测试用例py

# -*- coding: utf-8 -*-
import unittest
from BeautifulReport import BeautifulReport # 用例存放位置
test_case_path="E:/test/auto_test_local/Auto_Test/Test_Case"
# 测试报告存放位置
log_path='E:/test/auto_test_local/Auto_Test/Test_Result/Test_Report'
# 测试报告名称
filename='测试报告-百度'
#用例名称
description='百度登录'
# 需要执行哪些用例,如果目录下的全部,可以改为"*.py",如果是部分带test后缀的,可以改为"*test.py"
pattern="login_test.py" if __name__ == '__main__':
test_suite = unittest .defaultTestLoader.discover(test_case_path, pattern=pattern)
result = BeautifulReport(test_suite)
result.report(filename=filename,description=description,log_path=log_path)

3、执行测试:每次执行测试,只需要执行整合测试用例py就可以了

 
测试完成

4、测试报告展示:

 
测试报告

作者:车陂IT仔
链接:https://www.jianshu.com/p/3d2c0e092ffb
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

最新文章

  1. MVC Core 网站开发(Ninesky) 1、创建项目
  2. HAproxy的安装与配置讲解
  3. .NET跨平台之旅:借助ASP.NET 5 Beta5的新特性显示CLR与操作系统信息
  4. SE1-soc入手又有的东西可以玩了
  5. ODATA WEB API(二)----ODATA服务与客户端
  6. poj3159 Candies(差分约束,dij+heap)
  7. hash算法
  8. [置顶] Oracle 11g R2 ASM:了解 Oracle ASM 基本概念
  9. ASP.NET网页抓取数据
  10. mysql 结合keepalived测试
  11. perl lwp 默认的请求头
  12. OWIN与Katana
  13. linux下让irb实现代码自动补全的功能
  14. SpringCloud概述
  15. list基本代码
  16. Python常用字符编码
  17. shell编程的笔记
  18. Mysql中使用Group_Concat将列组合进来。
  19. Ubuntu下sh *.sh使用==操作符执行报错
  20. SQL Server 获取某时间点后修改的函数Function 并以文本格式显示

热门文章

  1. python 爬虫 selenium 与 chromedriver
  2. Ubuntu20.04安装PEA软件
  3. webapi fromurl frombody
  4. 【快问快答】为什么NPOI读取表格数据的时候,遇到空格单元值会直接忽略
  5. C2驾驶车型
  6. vue3 深度选择器 scss用法
  7. 浅谈JS输出中的“+”作用问题
  8. Python游戏开发常用库
  9. vue-图书管理系统
  10. 防止react-re-render: Why Suspense and how ?