Espresso

public final class Espresso
extends Object

java.lang.Object
   ↳ android.support.test.espresso.Espresso


入口指向Espresso框架。 测试作者可以通过使用on *方法之一(例如onView)或者执行顶级用户操作(例如pressBack)来启动测试。

Summary

Public methods

static void closeSoftKeyboard()

如果打开,关闭软键盘。

static List<IdlingResource> getIdlingResources()

返回所有当前注册的 IdlingResource的列表。

static DataInteraction onData(Matcher<? extends Object> dataMatcher)

为应用程序显示的数据对象创建一个 DataInteraction

static ViewInteraction onView(Matcher<View> viewMatcher)

为给定视图创建一个 ViewInteraction

static void openActionBarOverflowOrOptionsMenu(Context context)

打开在ActionBar中显示的溢出菜单。

static void openContextualActionModeOverflowMenu()

打开ActionMode上下文选项中显示的溢出菜单。

static void pressBack()

按下后退按钮。

static boolean registerIdlingResources(IdlingResource... resources)

在框架中注册一个或多个 IdlingResource

static void registerLooperAsIdlingResource(Looper looper)

注册一个Looper与框架进行空闲检查。

static void registerLooperAsIdlingResource(Looper looper, boolean considerWaitIdle)

注册一个Looper与框架进行空闲检查。

static void setFailureHandler(FailureHandler failureHandler)

将默认 FailureHandler更改为给定的。

static boolean unregisterIdlingResources(IdlingResource... resources)

取消注册一个或多个 IdlingResource

Inherited methods

From class java.lang.Object

Public methods

closeSoftKeyboard

void closeSoftKeyboard ()

如果打开,关闭软键盘。

getIdlingResources

List<IdlingResource> getIdlingResources ()

返回所有当前注册的 IdlingResource的列表。

Returns
List<IdlingResource>

onData

DataInteraction onData (Matcher<? extends Object> dataMatcher)

为应用程序显示的数据对象创建一个DataInteraction 使用此方法从AdapterView小部件(例如ListView)加载(进入视图层次结构)项目。

Parameters
dataMatcher Matcher: a matcher used to find the data object.
Returns
DataInteraction

onView

ViewInteraction onView (Matcher<View> viewMatcher)

为给定视图创建一个ViewInteraction 注意:该视图必须是视图层次结构的一部分。 如果它作为AdapterView的一部分呈现(例如ListView),则情况可能并非如此。 如果是这种情况,请使用Espresso.onData首先加载视图。

Parameters
viewMatcher Matcher: used to select the view.
Returns
ViewInteraction

也可以看看:

openActionBarOverflowOrOptionsMenu

void openActionBarOverflowOrOptionsMenu (Context context)

打开在ActionBar中显示的溢出菜单。

这适用于native和SherlockActionBar ActionBars。

请注意ActionMode和ActionBars之间在UX溢出方面的显着差异。 如果存在硬件菜单键,则溢出图标不会显示在ActionBars中,只能通过菜单按键进行交互。

Parameters
context Context

openContextualActionModeOverflowMenu

void openContextualActionModeOverflowMenu ()

打开ActionMode上下文选项中显示的溢出菜单。

这适用于native和SherlockActionBar动作模式。

请注意,ActionMode和ActionBar之间的用户体验差异显着溢出 - ActionMode将始终显示溢出图标,该图标仅响应点击。 菜单按钮(如果存在)对其没有影响。

pressBack

void pressBack ()

按下后退按钮。

Throws
PerformException if currently displayed activity is root activity, since pressing back button would result in application closing.

registerIdlingResources

boolean registerIdlingResources (IdlingResource... resources)

在框架中注册一个或多个IdlingResource 尽管没有严格要求,但预计这种方法将在与被测应用程序进行任何交互之前的测试设置时间被调用。 注册多个资源时,确保每个资源都有唯一的名称。 如果任何给定资源已经注册,则会记录警告。

Parameters
resources IdlingResource
Returns
boolean true if all resources were successfully registered

registerLooperAsIdlingResource

void registerLooperAsIdlingResource (Looper looper)

注册一个Looper与框架进行空闲检查。 这旨在用于非UI线程循环。

Parameters
looper Looper
Throws
IllegalArgumentException if looper is the main looper.

registerLooperAsIdlingResource

void registerLooperAsIdlingResource (Looper looper, 
                boolean considerWaitIdle)

注册一个Looper与框架进行空闲检查。 这旨在用于非UI线程循环。

此方法允许调用者将Thread.State.WAIT视为“空闲”。

这在循环者通过等待/通知机制同步向UI线程发送消息的情况下很有用。

Parameters
looper Looper
considerWaitIdle boolean
Throws
IllegalArgumentException if looper is the main looper.

setFailureHandler

void setFailureHandler (FailureHandler failureHandler)

将默认 FailureHandler更改为给定的。

Parameters
failureHandler FailureHandler

unregisterIdlingResources

boolean unregisterIdlingResources (IdlingResource... resources)

取消注册一个或多个IdlingResource 如果任何给定资源尚未注册,则会记录警告。

Parameters
resources IdlingResource
Returns
boolean true if all resources were successfully unregistered