python selenium-webdriver 生成测试报告 (十四)
测试最后的一个重要的过程就是生成一份完整的测试报告,生成测试报告的主要是通过python的一个第三方模块HTMLTestRunner.py生成,但是生成的测试报告不是特别的美观,而且没有办法统计测试结果分类,同时也没有办法把测试结果的图片保存下来。通过github 查找到一个改版后的HTMLTestRunner,但是发现美观是美观些,但是有些小问题,而且也不能把我的测试结果截图显示,所以自己又在其基础上增加了图片、测试结果的饼图分布、对测试结果进行错误、失败、通过进行分类。
生成的报告
下面看下如何生成报告,接下来我们为写一个测试演示的代码生成一份报告,生成报告的时候主要利用unittest和HTMLTestReport构建。
# -*- coding: utf-8 -*-
from selenium import webdriver
import unittest
import os,sys,time
import HTMLTestReport class Baidu(unittest.TestCase): def setUp(self):
self.driver = webdriver.Chrome()
self.driver.implicitly_wait(30)
self.driver.maximize_window()
self.base_url = "https://www.baidu.com"
self.driver.get(self.base_url) def test_case1(self):
'''设计测试失败case'''
print ("========【case_0001】打开百度搜索 =============")
current_time = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time()))
# 必须打印图片路径HTMLTestRunner才能捕获并且生成路径,\image\**\\**.png 是获取路径的条件,必须这样的目录
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()))
pic_path = '.\\result\\image\\'+ '2017-07-17\\' + current_time + '.png'
print (pic_path)
self.driver.save_screenshot(pic_path) #截图测试结果
self.assertIn1('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()
time.sleep(2)
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)
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='梦雨')
runner.run(testunit)
fp.close()
过程很简单,过程需要理解整个过程,HTMLTestReport代码已经共享,请下载整体工程。
python selenium-webdriver 生成测试报告 (十四)的更多相关文章
- Python+selenium自动化生成测试报告
批量执行完用例后,生成的测试报告是文本形式的,不够直观,为了更好的展示测试报告,最好是生成HTML格式的. unittest里面是不能生成html格式报告的,需要导入一个第三方的模块:HTMLTest ...
- Python+Selenium+webdriver环境搭建(windows)以及相关资源下载链接
今天记录一下测试小菜鸟alter在测试入门的一点关于python+Selenium+webdriver环境搭建的经历以及资源分享.欢迎交流学习,批评指正. 一.Python的下载与安装 1.pytho ...
- Python Selenium Webdriver常用方法总结
Python Selenium Webdriver常用方法总结 常用方法函数 加载浏览器驱动: webdriver.Firefox() 打开页面:get() 关闭浏览器:quit() 最大化窗口: m ...
- Python之路【第十四篇】:AngularJS --暂无内容-待更新
Python之路[第十四篇]:AngularJS --暂无内容-待更新
- python selenium webdriver入门基本操作
python selenium webdriver入门基本操作 未经作者允许,禁止转载! from selenium import webdriver import time driver=webdr ...
- selenium webdriver学习(十)------------如何把一个元素拖放到另一个元素里面(转)
selenium webdriver学习(十)------------如何把一个元素拖放到另一个元素里面 博客分类: Selenium-webdriver 元素拖放drag and drop Q群里 ...
- python+selenium +unittest生成HTML测试报告
python+selenium+HTMLTestRunner+unittest生成HTML测试报告 首先要准备HTMLTestRunner文件,官网的HTMLTestRunner是python2语法写 ...
- Python脚本控制的WebDriver 常用操作 <十四> 处理button dropdown 的定位
测试用例场景 模拟选择下拉菜单中数据的操作 Python脚本 测试用HTML代码: <html> <body> <form> <select name=&qu ...
- Selenium2+python自动化54-unittest生成测试报告(HTMLTestRunner)
前言 批量执行完用例后,生成的测试报告是文本形式的,不够直观,为了更好的展示测试报告,最好是生成HTML格式的. unittest里面是不能生成html格式报告的,需要导入一个第三方的模块:HTMLT ...
- Python+Selenium WebDriver API:浏览器及元素的常用函数及变量整理总结
由于网页自动化要操作浏览器以及浏览器页面元素,这里笔者就将浏览器及页面元素常用的函数及变量整理总结一下,以供读者在编写网页自动化测试时查阅. from selenium import webdrive ...
随机推荐
- ueditor 设置高度height. ue.setHeight(400); 设置宽度 width
1.引入的文件: <script type="text/javascript" src="../../dist/ueditor1_4_3-utf8-php/uedi ...
- HDU 6049 17多校2 Sdjpx Is Happy(思维题difficult)
Problem Description Sdjpx is a powful man,he controls a big country.There are n soldiers numbered 1~ ...
- Set和Map数据结构
1.Set ES6 提供了新的数据结构 Set.它类似于数组,但是成员的值都是唯一的,没有重复的值. Set 本身是一个构造函数,用来生成 Set 数据结构. 2.Map JavaScript 的对象 ...
- angularJS使用编写KindEditor,UEidtor,jQuery指令,双重绑定
第一步 <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8 ...
- JAVA个人小程序GUI篇-收银(标签、按钮、复选框、下拉标、文本域、表格······)
如果用eclipse需先装载windowsbuild //导入包 import java.awt.BorderLayout; import java.awt.EventQueue; import ja ...
- Python之路,第六篇:Python入门与基础6
python 列表 序列类型简介(sequence) 字符串str 列表list 元祖tuple 概念: ...
- LAMP搭建个人网站
最近发了一篇paper,需要把成果展示出来,想到正好想到自己有一个阿里云服务器,并且在万网上看到www.yongjieshi.com这个域名一年才50块钱,于是决定搭建一个自己的网站 如果linux玩 ...
- [LeetCode&Python] Problem 696. Count Binary Substrings
Give a string s, count the number of non-empty (contiguous) substrings that have the same number of ...
- hdoj-1503 (LCS解的输出)
题目链接 回溯输出解 #include <bits/stdc++.h> using namespace std; ; int dp[N][N],dir[N][N]; char s1[N], ...
- HDU5952 Counting Cliques (暴力深搜+剪枝) (2016ACM/ICPC亚洲赛区沈阳站 Problem E)
题目链接:传送门 题目: Counting Cliques Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total S ...