是否有任何機構知道如何致電
am start -a ACTIVITY
從uiautomator
代碼。
或者是否有可能從junit
代碼開始活動。Uiautomator「am start」
3
A
回答
5
下面是我用從.jar文件啓動一個活動的例子:
private boolean startSettings() {
try {
Runtime.getRuntime().exec(
"am start -n com.android.settings/.Settings");
sleep(1000);
} catch (IOException e) {
e.printStackTrace();
}
for (int i = 0; i < 5; i++) {
sleep(1000);
if (getUiDevice().getCurrentPackageName().contains(
"com.android.settings")) {
return true;
}
}
return false;
}
您可以修改代碼以啓動任何應用程序。您還可以通過爲包/活動值添加參數來使該方法更通用。
0
我所做的是,啓動應用程序並運行UIAutomator測試版本的一部分。這是我在構建Ant build.xml之後如何運行我的UIAutomator測試。這段代碼被添加到build.xml的最後,並啓動你的應用程序,然後開始你的UI測試。使用Eclipse確保你去右擊build.xml,然後 - >運行 - > Ant Build ...並確保選擇了正確的目標:'build','install','start','mytest'。目標'開始'和'mytest'通過以下代碼添加。
<!-- version-tag: VERSION_TAG -->
<!-- This line should already be at the end of build.xml -->
<import file="${sdk.dir}/tools/ant/uibuild.xml" />
<target name="start" description="Start App" depends="build, install">
<echo>Starting Navigation Example</echo>
<exec executable="${adb}" failonerror="true">
<arg value="shell" />
<arg value="am" />
<arg value="start" />
<arg value="-n" />
<arg value="com.example.android.navigationdrawerexample/.MainActivity" />
</exec>
</target>
<target name="mytest" description="Runs UI tests" depends="build, install, start">
<echo>Running UI Tests</echo>
<exec executable="${adb}" failonerror="true">
<arg value="shell" />
<arg value="uiautomator" />
<arg value="runtest" />
<arg value="${out.filename}" />
<arg value="-c" />
<arg value="com.example.android.navigationdrawerexample.MainTestCase" />
</exec>
</target>
3
它可以通過下面的代碼進行。我在測試中使用這個。
UiDevice device = UiDevice.getInstance(getInstrumentation());
final String TARGET_PACKAGE =
InstrumentationRegistry.getTargetContext().getPackageName();
Context context = InstrumentationRegistry.getContext();
final Intent intent = context.getPackageManager().getLaunchIntentForPackage(TARGET_PACKAGE);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
context.startActivity(intent);
device.wait(Until.hasObject(By.pkg(TARGET_PACKAGE).depth(0)), 5000);
相關問題
- 1. 通過「am start」開始tvout
- 2. adb shell am start給予ClassNotFoundException
- 3. 通過「am start」啓動電影回放
- 4. 使用am start命令從adb shell登錄到應用程序
- 5. 使用adb shell發送測試參數am start命令
- 6. 使用am start命令登錄Facebook應用程序/ ADB shell
- 7. Android studio錯誤執行「am start」,無法附加調試器
- 8. UiAutomator getLastTraversedText()
- 9. 在UiAutomator 2.0
- 10. UiAutomator的同步
- 11. Android UiAutomator測試
- 12. UIAutomator與Android timepicker
- 13. UIautomator的GUI
- 14. 類不uiautomator
- 15. Android Exception在運行時沒有命令輸出:'am start <application/application>
- 16. 發送數據回到通過adb shell啓動活動的腳本am start
- 17. 如何中止uiautomator
- 18. 用UIAutomator測試android
- 19. Android電視的Uiautomator
- 20. Android UiAutomator - 檢測應用程序是否在uiautomator模式下
- 21. UiAutomator:如何使用uiautomator實現粘貼操作?
- 22. JS AM/PM時間總是顯示AM
- 23. 如何從UIautomator廣播意圖
- 24. 如何從MainActivity運行UiAutomator?
- 25. UIAutomator和Android圖片庫
- 26. UiAutomator和AccessibilityServices不兼容?
- 27. 在哪裏把uiautomator測試
- 28. UIAutomator錯誤當runnging測試
- 29. clearTextField()在UIAutomator中不工作
- 30. Android uiautomator - 與酒吧合作
我試過了,我開始-n'com.app.myapp/.MainActivity' 不工作。完全合格的名稱也不起作用。 但從命令提示符'adb shell am start -n com.app.myapp/.MainActivity'正在工作 有什麼想法? –
我不知道爲什麼會發生這種情況。我定義了一種啓動應用程序的方法,並使用上面的代碼沒有問題。 你可以嘗試使用python版本的uiautomator:https://github.com/xiaocong/uiautomator 我一直在使用它一段時間,它的效果很好。然後你可以使用python subprocess.Popen()來運行「adb shell am start」命令。 –