回答
其实没有。 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