gpt4 book ai didi

android - 在 ViewAnimator 中的按钮上执行(单击())后,Espresso 测试卡住/不活动

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:05:18 29 4
gpt4 key购买 nike

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

上下文: 我有一个包含两个并排 fragment 的 Activity ,右侧的 fragment 处理用户名和密码 EditTexts 以及登录按钮。这个 fragment 是用一个 ViewAnimator 和两个 LinearLayouts 作为 subview 构建的,第一个 LinearLayout 有前面提到的元素,第二个有其他东西。

这是单击登录按钮时 UI 上发生的情况:

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

与服务器进行身份验证后,这是我处理 UI 的方式:

@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);
}
});
}

Espresso 测试

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")));

谢谢大家的帮助和任何建议🌚😄

最佳答案

我有一个类似的问题,在我的例子中,它是一个加载在未显示的 fragment 上的进度条。那个进度条没有被错误地关闭并且阻止了测试。正如您所描述的那样,在卡住 45 秒后测试失败,我得到了相同的结果。总而言之,检查 UI 线程上是否没有运行进度条或任何其他动画。

关于android - 在 ViewAnimator 中的按钮上执行(单击())后,Espresso 测试卡住/不活动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38445701/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com