Android Automation - Getting Started
abstract
This section helps you quickly get started with Android Automation.
To automate an Android Devices/Simulators using Sahi Pro Classic, refer Android Automation - Getting Started.
Pre-requisites
-
Desktop
- The machine needs to have Android Platform Tools installed so that ADB is available in the system. Having a full blown Android SDK is even better.
- Make sure the path to the Android Platform Tools folder is added to the PATH environment variable. To test this, open a command prompt and type adb (or adb.exe). ADB should start up if the Android Platform Tools folder is in the PATH.
-
Device
-
Connect the device. Enable USB debugging from Settings -> Developer options.
- To enable Developer options, go to Setting -> About phone -> scroll to Build number and tap it 7 times.
- If you already have the driver for the device installed, you should now be connected through adb. If not, install the USB driver for the device.
- The device has to be connected through USB cable throughout the duration of the test. Alternatively, you can setup adb over Wi-Fi as well if you do not wish to tether the device.
- Screen lock should be removed and display options should be set such that the device does not sleep throughout the execution of the script.
- When the device is connected for the first time, you may get an alert asking for permission to connect. Set it to always accept the connection.
- To know the device ID which is connected to the machine, type
adb devices
in command prompt.
-
Connect the device. Enable USB debugging from Settings -> Developer options.
Play Protect Warning
On the Android device,Google Play Protect
scans for apps that are not known to Play Protect
and warns the user during installation.
When running a script on the Android device or connecting to it through the Android Viewer for the first time, Sahi first installs 2 apps on the device to facilitate Android testing. Since these apps are for testing purpose and are not from the Play Store,
Google Play Protect
can display the following warning.
Warning: Send app for a security check?
- Click on
Don't send
to dismiss the warning. - You will see a similar warning for the 2nd app -
in.co.sahi.android.test
. - Click on
Don't send
again to dismiss the 2nd warning. The connection will proceed successfully.
- Open the
Play Store
app on the device. - At the top right, tap the
Profile
icon. - Tap
Play Protect
from the list. Play Protect
screen opens. At the top right, tap theSettings
icon.- The following screen opens.
- Tap the second option,
Improve harmful app detection
to switch itOFF
. The screen now looks like this. - Connecting the Android Viewer again or running the script will not show the
Play Protect
warning again.
Download and Install Sahi Pro Mobile Add-on
You need to install Sahi Pro Mobile Add-on before you can proceed with the Quick TutorialQuick Tutorial
Connect Session and Element Identification
- Connect the Android Device to the system.
- Install the Sample Application
<SAHI_INSTALLATION_FOLDER>/userdata/android/testapps/AndroidApp.apk
on the device.
- Open a Command Prompt(Windows) or Terminal Shell(Mac, Linux etc.)
- Type
cd <SAHI_INSTALLATION_FOLDER>/userdata/android/testapps
and press enter.
- Type
adb install AndroidApp.apk
and press enter to install the app.
- Start Sahi Dashboard and click on the
Flowcharts
.
- On the Flowcharts window, click on the dropdown arrow next to Launch and then select
Launcher Settings
.
Launcher Settings
dialog opens.
Description of the image labeling:
- Select the Mode: Android
- Now select the device from the
Device Info
dropdown
Specify Application Package Name:
com.sahipro.SahiTestApp
- Click on Launch to launch the Application.
- This brings up Android Viewer in system's default browser.
- Now click on
Connect Session
button.
- This will start
com.sahipro.SahiTestApp
application in Android device. The device screen is also visible on the Android Viewer.
- On the Flowcharts window, click on the dropdown arrow next to Launch and then select
Open Controller
. You can now start identifying/automating.
Like normal Sahi Pro Flowcharts for web pages, you can use CTRL-Hover to identify various elements on the Java Web Start application.
Automating a Keyword
This is similar to automating a Sahi Pro Flowcharts keyword for normal browser testing.
Connect Session and Element Identification
- Connect the Android Device to the system.
- Install the Sample Application
<SAHI_INSTALLATION_FOLDER>/userdata/android/testapps/AndroidApp.apk
on the device.- Open a Command Prompt(Windows) or Terminal Shell(Mac, Linux etc.)
- Type
cd <SAHI_INSTALLATION_FOLDER>/userdata/android/testapps
and press enter. - Type
adb install AndroidApp.apk
and press enter to install the app.
- Start Sahi Dashboard and click on the
Flowcharts
. - On the Flowcharts window, click on the dropdown arrow next to Launch and then select
Launcher Settings
. Launcher Settings
dialog opens.- Select the Mode: Android
- Now select the device from the
Device Info
dropdown
SpecifyApplication Package Name:
com.sahipro.SahiTestApp - Click on Launch to launch the Application.
- This brings up Android Viewer in system's default browser.
- Now click on
Connect Session
button. - This will start
com.sahipro.SahiTestApp
application in Android device. The device screen is also visible on the Android Viewer. - On the Flowcharts window, click on the dropdown arrow next to Launch and then select
Open Controller
. You can now start identifying/automating. Like normal Sahi Pro Flowcharts for web pages, you can use CTRL-Hover to identify various elements on the Java Web Start application.
Description of the image labeling:
Automating a Keyword
This is similar to automating a Sahi Pro Flowcharts keyword for normal browser testing.Automate
, click on Start Record
button, Actions done on the application in Android device are recorded automatically.
-
A. You can use Click, Set, Assert, choose 'Other Actions' to perform an action on the Android device.
B. You will need to record these steps explicitly by clicking on 'Add Step'.
Playback
- On the
Automate
dialog click onRun
button. - The
Run Settings
dialog opens. Select the ModeAndroid
and clickRUN
.
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.
View Report
- Click on the
Reports
button.. - The Report opens in a new browser tab.
infoRefer Run Flowchart for a better understanding.
Further Reading
Android Automation in DetailAndroid Accessor APIs
Mobile APIs
Working with Multiple Modes in a Single Script