robotframework+appium進行app自動化,自動亮屏安卓手機方法
阿新 • • 發佈:2019-02-07
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)