Automating Android Apps - Details

abstract This page describes Android Automation in detail. If you wish to get a quick start, read Android Automation - Getting Started.

Features

Limitations

Android Viewer

Android Viewer allows an end user to view the Android device/emulator screen on a Desktop browser. The user can launch the Controller and then identify Android elements by pressing the CTRL key and hovering the mouse over the element.

This section details how to use the Android Viewer.
  1. On the Flowcharts window, click on the dropdown arrow next to Launch and then select Launcher Settings.

  2. Launcher Settings dialog opens.

  3. Description of the image labeling:

    1. Select the Mode: Android
    2. Now select the device from the Device Info dropdown
      Specify Application Package Name:com.sahipro.SahiTestApp

  4. Click on Launch to launch the Application.
  5. This brings up Android Viewer in system's default browser. If the user wants to launch Android Viewer in a specific browser then, open that Sahi browser and then click on the Android Viewer link from the start page, this brings up Android Viewer in that browser.
  6. Device Info: shows the list of the connected device to the system Application Package Name: allows an end user to start an application by it's package name which is already installed in that device. Leave it blank if you want to start the device session in its current state of the screen.
  7. infoNote: if device list doesn't contain the connected device, then click on the refresh button next to devices dropdown.
  8. Make sure that the device is connected through a USB cable or over Wi-Fi. Click on Connect Session. If the connection is successful, you will see the device screenshot in a short while.
  9. When some action is performed from the Android Viewer, the screenshot will be refreshed a few times, to display the latest device state. However, if actions are performed on the device manually, the screenshot will not get refreshed. Click on the Refresh icon manually to refresh the screenshot.
  10. One can interact with the device from the Android Viewer itself without launching the Controller.
  11. Launch the Controller by ALT and Double clicking on the android device.
  12. You can now start identifying elements by pressing the CTRL key and hovering the mouse over elements on the Desktop screenshot. You will notice the Accessor textbox on the Controller, showing the accessor for the element. The dropdown displays the alternatives for the accessor.

Android Viewer Actions:

These buttons perform various actions on the Android device and these actions are recorded while Record a steps. These will give quick access to Android assist functions during debugging/script recording.

Screenshot Outline View

Security restrictions may prohibit Android Viewer from capturing the screen shot to be displayed. In such a case, you can use the Screenshot Outline View feature to toggle the outline view.
For example, let's assume that for the below screen, Android Viewer is unable to take the screenshot. To enable the outline view, check the highlighted checkbox in Android Viewer. After checking it, the Android Viewer will display the outline view like this. Now you will be able to identify the elements in controller.

info A few things to note...
  • If the app orientation changes from portrait to landscape or vice versa, do a manual refresh by clicking on the Refresh icon, to view the screenshot correctly.
  • If you resize the Android Viewer page, do a manual refresh by clicking on the Refresh icon, to view the screenshot correctly.
  • Do not disconnect (physically or via wifi) the device before disconnecting the session. In case you do so and on reconnecting you find that Connect Session does not seem to connect the device, please have a look at the Sahi console. If the Sahi console indicates that you should reconnect the device, please do so.
  • Closing the Android Viewer browser does NOT disconnect the session. So always disconnect the session before closing the browser. If you fail to do so and open the Android Viewer again, it will show the session to be in a connected state.
  • As of now, Android Viewer supports only one device at a time. The device has to be connected to the machine that runs Sahi.

Configure Android Devices/Emulators

  1. Click on the All Settings button on the Dashboard. It will open up all Settings dialog.
  2. Click on the Sahi Pro Settings button. It will open up Configure Sahi Pro page.
Click on android_devices.xml on the left. This will open page similar to image given below.

androidDevice Node

<androidDevices>
	<!-- Moto device with 2 capacity -->

	<androidDevice>
		<name>Moto</name>
		<displayName>Moto G5</displayName>
		<deviceId>XXXX</deviceId>
		<deviceId>YYYY</deviceId>
	</androidDevice>
</androidDevices>


ElementValue
nameKey by which this androidDevice will be referred. This can be any value without spaces.
displayNameBetter name displayed in Android Viewer.
deviceIdId of the device, multiple Id can be added under same name.
you can get the Device Id by executing this command
adb devices
infoFor example, Two devices are configured under Moto. For parallel playback of data driven suite on this two devices, select Moto as Android Device from editor (or specify Moto as Android Device in ANT target). Scripts will be distributed in two devices.

Automating a Keyword

This is similar to automating a Sahi Pro Flowcharts keyword for normal browser testing.
  • To automate a Keyword, click on the Keyword from the Sahi Pro Flowcharts page, click on the Automate, click on Start Record button, Actions done on the application on Android device are recorded automatically.
  • Steps can also be recorded from the Flowcharts Controller.
  • Automating Hybrid App

    Pre-requisites

    For recording Android application which contains Webview (Hybrid content), open the application in Android Viewer and go to the screen which contains webview.
    If the screen is displaying hybrid contents then there will be one checkbox labeled Enable web view identification.
    1. Check the checkbox to identify/record hybrid elements as Web.
    2. Press the CTRL key and mouse over the hybrid element.
    3. Element's accessor will be displayed in Flowchart Controller.
    4. To automate the hybrid app, perform the actions directly from Android Device.
    info NOTE: To identify/record the hybrid element as native, uncheck the checkbox in Android Viewer.

    Playback

    1. On the Automate dialog click on Runbutton.
    2. The Run Settings dialog opens. Select the Mode Android if we did not mentioned in the scipt and click RUN.
    3. infoWhen the flow is being played back, you CANNOT see the playback happening on the Android Viewer. The Android Viewer does not get refreshed during playback.

    More Info

    Android Accessor APIs
    Mobile APIs