自動テスト--UiAutomatorのAndroidの基本 - (クロスアプリケーションのUIテスト)上記4.3

ディレクトリ

元素ポジショニングUI Automatorのビューアの使用

UiAutomator API

UIDevice

パブリック・メソッド

Uiselector

UIObjectクラス

パブリック・メソッド

 UiCollection

UiScrollable

使用


元素ポジショニングUI Automatorのビューアの使用

 

UiAutomator API

UI Automatorのテストフレームワークを提供する  UiDevice ターゲットアプリケーションを実行しているデバイスの操作にアクセスし、実行するためのクラス。あなたは、現在の画面の向きや表示サイズなどのデバイスのプロパティにアクセスするためのメソッドを呼び出すことができます。UiDevice クラスはまた、あなたが次のことを行うことができます:

  • 回転機器に変更します。
  • などを押してハードウェアキー、「音量アップボタンを押します。」
  • 押して、メイン画面やメニューボタンに戻ります。
  • 通知バーを開きます。
  • あなたの現在のウィンドウのスクリーンショット。

例えば、操作押しますホームボタンをシミュレートするために、呼び出す  UiDevice.pressHome() メソッドを。

出典:  https://developer.android.google.cn/training/testing/ui-automator

 

  • UiCollection:列挙コンテナインタフェース要素、記載されるような特性または可視テキストまたはコンテンツ位置決め要素をカウントする目的。
  • UiObject:すなわち、デバイスインターフェース要素上で可視です。
  • UiScrollable:サポートは、スクロール可能なインタフェースのコンテナプロジェクトを検索します。
  • UiSelector:デバイス上の1つ以上のターゲット・インタフェース要素に問い合わせていることを示します。
  • Configurator:あなたは、UI Automatorのテストを実行するために使用されるキーパラメータを設定することができます。

UIDevice

出典:  https://developer.android.google.cn/reference/androidx/test/uiautomator/UiDevice

パブリック・メソッド

void clearLastTraversedText()

最後のUIトラバーサルのイベントからテキストをクリアします。

boolean click(int x, int y)

ユーザーが指定した任意の座標でクリックを実行します

boolean drag(int startX, int startY, int endX, int endY, int steps)

Performs a swipe from one coordinate to another coordinate.

void dumpWindowHierarchy(File dest)

Dump the current window hierarchy to a File.

void dumpWindowHierarchy(OutputStream out)

Dump the current window hierarchy to an OutputStream.

void dumpWindowHierarchy(String fileName)

This method is deprecated. Use dumpWindowHierarchy(File) or dumpWindowHierarchy(OutputStream) instead.

UiObject findObject(UiSelector selector)

Returns a UiObject which represents a view that matches the specified selector criteria.

UiObject2 findObject(BySelector selector)

Returns the first object to match the selector criteria, or null if no matching objects are found.

List<UiObject2> findObjects(BySelector selector)

Returns all objects that match the selector criteria.

void freezeRotation()

Disables the sensors and freezes the device rotation at its current rotation state.

String getCurrentActivityName()

This method is deprecated. The results returned should be considered unreliable

String getCurrentPackageName()

Retrieves the name of the last package to report accessibility events.

 

Uiselector

来源: https://developer.android.google.cn/reference/androidx/test/uiautomator/UiSelector.html

UiSelector packageName(String name)

Set the search criteria to match the package name of the application that contains the widget.

UiSelector packageNameMatches(String regex)

Set the search criteria to match the package name of the application that contains the widget.

UiSelector resourceId(String id)

Set the search criteria to match the given resource ID.

UiSelector resourceIdMatches(String regex)

Set the search criteria to match the resource ID of the widget, using a regular expression.

UiSelector scrollable(boolean val)

Set the search criteria to match widgets that are scrollable.

UiSelector selected(boolean val)

Set the search criteria to match widgets that are currently selected.

UiSelector text(String text)

Set the search criteria to match the visible text displayed in a widget (for example, the text label to launch an app).

UiSelector textContains(String text)

Set the search criteria to match the visible text in a widget where the visible text must contain the string in your input argument.

UiSelector textMatches(String regex)

Set the search criteria to match the visible text displayed in a layout element, using a regular expression.

UiSelector textStartsWith(String text)

Set the search criteria to match visible text in a widget that is prefixed by the text parameter.

String toString()

UiObject

来源: https://developer.android.google.cn/reference/androidx/test/uiautomator/UiObject.html

Public methods

void clearTextField()

Clears the existing text contents in an editable field.

boolean click()

Performs a click at the center of the visible bounds of the UI element represented by this UiObject.

boolean clickAndWaitForNewWindow()

Waits for window transitions that would typically take longer than the usual default timeouts.

boolean clickAndWaitForNewWindow(long timeout)

Performs a click at the center of the visible bounds of the UI element represented by this UiObject and waits for window transitions.

boolean clickBottomRight()

Clicks the bottom and right corner of the UI element

boolean clickTopLeft()

Clicks the top and left corner of the UI element

boolean dragTo(UiObject destObj, int steps)

Drags this object to a destination UiObject.

boolean dragTo(int destX, int destY, int steps)

Drags this object to arbitrary coordinates.

boolean exists()

Check if view exists.

Rect getBounds()

Returns the view's bounds property.

UiObject getChild(UiSelector selector)

Creates a new UiObject for a child view that is under the present UiObject.

int getChildCount()

Counts the child views immediately under the present UiObject.

String getClassName()

Retrieves the className property of the UI element.

String getContentDescription()

Reads the content_desc property of the UI element

UiObject getFromParent(UiSelector selector)

Creates a new UiObject for a sibling view or a child of the sibling view, relative to the present UiObject.

String getPackageName()

Reads the view's package property

final UiSelector getSelector()

Debugging helper.

String getText()

Reads the text property of the UI element

 UiCollection

boolean clickTopLeft()

Clicks the top and left corner of the UI element

boolean dragTo(UiObject destObj, int steps)

Drags this object to a destination UiObject.

boolean dragTo(int destX, int destY, int steps)

Drags this object to arbitrary coordinates.

boolean exists()

Check if view exists.

Rect getBounds()

Returns the view's bounds property.

UiObject getChild(UiSelector selector)

Creates a new UiObject for a child view that is under the present UiObject.

int getChildCount()

Counts the child views immediately under the present UiObject.

String getClassName()

Retrieves the className property of the UI element.

String getContentDescription()

Reads the content_desc property of the UI element

UiObject getFromParent(UiSelector selector)

Creates a new UiObject for a sibling view or a child of the sibling view, relative to the present UiObject.

String getPackageName()

Reads the view's package property

final UiSelector getSelector()

Debugging helper.

String getText()

Reads the text property of the UI element

 

UiScrollable

 

来源: https://developer.android.google.cn/reference/androidx/test/uiautomator/UiScrollable.html

boolean scrollBackward()

Performs a backward scroll with the default number of scroll steps (55).

boolean scrollDescriptionIntoView(String text)

Performs a forward scroll action on the scrollable layout element until the content-description is found, or until swipe attempts have been exhausted.

boolean scrollForward(int steps)

Performs a forward scroll.

boolean scrollForward()

Performs a forward scroll with the default number of scroll steps (55).

boolean scrollIntoView(UiObject obj)

Perform a forward scroll action to move through the scrollable layout element until a visible item that matches the UiObject is found.

boolean scrollIntoView(UiSelector selector)

Perform a scroll forward action to move through the scrollable layout element until a visible item that matches the selector is found.

boolean scrollTextIntoView(String text)

Performs a forward scroll action on the scrollable layout element until the text you provided is visible, or until swipe attempts have been exhausted.

boolean scrollToBeginning(int maxSwipes)

Scrolls to the beginning of a scrollable layout element.

boolean scrollToBeginning(int maxSwipes, int steps)

Scrolls to the beginning of a scrollable layout element.

boolean scrollToEnd(int maxSwipes)

Scrolls to the end of a scrollable layout element.

boolean scrollToEnd(int maxSwipes, int steps)

Scrolls to the end of a scrollable layout element.

UiScrollable setAsHorizontalList()

Set the direction of swipes to be horizontal when performing scroll actions.

UiScrollable setAsVerticalList()

Set the direction of swipes to be vertical when performing scroll actions.

使用

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

发布了58 篇原创文章 · 获赞 4 · 访问量 4万+

おすすめ

転載: blog.csdn.net/jackron2014/article/details/104061522