第一种

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种样式的测试报告的更多相关文章

  1. Python&Selenium&pytest借助allure生成自动化测试报告

    一.摘要 本篇博文将介绍Python和Selenium进行自动化测试时,如何借助allure生成自动化测试报告 二.环境配置 首先python环境中安装pytest和pytest_allure_ada ...

  2. python + selenium webdriver 复合型css样式的元素定位方法

    <div class="header layout clearfix"></div> 当元素没有id,没有name,没有任何,只有一个class的时候,应该 ...

  3. python 输出颜色与样式的方法

    上次遇到这个问题就想写下来,其实当时我也不怎么会,老师说这个东西不需要理解,只需要死记硬背,写的多了就记住了,所以今天搜集了几篇文章,加上自己的理解,写下了这篇python 输出颜色的样式与方法的文章 ...

  4. Jenkins自动执行python脚本输出测试报告

    前言 在用python做自动化测试时,我们写好代码,然后需要执行才能得到测试报告,这时我们可以通过 Jenkins 来进一步完成自动化工作. 借助Jenkins,我们可以结合 Git/SVN 自动拉取 ...

  5. python输出颜色与样式的方法

    一.输出颜色与样式的方法 上次遇到这个问题就想写下来,其实当时我也不怎么会,老师说这个东西不需要理解,只需要死记硬背,写的多了就记住了,所以今天搜集了几篇文章,加上自己的理解,写下了这篇python ...

  6. Python+Selenium自动化-定位页面元素的八种方法

    Python+Selenium自动化-定位页面元素的八种方法   本篇文字主要学习selenium定位页面元素的集中方法,以百度首页为例子. 0.元素定位方法主要有: id定位:find_elemen ...

  7. python selenium 三种等待方式详解[转]

    python selenium 三种等待方式详解   引言: 当你觉得你的定位没有问题,但是却直接报了元素不可见,那你就可以考虑是不是因为程序运行太快或者页面加载太慢造成了元素不可见,那就必须要加等待 ...

  8. 【转】【Python + selenium】linux和mac环境,驱动器chromedriver和测试报告HTMLTestRunner放置的位置

    感谢: 作者:gz_tester,文章:<linux和mac环境,chromedriver和HTMLTestRunner放置的位置> 使用场景 配置python selenium 环境 使 ...

  9. Python selenium chrome打包exe后禁用控制台输出滚动日志

    Python selenium chrome打包exe后,在运行的过程中,如果遇到需要input()输入时,会发现被不断滚动刷新的日志把命令行输入快速顶掉了,通过查阅资料不断实践,发现以下方法有效: ...

随机推荐

  1. web Components 学习之路

    就目前而言,纯粹的Web Components在兼容性方面还有着较为长远的路,这里做个记录总结,以纪念自己最近关于Web Components的学习道路. 参考教材 JavaScript 标准参考教程 ...

  2. JVM基础系列第9讲:JVM垃圾回收器

    前面文章中,我们介绍了 Java 虚拟机的内存结构,Java 虚拟机的垃圾回收机制,那么这篇文章我们说说具体执行垃圾回收的垃圾回收器. 总的来说,Java 虚拟机的垃圾回收器可以分为四大类别:串行回收 ...

  3. Lucene 07 - 对Lucene的索引库进行增删改查

    目录 1 添加索引 2 删除索引 2.1 根据Term删除索引 2.2 删除全部索引(慎用) 3 更新索引 数据保存在关系型数据库中, 需要实现增.删.改.查操作; 索引保存在索引库中, 也需要实现增 ...

  4. .NET应用程序管理服务AMS设计

    AMS全称是Application Management Server即应用程序管理服:由于经常要写些一些应用服务,每次部署和维护都比较麻烦,首先要针对服务编写一个windows服务程序方便系统启动里 ...

  5. java~spring-ioc的使用

    spring-ioc的使用 IOC容器在很多框架里都在使用,而在spring里它被应用的最大广泛,在框架层面 上,很多功能都使用了ioc技术,下面我们看一下ioc的使用方法. 把服务注册到ioc容器 ...

  6. 前端笔记之JavaScript(九)定时器&JSON&同步异步/回调函数&函数节流&call/apply

    一.快捷位置和尺寸属性 DOM已经提供给我们计算后的样式,但是还是觉得不方便,因为计算后的样式属性值都是字符串类型. 不能直接参与运算. 所以DOM又提供了一些API:得到的就是number类型的数据 ...

  7. springboot情操陶冶-web配置(六)

    本文则针对数据库的连接配置作下简单的分析,方便笔者理解以及后续的查阅 栗子当先 以我们经常用的mybatis数据库持久框架来操作mysql服务为例 环境依赖 1.JDK v1.8+ 2.springb ...

  8. 自动化运维工具fabric使用教程

    摘要:当需要同时管理许多服务器时,如果我们一台一台登陆上去操作会显得费时又费力.此时我们可以用fabric这个包提供的API来编写python脚本完成服务器集群的统一管理. 核心原理:fabric为主 ...

  9. QSS的使用(二)——实现ColorLabel

    在上一篇文章中,我们已经了解了QSS的基础使用,现在我们将会看到一个简单的例子来加深对QSS的理解. 需求分析 我们想要在界面中让文本显示出指定的颜色,现在有几种方案: 使用paintEvent手动计 ...

  10. jquery/js知识点收藏

    1]关于页面跳转 "window.location.href"."location.href"是本页面跳转 "parent.location.href ...