2016-02-17 31 views
1

我正在爲我的跨應用程序UI自動化應用程序實現UiAutomator。我已經把它放在AndroidTest類下。當我運行我的測試類時它工作正常,但我需要它從我的應用程序運行(不必將其連接到計算機)。 我發現這個解決辦法,但它不工作:如何從MainActivity運行UiAutomator?

private void runTests() { 
    Bundle arguments = new Bundle(); 
    final String packageName = getPackageName(); 
    final List<InstrumentationInfo> list = 
      getPackageManager().queryInstrumentation(packageName, 0); 
    if (list.isEmpty()) { 
     return; 
    } 
    final InstrumentationInfo instrumentationInfo = list.get(0); 
    final ComponentName componentName = 
      new ComponentName(instrumentationInfo.packageName, 
        instrumentationInfo.name); 

    arguments.putString("package", "my package"); 
    startInstrumentation(componentName,null,arguments); 
    } 

顯然儀器的UiAutomator參數返回null。任何想法如何從主應用程序運行UiAutomator?

+0

「它工作正常,當我運行我的測試類,但我需要從我的應用程序運行(沒有將它連接到電腦)」 - 你不能運行的儀器測試,方式。他們必須由合適的過程由測試運行者運行。 「我正在爲我的跨應用程序UI自動化應用程序實現UiAutomator」 - 您可能希望更詳細地解釋您的意思。 – CommonsWare

回答

1

這是不可能的。看到這個答案對一個類似問題:

UiAutomator 2.0依賴於儀器儀表,當你使用時儀器運行測試這是唯一可用的.​​...普通(非測試)的應用程序沒有訪問儀表。

https://stackoverflow.com/a/29419540/1999084