robotframework+appium 进行 app 自动化时,为了做到定时可以执行用例,保证手机可以一直在亮屏状态,写了如下方法以资源方式导入项目,直接使用 adb_screenOn() 方法,不论屏幕是否亮屏,都可以正常执行用例
# -*- coding:utf-8 -*-
import os
class Adb(object):
def __init__(self):
pass
def adb_uninstall_package(self, package_name):
"""
# 卸载手机内指定包名的app
"""
try:
cmd = 'adb uninstall {}'.format( package_name)
print cmd
text = os.popen(cmd)
content = text.read()
print content
if 'Success' in content:
print 'Pass: 卸载手机app成功'.decode('UTF-8').encode('GBK')
else:
print 'Fail: 卸载手机app失败 '.decode('UTF-8').encode('GBK')
except Exception as e:
print str(e)
def __adb_rouse_phone(self):
"""
#亮屏手机
"""
try:
cmd = 'adb shell input keyevent 26'
print cmd
text = os.popen(cmd)
content = text.read()
print content+'手机屏幕亮屏成功'.decode('UTF-8').encode('GBK')
except Exception as e:
print str(e)
def adb_screenOn(self):
"""
#先查看手机是否亮屏,如果没有使之亮屏
"""
a = Adb()
try:
cmd = 'adb shell dumpsys window policy^|grep mScreenOnFully'
print cmd
text = os.popen(cmd)
content = text.read()
print content
if 'mScreenOnEarly=true mScreenOnFully=true' in content:
print 'Pass: 手机屏幕已经是亮屏'.decode('UTF-8').encode('GBK')
else:
a.__adb_rouse_phone()
except Exception as e:
print str(e)