欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > python >内容正文

python

python:当文件中出现特定字符串时执行robot用例

发布时间:2023/11/29 python 60 豆豆
生活随笔 收集整理的这篇文章主要介绍了 python:当文件中出现特定字符串时执行robot用例 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

 

 

#coding:utf-8 import os import datetime import timedef execute_rpt_db_full_effe_cainiao_city():flag = Truewhile flag:# 判断该文件是否存在# os.path.isfile("/home/ytospid/opt/docker/jsc_spider/jsc_spider/log/call_proc.log")# 存在则获取昨天日期字符串yesterday = datetime.datetime.now()+ datetime.timedelta(-1)yesterday_str = datetime.datetime.strftime(yesterday,'%Y%m%d')# 判断该日志文件中是否包含该字符串,如果存在则表示今日数据已经爬完入库 with open('/home/ytospid/opt/docker/jsc_spider/jsc_spider/log/call_proc.log') as f:for line in f.readlines():if yesterday_str in line:# 再执行30场景检查该表os.system("robot -i rpt_db_full_effe_cainiao_city -l case30_log.html -r case30_report.html -o case30_output.xml /home/ytospid/opt/spider_monitor/菜鸟指数爬虫监控/01_测试用例/接口测试用例/菜鸟指数爬虫结果监控.txt")# print lineprint '已执行30场景'flag = Falsereturn 'OK'print u'休眠5秒'time.sleep(60)execute_rpt_db_full_effe_cainiao_city()if __name__ == '__main__':execute_rpt_db_full_effe_cainiao_city()

例子: 每5秒检查一次test.txt文件,如果出现“hello”,则打开计算器,

import os,timedef execute():with open('test.txt') as f:for line in f.readlines():if 'hello' in line:os.system("calc.exe")returnprint '休息10秒再试试'time.sleep(5)execute()if __name__ == '__main__':execute()

 

转载于:https://www.cnblogs.com/gcgc/p/11479538.html

总结

以上是生活随笔为你收集整理的python:当文件中出现特定字符串时执行robot用例的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。