回答
其實沒有。 Espresso將允許您點擊按鈕,一旦瀏覽器啓動,測試將結束。您的選擇是讓您的課程觸發瀏覽器意圖嘲笑,以便您可以測試剩餘流量(如果有)。
看到這個答案:Controlling when an automation test ends - Espresso,在那裏我描述你如何實現這一點。
雖然這是一個老問題,但只是張貼在這裏幫助其他人。我有同樣的情況,我想驗證一個特定的url是否在瀏覽器中啓動。我得到真正的幫助,從這個link
我得到它的工作使用這個代碼塊:
Intents.init();
Matcher<Intent> expectedIntent = allOf(hasAction(Intent.ACTION_VIEW), hasData(EXPECTED_URL));
intending(expectedIntent).respondWith(new Instrumentation.ActivityResult(0, null));
onView(withId(R.id.someid)).perform(click());
intended(expectedIntent);
Intents.release();
所以,瀏覽器中打開與正確的網址時,並intending()通過實現意圖存根這裏確實神奇它測試。使用這個,我們可以攔截它,所以意圖不會被髮送到系統。
作品魅力 –
@FalcoWinkler很好的知道。這將是很好,如果你也可以接受它作爲答案:) –
我沒有問這個問題 –
爲了方便起見,我建議一個完整的例子:
生產代碼:
register_terms.text = Html.fromHtml(getString(R.string.register_terms,
getString(R.string.privacy_policy_url),
getString(R.string.register_terms_privacy_policy),
getString(R.string.general_terms_and_conditions_url),
getString(R.string.register_terms_general_terms_and_conditions)))
字符串XML:
<string name="register_terms">By registering you accept our <a href=\"%1$s\">%2$s</a> and the <a href=\"%3$s\">%4$s</a>.</string>
<string name="register_terms_privacy_policy">Privacy Policy</string>
<string name="register_terms_general_terms_and_conditions">General Terms and Conditions</string>
<string name="privacy_policy_url" translatable="false">https://www.privacypolicy.com</string>
<string name="general_terms_and_conditions_url" translatable="false">https://www.generraltermsandconditions.com</string>
測試代碼:
@Before
fun setUp() {
Intents.init()
}
@After
fun tearDown() {
Intents.release()
}
@Test
fun when_clickPrivacyLink_then_openPrivacyUrl() {
val expected = allOf(IntentMatchers.hasAction(Intent.ACTION_VIEW), IntentMatchers.hasData(string(privacy_policy_url)))
Intents.intending(expected).respondWith(Instrumentation.ActivityResult(0, null))
onView(ViewMatchers.withId(R.id.register_terms))
.perform(openLinkWithText(string(register_terms_privacy_policy)))
Intents.intended(expected)
}
- 1. 安卓咖啡與匕首
- 2. 安卓濃咖啡庫導入
- 3. 消失HUD酒吧咖啡安卓
- 4. 安卓網頁瀏覽與通知
- 5. 安卓咖啡的新聞概覽按鈕
- 6. 打開瀏覽器到網頁安卓應用
- 7. 安卓網頁瀏覽器和虛擬鍵盤
- 8. 安卓瀏覽器網頁一次登錄
- 9. 安裝 - 未識別咖啡
- 10. 咖啡分類器
- 11. 安卓咖啡測試多進程應用
- 12. 在wpf網絡瀏覽器控件中瀏覽安全網頁
- 13. 片狀安卓咖啡測試 - 小吃店
- 14. 安卓咖啡測試更高:視圖1高於視圖2
- 15. 安卓咖啡 - 無法解析所有打算的方法
- 16. 安卓咖啡輔助功能檢查失敗
- 17. 哪個網頁瀏覽器最安全?
- 18. 網頁瀏覽器內的網頁瀏覽器
- 19. 安卓瀏覽器PDF下載失敗
- 20. 安卓瀏覽器中的Flexbox屬性
- 21. 安卓瀏覽器和火狐的css
- 22. 顛覆網頁瀏覽器
- 23. galaxy s iii網頁瀏覽器DisplayModeProvider「MVC4」
- 24. Android咖啡廳
- 25. ProgressBars和咖啡
- 26. JavaScript入咖啡
- 27. SAS:咖啡人?
- 28. 濃咖啡AmbiguousViewMatcherException
- 29. 咖啡和postDelayed
- 30. 。 $#咖啡腳本?
請參閱下面的Wahib的真實答案。 – Jamey