2015-04-23 63 views
1

嘗試測試應用程序的共享功能,該應用程序在應用程序中調用createChooser()以打開「共享」選擇器窗體。如何使用android espresso測試點擊「分享」表單中的項目

startActivity(Intent.createChooser(sharingIntent, "Share something")); 

問題是之後的「共享」選配形式是高達如何模擬對部分上市應用項目的點擊,可以說有應用已經說明「APPNAME」。嘗試跟着它不起作用,選擇器形式一直呆在那裏,直到測試超時。

嘗試:

onView(withContentDescription("AppName")) 
      .perform(click()); 

和:

onView(withText("AppName")) 
      .perform(click()); 
+0

什麼是你想要共享的應用程序包? –

回答

0

下面是WhatsApp的分享一些例子:

Intent waIntent = new Intent(Intent.ACTION_SEND); 
waIntent.setType("text/plain"); 
waIntent.setPackage("com.whatsapp");//package name of whatsapp 
waIntent.putExtra(Intent.EXTRA_TEXT, "Share Something");//text to share 
startActivity(Intent.createChooser(waIntent,"Share via...")); 

我希望這可以幫助你。

+0

謝謝Scion。但我的問題不是如何打開共享選擇器。選擇器啓動後,我想在espresso測試中模擬點擊應用程序。或者我錯過了你的回答? – lannyf

+0

我不認爲這可能在我的知識 –

相關問題