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 ...
随机推荐
- SRAM SROM DRAM DROM DDR NAND FLASH EMMC的区别
RAM(Random Access Memory)的全名为随机存取记忆体,它相当于PC机上的移动存储,用来存储和保存数据的.它在任何 时候都可以读写,RAM通常是作为操作系统或其他正在运行程序的临时存 ...
- 32bit / 64bit co-exist Linux, ld-linux.so, linux-gate.so.1 etc
before this, confirm that you don't have 32bit libs notably 32bit libc, e.g. you have /lib64/ld-linu ...
- Git 分支管理 多人协作 远程仓库 补充
当你从远程仓库克隆时,实际上Git自动把本地的master分支和远程的master分支对应起来了, 并且,远程仓库的默认名称是origin. 如果是本地仓库关联远程仓库 --- 要查看远程库的信息,用 ...
- (转)深度学习(Deep Learning, DL)的相关资料总结
from:http://blog.sciencenet.cn/blog-830496-679604.html 深度学习(Deep Learning,DL)的相关资料总结 有人认为DL是人工智能的一场革 ...
- STL——queue
1.初始化 需要头文件<queue> queue<int>que; 2.成员函数 C++队列Queue类成员函数如下: back()返回最后一个元素 empty()如果队列空则 ...
- IT兄弟连 Java语法教程 Java平台的版本划分
自从Sun公司推出Java以来,就力图使之无所不能.Java发展至今,按应用范围划分为3个版本,即Java SE.Java EE和Java ME,也就是SunOne(Open Net Environm ...
- pytest框架(五)
代码示例一 # coding=utf-8 import pytest @pytest.fixture() def login(): print("输入账号,密码先登录") def ...
- 剑指Offer的学习笔记(C#篇)-- 数组中只出现一次的数字
题目描述 一个整型数组里除了两个数字之外,其他的数字都出现了两次.请写程序找出这两个只出现一次的数字. 题目给定:num1,num2分别为长度为1的数组.传出参数:将 num1[0], num2[0 ...
- django导入导出excel实践
一.xlrd和xlwt模块介绍 xlrd模块提供在任何平台上从excel电子表格(.xls和.xlsx)中提取数据的功能,xlwt模块提供生成与Microsoft Excel 95 到2003版本兼容 ...
- iOS 技术支持
iOS 技术支持网址:有问题或建议请留言. 邮箱地址:odeyrossskudder4266848@mail.com iOS program design & system consultat ...