在执行(单击())ViewAnimator中的按钮后,espresso测试卡住/不活动 [英] Espresso test stuck/inactive after perform(click()) on button in ViewAnimator

查看:67
本文介绍了在执行(单击())ViewAnimator中的按钮后,espresso测试卡住/不活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题: 我在运行Espresso测试时遇到了问题,在登录按钮上调用Perform(Click())方法后,测试继续运行,但不会继续运行,直到45秒过去,测试自动失败。同时正常登录。

上下文:我有一个并排有两个片段的活动,右侧的片段处理用户名和密码Edittex以及登录按钮。这个片段是用一个ViewAnimator和两个LinearLayout作为子视图构建的,第一个LinearLayout具有前面提到的元素,第二个具有其他元素。

当单击登录按钮时,用户界面上会发生以下情况:

    @Override
public void setUILoggingIn() {
    spinnerLogin.setVisibility(View.VISIBLE);
    loginButton.setEnabled(false);
    loginButton.setText(R.string.logging_in);
    usernameText.setEnabled(false);
    passwordText.setEnabled(false);
}

向服务器进行身份验证后,我处理用户界面的方式如下:

@Override
public void setUIAuthorized() {
    new Handler(Looper.getMainLooper()).post(new Runnable() {
        @Override
        public void run() {
            viewAnimator.showNext();
            // elements on the first child of the ViewAnimator
            loginButton.setEnabled(true);
            spinnerLogin.setVisibility(View.GONE);

            // elements on the second child of the ViewAnimator
            sendMessageButton.setEnabled(true); 
            chatInputText.setEnabled(true);
        }
    });
}

浓缩咖啡测试

ViewInteraction loginButton2 = onView(withId(R.id.login_button));
        loginButton2.perform(click());        // Test gets stuck here.
        loginButton2.check(doesNotExist());   // Never reached.

有没有人知道如何在这种情况下成功测试?只要检测到ViewAnimator何时更改就足够了,但测试在单击时停滞。

还有:这不是测试的开始,在前面显示的代码之前,我运行了这个测试,它像梦一样工作:

ViewInteraction loginButton = onView(withId(R.id.login_button));

    /** Failed login **/

    loginButton.perform(click());

    ViewInteraction snackBarTextView = onView(
            allOf(withId(R.id.snackbar_text), withText("Login error"), isDisplayed()));
    snackBarTextView.check(matches(withText("Login error")));

感谢大家的帮助和建议🌚😄

推荐答案

我遇到了类似的问题,在我的情况下,它是加载到未显示的片段上的进度条。这个进步条并没有被错误地忽视,它阻碍了测试。我得到了同样的结果,45秒后测试失败,就像你所描述的那样。 总而言之,请检查UI线程上是否没有作为进度条或任何其他形式运行的动画。

这篇关于在执行(单击())ViewAnimator中的按钮后,espresso测试卡住/不活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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