本文介绍了ProgressBars和义式浓缩咖啡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在运行某些意式浓缩咖啡测试时所显示的布局中有一个ProgressBar时,我会遇到:
When I have a ProgressBar in layouts that are displayed when running some espresso-tests - then I run into:
Caused by: android.support.test.espresso.AppNotIdleException: Looped for 1670 iterations over 60 SECONDS. The following Idle Conditions failed .
解决此问题的一种好方法是什么?发现了一些骇人听闻的东西,但正在寻找一种好方法
What is a nice way to work around this? Found some hackish things but searching for a nice way
推荐答案
如果在测试开始时ProgressBar
不可见,则Drawable
可以用自定义的ViewAction
替换:
If the ProgressBar
is invisible when the test starts, the Drawable
can be replaced with by a custom ViewAction
:
// Replace the drawable with a static color
onView(isAssignableFrom(ProgressBar.class)).perform(replaceProgressBarDrawable());
// Click a button (that will make the ProgressBar visible)
onView(withText("Show ProgressBar").perform(click());
自定义ViewAction
:
public static ViewAction replaceProgressBarDrawable() {
return actionWithAssertions(new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isAssignableFrom(ProgressBar.class);
}
@Override
public String getDescription() {
return "replace the ProgressBar drawable";
}
@Override
public void perform(final UiController uiController, final View view) {
// Replace the indeterminate drawable with a static red ColorDrawable
ProgressBar progressBar = (ProgressBar) view;
progressBar.setIndeterminateDrawable(new ColorDrawable(0xffff0000));
uiController.loopMainThreadUntilIdle();
}
});
}
这篇关于ProgressBars和义式浓缩咖啡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!