UiController

public interface UiController

android.support.test.espresso.UiController


提供可用于构建用户操作(如点击,滚动,滑动等)的基本级UI操作(例如注入MotionEvent )。这取代了部分提供类似功能的Android Instrumentation类。 但是,它为测试操作提供了更高级的同步机制。 关键的区别是:

Summary

Public methods

abstract boolean injectKeyEvent(KeyEvent event)

将关键事件注入到应用程序中。

abstract boolean injectMotionEvent(MotionEvent event)

将动作事件注入到应用程序中。

abstract boolean injectString(String str)

使用一系列 KeyEvent s将字符串 KeyEvent应用程序。

abstract void loopMainThreadForAtLeast(long millisDelay)

将主线程循环一段指定的时间。

abstract void loopMainThreadUntilIdle()

循环主线程,直到应用程序闲置。

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
Throws
InjectEventSecurityException if the event couldn't be injected because it would interact with another application.

injectMotionEvent

boolean injectMotionEvent (MotionEvent event)

将动作事件注入到应用程序中。

Parameters
event MotionEvent: the (non-null!) event to inject
Returns
boolean true if the event was injected, false otherwise
Throws
InjectEventSecurityException if the event couldn't be injected because it would interact with another application.

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
Throws
InjectEventSecurityException if the events couldn't be injected because it would interact with another application.

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.