网站首页 > 技术文章 正文
创建定时任务,在指定的时间自动运行测试用例
设置指定的时间让自动化python脚本自动运行起来,不需要人为手动点击启动运行
私信小编01即可获取大量Python学习资料
一、创建定时任务的方法
1.通过程序创建定时任务
利用Python提供的os模块中里的system()方法运行程序命令
例如:os.system('E:\\test_baidu\\test_baidu.py')
又或者可以先切换到要运行的py文件目录下,os.chdir(),chdir()用切换到某个目录下,当相于shell中的“cd”命令,
os.chdir("E:\\Test_baidu\\abandon\\测试用例集Testsuit")
os.system('Python baidu1.py') # 自动启动baidu1.py
定时任务的实例代码如下:
#coding=utf-8
import os, time
t = 1
while t < 2:
curr_time = time.strftime('%H_%M')
if now_time == '17_31':
print(u"开始运行脚本:")
os.chdir("E:\\Test_baidu\\abandon\\测试用例集Testsuit")
os.system('Python baidu1.py') #自动启动baidu1.py
break
else:
time.sleep(5)
print(curr_time )
2.Windows添加任务计划
进入控制面板--》管理工具--》任务计划程序-》,步骤演示如下:
猜你喜欢
- 2025-01-11 管理定时任务的简单工具——Pythonschedule库
- 2025-01-11 Python定时任务:schedule库使用指南
- 2025-01-11 使用Python快速实现一个高级定时任务
- 2025-01-11 Python脚本如何定时运行
- 2025-01-11 python定时任务最强框架APScheduler详细教程
- 2025-01-11 Python「定时任务」:你的自动化小能手,了解一下?
- 2025-01-11 讲解下python的定时任务(sched模块用法实例)零基础不可错过
- 2025-01-11 Python定时任务,三步实现自动化
- 05-25Python 3.14 t-string 要来了,它与 f-string 有何不同?
- 05-25Python基础元素语法总结
- 05-25Python中的变量是什么东西?
- 05-25新手常见的python报错及解决方案
- 05-2511-Python变量
- 05-2510个每个人都是需要知道Python问题
- 05-25Python编程:轻松掌握函数定义、类型及其参数传递方式
- 05-25Python基础语法
- 257℃Python短文,Python中的嵌套条件语句(六)
- 257℃python笔记:for循环嵌套。end=""的作用,图形打印
- 256℃PythonNet:实现Python与.Net代码相互调用!
- 251℃Python操作Sqlserver数据库(多库同时异步执行:增删改查)
- 251℃Python实现字符串小写转大写并写入文件
- 106℃原来2025是完美的平方年,一起探索六种平方的算吧
- 90℃Python 和 JavaScript 终于联姻了!PythonMonkey 要火?
- 81℃Ollama v0.4.5-v0.4.7 更新集合:Ollama Python 库改进、新模型支持
- 最近发表
- 标签列表
-
- python中类 (31)
- python 迭代 (34)
- python 小写 (35)
- python怎么输出 (33)
- python 日志 (35)
- python语音 (31)
- python 工程师 (34)
- python3 安装 (31)
- python音乐 (31)
- 安卓 python (32)
- python 小游戏 (32)
- python 安卓 (31)
- python聚类 (34)
- python向量 (31)
- python大全 (31)
- python次方 (33)
- python桌面 (32)
- python总结 (34)
- python浏览器 (32)
- python 请求 (32)
- python 前端 (32)
- python验证码 (33)
- python 题目 (32)
- python 文件写 (33)
- python中的用法 (32)