网络编程
位置:首页>> 网络编程>> Python编程>> python自动循环定时开关机(非重启)测试

python自动循环定时开关机(非重启)测试

作者:享有盛誉之名  发布时间:2022-11-23 21:27:45 

标签:python,开关机

做手机整机测试的,肯定有开关机的需求,关机,几分钟后再开机(一直循环操作测试,就是不能重启);这个需求在关机后就没有办法开机了,任何脚本命令都不行,除非做APP;重启功能的缺点是关机后就立即开机了,需求是关机后几分钟才开机,reboot做不到;

基本思路:现在借用终端自带的定时开关机APP功能,定时开关机只能定时一天就一个时间,达不到这个目的,这个APP作为辅助,关机后几分钟自动开机,开机后更改系统时间或者定时开关机APP时间,来达到测试多次开关机功能

废话不多说,来看看脚本怎么写 


# -*- coding:UTF-8 -*-
import os
import time
time.sleep(5)
test_times = 9999 #设置测试循环次数
for i in range(0,test_times):
 os.popen("adb root tengxun.com")  #获取root权限
 time.sleep(3)
 os.popen("adb shell date -D SET_FORMAT '06271203'")  #设置系统时间
 time.sleep(165)
 stdout1 = os.popen("adb devices").read()
 if 'xx635' in stdout1:   #检测终端状态关机还是开机
   print("定时关机失败,异常时间点:")
   print (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
 else:
   print("定时关机成功,当前关机次数 : %d" % (i+1))
 time.sleep(630)
 stdout2 = os.popen("adb devices").read()
 if 'xx635' in stdout2:
   print("定时开机成功,当前开机次数 : %d" % (i+1))
 else:
   print("定时开机失败,异常时间点:")
   print (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))

来源:https://blog.csdn.net/bbs11007/article/details/93884101

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com