Taffy Web开发,Python Flask实践详解
1. 前言
2. 实现细节
2.1 安装相关lib
pip install flask
pip install flask-bootstrap
pip install flask-wtf
pip install nose
pip install nose-html-reporting
reload(sys)
sys.setdefaultencoding("utf-8")
在文件最下方_format_output方法中修改return o.decode('latin-1')为return o.decode('utf-8')

2.2 下载Bootstrap

3) 解压下载的bootstrap-3.3.7.zip,其中dashboard模板目录为bootstrap-3.3.7\docs\examples\dashboard
2.3 Taffy_Web项目基本结构

2.4 核心代码讲解
2.4.1 “运行测试”按钮通过onclick绑定了一个runCase()的js方法
<button type="button" id="run-case" class="btn btn-success" onclick="runCase()">运行测试</button>
2.4.2 runCase() js方法
function runCase() {
var params = {};
var selects=getSelect();
var button=$("#run-case"); if(selects == "") {
alertMessage('未选中任何文件!','warning');
}
else {
button.attr("disabled", true);
params["caseFiles"]=selects;
alertMessage("后台运行测试中,请稍候...");
$.post("/runCase",params,function(result){
if (result['desc']=='0' || result['desc']) {
alertMessage('测试运行完成,返回码:<strong>'+result['desc']+'</strong>.\t<a href="report" class="alert-link">点击查看报告!</a>');
//刷新用例列表
getCase();}
else {
alertMessage(result['desc'],'danger');}
button.removeAttr("disabled");
});
}
}
2.4.3 views.py中定义的runcCase视图函数
@app.route("/runCase", methods=["GET", "POST"])
def runCase():
if request.method == "POST":
# 获取数组参数
caseFiles = request.form.getlist("caseFiles[]")
result = {}
try:
caseFiles = ' '.join(map(lambda i: '"' + i + '"', caseFiles)).encode('gbk')
config = yaml.load(file(CONFIG_FILE, 'r'))
# Taffy路径
taffy_dir = config['taffy_dir']
# 测试报告名称
report_name = config['report_name'] + '_{0}.html'.format(dt.now().strftime('%Y%m%d_%H%M%S'))
# 先判断文件夹是否存在,不存在则新建
reportDir = os.path.join(taffy_dir, 'Results')
if not os.path.exists(reportDir):
os.makedirs(reportDir)
# 测试报告路径
report_file = os.path.join(reportDir, report_name)
command = 'nosetests -v {0} --with-html --html-report="{1}"'.format(caseFiles, report_file.encode('gbk'))
result['desc'] = os.system(command) # 判断是否自动发送结果邮件
if config['auto_send']:
result = sendReportMail(report_file)
except Exception as e:
result['exception'] = u'用例运行失败:{0}'.format(e)
return jsonify(result)
3. 成果展示
3.1 示例视频
3.2 示例图片
3.2.1 首页
3.2.2 用例
3.2.3 报告
3.2.4 配置

4. 源码下载
5. 参考资料
Taffy Web开发,Python Flask实践详解的更多相关文章
- Taffy自动化测试框架Web开发,Python Flask实践详解
1. 前言 最近为Taffy自动化测试框架写了个页面,主要实现了用例管理.执行,测试报告查看管理.发送邮件及配置等功能. 本页面适用所有基于taffy/nose框架编写的自动化测试脚本,或基于un ...
- python flask框架详解
Flask是一个Python编写的Web 微框架,让我们可以使用Python语言快速实现一个网站或Web服务.本文参考自Flask官方文档, 英文不好的同学也可以参考中文文档 1.安装flask pi ...
- Python基础知识详解 从入门到精通(七)类与对象
本篇主要是介绍python,内容可先看目录其他基础知识详解,欢迎查看本人的其他文章Python基础知识详解 从入门到精通(一)介绍Python基础知识详解 从入门到精通(二)基础Python基础知识详 ...
- VirtualBox开发环境的搭建详解(转)
VirtualBox开发环境的搭建详解 有关VirtualBox的介绍请参考:VirtualBox_百度百科 由于VirtualBox官网提供的搭建方法不够详细,而且本人在它指导下,从下载所需的开 ...
- IE8"开发人员工具"使用详解下(浏览器模式、文本模式、JavaScript调试、探查器)
来源: http://www.cnblogs.com/JustinYoung/archive/2009/04/03/kaifarenyuangongju2.html 在上一篇文章IE8“开发人员工具” ...
- IE8“开发人员工具”使用详解上(各级菜单详解)
来源: http://www.cnblogs.com/JustinYoung/archive/2009/03/24/kaifarenyuangongju.html IE8“开发人员工具”使用详解上(各 ...
- iOS 开发之照片框架详解
转载自:http://kayosite.com/ios-development-and-detail-of-photo-framework.html 一. 概要 在 iOS 设备中,照片和视频是相当重 ...
- nginx高性能WEB服务器系列之四配置文件详解
nginx系列友情链接:nginx高性能WEB服务器系列之一简介及安装https://www.cnblogs.com/maxtgood/p/9597596.htmlnginx高性能WEB服务器系列之二 ...
- Python之print详解
Python之print详解 http://www.jb51.net/article/55768.htm print的一些基本用法,在前面的讲述中也涉及一些,本讲是在复习的基础上,尽量再多点内容. ...
随机推荐
- C#中的异常处理(try-catch的使用)——使程序更加稳定
使用try-catch来对代码中容易出现异常的语句进行异常捕获. try { 可能出现异常的代码: } catch { 出现异常后需要执行的代码: } 注:1.在执行过程中,如果try中的代码没有出现 ...
- 深度学习系列 Part (2)
1. 神经网络原理 神经网络模型,是上一章节提到的典型的监督学习问题,即我们有一组输入以及对应的目标输出,求最优模型.通过最优模型,当我们有新的输入时,可以得到一个近似真实的预测输出. 我们先看一下如 ...
- Leetcode题解(20)
59. Spiral Matrix II 题目 这道题copy网上的代码 class Solution { private: ][]; ][]; public: void dfs(int dep, v ...
- Can you solve this equation?
Problem Description Now,given the equation 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,can you find its sol ...
- Increasing Speed Limits
Increasing Speed Limits Time Limit: 2000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- Grunt打包之seajs项目【转】
原文:http://www.cnblogs.com/accordion/p/4508154.html grunt与seajs grunt是前端流行的自定义任务的脚手架工具,我们可以使用grunt来为我 ...
- PHPMailer < 5.2.21 - Local File Disclosure(CVE-2017-5223)
CVE-2017-5223 :PHPMailer < 5.2.21 - Local File Disclosure 本文主要介绍一下PHPMailer < 5.2.21 - Local F ...
- 开源代码学习之Tinyhttpd
想开始陆续研究一些感兴趣的开源代码于是先挑一个代码量短的来过渡一下,写这篇博客的目的是记录下自己学习的过程.Tinyhttpd算是一个微型的web服务器,浏览器与Web服务器之间的通信采用的是Http ...
- .Net主线程扑捉子线程中的异常
首先看一段C#代码:运行后发现主线程通过try{}catch{}是不能扑捉子线程中的抛出来的异常. 代码 ); } public void run() { ...
- MySQL相关的书籍
http://item.jd.com/11389754.htmlhttp://item.jd.com/11390423.html http://item.jd.com/11398721.html