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

yipeiwu_com7年前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()))

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python列表操作之extend和append的区别实例分析

本文实例讲述了python列表操作之extend和append的区别。分享给大家供大家参考。具体如下: li = ['a', 'b', 'c'] li.extend(['d', '...

Python加pyGame实现的简单拼图游戏实例

本文实例讲述了Python加pyGame实现的简单拼图游戏。分享给大家供大家参考。具体实现方法如下: import pygame, sys, random from pygame.l...

实例讲解Python中global语句下全局变量的值的修改

Python的全局变量:int string, list, dic(map) 如果存在global就能够修改它的值。而不管这个global是否是存在于if中,也不管这个if是否能够执行到...

解决python3 安装完Pycurl在import pycurl时报错的问题

此次遇到的问题是在import pycurl 时报错 pycurl:libcurl link-time version is older than compile-time versi...

python中subprocess批量执行linux命令

可以执行shell命令的相关模块和函数有: os.system os.spawn os.popen --废弃 popen --废弃 commands --废弃,3....