得益于公司坑爹的网络,整理一下Android自动化测试框架UI Automator的API接口,方便以后使用查询,也更好的熟悉下API接口。
UI Automator
UI Automator是一个Android UI测试框架,适用于系统应用和已安装应用程序之间进行跨应用程序功能测试的测试框架。它只能在API18以上使用,必须借助于手机,至于速度么,一把辛酸泪…😭😭😭
By
static BySelector checkable(boolean isCheckable) static BySelector checked(boolean isChecked) static BySelector clazz(String packageName, String className) static BySelector clazz(Class clazz) static BySelector clazz(Pattern className) static BySelector clazz(String className) static BySelector clickable(boolean isClickable) static BySelector copy(BySelector original) static BySelector depth(int depth) static BySelector desc(String contentDescription) static BySelector desc(Pattern contentDescription) static BySelector descContains(String substring) static BySelector descEndsWith(String substring) static BySelector descStartsWith(String substring) static BySelector enabled(boolean isEnabled) static BySelector focusable(boolean isFocusable) static BySelector focused(boolean isFocused) static BySelector hasChild(BySelector childSelector) static BySelector hasDescendant(BySelector descendantSelector) static BySelector hasDescendant(BySelector descendantSelector, int maxDepth) static BySelector longClickable(boolean isLongClickable) static BySelector pkg(Pattern applicationPackage) static BySelector pkg(String applicationPackage) static BySelector res(String resourceName) static BySelector res(String resourcePackage, String resourceId) static BySelector res(Pattern resourceName) static BySelector scrollable(boolean isScrollable) static BySelector selected(boolean isSelected) static BySelector text(Pattern regex) static BySelector text(String text) static BySelector textContains(String substring) static BySelector textEndsWith(String substring) static BySelector textStartsWith(String substring)
|
BySelector
BySelector checkable(boolean isCheckable) BySelector checked(boolean isChecked) BySelector clazz(String packageName, String className) BySelector clazz(Class clazz) BySelector clazz(Pattern className) BySelector clazz(String className) BySelector clickable(boolean isClickable) BySelector depth(int min, int max) BySelector depth(int exactDepth) BySelector desc(String contentDescription) BySelector desc(Pattern contentDescription) BySelector descContains(String substring) BySelector descEndsWith(String substring) BySelector descStartsWith(String substring) BySelector enabled(boolean isEnabled) BySelector focusable(boolean isFocusable) BySelector focused(boolean isFocused) BySelector hasChild(BySelector childSelector) BySelector hasDescendant(BySelector descendantSelector) BySelector hasDescendant(BySelector descendantSelector, int maxDepth) BySelector longClickable(boolean isLongClickable) BySelector maxDepth(int max) BySelector minDepth(int min) BySelector pkg(Pattern applicationPackage) BySelector pkg(String applicationPackage) BySelector res(String resourceName) BySelector res(String resourcePackage, String resourceId) BySelector res(Pattern resourceName) BySelector scrollable(boolean isScrollable) BySelector selected(boolean isSelected) BySelector text(Pattern textValue) BySelector text(String textValue) BySelector textContains(String substring) BySelector textEndsWith(String substring) BySelector textStartsWith(String substring) String toString()
|
Configurator
long getActionAcknowledgmentTimeout() static Configurator getInstance() long getKeyInjectionDelay() long getScrollAcknowledgmentTimeout() int getToolType() int getUiAutomationFlags() long getWaitForIdleTimeout() long getWaitForSelectorTimeout() Configurator setActionAcknowledgmentTimeout(long timeout) Configurator setKeyInjectionDelay(long delay) Configurator setScrollAcknowledgmentTimeout(long timeout) Configurator setToolType(int toolType) Configurator setUiAutomationFlags(int flags) Configurator setWaitForIdleTimeout(long timeout) Configurator setWaitForSelectorTimeout(long timeout)
|
UiCollection
UiObject getChildByDescription(UiSelector childPattern, String text) UiObject getChildByInstance(UiSelector childPattern, int instance) UiObject getChildByText(UiSelector childPattern, String text) int getChildCount(UiSelector childPattern)
|
UiDevice
void clearLastTraversedText() boolean click(int x, int y) boolean drag(int startX, int startY, int endX, int endY, int steps) void dumpWindowHierarchy(File dest) void dumpWindowHierarchy(OutputStream out) void dumpWindowHierarchy(String fileName) UiObject2 findObject(BySelector selector) UiObject findObject(UiSelector selector) List<UiObject2> findObjects(BySelector selector) void freezeRotation() String getCurrentActivityName() String getCurrentPackageName() int getDisplayHeight() int getDisplayRotation() Point getDisplaySizeDp() int getDisplayWidth() static UiDevice getInstance() static UiDevice getInstance(Instrumentation instrumentation) String getLastTraversedText() String getLauncherPackageName() String getProductName() boolean hasAnyWatcherTriggered() boolean hasObject(BySelector selector) boolean hasWatcherTriggered(String watcherName) boolean isNaturalOrientation() boolean isScreenOn() boolean openNotification() boolean openQuickSettings() <R> R performActionAndWait(Runnable action, EventCondition<R> condition, long timeout) boolean pressBack() boolean pressDPadCenter() boolean pressDPadDown() boolean pressDPadLeft() boolean pressDPadRight() boolean pressDPadUp() boolean pressDelete() boolean pressEnter() boolean pressHome() boolean pressKeyCode(int keyCode) boolean pressKeyCode(int keyCode, int metaState) boolean pressMenu() boolean pressRecentApps() boolean pressSearch() void registerWatcher(String name, UiWatcher watcher) void removeWatcher(String name) void resetWatcherTriggers() void runWatchers() void setCompressedLayoutHeirarchy(boolean compressed) void setOrientationLeft() void setOrientationNatural() void setOrientationRight() void sleep() boolean swipe(int startX, int startY, int endX, int endY, int steps) boolean swipe(Point[] segments, int segmentSteps) boolean takeScreenshot(File storePath, float scale, int quality) boolean takeScreenshot(File storePath) void unfreezeRotation() <R> R wait(SearchCondition<R> condition, long timeout) void waitForIdle(long timeout) void waitForIdle() boolean waitForWindowUpdate(String packageName, long timeout) void wakeUp()
|
UiObject
void clearTextField() boolean click() boolean clickAndWaitForNewWindow() boolean clickAndWaitForNewWindow(long timeout) boolean clickBottomRight() boolean clickTopLeft() boolean dragTo(UiObject destObj, int steps) boolean dragTo(int destX, int destY, int steps) boolean exists() Rect getBounds() UiObject getChild(UiSelector selector) int getChildCount() String getClassName() String getContentDescription() UiObject getFromParent(UiSelector selector) String getPackageName() final UiSelector getSelector() String getText() Rect getVisibleBounds() boolean isCheckable() boolean isChecked() boolean isClickable() boolean isEnabled() boolean isFocusable() boolean isFocused() boolean isLongClickable() boolean isScrollable() boolean isSelected() boolean longClick() boolean longClickBottomRight() boolean longClickTopLeft() boolean performMultiPointerGesture(PointerCoords... touches) boolean performTwoPointerGesture(Point startPoint1, Point startPoint2, Point endPoint1, Point endPoint2, int steps) boolean pinchIn(int percent, int steps) boolean pinchOut(int percent, int steps) boolean setText(String text) boolean swipeDown(int steps) boolean swipeLeft(int steps) boolean swipeRight(int steps) boolean swipeUp(int steps) boolean waitForExists(long timeout) boolean waitUntilGone(long timeout)
|
UiObject2
void clear() void click() void click(long duration) <R> R clickAndWait(EventCondition<R> condition, long timeout) void drag(Point dest) void drag(Point dest, int speed) boolean equals(Object object) UiObject2 findObject(BySelector selector) List<UiObject2> findObjects(BySelector selector) boolean fling(Direction direction, int speed) boolean fling(Direction direction) String getApplicationPackage() int getChildCount() List<UiObject2> getChildren() String getClassName() String getContentDescription() UiObject2 getParent() String getResourceName() String getText() Rect getVisibleBounds() Point getVisibleCenter() boolean hasObject(BySelector selector) int hashCode() boolean isCheckable() boolean isChecked() boolean isClickable() boolean isEnabled() boolean isFocusable() boolean isFocused() boolean isLongClickable() boolean isScrollable() boolean isSelected() void longClick() void pinchClose(float percent) void pinchClose(float percent, int speed) void pinchOpen(float percent) void pinchOpen(float percent, int speed) void recycle() boolean scroll(Direction direction, float percent, int speed) boolean scroll(Direction direction, float percent) void setGestureMargin(int margin) void setGestureMargins(int left, int top, int right, int bottom) void setText(String text) void swipe(Direction direction, float percent, int speed) void swipe(Direction direction, float percent) <R> R wait(UiObject2Condition<R> condition, long timeout) <R> R wait(SearchCondition<R> condition, long timeout)
|
boolean flingBackward() boolean flingForward() boolean flingToBeginning(int maxSwipes) boolean flingToEnd(int maxSwipes) UiObject getChildByDescription(UiSelector childPattern, String text) UiObject getChildByDescription(UiSelector childPattern, String text, boolean allowScrollSearch) UiObject getChildByInstance(UiSelector childPattern, int instance) UiObject getChildByText(UiSelector childPattern, String text, boolean allowScrollSearch) UiObject getChildByText(UiSelector childPattern, String text) int getMaxSearchSwipes() double getSwipeDeadZonePercentage() boolean scrollBackward(int steps) boolean scrollBackward() boolean scrollDescriptionIntoView(String text) boolean scrollForward(int steps) boolean scrollForward() boolean scrollIntoView(UiSelector selector) boolean scrollIntoView(UiObject obj) boolean scrollTextIntoView(String text) boolean scrollToBeginning(int maxSwipes) boolean scrollToBeginning(int maxSwipes, int steps) boolean scrollToEnd(int maxSwipes) boolean scrollToEnd(int maxSwipes, int steps) UiScrollable setAsHorizontalList() UiScrollable setAsVerticalList() UiScrollable setMaxSearchSwipes(int swipes) UiScrollable setSwipeDeadZonePercentage(double swipeDeadZonePercentage)
|
UiSelector
UiSelector checkable(boolean val) UiSelector checked(boolean val) UiSelector childSelector(UiSelector selector) UiSelector className(String className) <T> UiSelector className(Class<T> type) UiSelector classNameMatches(String regex) UiSelector clickable(boolean val) UiSelector description(String desc) UiSelector descriptionContains(String desc) UiSelector descriptionMatches(String regex) UiSelector descriptionStartsWith(String desc) UiSelector enabled(boolean val) UiSelector focusable(boolean val) UiSelector focused(boolean val) UiSelector fromParent(UiSelector selector) UiSelector index(int index) UiSelector instance(int instance) UiSelector longClickable(boolean val) UiSelector packageName(String name) UiSelector packageNameMatches(String regex) UiSelector resourceId(String id) UiSelector resourceIdMatches(String regex) UiSelector scrollable(boolean val) UiSelector selected(boolean val) UiSelector text(String text) UiSelector textContains(String text) UiSelector textMatches(String regex) UiSelector textStartsWith(String text) String toString()
|
Until
static UiObject2Condition<Boolean> checkable(boolean isCheckable) static UiObject2Condition<Boolean> checked(boolean isChecked) static UiObject2Condition<Boolean> clickable(boolean isClickable) static UiObject2Condition<Boolean> descContains(String substring) static UiObject2Condition<Boolean> descEndsWith(String substring) static UiObject2Condition<Boolean> descEquals(String contentDescription) static UiObject2Condition<Boolean> descMatches(String regex) static UiObject2Condition<Boolean> descMatches(Pattern regex) static UiObject2Condition<Boolean> descStartsWith(String substring) static UiObject2Condition<Boolean> enabled(boolean isEnabled) static SearchCondition<UiObject2> findObject(BySelector selector) static SearchCondition<List<UiObject2>> findObjects(BySelector selector) static UiObject2Condition<Boolean> focusable(boolean isFocusable) static UiObject2Condition<Boolean> focused(boolean isFocused) static SearchCondition<Boolean> gone(BySelector selector) static SearchCondition<Boolean> hasObject(BySelector selector) static UiObject2Condition<Boolean> longClickable(boolean isLongClickable) static EventCondition<Boolean> newWindow() static EventCondition<Boolean> scrollFinished(Direction direction) static UiObject2Condition<Boolean> scrollable(boolean isScrollable) static UiObject2Condition<Boolean> selected(boolean isSelected) static UiObject2Condition<Boolean> textContains(String substring) static UiObject2Condition<Boolean> textEndsWith(String substring) static UiObject2Condition<Boolean> textEquals(String text) static UiObject2Condition<Boolean> textMatches(String regex) static UiObject2Condition<Boolean> textMatches(Pattern regex) static UiObject2Condition<Boolean> textNotEquals(String text) static UiObject2Condition<Boolean> textStartsWith(String substring)
|