居preSSO:视频下载(); [英] Espresso: Thread.sleep( );
问题描述
居preSSO声称,没有必要对视频下载();
,但我的code没有工作,除非我有它。我连接到IP。连接时,显示一个进度对话框。我需要一个睡眠
等待对话框解雇。这是我的测试片段,我使用它:
Espresso claims that there is no need for Thread.sleep();
, but my code doesn't work unless I include it. I am connecting to an IP. While connecting, a progress dialog is shown. I need a sleep
to wait for the dialog to dismiss. This is my test snippet where I use it:
IP.enterIP(); // fills out an IP dialog (this is done with espresso)
//progress dialog is now shown
Thread.sleep(1500);
onView(withId(R.id.button).perform(click());
我已经试过这code的与和没有的的视频下载();
,但它说 R.id.Button
不存在。我可以得到它的工作的唯一办法就是睡眠。
I have tried this code with and without the Thread.sleep();
but it says R.id.Button
doesn't exist. The only way I can get it to work is with sleep.
另外,我曾尝试更换视频下载();
的东西像 getInstrumentation()waitForIdleSync();
,仍然没有运气。
Also, I have tried replacing Thread.sleep();
with things like getInstrumentation().waitForIdleSync();
and still no luck.
这是做到这一点的唯一途径?还是我失去了一些东西?
Is this the only way to do this? Or am I missing something?
在此先感谢。
推荐答案
在我的脑海里正确的做法是:
On my mind correct approach will be:
/** Perform action of waiting for a specific view id. */
public static ViewAction waitId(final int viewId, final long millis) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isRoot();
}
@Override
public String getDescription() {
return "wait for a specific view with id <" + viewId + "> during " + millis + " millis.";
}
@Override
public void perform(final UiController uiController, final View view) {
uiController.loopMainThreadUntilIdle();
final long startTime = System.currentTimeMillis();
final long endTime = startTime + millis;
final Matcher<View> viewMatcher = withId(viewId);
do {
for (View child : TreeIterables.breadthFirstViewTraversal(view)) {
// found view with required ID
if (viewMatcher.matches(child)) {
return;
}
}
uiController.loopMainThreadForAtLeast(50);
}
while (System.currentTimeMillis() < endTime);
// timeout happens
throw new PerformException.Builder()
.withActionDescription(this.getDescription())
.withViewDescription(HumanReadables.describe(view))
.withCause(new TimeoutException())
.build();
}
};
}
和再使用的模式将是:
// wait during 15 seconds for a view
onView(isRoot()).perform(waitId(R.id.dialogEditor, Sampling.SECONDS_15));
这篇关于居preSSO:视频下载();的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!