测试脚本定时执行(即:创建定时任务)
来源:互联网 发布:已经备案的域名 购买 编辑:程序博客网 时间:2024/06/13 10:06
测试脚本的执行时间可通过创建定时任务来进行。
前提:
创建all_python.py文件(该文件主要用于搜索所有测试脚本,将筛选出来的用例,循环添加到测试套件中)例:
例:all_python.py文件内容如下:#coding=utf8
'''
Created on 2016-11-22
@author: Administrator
'''
import unittest
import HTMLTestRunner,time
def createsuite():
testunit = unittest.TestSuite()
#定义测试文件查找的目录
test_dir='F:\\estone_auto\\test_estone\\test_case'
#定义discover 方法的参数
discover=unittest.defaultTestLoader.discover(test_dir,pattern ='test_*.py',top_level_dir=None)
#discover 方法筛选出来的用例,循环添加到测试套件中
for test_suite in discover:
for test_case in test_suite:
testunit.addTests(test_case)
print testunit
return testunit
now = time.strftime("%Y_%m_%d_%H_%M_%S")
filename = 'F:\\estone_auto\\test_estone\\report\\'+now+'result.html'
fp = file(filename,'wb')
runner = HTMLTestRunner.HTMLTestRunner(stream=fp,title=u'测试结果',description=u'用例执行情况')
if __name__ == '__main__':
all_test = createsuite()
runner.run(all_test)
fp.close()
"""runner =unittest.TextTestRunner()
runner.run(all_test)"""
创建方式有两种:
第一种:通过WINDOWS的定时任务创建
通过:控制面板-->任务计划程序-->添加任务计划,按计划向导一步步添加,通过浏览操作,添加all_python.py
添加成功。系统会根据定时任务触发定时事件。
第二种:通过程序创建定时任务
1.创建一个运行文件(该文件主要指定在何时运行何文件,即:定时执行作用),例:建立start_run.py,内容如下:
#coding=utf8
'''
Created on 2016-11-24
@author: Administrator
@summary: 定时执行测试用例
'''
import time,os
k=1
while k<2:
now = time.strftime("%H:%M")
print now
if (now == '11:40'):
print u"开始运行脚本:"
os.chdir("F:\\estone_auto\\test")
os.system('python all_python.py') #执行脚本
print u"运行完成退出"
break
else:
time.sleep(10)
print now
2.cmd方式进入start_run.py,的目录,执行python start_run.py,系统会待定时去执行测试任务
见图:
- 测试脚本定时执行(即:创建定时任务)
- windows创建定时任务执行python脚本
- python设置定时任务(定时执行脚本)
- windows下python设置定时任务(定时执行脚本)
- linux 定时执行shell脚本 定时任务
- 定时任务执行脚本文件
- Linux定时任务执行脚本
- javascript定时任务执行脚本
- 003_010 Python 重复执行任务,即定时任务
- centos 设置定时任务执行指定脚本。
- 定时任务中shell脚本的执行
- MySQL定时执行脚本(计划任务)实例
- Linux 定时执行任务 php脚本 crontab
- kettel job脚本执行定时任务步骤
- centos 设置定时任务执行指定脚本
- Linux定时任务crontab执行脚本出错
- Linux计划任务定时执行脚本
- liunx设置定时任务脚本执行
- cocos2d 角度转换 (精灵图片如何指向点击位置)
- matlab批量读写与处理大量一样的Text
- MySQL备份与恢复
- UITableView自定义左滑删除按钮(带图片)
- Angular2 @Input 和 @Input 用法
- 测试脚本定时执行(即:创建定时任务)
- 牛客:剑指offer:孩子们的游戏(圆圈中最后剩下的数) (Java)
- 从一个页面获取另一个页面是数据
- Discuz!目录结构
- 如何选择机器学习算法
- raml转换为html,js,markdown
- [乐意黎转载]json的解析与序列化
- Javascript定义类(class)的三种方法
- Maven中properties属性