Python+selenium之测试报告(3)
较测试报告(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)的更多相关文章
- Python+selenium之测试报告(1)
一.下载HTMLTestRunner.py HTMLTestRunner 是 Python 标准库的 unittest 模块的一个扩展.它生成易于使用的 HTML 测试报告.HTMLTestRunne ...
- Python+selenium之测试报告(2)
# -*- coding: utf-8 -*- import HTMLTestReport import HTMLTestRunner import os import sys import time ...
- python+selenium生成测试报告后自动发送邮件
标签(空格分隔): 自动化测试 运行自动化脚本后,会产生测试报告,而将测试报告自动发送给相关人员,能够让对方及时的了解测试情况,查看测试结果. 整个脚本包括三个部分: 生成测试报告 获取最新的测试报告 ...
- python selenium自动化测试报告
先记录一下,后续继续更新. 首先:HTMLTestRunner的下载地址:http://tungwaiyip.info/software/HTMLTestRunner.html 选中后单击右键,在弹出 ...
- 【转】【Python + selenium】linux和mac环境,驱动器chromedriver和测试报告HTMLTestRunner放置的位置
感谢: 作者:gz_tester,文章:<linux和mac环境,chromedriver和HTMLTestRunner放置的位置> 使用场景 配置python selenium 环境 使 ...
- python+selenium +unittest生成HTML测试报告
python+selenium+HTMLTestRunner+unittest生成HTML测试报告 首先要准备HTMLTestRunner文件,官网的HTMLTestRunner是python2语法写 ...
- 使用python selenium进行自动化functional test
Why Automation Testing 现在似乎大家都一致认同一个项目应该有足够多的测试来保证功能的正常运作,而且这些此处的‘测试’特指自动化测试:并且大多数人会认为如果还有哪个项目依然采用人工 ...
- Python Selenium设计模式-POM
前言 本文就python selenium自动化测试实践中所需要的POM设计模式进行分享,以便大家在实践中对POM的特点.应用场景和核心思想有一定的理解和掌握. 为什么要用POM 基于python s ...
- Jenkins持续集成项目搭建与实践——基于Python Selenium自动化测试(自由风格)
Jenkins简介 Jenkins是Java编写的非常流行的持续集成(CI)服务,起源于Hudson项目.所以Jenkins和Hudson功能相似. Jenkins支持各种版本的控制工具,如CVS.S ...
随机推荐
- EasyUI把datagrid的值赋给表单
$('#infoForm${INDEX}').form('load', rowToDto(pageConfig${INDEX}.infoName, row)); function rowToDto(i ...
- FZU 2059 MM (并查集+排序插入)
Problem 2059 MM Accept: 109 Submit: 484Time Limit: 1000 mSec Memory Limit : 32768 KB Problem ...
- jQuery 操作select 下拉列表
jQuery这个框架方便了我们对于HTML元素的操作,本来以为自己对于Select操作也算是熟悉了,但上午在测试的时候才发现自己了解的还真不多. 看了一下jQuery的一些方法后,理出了一些常用的方法 ...
- java大神进阶之路
既然励志在java路上走的更远,那就必须了解java的路径.先看图 更加细化的细节如下 一: 编程基础 不管是C还是C++,不管是Java还是PHP,想成为一名合格的程序员,基本的数据结构和算法基础还 ...
- UE4]不使用角色蓝图、动画蓝图、状态机,用“24K纯C++”实现动画播放
http://aigo.iteye.com/blog/2283454 原文作者:@玄冬Wong 不好意思,我稍稍标题党了,目前还不清楚如何用C++代码来实现BlendSpace和Montage的逻辑, ...
- ue4 motage
Montage是什么 一个(可以自由拼接动画的)动画剪辑,通过slot,在任意时候由玩家主动向动画系统push自己制作的动画剪辑 Montage用途 上图是一个近身攻击动画,含有 3 个片段 [开始. ...
- hdu1166(线段树单点更新&区间求和模板)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1166 题意:中文题诶- 思路:线段树单点更新,区间求和模板 代码: #include <iost ...
- Fire (poj 2152 树形dp)
Fire (poj 2152 树形dp) 给定一棵n个结点的树(1<n<=1000).现在要选择某些点,使得整棵树都被覆盖到.当选择第i个点的时候,可以覆盖和它距离在d[i]之内的结点,同 ...
- codevs1074 食物链
1074 食物链 2001年NOI全国竞赛 时间限制: 3 s 空间限制: 64000 KB 题目等级 : 钻石 Diamond 题解
- 面试大厂回来后,有一些话想对 Java 后端开发说一说
在上周,我密集面试了若干位Java后端的候选人,工作经验在3到5年间.我的标准其实不复杂:第一能干活,第二Java基础要好,第三最好熟悉些分布式框架,我相信其它公司招初级开发时,应该也照着这个标准来面 ...