较测试报告(2),该文章将测试报告和测试截图存放在随机变动的文件夹下面,去除了要存放在指定文件夹下面的限制。

注:遇到问题有:

1.创建由时间自动拼接的多级文件夹

2.

 import os
import time current_time = time.strftime("%Y-%m-%d-%H_%M", time.localtime(time.time()))
current_time1 = time.strftime("%H_%M_%S", time.localtime(time.time()))
pic_path1 = '.\\' + current_time + "\\result\\"
pic_path = pic_path1 + "image"+"\\" + current_time1 + '.png'
os.makedirs(pic_path)
print(pic_path)

拼接好的路径要使用os.makedirs()创建对应的文件夹目录

path = pic_path1 + current_time1 + '.png'  
创建好的文件夹无法再使用该路径继续创建下级路径,只能存放对应的内容
3.测试报告必须得放在测图文件的外层目录下,否者在测试报告中查找图片会报如下的错误

整个代码如下:

 # -*- coding: utf-8 -*-
import HTMLTestReport
import HTMLTestRunner
import os
import sys
import time
import unittest
from selenium import webdriver current_time = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime(time.time()))
pic_path = '.\\' + current_time + "\\result\\"
pic_path1 = '.\\' + current_time + "\\result\\image\\"
os.makedirs(pic_path)
os.makedirs(pic_path1) class Baidu(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.driver.maximize_window()
self.driver.get("https://www.baidu.com")
time.sleep(5) def test_case1(self):
"""设计测试case""" # *****效果是在测试报告中显示显示出测试名称*****
print("========【case_0001】打开百度搜索 =============")
# "."表示创建的路径为当.py文件所处的地址,\\是用\将“\”转义
current_time1 = time.strftime("%H_%M_%S", time.localtime(time.time()))
path = pic_path1 + current_time1 + '.png'
print(path) # 打印图片的地址
time.sleep(5)
self.driver.save_screenshot(path) # 截图,获取测试结果
time.sleep(2)
self.assertEqual('百度一下,你就知道', self.driver.title) # 断言判断测试是否成功,判断标题是否为百度(设计失败的case) def test_case2(self):
"""设计测试过程中报错的case"""
global pic_path
print("========【case_0002】搜索selenium =============")
self.driver.find_element_by_id("kw").clear()
self.driver.find_element_by_id("kw").send_keys(u"selenium")
self.driver.find_element_by_id('su').click()
time.sleep(2)
# "."表示创建的路径为当.py文件所处的地址,\\是用\将“\”转义
current_time1 = time.strftime("%H_%M_%S", time.localtime(time.time()))
path = pic_path1 + current_time1 + '.png'
print(path) # 打印图片的地址
time.sleep(5)
self.driver.save_screenshot(path) # 截图,获取测试结果
time.sleep(2)
self.assertIn('selenium', self.driver.title) # 断言书写错误,导致case出错 def test_case3(self):
"""设计测试成功的case"""
print("========【case_0003】 搜索梦雨情殇博客=============")
self.driver.find_element_by_id("kw").clear()
self.driver.find_element_by_id("kw").send_keys(u"明道")
self.driver.find_element_by_id('su').click()
# "."表示创建的路径为当.py文件所处的地址,\\是用\将“\”转义
current_time1 = time.strftime("%H_%M_%S", time.localtime(time.time()))
path = pic_path1 + current_time1 + '.png'
print(path) # 打印图片的地址
time.sleep(5)
self.driver.save_screenshot(path) # 截图,获取测试结果
time.sleep(3)
print(self.driver.title) self.assertIn('明道', self.driver.title) def tearDown(self):
self.driver.quit() if __name__ == "__main__":
'''生成测试报告'''
current_time1 = time.strftime("%H_%M_%S", time.localtime(time.time()))
testunit = unittest.TestSuite()
testunit.addTest(Baidu("test_case1"))
testunit.addTest(Baidu("test_case2"))
testunit.addTest(Baidu("test_case3"))
report_path = pic_path + "SoftTestReport_" + current_time1 + '.html' # 生成测试报告的路径
fp = open(report_path, "wb")
runner = HTMLTestReport.HTMLTestRunner(stream=fp, title=u"自动化测试报告", description='自动化测试演示报告', tester='fyr')
# runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title=u"自动化测试报告", description='自动化测试演示报告')
runner.run(testunit)
fp.close()


 

Python+selenium之测试报告(3)的更多相关文章

  1. Python+selenium之测试报告(1)

    一.下载HTMLTestRunner.py HTMLTestRunner 是 Python 标准库的 unittest 模块的一个扩展.它生成易于使用的 HTML 测试报告.HTMLTestRunne ...

  2. Python+selenium之测试报告(2)

    # -*- coding: utf-8 -*- import HTMLTestReport import HTMLTestRunner import os import sys import time ...

  3. python+selenium生成测试报告后自动发送邮件

    标签(空格分隔): 自动化测试 运行自动化脚本后,会产生测试报告,而将测试报告自动发送给相关人员,能够让对方及时的了解测试情况,查看测试结果. 整个脚本包括三个部分: 生成测试报告 获取最新的测试报告 ...

  4. python selenium自动化测试报告

    先记录一下,后续继续更新. 首先:HTMLTestRunner的下载地址:http://tungwaiyip.info/software/HTMLTestRunner.html 选中后单击右键,在弹出 ...

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

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

  6. python+selenium +unittest生成HTML测试报告

    python+selenium+HTMLTestRunner+unittest生成HTML测试报告 首先要准备HTMLTestRunner文件,官网的HTMLTestRunner是python2语法写 ...

  7. 使用python selenium进行自动化functional test

    Why Automation Testing 现在似乎大家都一致认同一个项目应该有足够多的测试来保证功能的正常运作,而且这些此处的‘测试’特指自动化测试:并且大多数人会认为如果还有哪个项目依然采用人工 ...

  8. Python Selenium设计模式-POM

    前言 本文就python selenium自动化测试实践中所需要的POM设计模式进行分享,以便大家在实践中对POM的特点.应用场景和核心思想有一定的理解和掌握. 为什么要用POM 基于python s ...

  9. Jenkins持续集成项目搭建与实践——基于Python Selenium自动化测试(自由风格)

    Jenkins简介 Jenkins是Java编写的非常流行的持续集成(CI)服务,起源于Hudson项目.所以Jenkins和Hudson功能相似. Jenkins支持各种版本的控制工具,如CVS.S ...

随机推荐

  1. IIS7启用GZip压缩

    本文转载自 http://www.cnblogs.com/kissdodog/p/6252129.html GZip压缩通常会达到70%以上的压缩率,如果是手机Web这无疑会使网站的访问速度大大增加, ...

  2. 基于Laravel框架的一个简单易学的微信商城(新手必学)

    俗话说,麻雀虽小可五脏俱全呀! 今天分享的这个基于Laravel的小项目大概功能有这些: 1.实现会员登录.注册功能.数据双向验证功能.2.实现手机短信验证.邮件激活账号.邮件通知.3.ajax提交数 ...

  3. linux jar 后台运行

    在linux系统中可以利用nohup来执行任何命令,并把命令自动调到linux后台运行,不锁定当前ssh窗口,也不会被ctrl + c,alt + F4之类打断程序的动行.如: nohup java ...

  4. Finding Comments in Source Code Using Regular Expressions

    Many text editors have advanced find (and replace) features. When I’m programming, I like to use an ...

  5. js读取excel中日期格式转换问题

    在使用js-xlsx插件来读取excel时,会将2018/10/16这种数据自动装换成48264.12584511. 所以需要自己手动再转换回来 // excel读取2018/01/01这种时间格式是 ...

  6. Linux之vim常用扩展操作

    多窗口编辑 批量注释和自定义注释 显示行号 1.多窗口编辑 2.批量注释和自定义注释 3.显示行号(临时生效) 命令行模式下输入: set nu 显示行号 set nonu 不显示行号

  7. linux和windows下安装python拓展包及requirement.txt安装类库

    python拓展包安装 直接安装拓展包默认路径: Unix(Linux)默认路径:/usr/local/lib/pythonX.Y/site-packagesWindows默认路径:C:\Python ...

  8. 动画重定向技术分析和Unity中的应用

    http://www.jianshu.com/p/6e9ba1b9c99e 因为一些手游项目需要使用Unity引擎,但在动画部分需要使用重定向技术来实现动画复用,考虑到有些项目开发人员没有过这方面的经 ...

  9. 如何使用Xshell连接VMware上的Linux虚拟机

    前序:最近开始研究Hadoop平台的搭建,故在本机上安装了VMware workstation pro,并创建了Linux虚拟机(centos系统),为了方便本机和虚拟机间的切换,准备使用Xshell ...

  10. php高并发之opcache

    今天工作的时候接触到客户的一台服务器,业务逻辑比较简单 .估算pv在120w左右吧,用的是阿里云2c4g的服务器.一大早就开始卡顿了,登陆服务器后查看负载到了八九十. 之后就想办法调整一下吧.突然想起 ...