本文原创,版权属作者个人所有,如需转载请联系作者本人。Q&微:155122733
testCaseClasses.py内容如下:
1 #!/usr/bin/python 2 import time 3 from time import ctime 4 import os 5 import sys 6 import traceback 7 class testCaseClasses(object): 8 #def __init__(self,times = 100): 9 # self.times= times 10 #print("resume_suspend = %d"%times) 11 def ADBCheck(self): 12 """ 13 函数功能:检测ADB是否存在 14 """ 15 if " " in os.popen("adb devices").read(): 16 #print ("%s:ADB CONNECTED"%ctime()) 17 pass 18 else: 19 print("%s:NOT CONNECTED !"%ctime()) 20 print("%s:TEST SCRIPTS STOP"%ctime()) 21 sys.exit(1) 22 def checkScreenSuspend(self): 23 self.ADBCheck() 24 infos = os.popen("adb shell dumpsys power").readlines() 25 for i in infos: 26 if "Display Power: state=" in i: 27 info = i.split("=")[1].strip(" ") #分割,然后去掉" " 28 if info == "OFF": 29 time.sleep(10) 30 print("目前手机处于黑屏状态,唤醒") 31 os.popen('adb shell input keyevent 26') 32 time.sleep(2) 33 print("手机已唤醒") 34 else: 35 self.checkScreenSuspend() 36 37 38 def init(self): 39 self.checkScreenSuspend() 40 def resume_suspend(self,times = 100): 41 print("expect resume_suspend = %d"%times) 42 try: 43 for i in range(0,times): 44 print(ctime()+":Press Power Key the %d times"%(i+1)) 45 self.checkScreenSuspend() 46 except: 47 print('traceback.format_exc(): %s'%traceback.format_exc())
StressTest_Resume_Suspend.py内容如下:
1 #!/usr/bin/python 2 import unittest 3 from testCaseClasses import * 4 class StressTest_Resume_Suspend(unittest.TestCase): 5 ''' 6 def setUp(self): 7 pass 8 def tearDown(self): 9 pass 10 ''' 11 def testRun(self): 12 testCase = testCaseClasses() 13 testCase.init() 14 testCase.resume_suspend(100) 15 16 if __name__ == "__main__": 17 testcase = StressTest_Resume_Suspend() 18 testcase.testRun()
终端执行python3 StressTest_Resume_Suspend.py即可。