较测试报告(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. JAVA类型信息——Class对象(转载)

    JAVA类型信息--Class对象 一.RTTI概要 1.类型信息RTTI :即对象和类的信息,例如类的名字.继承的基类.实现的接口等. 2.类型信息的作用:程序员可以在程序运行时发现和使用类型信息. ...

  2. 【239】◀▶IEW-Unit04

    Unit 4 Youth Issues: Computer Use 1 Model1题目及范文分析 Some teenagers spend a lot of time playing compute ...

  3. linux下c语言利用iconv函数实现utf-8转unicode

    iconv是linux下的编码转换的工具,它提供命令行的使用和函数接口支持 man手册iconv命令用法如下: iconv -f encoding -t encoding inputfile 有如下选 ...

  4. iframe和window对象的关系

    浏览器会在其打开一个 HTML 文档时创建一个对应的 window 对象.但是,如果一个文档定义了一个或多个框架(即,包含一个或多个 frame 或 iframe 标签),浏览器就会为原始文档创建一个 ...

  5. Centos7更新阿里yum源

    一.下载repo文件 wget http://mirrors.aliyun.com/repo/Centos-7.repo 二.备份并替换系统的repo文件 cp Centos-7.repo /etc/ ...

  6. cf791B(完全图&dfs)

    题目链接:http://codeforces.com/contest/791/problem/B 题意:给出一个无向图,问是否满足若存在边ab, bc则存在边ac: 思路:题意即,对于一个点,其所有子 ...

  7. [Xcode 实际操作]七、文件与数据-(3)创建文本文件、属性列表文件、图片文件

    目录:[Swift]Xcode实际操作 本文将演示如何创建各种类型的文件. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] import UIKit class V ...

  8. 在IDEA中设置页面背景护眼色的方法

    在IDEA中设置页面背景护眼色的方法如下:

  9. 出现提示ERROR 1289 The 'InnoDB' feature is disabled; you need MySQL built with 'InnoDB' to have IT working

    关闭mysql数据库 在mysql的安装目录中找到my.ini文件找到skip-innodb,在前面加上#号保存,重启mysql服务 OK.

  10. 原型设计模式(prototype

    # 什么是原型设计模式 > 这里与软件工程中的原型开发模式有那么一点类似的地方,我们首先需要构建出一个原型,这个原型可以在现实开发中抽象出来的具体类型,但是这个类型与具体的类又不同,需要抽取公共 ...