Espresso声称没有必要Thread.sleep();,但我的代码不起作用,除非我包含它.我正在连接到IP.连接时,会显示进度对话框.我需要sleep等待对话框解散.这是我使用它的测试片段:
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());
Run Code Online (Sandbox Code Playgroud)
我曾尝试使用和不使用此代码,Thread.sleep();但它说不R.id.Button存在.我能让它发挥作用的唯一方法就是睡觉.
此外,我尝试用Thread.sleep();类似的东西替换,getInstrumentation().waitForIdleSync();但仍然没有运气.
这是唯一的方法吗?或者我错过了什么?
提前致谢.
我正在尝试检查Espresso是否显示视图.这是一些伪代码来显示我正在尝试的内容:
if (!Espresso.onView(withId(R.id.someID)).check(doesNotExist()){
// then do something
} else {
// do nothing, or what have you
}
Run Code Online (Sandbox Code Playgroud)
但我的问题是.check(doesNotExist())不返回布尔值.这只是一个断言.使用UiAutomator,我能够做到这样的事情:
if (UiAutomator.getbyId(SomeId).exists()){
.....
}
Run Code Online (Sandbox Code Playgroud)