Python+selenium之测试报告(2)
# -*- coding: utf-8 -*-
import HTMLTestReport
import HTMLTestRunner
import os
import sys
import time
import unittest
from selenium import webdriver class Baidu(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.driver.maximize_window()
# self.base_url = "https://www.baidu.com"
# self.driver.get(self.base_url)
self.driver.get("https://www.baidu.com") def test_case1(self):
"""设计测试失败case""" # *****效果是在测试报告中显示显示出测试名称*****
print("========【case_0001】打开百度搜索 =============")
# current_time = time.strftime("%Y-%M-%D-%H-%M-%S", time.localtime(time.time()))
# "."表示创建的路径为当.py文件所处的地址,\\是用\将“\”转义
# pic_path = '.\\result\\image\\' + current_time + '.png'
current_time = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time()))
pic_path = '.\\result\\image\\' + '2017-07-17\\' + current_time + '.png'
print(pic_path) # 打印图片的地址
time.sleep(2)
self.driver.save_screenshot(pic_path) # 截图,获取测试结果
self.assertEqual('百度一下,你就知道', self.driver.title) # 断言判断测试是否成功,判断标题是否为百度(设计失败的case) def test_case2(self):
"""设计测试过程中报错的case"""
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)
# current_time = time.strftime("%Y-%M-%D-%H-%M-%S", time.localtime(time.time()))
current_time = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time()))
# "."表示创建的路径为当.py文件所处的地址,\\是用\将“\”转义
pic_path = '.\\result\\image\\'+'2017-07-17\\' + current_time + '.png'
print(pic_path) # 打印图片的地址
time.sleep(2)
self.driver.save_screenshot(pic_path) # 截图,获取测试结果
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()
# current_time = time.strftime("%Y-%M-%D-%H-%M-%S", time.localtime(time.time()))
current_time = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time()))
# "."表示创建的路径为当.py文件所处的地址,\\是用\将“\”转义
pic_path = '.\\result\\image\\2017-07-17\\' + current_time + '.png'
print(pic_path) # 打印图片的地址
time.sleep(2)
self.driver.save_screenshot(pic_path) # 截图,获取测试结果 self.assertIn('梦雨情殇', self.driver.title) def tearDown(self):
self.driver.quit() if __name__ == "__main__":
'''生成测试报告'''
current_time = time.strftime("%Y-%m-%d-%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 = ".\\result\\SoftTestReport_" + current_time + '.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()
注意事项:
1.获取当前时间的格式为:
%Y-%m-%d-%H_%M_%S 而不是 %Y-%M-%D-%H-%M-%S
2.填写的截图存放地址“\”,要用转义字符“\”进行转义,变为“\\”
3.runner = HTMLTestReport.HTMLTestRunner(stream=fp, title=u"自动化测试报告", description='自动化测试演示报告', tester='fyr')的测试报告如图所示:

4.runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title=u"自动化测试报告", description='自动化测试演示报告') 的效果图如图所示:

Python+selenium之测试报告(2)的更多相关文章
- Python+selenium之测试报告(1)
一.下载HTMLTestRunner.py HTMLTestRunner 是 Python 标准库的 unittest 模块的一个扩展.它生成易于使用的 HTML 测试报告.HTMLTestRunne ...
- Python+selenium之测试报告(3)
较测试报告(2),该文章将测试报告和测试截图存放在随机变动的文件夹下面,去除了要存放在指定文件夹下面的限制. 注:遇到问题有: 1.创建由时间自动拼接的多级文件夹 2. import os impor ...
- 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 ...
随机推荐
- Linux命令总结_touch创建文件
1.touch命令,用来创建文件或者修改文件时间戳 格式:touch [选项]... 文件... 选项 : -a 或--time=atime或--time=access或--time=use 只 ...
- 【hdu2955】 Robberies 01背包
标签:01背包 hdu2955 http://acm.hdu.edu.cn/showproblem.php?pid=2955 题意:盗贼抢银行,给出n个银行,每个银行有一定的资金和抢劫后被抓的概率,在 ...
- Spring入门第八课
看如下代码 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http:// ...
- LIS与LCS的nlogn解法
LIS(nlogn) #include<iostream> #include<cstdio> using namespace std; ; int a[maxn]; int n ...
- hdu2612(dijkstra)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2612 题意:给出一个n*m的矩阵,' . ' 表示可以走的路, ' # '表示不能走的路 ,’ @'表 ...
- AGC001 C - Shorten Diameter【枚举】
一开始没看到要保证最后是树--所以一定要从叶子开始删 枚举重心,如果k是偶数,那么按当前重心提起来deep大于k/2的全都要切掉,这样枚举重心然后取min即可 奇数的话就是枚举直径中间的边,然后从两边 ...
- codevs1051接龙游戏
1051 接龙游戏
- Hadoop安装包下载方法
Hadoop3.0版本的诞生,引入了很多新功能,为了验证Hadoop2.0与3.0版本的性能,需下载Hadoop的不同版本.故下文演示如何下载Hadoop安装包的方法. 1. 进入Apache Had ...
- iOS 技术支持
iOS 技术支持网址:有问题或建议请留言. 邮箱地址:odeyrossskudder4266848@mail.com iOS program design & system consultat ...
- 关于JS点击button之灵活替换改变内容方法
<p id="demo">JavaScript 能改变 HTML 元素的内容.</p> <script>function myFunction( ...