前一阵子刚接触了PySimpleGUI库,可通过它来实现GUI界面;测试过程中经常使用ADB命令,我们是否可以将其封装起来,方便后续使用?
常用功能如下:安装应用
、卸载应用
、清除缓存
、填充文件
、查看设备
、模拟HOME键
我们使用python中subprocess模块嵌入adb命令并进行封装,然后通过PySimpleGUI来显示布局
ADB功能代码,如下:
import subprocess
#查看连接设备
def device_list():
adb_shell='adb devices -l'
devices_info=subprocess.getoutput(adb_shell)
#pi=subprocess.Popen(order,shell=True,stdout=subprocess.PIPE)
return devices_info
#查看日志
def logcat_list():
adb_shell='adb logcat'
log_info=subprocess.getoutput(adb_shell)
return log_info
#模拟HOME键
def key_home():
adb_shell='adb shell input keyevent 3'
info=subprocess.getoutput(adb_shell)
return info
#查看应用列表
def packages_list():
adb_shell='adb shell pm list packages'
package_list=subprocess.getoutput(adb_shell)
return package_list
#卸载应用
def uninstall_apks():
adb_shell='adb uninstall com.uqu.live'
log=subprocess.getoutput(adb_shell)
return log
#安装应用
def install_apks():
file='/Users/admin/Desktop/project/pytest_t/uqlive.apk'
adb_shell='adb install '+file
print(adb_shell4)
log=subprocess.getoutput(adb_shell)
return log
#清除缓存
def clear_apks():
apk_name='com.uqu.live'
adb_shell='adb shell pm clear '+apk_name
log=subprocess.getoutput(adb_shell)
return log
#填充文件a
def fill_file():
adb_shell='adb shell dd if=/dev/zero of=/mnt/sdcard/bigfile'
log=subprocess.getoutput(adb_shell)
return log
通过PySimpleGUI库中Column列来布局功能入口,代码如下:
import PySimpleGUI as sg
import adb_test
#import adb_method
col=[[sg.Button('连接设备',key='device'),sg.Button('HOME键',key='home')],
[sg.Button('卸载应用',key='uninstall'),sg.Button('安装应用',key='install')],
[sg.Button('清除数据',key='clear'),sg.Button('填充缓存',key='fillfile')],
[sg.Quit('exit',key='q')],]
layout=[
[sg.Column(col)],
[sg.Text('',key='devices',size=(100,10))]
]
window=sg.Window('ADB tools',layout,font='微软雅黑')
网友评论