unittest框架之 BeautifulReport 模板报告生成的正确姿势
使用unittest框架的自动化测试,报告一定很重要,目前介绍一个比较高大上的报告模板 BeautifulReport。如果首次使用的话需要安装 pip install beautifulreport
下面直接上代码,里面关键的地方通过注释体现
# -*- coding:utf-8 -*-
'''
# @Time : 2019/12/3 16:50
# @Author : nihaoya
# @FileName: WeiBo_test.py
# @Software: PyCharm
'''
import os
import time
import unittest
from appium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from BeautifulReport import BeautifulReport as bf server = 'http://localhost:4723/wd/hub'
desired_capabilities = {
'platformName': 'Android',
'deviceName': 'wohenhao',
'appPackage': 'com.sina.weibo',
'appActivity': 'com.sina.weibo.VisitorMainTabActivity',
'autoGrantPermissions': True # 添加这个是防止每次拉起应用时要重新授权
} driver = webdriver.Remote(server, desired_capabilities)
wait = WebDriverWait(driver, 30) class WeiBo(unittest.TestCase):
def setUp(self) -> None:
print(time.strftime("%Y-%m-%d %H:%M:%S"), "start to test") def tearDown(self) -> None:
print(time.strftime("%Y-%m-%d %H:%M:%S"), "end test") def test_a_switch_guest_mode(self):
print(time.strftime("%Y-%m-%d %H:%M:%S"), "switch to guest mode")
if wait.until(EC.element_to_be_clickable((By.ID, "com.sina.weibo:id/tv_title_lookaround"))):
driver.find_element_by_id("com.sina.weibo:id/tv_title_lookaround").click() def test_b_browsing(self):
print(time.strftime("%Y-%m-%d %H:%M:%S"), "begging to browse the content")
for i in range(5):
print((time.strftime("%Y-%m-%d %H:%M:%S") + " This is the {} time to refresh").format(i+1))
time.sleep(5)
driver.swipe(400, 100, 400, 350, 10) if __name__ == "__main__":
suite = unittest.TestLoader().loadTestsFromTestCase(WeiBo)
# unittest.TextTestRunner().run(suite)
# bf(suite).report("WebBo", "WeiBoTest")
run = bf(suite)
run.report(filename=u"./report/WeiBo报告_" + time.strftime("%Y-%m-%d_%H_%M_%S"), description=u"以游客形式浏览微博") # 这个filename关键字参数中,给的值一定不能出现冒号,否则最后生成报告时必定提示参数异常
注意:
1、如果是使用pycharm的话,一定不要在pycharm中执行脚本,它是不会生成报告的,原因是用pycharm自带的unittest执行的,并不会走脚本中的 main 方法,所以也就不会有报告。正确的姿势就是在命令行通过 python xxx.py 进行执行,这样就肯定会有报告生成。
2、在最后报告生成时至于filename那块不能带有冒号,大家可以在windows端自行去新建一个文件,以冒号(英文)的形式去创建一个文件,它也会提示这9个特殊字符是不能被包含的,例如: \ / : * ? " < > |
下面show一下生成的报告文件及报告内容:


unittest框架之 BeautifulReport 模板报告生成的正确姿势的更多相关文章
- unittest框架,漂亮的报告BeautifulReport配置与错误截图详细解说
1.下载BeautifulReport模块 下载地址:https://github.com/TesterlifeRaymond/BeautifulReport 2.解压与存放路径 下载Beautifu ...
- unittest框架下的HTMLTestRunner报告模块使用及优化
引言 在做接口自动化测试的时候,使用python单元测试框架unittest下HTMLTestRunner报告模板,可以很好的展示我们测试结果的数据. 官方的标准版模板地址:http://tungwa ...
- 聊聊 Web 项目二维码生成的最佳姿势
在设计和实现的过程之后,你永远不知道部署上去的程序会已什么样的姿势运行. 本篇借一次生成二维码逻辑的不同实现,阐述 Web 项目中二维码生成的正确姿势. 文中如有批量,欢迎各位看客老爷拍砖.试运行前5 ...
- 解惑unittest框架中导入HTMLTestRunner模块后正常运行却无法生成HTML报告问题
1.HTMLTestRunner介绍 HTMLTestRunner是一个第三方的unittest HTML报告库,用于python单元测试框架的TestRunner.它是生成一个HTML报告,以一目了 ...
- unittest框架扩展(自动生成用例)自动化-上
一.思想: 基于数据驱动和代码驱动结合的自动化测试框架. 二.自动化测试框架步骤: 1.获取用例,用例格式:.ymal 2.调用接口 3.校验结果 4.发送测试报告 5.异常处理 6.日志模块 三.基 ...
- python+requests+excel+unittest+ddt接口自动化数据驱动并生成html报告
1.环境准备: python3.6 requests xlrd openpyxl HTMLTestRunner_api 2.目前实现的功能: 封装requests请求方法 在excel填写接口请求参数 ...
- python+requests+excel+unittest+ddt接口自动化数据驱动并生成html报告(二)
可以参考 python+requests接口自动化完整项目设计源码(一)https://www.cnblogs.com/111testing/p/9612671.html 原文地址https://ww ...
- python+requests+excel+unittest+ddt接口自动化数据驱动并生成html报告(已弃用)
前言 1.环境准备: python3.6 requests xlrd openpyxl HTMLTestRunner_api 2.目前实现的功能: 封装requests请求方法 在excel填写接口请 ...
- Python3 完美解决unittest框架下不生成测试报告
前提: 1.运行测试用例一切正常,只是没有测试报告显示 2.使用命令行pyhon 脚本名字.py 却可以生成测试报告 3.pycharm 在运行测试用例的时候 默认是以unittest 框架来运行的, ...
随机推荐
- SPOJ- Distinct Substrings(后缀数组&后缀自动机)
Given a string, we need to find the total number of its distinct substrings. Input T- number of test ...
- 2017 ACM/ICPC 沈阳 F题 Heron and his triangle
A triangle is a Heron’s triangle if it satisfies that the side lengths of it are consecutive integer ...
- 2018HDU多校训练一 A - Maximum Multiple
Given an integer nn, Chiaki would like to find three positive integers xx, yy and zzsuch that: n=x+y ...
- Python3 常用模块2
目录 time 模块 时间戳形式 格式化时间 结构化时间 time.time() time.sleep() datetime 模块 random 模块 hashlib 模块 和 hmac 模块 typ ...
- Java_计算1-100的和,奇数和
public class Work1{ public static void main(String[] args){ // 定义和并赋值 int sum = 0; for(int i = 1;i & ...
- 2019年终总结:10场演讲、内推20人、公众号2万粉丝、Code Runner 1000万下载
2019年是值得记录的一年,成长许多,也收获许多. 做了 10 场大会的技术演讲,成功内推 20 人拿到微软 Offer,知乎 Live 2000 听众,公众号 2 万粉丝,GitHub 2万 sta ...
- 如何为.NETCore安装汉化包智能感知
引言 具体不记得是在群里还是什么地方有人问过,.NETCore有没有汉化包,答案是有,目前微软已经为我们提供了.NETCore多种语言的语言包.下面看看如何安装与使用吧. 在哪下载? 在微软官方下载 ...
- Redis来啦~~
一. 先聊点别的 1. sql & nosql sql指关系型数据库,如Oracle,MySQL等,nosql泛指非关系型数据库,如MongoDB,Redis等:SQL数据存在特定结构的表中, ...
- 使用react-app-rewired和customize-cra对默认webpack自定义配置
最近在学习react框架,之前一直都是用vue 开发,知道在vue 中知道如何配置一下相关的webpack 有助于开发,学react 过程中,我也在想这些该怎么配置啊,所以就有这篇文章. 这篇文章主要 ...
- Sqlite—Python接口
#!/usr/bin/env python # -*- coding:utf-8 -*- import sqlite3,os,time import traceback class Sqlite(): ...