【Android自动化】测试android手机唤醒性能测试

 1 # -*- coding:utf-8 -*-
 2 import time
 3 import os
 4 import common.common
 5 from common.getconfigs import GetConfigs
 6 from uiautomator import device as d
 7 
 8 cfg = GetConfigs('11_unlockscreen')
 9 dict_times = cfg.get_test_times()
10 
11 def CheckPhoneStatus():
12     """
13     Check the phone status first,if it not in suspend mode,will enter the suspend mode first and start the test.
14     
15     """
16     if d(packageName = 'com.tct.launcher',description = 'Apps').exists:
17         print 'The phone isn\'t in suspend mode,will lock it first'
18         LockPhone()
19 
20 def UnlockPhone():
21     """
22     Unlock the phone and check the phone whether enter the homepage base on the ALL Apps icon 
23     
24     """
25     d.wakeup()
26     time.sleep(1)
27     if d(resourceId='com.android.systemui:id/lock_icon').exists:
28         d.swipe(397, 1165, 500, 500, steps=5)
29         time.sleep(1)
30         if d(description='Apps').exists:
31             print 'unlock successfully'
32         else:
33             print 'itn\'t unlock'
34     else:
35         print 'The phone unlock failed'
36 
37 def LockPhone():
38     d.press('power')
39 
40 def Run(key):
41     times = int(dict_times.get(key.lower(),0))
42     CheckPhoneStatus()
43     for i in range(times):
44         UnlockPhone()
45         time.sleep(2)
46         LockPhone()
47         time.sleep(2)
48         print i
49 
50 if __name__ == '__main__':
51     Run('Lock')

 

posted @ 2018-07-04 10:59  iSZ  阅读(572)  评论(0)    收藏  举报