第一种

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. 从源码分析如何优雅的使用 Kafka 生产者

    前言 在上文 设计一个百万级的消息推送系统 中提到消息流转采用的是 Kafka 作为中间件. 其中有朋友咨询在大量消息的情况下 Kakfa 是如何保证消息的高效及一致性呢? 正好以这个问题结合 Kak ...

  2. Spring Security OAuth 2.0

    续·前一篇<OAuth 2.0> OAuth 2.0 Provider 实现 在OAuth 2.0中,provider角色事实上是把授权服务和资源服务分开,有时候它们也可能在同一个应用中, ...

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

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

  4. 【Python3爬虫】下载酷狗音乐上的歌曲

    经过测试,可以下载要付费下载的歌曲(n_n) 准备工作:Python3.5+Pycharm 使用到的库:requests,re,json,time,fakeuseragent 步骤: 打开酷狗音乐的官 ...

  5. Chapter 5 Blood Type——8

    He chuckled. "What are your plans?" 他窃笑道.“那你的计划是什么?” I blushed. I had been vacillating dur ...

  6. Flink生成Parquet格式文件实战

    1.概述 在流数据应用场景中,往往会通过Flink消费Kafka中的数据,然后将这些数据进行结构化到HDFS上,再通过Hive加载这些文件供后续业务分析.今天笔者为大家分析如何使用Flink消费Kaf ...

  7. Java 8的用法(泛型接口,谓词链)

    1.泛型接口 我们举个例子,以前来看一下JPA定义的写法: Specification接口为: public interface Specification<T> { Predicate ...

  8. 【C#加深理解系列】(二)序列化

    什么是序列化 序列化,它又称串行化,是.NET运行时环境用来支持用户定义类型的流化的机制.序列化就是把一个对象保存到一个文件或数据库字段中去,反序列化就是在适当的时候把这个文件再转化成原来的对象使用. ...

  9. 查看服务器运行多少个ASP.NET Core程序

    有时候,我们会想知道某台机器上面跑了什么程序. 当程序部署到IIS上面的时候,我们只需要打开IIS一看,就知道有多少个站点在运行了. 当我们在CentOS上面部署的时候,就没那么的直观了. 当然对于熟 ...

  10. java web 项目打包(war 包)并部署

    1.在eclipse中右键单击项目,然后Export选择WAR file,生成项目的WAR文件.具体步骤请看图片详细操作步骤: 2.把生成的WAR文件放到tomcat解压之后的webapps文件夹下. ...