Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do UI automation in android?

Is there any guide to do following UI automation like selecting an item, writing text, pressing buttons in Android. Please list the steps to integrated this UI automation of one of the above thing.

Thanks

like image 270
blackfyre Avatar asked Sep 18 '12 10:09

blackfyre


3 Answers

You should use it like python script. Example:

import sys
import os
import time
import shlex
import subprocess

from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
device = MonkeyRunner.waitForConnection(99, ANDROID_SERIAL_NUMBER)

def Click(device, left, top, duration = 0):
    if duration == 0:
        device.touch(left, top, MonkeyDevice.DOWN_AND_UP)
    else:
        device.touch(left, top, MonkeyDevice.DOWN)
        time.sleep(duration)
        device.touch(left, top, MonkeyDevice.UP)

def Drag_example():
    device.drag((100, 200), (1500, 150), 1, 10) 

def Settings_menu():
    package='com.android.settings'
    activity='.Settings'
    component_name=package + "/" + activity
    device.startActivity(component=component_name)
Settings_menu();

For run script use: monkeyrunner script_name

Here is: Click it's function for clicking on screen in x and y position;
Drag_example simple example of dragging
Settings_menu simple example of running activity

Don't forget to change ANDROID_SERIAL_NUMBER to your serial number.
You can get it nu,ber by adb devices command.

For more information you can read google documentation.

For using in Java read this post

like image 198
Laser Avatar answered Oct 06 '22 19:10

Laser


Some useful link,

  1. Android: Sample Code To Demonstrate Monkeyrunner

  2. Android Guide: monkeyrunner Overview

  3. Android Guide: MonkeyDevice

  4. Android Guide: MonkeyRunner

  5. Monkeyrunner: interacting with the Views Last link but best...

like image 44
RPB Avatar answered Oct 06 '22 17:10

RPB


Automate is an app that can do all jobs you mentioned and many more. You wouldn't need a laptop or ADB connection. Also, no coding is required since programming is in the form of blocks and mostly synchronous.

Play Store link.

like image 45
Lucky Thakur Avatar answered Oct 06 '22 17:10

Lucky Thakur