较测试报告(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. 02_SQliteOpenHelper介绍&oncreate方法介绍

    file:///D:/BaiduNetdiskDownload/adt-bundle-windows-x86_64_20140101/adt-bundle-windows-x86_64_2014010 ...

  2. [poj1236]Network of Schools(targin缩点SCC)

    题意:有N个学校,从每个学校都能从一个单向网络到另外一个学校.1:初始至少需要向多少个学校发放软件,使得网络内所有的学校最终都能得到软件.2:至少需要添加几条边,使任意向一个学校发放软件后,经过若干次 ...

  3. Power OFF and ON USB device in linux (ubuntu)

    Power OFF and ON USB device in linux (ubuntu) http://loginroot.com/power-off-and-on-usb-device-in-li ...

  4. winform防止界面卡死的三种方法

    在编程过程中经常会遇到耗时操作,这个时候如果不采取一些必要的异步操作,就会导致界面的卡死,这里以winform为例子,介绍三种方法防止界面卡死,对这几个方法稍加修改同样适用于wpf,silverlig ...

  5. JavaScript 的基本语法

    说明:此类博客来自以下链接,对原内容做了标注重点知识,此处仅供自己学习参考! 来源:https://wangdoc.com/javascript/basic/introduction.html 1. ...

  6. Js获取当前的日期和时间以及时间戳转化为时间

    /** *获取当前时间 *format=1精确到天 *format=2精确到分 */ function getCurrentDate(format) { var now = new Date(); v ...

  7. 转载-聊一聊深度学习的activation function

    目录 1. 背景 2. 深度学习中常见的激活函数 2.1 Sigmoid函数 2.2 tanh函数 2.3 ReLU函数 2.4 Leaky ReLu函数 2.5 ELU(Exponential Li ...

  8. 容易忘记的css属性和动画属性

    动画属性 @keyframes 关键帧 --> animation 活泼 (配合使用) transform 变换 --> transition 过渡 (配合使用) 1.animation ...

  9. express使用post方法

    express有get.post和在路由后面跟参数,这三种接参方式,这篇文章我主要记录post使用方法 1.json解析中间件(body-parser) cnpm install body-parse ...

  10. 源码分析(一) 进程cleos的命令解析

    EOS版本:4.0   一.进程cleos的作用   cleos,即为client eos.从名字就可以猜出来,它是一个标准的客户端程序,而实际上,它也确实为一个标准的client^_^   准确地说 ...