Category Archives: Android Monkey Script

Android adb Commands

A quick list of adb commands for Android Testing (mostly for my reference) – this list will be updated at my testing continues.  If you multiple devices connected you can use “-s” to get information for a particular device – helpful if you have 2 devices connected and only want the logcat output for a single device.

Devices – Get list of connected devices, either real or devices in the emulator

adb devices

List of devices attached
CC96A0133C10    device
781DBA1586BE    device

Install – installing a package to a device, it installs to the only connected device, if one device is connected.

adb install myapp.apk

Reboot – like the name says reboot the device

adb reboot

Remount – this allows you to remount an emulated device  image as writable (so you can change things like the host file

adb remount

Pull – get stuff all the device

adb pull /system/etc/hosts c:\Android\hosts

This example pulls a copy of the hosts file from the device

Push – put stuff on the device

adb push name.txt /sdcard/name.txt

This example pushes a test file called “name.txt” to the “sdcard” – as the same name, but you can change the file name for the destination

Uninstall – remove your installed package

adb uninstall com.mm.app.android

List installed Packages  – list everything installed on your device

adb shell pm list packages

Logging – log what is going on the device as it is being used

adb logcat

Logging – to clear the log use the “-c” option

adb logcat -c

Logging – log what is going on for a particular device as it is being used

adb -s CC96A0133C10 logcat

Getevent – Capture events being touched on the screen, note it captures in hexadecimal and the values need to be converted to decimal in order to use

adb shell getevent

Run Shell script – How to run a shell script once it is pushed until the android

adb shell sh /sdcard/<script name>

File Listing – to find the files listed on a device (I mostly check  sdcard) – use your standard unix comment ls

adb shell ls

To check the On the SDCARD

adb shell ls /sdcard/

Advertisements

Monkey Script: the ‘Tap’ command

Per the source code, “tap” is a supported command, however it doesn’t really go much.

With my testing I found that the “tap” does not work for tapping keys..  The field I am highlighting has an attached keyboard, however “tap(5)” does not type a “5” on the keyboard.  All tap does, is if a field is in focus, and you “tap” it, the associated popup keyboard will appear.

Source Code (Look for EVENT_KEYWORD_TAP):

http://www.java2s.com/Open-Source/Android/android-core/platform-development/com/android/commands/monkey/MonkeySourceScript.java.htm

Android – My Monkey Script – Example

Notes:

  1. I got the Keycodes from:  Keycodes for DispatchPress Command (Scroll down to Summary table)
  2. To Launch the Activity I had to put in the full app name (com.mpowerlabs.coin.android) and full app name plus the activity I was going to test (com.mpowerlabs.coin.android.LoginActivity))
  3. “count” doesn’t do anything in this test case

# Start of Script
type= user
count= 49
speed= 1.0
start data >>
LaunchActivity(com.mpowerlabs.coin.android, com.mpowerlabs.coin.android.LoginActivity)
# 3120021258
DispatchPress(KEYCODE_3)
UserWait(200)
DispatchPress(KEYCODE_1)
UserWait(200)
DispatchPress(KEYCODE_3)
UserWait(200)
DispatchPress(KEYCODE_5)
UserWait(200)
DispatchPress(KEYCODE_0)
UserWait(200)
DispatchPress(KEYCODE_2)
UserWait(200)
DispatchPress(KEYCODE_1)
UserWait(200)
DispatchPress(KEYCODE_2)
UserWait(200)
DispatchPress(KEYCODE_5)
UserWait(200)
DispatchPress(KEYCODE_8)
UserWait(200)
# Pin 12345
DispatchPress(KEYCODE_DPAD_DOWN)
UserWait(250)
DispatchPress(KEYCODE_1)
UserWait(200)
DispatchPress(KEYCODE_2)
UserWait(200)
DispatchPress(KEYCODE_3)
UserWait(200)
DispatchPress(KEYCODE_4)
UserWait(200)
DispatchPress(KEYCODE_5)
UserWait(200)
# Down and enter
DispatchPress(KEYCODE_DPAD_DOWN)
UserWait(250)
DispatchPress(KEYCODE_ENTER)