python+selenium 输出2种样式的测试报告
第一种
1.通过 HTMLTestRunner 模块输出报告
2.下载连接 http://tungwaiyip.info/software/HTMLTestRunner.html
3.将下载好的文件放到python安装目录的lib下面
生成测试报告实例代码
Myunittest.py
#! user/bin/python
#----------------------------------
'''
代码说明:
编写日期:
设计 者:
'''
#---------------------------------- import unittest
from selenium import webdriver
import time
class Myunittest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
time.sleep(2)
self.driver.get(url)# url自己填写
def tearDown(self):
self.driver.quit()
login_test.py
#! user/bin/python
#----------------------------------
'''
代码说明:
编写日期:
设计 者:
'''
#----------------------------------
from selenium import webdriver
import unittest
import time
from BeautifulReport import BeautifulReport
from Myunittest import Myunittest class LoginTest(Myunittest): def test_login01(self):
self.driver.find_element_by_id('username').send_keys('rmln')
self.driver.find_element_by_id('password').send_keys('qwert1234!@#')
time.sleep(2)
self.driver.find_element_by_id('loginSubmitButton')
self.driver.save_screenshot('logon.png')
def test_login02(self):
self.driver.find_element_by_id('username').send_keys('rmln')
self.driver.find_element_by_id('password').send_keys('qwert1234!@#')
time.sleep(2)
self.driver.find_element_by_id('loginSubmitButton')
def test_login03(self):
self.driver.find_element_by_id('username').send_keys('rmln')
self.driver.find_element_by_id('password').send_keys('qwert1234!@#')
time.sleep(2)
self.driver.find_element_by_id('loginSubmitButton') if __name__ == '__main__':
pass
runtest.py
#! user/bin/python
#----------------------------------
'''
代码说明:
编写日期:
设计 者:
'''
#----------------------------------
import unittest
import HTMLTestRunner
import time
if __name__ == '__main__':
test_suite = unittest.defaultTestLoader.discover(r'D:\testselenium', pattern='login_test.py')
currTime = time.strftime('%Y-%m-%d %H_%M_%S')
filename = currTime+'.html'
fp = open(filename, 'wb')
runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title='Retail sys测试报告',
description='处理器:Intel(R) Core(TM) '
'i5-6200U CPU @ 2030GHz 2.40 GHz '
'内存:8G 系统类型: 64位 版本: windows 10 家庭中文版')
runner.run(test_suite)
测试报告样例

第二种
1.通过BeautifulReport 模块输出报告
2.下载连接 https://github.com/TesterlifeRaymond/BeautifulReport
3.将下载好的BeautifulReport包放到python安装目录的site-packages下面
生成测试报告实例代码
Myunittest.py
#! user/bin/python
#----------------------------------
'''
代码说明:
编写日期:
设计 者:
'''
#---------------------------------- import unittest
from selenium import webdriver
import time
class Myunittest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
time.sleep(2)
self.driver.get(url)# url 自己填写
def tearDown(self):
self.driver.quit()
login_test.py
#! user/bin/python
#----------------------------------
'''
代码说明:
编写日期:
设计 者:
'''
#----------------------------------
import time
from BeautifulReport import BeautifulReport
from Myunittest import Myunittest class LoginTest(Myunittest): @BeautifulReport.add_test_img('login.png')
def test_login01(self):
self.driver.find_element_by_id('username').send_keys('rmln')
self.driver.find_element_by_id('password').send_keys('qwert1234!@#')
time.sleep(2)
self.driver.find_element_by_id('loginSubmitButton')
self.driver.save_screenshot('logon.png')
def test_login02(self):
self.driver.find_element_by_id('username').send_keys('rmln')
self.driver.find_element_by_id('password').send_keys('qwert1234!@#')
time.sleep(2)
self.driver.find_element_by_id('loginSubmitButton')
def test_login03(self):
self.driver.find_element_by_id('username').send_keys('rmln')
self.driver.find_element_by_id('password').send_keys('qwert1234!@#')
time.sleep(2)
self.driver.find_element_by_id('loginSubmitButton') if __name__ == '__main__':
pass
runtest.py
#! user/bin/python
#----------------------------------
'''
代码说明:
编写日期:
设计 者:
'''
#----------------------------------
from BeautifulReport import BeautifulReport
import unittest
import time
if __name__ == '__main__':
currTime = time.strftime('%Y-%m-%d %H_%M_%S')
filename = currTime+'.html'
test_suite = unittest.defaultTestLoader.discover(r'D:\testselenium', pattern='login_test.py')
result = BeautifulReport(test_suite)
result.report(filename=filename, description='测试deafult报告', log_path='.')
测试报告样例

最后一个报告还是挺漂亮的,可以考虑使用,我相信随着时间的推移,会有更多的好看的报告面试(只能把期望交给行业中的大牛了^-^)
python+selenium 输出2种样式的测试报告的更多相关文章
- Python&Selenium&pytest借助allure生成自动化测试报告
一.摘要 本篇博文将介绍Python和Selenium进行自动化测试时,如何借助allure生成自动化测试报告 二.环境配置 首先python环境中安装pytest和pytest_allure_ada ...
- python + selenium webdriver 复合型css样式的元素定位方法
<div class="header layout clearfix"></div> 当元素没有id,没有name,没有任何,只有一个class的时候,应该 ...
- python 输出颜色与样式的方法
上次遇到这个问题就想写下来,其实当时我也不怎么会,老师说这个东西不需要理解,只需要死记硬背,写的多了就记住了,所以今天搜集了几篇文章,加上自己的理解,写下了这篇python 输出颜色的样式与方法的文章 ...
- Jenkins自动执行python脚本输出测试报告
前言 在用python做自动化测试时,我们写好代码,然后需要执行才能得到测试报告,这时我们可以通过 Jenkins 来进一步完成自动化工作. 借助Jenkins,我们可以结合 Git/SVN 自动拉取 ...
- python输出颜色与样式的方法
一.输出颜色与样式的方法 上次遇到这个问题就想写下来,其实当时我也不怎么会,老师说这个东西不需要理解,只需要死记硬背,写的多了就记住了,所以今天搜集了几篇文章,加上自己的理解,写下了这篇python ...
- Python+Selenium自动化-定位页面元素的八种方法
Python+Selenium自动化-定位页面元素的八种方法 本篇文字主要学习selenium定位页面元素的集中方法,以百度首页为例子. 0.元素定位方法主要有: id定位:find_elemen ...
- python selenium 三种等待方式详解[转]
python selenium 三种等待方式详解 引言: 当你觉得你的定位没有问题,但是却直接报了元素不可见,那你就可以考虑是不是因为程序运行太快或者页面加载太慢造成了元素不可见,那就必须要加等待 ...
- 【转】【Python + selenium】linux和mac环境,驱动器chromedriver和测试报告HTMLTestRunner放置的位置
感谢: 作者:gz_tester,文章:<linux和mac环境,chromedriver和HTMLTestRunner放置的位置> 使用场景 配置python selenium 环境 使 ...
- Python selenium chrome打包exe后禁用控制台输出滚动日志
Python selenium chrome打包exe后,在运行的过程中,如果遇到需要input()输入时,会发现被不断滚动刷新的日志把命令行输入快速顶掉了,通过查阅资料不断实践,发现以下方法有效: ...
随机推荐
- 使用reflector对.NET反编译
reflector的下载地址:https://www.cr173.com/soft/355285.html 反编译后的结果:
- 『最短Hamilton路径 状态压缩DP』
状压DP入门 最短Hamilton路径 Description 给定一张 n(n≤20) 个点的带权无向图,点从 0~n-1 标号,求起点 0 到终点 n-1 的最短Hamilton路径. Hamil ...
- Elasticsearch索引原理
转载 http://blog.csdn.net/endlu/article/details/51720299 最近在参与一个基于Elasticsearch作为底层数据框架提供大数据量(亿级)的实时统计 ...
- TypeScript 基础知识点整理
一.TypeScript的特点 1.支持ES6规范 2.强大的IDE支持(集成开发环境) 允许为变量指定类型,减少你在开发阶段犯错误的几率. 语法提示,在IDE编写代码时,它会根据你所处的上下文把你能 ...
- JavaScript面向对象--封装
一.封装的概念 面向对象的类包括两大成员,一种是暴露给外部的接口,另一种是只在类内部才能访问的私有属性.在这个类被实例化成对象后,用户只能通过操作给定的接口来访问该类内部的私有属性,这就被称为面向对象 ...
- 二进制安装部署kubernetes集群---超详细教程
本文收录在容器技术学习系列文章总目录 前言:本篇博客是博主踩过无数坑,反复查阅资料,一步步搭建完成后整理的个人心得,分享给大家~~~ 本文所需的安装包,都上传在我的网盘中,需要的可以打赏博主一杯咖啡钱 ...
- Smobiler 4.4 更新预告 Part 1(Smobiler能让你在Visual Studio上开发APP)
在4.4版本中,大家对产品优化的一些建议和意见进行了相应的优化和修复,同时,还新增了一些令人激动的功能和插件. 下面先为大家介绍4.4版本中Smobiler的优化和修复: 优化 1, PageView ...
- 【转】java缩放图片、java裁剪图片代码工具类
一首先看下效果 二工具类 三测试类 在系统的上传图片功能中,我们无法控制用户上传图片的大小,用户可能会上传大到几十M小到1k的的图片,一方面图片太大占据了太多的空间,另一方面,我们没办法在页面上显示统 ...
- 从零开始学安全(三十六)●利用python 爆破form表单
import sys import requests from requests.auth import HTTPBasicAuth def Brute_Force_Web(postData): re ...
- Java开发笔记(二十三)数组工具Arrays
数组作为一种组合形式的数据类型,必然要求提供一些处理数组的简便办法,包括数组比较.数组复制.数组排序等等.为此Java专门设计了Arrays工具,该工具包含了几个常用方法,方便程序员对数组进行加工操作 ...