本帖轉自搜狗測試公眾號
【一、前言】
【二、python中使用adb、aapt命令】
在python中使用adb命令,可以導入os模塊
1、簡單的adb命令
如:os.system('adb devices)
2、稍微復雜的adb命令
如:os.system('adb shell "dumpsys activity | grep "com.sogou.map.android.***.*""')
3、將adb讀出的內容保存(os.system不支持讀取,os.popen支持讀取)
如:out = os.popen('adb shell "dumpsys activity | grep
"com.sogou.map.android.***.*""').read()


在python中使用aapt命令
aapt即Android Asset Packaging Tool,可以在Android SDK的platform-tools目錄下找到該工具。aapt可以查看、創建、更新ZIP格式的文檔,也可將資源文件編譯成二進制文件。
1、 列出apk包的內容
aapt l[ist] [-v] [-a]file.{zip,jar,apk}
-v 以table形式列出來
-a 詳細列出內容
2、 查看apk一些信息
aapt d[ump] [--values]WHAT file.{apk} [asset [asset ...]]
badging Print the label and icon for the app declaredin APK
permissions Print the permissions from the APK.
Resources Print the resource table from the APK.
Configurations Print the configurations in the APK.
Xmltree Print the compiled xmls in the given assets.
Xmlstrings Print the strings of the given compiled xmlassets.
例如:執行aapt d badging **.apk,可以看到其中包含了應用包名、版本號、permission等信息。


【三、Python-UiAutomator2使用】
【四、參考文獻】
參考
https://github.com/openatx/uiautomator2
https://github.com/xiaocong/uiautomator#uiautomator
https://blog.csdn.net/jgw2008/article/details/78286469
https://testerhome.com/topics/11357