UiController
public interface UiController
android.support.test.espresso.UiController |
提供可用于构建用户操作(如点击,滚动,滑动等)的基本级UI操作(例如注入MotionEvent
)。这取代了部分提供类似功能的Android Instrumentation类。 但是,它为测试操作提供了更高级的同步机制。 关键的区别是:
- test actions are assumed to be called on the main thread
- after a test action is initiated, execution blocks until all messages in the main message queue have been cleared.
Summary
Public methods
injectKeyEvent
boolean injectKeyEvent (KeyEvent event)
将关键事件注入到应用程序中。
Parameters |
event |
KeyEvent : the (non-null!) event to inject |
Returns |
boolean |
true if the event was injected, false otherwise |
injectMotionEvent
boolean injectMotionEvent (MotionEvent event)
将动作事件注入到应用程序中。
Parameters |
event |
MotionEvent : the (non-null!) event to inject |
Returns |
boolean |
true if the event was injected, false otherwise |
injectString
boolean injectString (String str)
使用一系列KeyEvent
s将字符串KeyEvent
到应用程序中。 由实现者决定如何将字符串映射到KeyEvent
对象。 如果您需要对使用injectKeyEvent(KeyEvent)
生成的关键事件进行特定控制。
Parameters |
str |
String : the (non-null!) string to type |
Returns |
boolean |
true if the string was injected, false otherwise |
loopMainThreadForAtLeast
void loopMainThreadForAtLeast (long millisDelay)
将主线程循环一段指定的时间。 控制可能不会立即返回,而是会在时间过去之后返回并且队列再次处于空闲状态。
Parameters |
millisDelay |
long : time to spend in looping the main thread |
loopMainThreadUntilIdle
void loopMainThreadUntilIdle ()
Loops the main thread until the application goes idle. An empty task is immediately inserted into the task queue to ensure that if we're idle at this moment we'll return instantly.