第一种

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. 【Spark篇】---Spark中Shuffle机制,SparkShuffle和SortShuffle

    一.前述 Spark中Shuffle的机制可以分为HashShuffle,SortShuffle. SparkShuffle概念 reduceByKey会将上一个RDD中的每一个key对应的所有val ...

  2. 【Docker】(5)---springCloud注册中心打包Docker镜像

    [Docker](5)---springCloud注册中心打包Docker镜像 上一篇文章讲了将镜像推送到远处私有仓库,然后再从私有仓库拉取该镜像的过程.而这里的镜像是直接从Docker拉取的. 所以 ...

  3. 【Docker】(4)搭建私有镜像仓库

    [Docker](4)搭建私有镜像仓库 说明 1. 这里是通过阿里云,搭建Docker私有镜像仓库. 2. 这里打包的镜像是从官网拉下来的,并不是自己项目创建的新镜像,主要测试功能 一.搭建过程 首先 ...

  4. Lucene 04 - 学习使用Lucene的Field(字段)

    目录 1 Field的特性 2 常用的Field类型 3 常用的Field种类使用 3.1 准备环境 3.2 需求分析 3.3 修改代码 3.4 重新建立索引 1 Field的特性 Document( ...

  5. MySQL 索引及查询优化总结

    本文由云+社区发表 文章<MySQL查询分析>讲述了使用MySQL慢查询和explain命令来定位mysql性能瓶颈的方法,定位出性能瓶颈的sql语句后,则需要对低效的sql语句进行优化. ...

  6. HTTP与HTTPS的理解

    最近一直也在面试的过程中,可能由于各个方面的问题,导致没有时间抽出更新博客,今天开始陆续更新!!!以后自己的博客,会向React Native,swift ,以及H5延展,成为一个全栈的技术人员.本篇 ...

  7. Captcha服务(后续1)

    既然标题为后续,就要放一下上一篇文章使用.Net Core 2.1开发Captcha图片验证码服务 继续挖坑 时隔7个月再次继续自己在GitHub上挖的坑 https://github.com/Puz ...

  8. WPF DesiredSize & RenderSize

    DesiredSize DesiredSize介绍 关于DesiredSize的介绍,可以查看最新微软文档对DesiredSize的介绍 DesiredSize,指的是元素在布局过程中计算所需要的大小 ...

  9. python3中time模块与datetime模块的简单用法

    __author__ = "JentZhang" import time # Timestamp 时间戳 print("Timestamp 时间戳:") pri ...

  10. xxxx-xx-xx的时间的加减

    <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8& ...