0

我正在尋找一種在Android上自動打開應用程序的方法。像Windows上的QTP。我閱讀了不少針對Android的測試工具,這些測試工具需要通過USB將手機連接到筆記本電腦。是否可以編寫一個可以自動在設備上打開另一個特定應用程序的android應用程序?Android設備上的自動化

我明白,如果它是我的應用程序或開源的,我可以獲取UI元素並使用代碼自動執行點擊或輸入,但是如何訪問設備上其他應用程序的UI元素。

示例:我的應用程序應該能夠打開我的手機鍵盤並輸入數字或打開Truecaller等應用程序並在主屏幕上輸入文本視圖?像網頁自動化,但爲Android設備。任何幫助,將不勝感激!謝謝!

回答

0

你可以使用意圖:

//consider context as being the Context of your current app 
PackageManager packageManager = context.getPackageManager(); 
Intent intent = packageManager.getLaunchIntentForPackage(PACKAGE_NAME); 
context.startActivity(intent); 
device.wait(Until.hasObject(By.pkg(PACKAGE_NAME)), 10000); //this is a UiAutomator method to wait for the application to be started (or 10 seconds). 

您還可以使用個人UiAutomator方法:打開應用程序菜單,點擊應用程序圖標。你可以看到一個例子here