• python3自动化测试-使用BeautifulReport生成可视化测试报告


    1、获取 BeautifulReport 包

    BeautifulReport,git地址:

    https://github.com/TesterlifeRaymond/BeautifulReport

    1)如果自己电脑上安装了git,可以直接使用git命令克隆到本地指定目录下

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

    2)如果没有安装git,直接在git上下载BeautifulReport.ZIP ,解压到到本地python的的/Lib/site-packages/目录下

    3)修改BeautifulReport.py的2个地方

    2、使用BeautifulReport,生成报告

     1 #coding=utf-8
     2 '''
     3 Created on 2020年8月13日
     4 
     5 @author: Administrator
     6 
     7 Descriptions: execute testcases
     8 '''
     9 import unittest
    10 import os, datetime
    11 from BeautifulReport import BeautifulReport
    12 from tools.sendmail import SendMail
    13 from config import conf
    14 
    15 root_dir = os.path.dirname(os.path.abspath(__file__)).replace('\', '/')
    16 test_dir = root_dir + '/testcases'#测试用例所在的目录
    17 report_dir = root_dir + '/testreport'#存放测试报告的目录
    18 
    19 discover = unittest.defaultTestLoader.discover(test_dir, 'login_testcase.py', None)
    20 now = datetime.datetime.now().strftime('%Y-%m-%d %H_%M_%S')
    21 filename = '测试报告' + str(now)
    22 BeautifulReport(discover).report(description='测试', filename=filename, log_path=report_dir)
    23 
    24 #发送邮件
    25 SendMail().sendEmail(filename)26 27 

    3、BeautifulReport截图需要在测试类中添加一个save_img的方法

    1 def save_img(self, img_name): 
    2       self.driver.get_screenshot_as_file('{}/{}.png'.format(conf.img_dir, img_name))

    然后调用时,只需要在测试方法上面加个装饰器就行了:

     1     """登录模块测试用例"""
     2     @BeautifulReport.add_test_img('登陆成功')
     3     def test_login1(self):
     4         """用户名正确,密码正确,登录成功"""
     5         self.login.loginFunc()
     6         self.save_img('登陆成功')
     7         time.sleep(3)
     8         currUrl = self.driver.current_url # 获取当前的url地址
     9         
    10         try:
    11             self.assertIn('index', currUrl, 'index not in current url!')#判断index在当前url中
    12         except Exception:
    13             self.login.saveScreenShot('cor_un_pw_fail.png')
    14             raise
    15         else:
    16             self.login.saveScreenShot('cor_un_pw_pass.png')
    17             log.logger.info('%s->run completed! ' % (sys._getframe().f_code.co_name))
    18             self.login.quit()

    4、测试报告样式

  • 相关阅读:
    libmv
    visualSFM
    opencv学习笔记——时间计算函数getTickCount()和getTickFrequency()
    opencv学习笔记——cv::mean()函数详解
    linux使用ip能ping通,但使用域名却不能访问的解决方法
    yum 安装出错--"Couldn't resolve host 'mirrors.aliyun.com'"
    vmware复制虚拟机出现Error:No suitable device found:no device found for connection 'System eth0'
    VMWare虚拟机 网络连接模式
    js监听input输入框值的实时变化实例
    本地连接linux虚拟机的方法
  • 原文地址:https://www.cnblogs.com/yaner2018/p/13496591.html
Copyright © 2020-2023  润新知