Appium+Python自動化 -獲取 app 包名和 activity
方法一:
①手機通過USB連接電腦
②打開手機上被測app
③在電腦上 dos命令窗口,輸入命令
adb shell dumpsys window w | findstr \/ | findstr name=
或 adb shell dumpsys window |findstr mCurrent
或 adb shell "dumpsys window w|grep \/|grep name=|sed ‘s/mSurface=Surface(name=//g‘|sed ‘s/)//g‘|sed ‘s/ //g‘"
各命令執行後截圖如下:(紅色選框中分別為包名和activity)
方法二:
利用sdk自帶的實用工具aapt (aapt即Android Asset Packaging Tool,在SDK的build-tools目錄下。該工具可以查看apk包名和launcherActivity)
①下載aapt
步驟1.在android-sdk裏面雙擊SDK-manager,下載buidl-tools
步驟2:勾選build-tools,隨便選一個版本,我這裏將28的相關版本都下載了
步驟3:下載完成後,在D:\Program Files (x86)\Android\sdk\build-tools\28.0.2(因步驟2中下載了多個版本的build-tools,這兒就以28.0.2為例)目錄下找到aapt.exe,將這個路徑設置環境變量,添加到path下
步驟4:打開cmd 命令窗口。輸入aapt出現如下界面,說明環境OK了
②獲取 app 包名 和 launcherActivity
步驟1、將被測app,安裝包放在電腦上 如:D:\Documents\Downloads\Xiudong.apk
步驟2、打開cmd,在dos命令窗口,輸入命令 aapt dump badging D:\Documents\Downloads\Xiudong.apk
如下截圖情況
adb 相關的其他命令(熟悉了解下):
adb devices:查看Android設備是否連接到電腦。
adb shell dumpsys activity:查看當前運行的是哪個activity,運行的一些進程等
adb shell dumpsys activity activities
adb shell pm list packages:列出所有的包名。
adb shell dumpsys package:列出所有的安裝應用的信息
adb shell dumpsys package com.android.XXX:查看某個包的具體信息
adb shell dumpsys activity | grep mFocusedActivity:查看當前resume的是哪個activity
adb logcat | grep ActivityManager:查看當前正在運行的Activity
adb logcat | grep Displayed:查看當前正在運行的Activity
Appium+Python自動化 -獲取 app 包名和 activity