如何检查新活动是否已开始 [英] How can I check if the new activity was started

查看:64
本文介绍了如何检查新活动是否已开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景:

  1. 用户启动应用程序
  2. 用户转到"CreateAccountActivity"
  3. 要使用该应用程序,用户必须输入电子邮件和密码
  4. 用户单击创建",将切换到下一个活动.

  1. The user starts the app
  2. The user goes to the "CreateAccountActivity"
  3. In order to use the application the user has to enter the email and a password
  4. The user clicks "create" which switches to the next activity.

@Test
public void createAccountAndLogIn() {
    onView(withId(R.id.login_create)).perform(click());
    onView(withId(R.id.create_email)).perform(clearText(),typeText("xxx@gmail.com"));
    onView(withId(R.id.create_pass)).perform(clearText(),typeText("pass"));
    onView(withId(R.id.create_pass_repeat)).perform(clearText(),typeText("pass"));
    onView(withId(R.id.create_create_button)).perform(click());
}

如何在最后一行之后检查是否启动了新的"MainActivity"?

How to check, after the last line, if the new "MainActivity" was launched?

推荐答案

可以使用

It is possible using ActivityLifecycleMonitor ... However it will not be a "black box" approach that you are looking for.

如果您想使用全黑框,则断言下一个活动的视图应该足以通过测试.

If you want to go full black box, asserting the view on the next activity should be sufficient enough to pass a test.

这是一个具有更详细说明的问题.

Here is the same question that has more detailed explanation.

有没有办法知道是否已经开始使用Espresso进行活动?

这篇关于如何检查新活动是否已开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆