Android automated test shell script (fast asphalt5)

Source: Internet
Author: User

Android automated test shell script (fast asphalt5)

This article is my original, reproduced please indicate the source: http://blog.csdn.net/lhzhang1985/article/details/6580595 thank you!

Because Automatic Testing of the high-speed asphalt5 is required, the high-speed asphalt5 cannot be started again automatically. Therefore, you need to write a script to complete the automated testing and then let it run for several days and nights. At the beginning, I was not familiar with automated testing scripts, so I had a lot of Google on the Internet. I found some references for the materials.

We know that there is a simulated click-touch screen simulator and a real machine on Android. The difference between the two is quite large. The simulators are generally more idealistic, And the simulator is more complicated on the real machine.

Refer to the following article:

1. http://www.eefocus.com/chongzi865458/blog/11-06/225120_23131.html this article mainly explains Android user input system, such as touch key trackball and other data acquisition and Input

2. http://blog.csdn.net/yiyaaixuexi/article/details/6574001 this article mainly describes the use of sendevent to simulate the keyboard or mouse click event.

3. Simulate keyboard and mouse events on the http://blog.csdn.net/roger_ge/article/details/5552740 Simulator

4. Android system-level in-depth development-transplantation and debugging Chapter 4 user input system

The following uses asphalt5 as an example to describe in detail:

Objective: To implement automated testing for Speeding without manual operation

Principle: start the competition for the first time, start the competition, touch the ESC or menu key, and then press the re-start button on the screen. In this way, re-start the event and set it.

 

1. Get the event corresponding to the device

Use # Cat/proc/bus/input/devices

C: \ tools> ADB Shell

# Cat/proc/bus/input/devices

CAT/proc/bus/input/devices

I: Bus = 0019 vendor = 0001 Product = 0001 version = 0001

N: Name = "s3c-keypad"

P: phys = YF-keypad/input0

S: sysfs =/devices/virtual/input/input0

U: uniq =

H: handlers = sysrq event0

B: EV = 3

B: Key = 400000 0 0 0 0 0 0 0 1 ffffffff fffffe

I: Bus = 0018 vendor = 0000 Product = 0000 version = 0000

N: Name = "pixcir_ts"

P: phys =

S: sysfs =/devices/platform/s3c2440-i2c.1/i2c-1/1-005c/input/input1

U: uniq =

H: handlers = mouse0 event1

B: EV = B

B: Keys = 400 0 0 0 0 0 0 0 0 0 0

B: ABS = 2650000 1000003

2. Get the device's corresponding event * Incoming Value

Getevent/dev/input/event * is used. * indicates the above 0 or 1, * Can Be 01234567 in a real machine, and so on. Different values indicate different devices, control different things, and multi-touch is much more complex than single-touch. In the simulator, the * value seems to be only 0.

# Getevent/dev/input/event0)

Getevent/dev/input/event0: Wait for the button event

When you press menu:

0001 0032 00000001

0001 0032 00000000

When you press ESC:

0001 0033 00000001
0001 0033 00000000

# Getevent/dev/input/event1 (the device controls the touch screen if any information is displayed on the touch screen)

Getevent/dev/input/event1 wait for the touch screen
0003 0000 0000035b ??
0003 0001 000001ba
0001 014a 00000001
0003 0018 00000001
0003 0039 00000000 ??
0003 0030 00000001
0003 0032 00000000
0003 0035 35b
0003 0036 000001ba
0000 0002 00000000
0000 0000 00000000
0003 0039 00000000 ??
0003 0030 00000001
0003 0032 00000000
0003 0035 35b
0003 0036 000001ba
0000 0002 00000000
0000 0000 00000000
0003 0039 00000000 ??
0003 0030 00000001
0003 0032 00000000
0003 0035 35b
0003 0036 000001ba
0000 0002 00000000
0000 0000 00000000

What are the above representatives? To find out these reasons, you need to familiarize yourself with the content first.

 

Iii. initial definition of user input/output system

 

Refer:

1. Underlying http://blog.csdn.net/guoshaobei/article/details/5824740 of Kernel

2. Android Layer Related http://blog.csdn.net/yiyaaixuexi/article/details/6574001

Kernel:

The header file of the event input DRIVER: Include/Linux/input. h.

The core and part of the event input device driver code are drivers/input. C and Drivers/input/evdev. C.

The device node of the event device in the file system is/dev/input/eventx. The specific value of the X is displayed in some parts.

Android:

Source code: Framework/base/CORE/Java/Android/View/rawinputevent. Java

Public static final int abs_mt_touch_major = 0x30;
Public static final int abs_mt_touch_minor = 0x31;
Public static final int abs_mt_width_major = 0x32;
Public static final int abs_mt_width_minor = 0x33;
Public static final int abs_mt_orientation = 0x34;
Public static final int abs_mt_position_x = 0x35; X axis
Public static final int abs_mt_position_y = 0x36; representing the Y axis
Public static final int abs_mt_tool_type = 0x37;
Public static final int abs_mt_blob_id = 0x38;
Public static final int abs_max = 0x3f;

What can I think of when I see these source codes?



Send mouse events (touch ):

Command Format: ADB shell sendevent [device] [type] [Code] [value]

For example, in the simulator, ADB shell sendevent/dev/input/event0 1 229 1 means to press the menu key

ADB shell sendevent/dev/input/event0 1 229 0 means to press and release the menu key

The preceding commands must be used in combination.

Let's go back to the content mentioned in the second part:

When you press menu:

0001 0032 00000001 (hexadecimal to decimal)-"event0 1 50 1 50 represents menu, and the second 1 represents pressing this key

0001 0032 00000000 (convert hexadecimal to decimal)-"event0 1 50 50 represents menu, 0 represents releasing the key

When you press ESC:

0001 0033 00000001 (hexadecimal to decimal)-"event0 1 51 1 51 represents ESC, and the second 1 represents pressing this key
0001 0033 00000000 (hexadecimal to decimal)-"event0 1 51 0 51 represents ESC, 0 represents releasing the key


Getevent/dev/input/event1 wait for the touch screen
0003 0000 0000035b?
0003 0001 000001ba?
0001 014a 00000001? 0x14a fixed value
0003 0018 00000001? 0x18 is also a fixed value
0003 0039 00000000?
0003 0030 00000001-> abs_mt_touch_major
0003 0032 00000000-> abs_mt_width_major
0003 0035 0000035b-> X axis is 0x35b
0003 0036 000001ba-> the Y axis is 0x1ba
0000 0002 00000000?
0000 0000 00000000-> A required row is equivalent to terminating a complete data record.


I have not found any definition for the question mark. If you have any idea, please leave a message and let us know. Thank you.

 

4. Automated shell Testing

With the above familiarity, we can finally start writing scripts. Based on the testing speed principle, you only need to write a loop script.


As follows:


#! /System/bin/sh
Key ()
{
Sendevent/dev/input/event0 1 $1 1
Sendevent/dev/input/event0 0 0 0
Sendevent/dev/input/event0 1 $1 0
Sendevent/dev/input/event0 0 0 0
Echo key $1 "(" $2 ")" "& sleep" $3
Sleep $3
}
Touch ()
{
Sendevent/dev/input/event1 3 0$1
Sendevent/dev/input/event1 3 1 $2
Sendevent/dev/input/event1 1 330 1
Sendevent/dev/input/event1 3 24 1
Sendevent/dev/input/event1 3 57 0
Sendevent/dev/input/event1 3 48 1

Sendevent/dev/input/event1 3 50 0

Sendevent/dev/input/event1 3 53$1

Sendevent/dev/input/event1 3 54$2

Sendevent/dev/input/event1 0
2 0

Sendevent/dev/input/event1 0 0 0

Sendevent/dev/input/event1 3 57 0
Sendevent/dev/input/event1 3 48 1

Sendevent/dev/input/event1 3 50 0

Sendevent/dev/input/event1 3 53$1

Sendevent/dev/input/event1 3 54$2

Sendevent/dev/input/event1 0 2 0

Sendevent/dev/input/event1 0 0 0

Echo touch $1 $2 "(" $3 ")" "& sleep" $4
Sleep $4
}

While true;
Do

Echo "==============================="

Key "50" "menu" 2"
Touch "854" "442" "Touch restart" "2"
Touch "319" "316" "yes" "215"

Done


V. Verification and summary

ADB push the script/data/

ADB Shell

# Cd/Data

# Chmod 777 this script

#./The script & // address character & indicates that the script runs in the background. You can run the script after pulling the USB.

 

Test successful on real machine

Note:

1. Different device nodes on different real machines have different control content and need to be tested in advance

2. The specific x and y values must be obtained through actual tests.

3. Pay attention to the loop content during script Loop


Wish you a successful test.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.