zoukankan      html  css  js  c++  java
  • python3测试手机suspend/resume(休眠/唤醒)

    本文原创,版权属作者个人所有,如需转载请联系作者本人。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即可。

  • 相关阅读:
    利用python脚本统计和删除redis key
    利用expect交互完成多台linux主机ssh key推送
    iptables -L很慢的原因
    tomcat各个端口的作用
    rabbitmq集群搭建
    ping 没有回icmp reply
    go mod 无法下载依赖问题
    0/1 nodes are available: 1 node(s) had taint
    go 编译:build constraints exclude all Go files in
    k8s单机部署
  • 原文地址:https://www.cnblogs.com/lcl0421/p/8416485.html
Copyright © 2011-2022 走看看