從命令列啟動uiautomator
工程師心法
從命令列啟動uiautomator
事先用AS先把測試代碼寫好,編成apk,然後安裝到手機上。
接下來可以透過command line啟動,有兩種方法
referring to: https://developer.android.com/studio/test/command-line
referring to: https://developer.android.com/reference/androidx/test/runner/AndroidJUnitRunner
1.用gradlew
./gradlew connectedAndroidTest
./gradlew cAT
2.用adb
$ adb shell am instrument -w <test_package_name>/<runner_class>
adb2 shell am instrument -w com.stlab.uiauto2.test/androidx.test.runner.AndroidJUnitRunner
adb2 shell am instrument -w com.example.android.testing.uiautomator.BasicSample.test/androidx.test.runner.AndroidJUnitRunner
但是要事先把這些apk裝在手機裡面
比較一下 Google範例檔案的 AndroidManifest
這是IDE自動產生的Manifest, 不需要去改動他!referring to:https://source.android.com/compatibility/tests/development/instrumentation
3月 07, 2021
adb
,
uiautomator
Get an activity name of a package and launch it
工程師心法
Older Android
adb shell dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'
Newer Android Q
adb shell "dumpsys activity activities | grep mResumedActivity"
referring to: https://stackoverflow.com/questions/13193592/adb-android-getting-the-name-of-the-current-activity
Class name
Once the package name has been found (for example com.symbol.wfc.voice), the class name of the main activity has to be determined.To find all activities published by a package, use the following command & replace com.symbol.wfc.voice by the name of the package to process.
adb shell [enter]
dumpsys package | grep -Eo "^[[:space:]]+[0-9a-f]+[[:space:]]+com.symbol.wfc.voice/[^[:space:]]+" | grep -oE "[^[:space:]]+$"
referring to: https://www.zebra.com/us/en/support-downloads/knowledge-articles/evm/Using-ADB-to-Determine-Package-Name-and-Launchable-Activity.html
Package name
To list only 3rd party application
adb shell pm list packages -3
啟動應用程式
格式:am start -n package name / activity name
adb2 shell am start -n com.android.calculator2/com.android.calculator2.Calculator
adb2 shell am start -n com.android.calculator2/com.android.calculator2.Calculator
不管幾層,立馬回到Home畫面
adb2 shell am start -a android.intent.action.MAIN -c android.intent.category.HOME
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] } Warning: Activity not started, its current task has been brought to the front
訂閱:
意見
(
Atom
)








