Enhance your Android tests with uiAutomatorViewer

This topic describes how to use the uiAutomatorViewer as an alternative to OpenText Functional Testing's Object Spy, to detect the runtime properties of elements in your app.

These properties can help you create unique descriptions for your mobile test objects.

The uiAutomatorViewer is an Android SDK tool that scans and analyzes the GUI components of an Android application.

Open the uiAutomatorViewer

Do the following before using the uiAutomatorViewer to analyze your app:

  1. Ensure that the Android SDK is installed.

    The Android SDK version should be the same as or newer than the Android version on the device being tested.

    Then, set the ANDROID_HOME system variable to the path where the Android SDK is installed on that computer.

  2. Connect an Android device to your computer. For details, see the Digital Lab Help.

To open the uiAutomatorViewer

Run the <android_sdk_installation_folder>\tools\bin\uiautomator.bat file.

Next, Analyze your app's user interface.

Back to top

Analyze your app's user interface

Use the following steps to analyze your app's user interface using the uiAutomatorViewer.

  1. Open the uiAutomatorViewer and ensure that the view you want to scan is clearly displayed.

  2. Take a screenshot of your app user interface.

  3. In uiAutomatorViewer, click the Device Screenshot button.

    If more than one device is connected, select the relevant device from the list shown.

  4. View the results to see a snapshot of the view and a test object tree, including all test objects recognized in the view.

    Highlight a node in the tree to show the object details and properties.

Supported uiAutomatorViewer properties

The following uiAutomatorViewer properties are relevant when working with OpenText Functional Testing:

package

The identifier of the application currently in view. Mapped to the identifier property of the App test object.

text

The text property of the object (usually available for TextView objects).

content-desc

The accessibilityid property of the object.

bounds

The bounding rectangle for the object in the application.

scrollable

Specifies if the control is a scrollable view.

class

Mapped to the class property of the test object.

Examples:

Android class: Digital Lab class

android.widget.TextView: Label

android.widget.ImageButton: ImageButton

Back to top

Add non-recordable objects to the object repository

Not all objects are recordable during an OpenText Functional Testing recording session. You may need to add some objects to the object repository manually, such as TextView and Image.

Tip: Not what you need? See also Use programmatic descriptions instead of test objects.

  1. Scan the views in your application that contain the objects you want to add to the object repository.
  2. For each object that you want to add, note the values for following properties:

  3. In the Object Repository window, select the Test Object root node, and create a new child test object (Object > Define New Test Object).
  4. In the Define New Test Object dialog box, define the Class as Mobile View and give the object a unique name.
  5. Under Test object details > Description properties, delete all properties except for class, text, and accessibilityid.
  6. Modify the remaining property values, as follows:

    class

    Enter the value you noted from the uiAutomatorViewer class property.

    accessibilityid

    Enter the value you noted from the uiAutomatorViewer content-desc property, if any.

    text

    Enter the value you noted from the uiAutomatorViewer text property, if any.

    index

    (Optional). If:

    • The content-desc property value is empty; and
    • The text property value is empty or dynamic (meaning it changes according to the current context),

    create and set an index property value by counting the number of objects of this type in the current view, from top to bottom, starting from 0.

    It may take several tries to set the index property value accurately.

  7. Drag the newly created test object under the relevant App test object.
  8. In the application you are testing, position the relevant page in the foreground.
  9. In the Script Editor, enter the following loop statement:

    For i = 0 To X Step 1 'X should be the estimated number of labels on the screen'
    	print i & "- " & Device.App.MobileView("class:=Label", _
    		"index:=" & i)  _   
    	.GetROProperty("text")
    		Next																		
  10. In OpenText Functional Testing's Record & Run Settings, make sure that the Install and Restart checkboxes are not selected.
  11. Run the loop statement you entered in the Script Editor to retrieve the ROProperty value.
  12. Look in OpenText Functional Testing's Output pane for the index of the label that contains the value.

    Use this index to identify the test object by adding a step similar to the following example to the test.

                            currentQuote = Device.App.MobileView("class:=Label", "index:=N") _
    	.GetROProperty("text")
                        

Back to top

Use programmatic descriptions instead of test objects

The following lines of code are examples of programmatic descriptions you can use in your steps instead of test objects.

Instead of using a test object from the object repository

                Device("D").App("A").MobileView("class:=Label", "accessibilityid:=sum").Tap
            

Instead of using a MobileView test object for scrolling

Device("D").App("A").MobileView("isscrollable:=True","index:=2").ScrollOnePage "forward"

Back to top

Add an App test object to the object repository

Sometimes, you may need to run steps on an application that cannot be loaded on the Digital Lab server, such as a system application.

In this case, you can add an application test object to the object repository to represent the application that cannot be loaded.

After you create the application test object, you can add mobile test objects under it and use these test objects in your test.

  1. Use uiAutomatorViewer to scan the view that contains your application.

    For details, see Analyze your app's user interface.

  2. Note the value of the package property.
  3. In OpenText Functional Testing, create a test object to represent the application.

    1. In the Object Repository window, select the relevant Device test object, and create a new child test object (ObjectDefine New Test Object).
    2. In the Define New Test Object dialog box, assign the child test object with the following unique description properties.

      Class App
      Name

      A unique name for the test object.

      Best practice: Assign a descriptive name that indicates the application's name or purpose.

      Test object details

      Description properties

      Remove all properties except for identifier.

      For identifier, enter the value you noted from the uiAutomatorViewer package property.

    3. Click to open the Add Properties dialog box, and then click to open the New Property dialog box.
    4. In the New Property dialog box, add a systemApp property with the value True.

Back to top

See also: