Ale*_*ruz 10 testing android android-fragments viewanimator android-espresso
问题: 我在运行Espresso测试时遇到问题,在登录按钮上调用perform(click())方法后,测试继续运行但是直到45秒后才会继续运行并且测试自动失败.同时,登录正常进行.
上下文:我有一个带有两个片段的Activity,右边的片段处理用户名和密码EditTexts以及登录按钮.这个片段使用ViewAnimator和两个LinearLayouts作为子视图构建,第一个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);
}
Run Code Online (Sandbox Code Playgroud)
在使用服务器进行身份验证后,这就是我处理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);
}
});
}
Run Code Online (Sandbox Code Playgroud)
浓咖啡测试
ViewInteraction loginButton2 = onView(withId(R.id.login_button));
loginButton2.perform(click()); // Test gets stuck here.
loginButton2.check(doesNotExist()); // Never reached.
Run Code Online (Sandbox Code Playgroud)
有没有人知道在这种情况下成功测试?只需检测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")));
Run Code Online (Sandbox Code Playgroud)
谢谢大家的帮助和任何建议
我有一个类似的问题,在我的情况下,它是一个加载在未显示的片段上的进度条.这个进度条没有被错误地解雇,并且阻止了测试.我得到了相同的结果,如你描述的那样,在45秒卡住后测试失败了.总而言之,检查UI线程上没有动画作为进度条或任何其他动画.
归档时间: |
|
查看次数: |
3280 次 |
最近记录: |