Android, writing events low level touch screen automated shell test, part #1

Android, writing events low level touch screen automated shell test, part #1

Hello everybody,

Some information I have already covered in the article:

How to click screen using shell script (Froyo)

– In the beginning of this article you will find how to reproduce click for before Froyo Android

So lets start from the beginning, for implementation of automated test you need only 2 simple and essential shell commands:

~$ adb shell getevent

~$ adb shell sendevent $device $command $argument $value

First command is dumping all events from all interfaces (usually /dev/input/event0-4) in real time into the terminal output. For high usability you can use grep with regular expression to set a filter for output (it is so useful because of there are a lot of events out of our interest) for example, we need to trace only touch interface events:

— Assume /dev/input/event2 is a touch screen interface

~$ adb shell getevent | grep event2

or we need to get only click coordinates:

~$ adb shell getevent | grep event2: 0003 003[56]

By this way we can very simply determinate UI elements position at the screen! Sure, after we will conver hexa values of getevent to the decimal. For this you can use a pretty nice online tool with various converters on the board: easy calculation converter

For checking consistency of your regular expressions, you are using with grep command, you are welcome to use: my favourite regexpal, sure you can use your favourite tools.

Okay, lets try to determinate what roadblocks you may have firing this commands:

  1. “adb is not a command” or something like this

– Check in what folder you are, and change it to the …/android_sdk_location/tools

– adb (Android debug bridge) is situated here

  1. “adb server is not running” or something like this

– try to start adb daemon using command adb start-server

  1. You have fired an event, all was properly set, but nothing happens!

– Make sure you are not using HEXA args/values, when you are using sendevent command

– you must specify all data in the decimal format (0-9)

Let me provide you with some examples:

~$ adb shell getevent | grep event2

-> I’m doing single tap on the screen

Following events sequence will be dumped:

/dev/input/event2: 0003 0030 00000068

/dev/input/event2: 0003 0032 0000000a

/dev/input/event2: 0003 0035 0000022e

/dev/input/event2: 0003 0036 00000039

/dev/input/event2: 0000 0002 00000000

/dev/input/event2: 0003 0012 0000002f

/dev/input/event2: 0003 0014 00000001

/dev/input/event2: 0000 0000 00000000

/dev/input/event2: 0003 0030 00000000

/dev/input/event2: 0003 0032 0000000a

/dev/input/event2: 0003 0035 0000022e

/dev/input/event2: 0003 0036 00000039

/dev/input/event2: 0000 0002 00000000

/dev/input/event2: 0003 0012 00000020

/dev/input/event2: 0003 0014 00000000

/dev/input/event2: 0000 0000 00000000

Okay, now we can analyse it and determinate what these numbers mean:

  1. Finger is touching the screen:

/dev/input/event2: 0003 0030 00000068

/dev/input/event2: 0003 0032 0000000a

  1. At screen coordinates:

/dev/input/event2: 0003 0035 0000022e

/dev/input/event2: 0003 0036 00000039

  1. Still not recognized part, but I assume it describes number of pointers and its ID:

/dev/input/event2: 0000 0002 00000000

/dev/input/event2: 0003 0012 0000002f

/dev/input/event2: 0003 0014 00000001

  1. Pure event separator:

/dev/input/event2: 0000 0000 00000000

  1. Finger is releasing the point at the screen:

/dev/input/event2: 0003 0030 00000000

/dev/input/event2: 0003 0032 0000000a

  1. At the screen position:

/dev/input/event2: 0003 0035 0000022e

/dev/input/event2: 0003 0036 00000039

  1. Not recognized series, possibly describing number of touches and ID of the current touch:

/dev/input/event2: 0000 0002 00000000

/dev/input/event2: 0003 0012 00000020

/dev/input/event2: 0003 0014 00000000

  1. Pure event separator, always should close events sequence

/dev/input/event2: 0000 0000 00000000

So what information can we extract from these dump?

A lot of information!

  1. How to set X,Y coordinate of the click:

/dev/input/event2: 0003 0035 0000022e

/dev/input/event2: 0003 0036 00000039

Convert it to decimal and you will get the valuable ids:

Where 0003 53 and 0003 54 set x and set y commands

accordignaly. 558 is X, 57 is Y, to reproduce it you can

send these events:

~$ adb shell sendevent /dev/input/event2 0003 53 558

~$ adb shell sendevent /dev/input/event2 0003 54 57

  1. I think it will be interesting for you to reflect other events

by yourself. Please let me know if you do not succeed to do

something yourself.

INFO: Click all params decoded. Shell script sample.

PART 2: implementing simple shell script with ClickOnScreen(x,y) function.

Happy clicking (:

Best regards,

Yahor

Want to stay updated on the latest tech news?

Sign up for our monthly blog newsletter in the form below.

13 REVIEWS

51 REVIEWS

Lithuania

82 Laisves al., Kaunas, 44250

42A, Dariaus ir Gireno st., Vilnius, 02189

United Kingdom

Loughborough Technology Centre, Epinal Way, Loughborough, LE11 3GE

United States

22 Juniper st., Wenham, Massachusetts, 01984

Poland

9A/4U Belwederska st., Warsaw, 00-761

Georgia

1 Meliton And Andria Balanchivadze st., Tbilisi, 0667

Bulgaria

Knyaginya Maria Luiza 1 Blvd., Plovdiv, 4000

United Arab Emirates

Office No. 19-177MF, Owned by Shamsa Mohammed Ibrahim
Al-Suwaidi, Al-Murar, Dubai

13 REVIEWS

22 REVIEWS

13 REVIEWS

22 REVIEWS

Softteco Logo Footer