android 脚本模拟点击屏幕

对低概率问题,需要多次测试以复现问题,使用脚本更容易实现,避免频繁人工操作

首先要了解手机的众多输入设备:

命令:adb shell cat /proc/bus/input/devices/

I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="qpnp_pon"
P: Phys=qpnp_pon/input0
S: Sysfs=/devices/virtual/input/input0
U: Uniq=
H: Handlers=event0 
B: PROP=40
B: EV=3
B: KEY=14000000000000 0

I: Bus=0018 Vendor=0000 Product=0000 Version=0000
N: Name="qcom-tpd"
P: Phys=
S: Sysfs=/devices/soc/78b7000.i2c/i2c-3/3-0038/input/input1
U: Uniq=
H: Handlers=mdss_fb kgsl event1 
B: PROP=2
B: EV=b
B: KEY=ff000000000000 0 0 0 0 0 400 0 0 0 160000000000 4004001400000
B: ABS=261800000000000

I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="gf5216"
P: Phys=
S: Sysfs=/devices/virtual/input/input2
U: Uniq=
H: Handlers=event2 
B: PROP=0
B: EV=3
B: KEY=2000000040000800 1016c000000008 0

I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="qwerty"
P: Phys=
S: Sysfs=/devices/virtual/input/input3
U: Uniq=
H: Handlers=event3 
B: PROP=0
B: EV=3
B: KEY=2000000040000800 1016c000000008 0

I: Bus=0019 Vendor=0001 Product=0001 Version=0100
N: Name="gpio-keys"
P: Phys=gpio-keys/input0
S: Sysfs=/devices/soc/soc:gpio_keys/input/input4
U: Uniq=
H: Handlers=event4 
B: PROP=0
B: EV=3
B: KEY=4000000000000000 0 0 10000 0 0 0 0 0 0 8000000000000 0

I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="msm8952-snd-card-mtp Headset Jack"
P: Phys=ALSA
S: Sysfs=/devices/soc/c051000.sound/sound/card0/input5
U: Uniq=
H: Handlers=event5 
B: PROP=0
B: EV=21
B: SW=3c0d4

I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="msm8952-snd-card-mtp Button Jack"
P: Phys=ALSA
S: Sysfs=/devices/soc/c051000.sound/sound/card0/input6
U: Uniq=
H: Handlers=event6 
B: PROP=40
B: EV=3
B: KEY=e0 400000000 0 c000000000000 0

对应输入设备的Name匹配我们需要使用的设备信息,

I: Bus=0018 Vendor=0000 Product=0000 Version=0000
N: Name="qcom-tpd"
P: Phys=
S: Sysfs=/devices/soc/78b7000.i2c/i2c-3/3-0038/input/input1
U: Uniq=
H: Handlers=mdss_fb kgsl event1 
B: PROP=2
B: EV=b
B: KEY=ff000000000000 0 0 0 0 0 400 0 0 0 160000000000 4004001400000
B: ABS=261800000000000

发现给设备对应tp。

命令:adb shell getevent1 /dev/input/event1

输入该命令后,做点击屏幕操作,这里我们以点击拍照为例:

终端输出:

0003 0039 00000000
0003 0030 00000003
0003 0035 00000163
0003 0036 00000476
0001 014a 00000001
0000 0000 00000000
0003 0030 00000004
0000 0000 00000000
0001 014a 00000000
0000 0000 00000000

扫描二维码关注公众号,回复: 1065405 查看本文章

注意:点击不同的点会输出不同的信息,这里的输出对应这点击事件的具体信息,我们之需要在脚本中做写下相同的命令既可以实现同样的操作

下面开始写脚本使用sendevent命令(这里需要注意的是,上买你的输出为十六进制,需要自行转换成十进制):

sendevent /dev/input/event1 0003 57 00000000
sendevent /dev/input/event1 0003 48 00000003
sendevent /dev/input/event1 0003 53 355
sendevent /dev/input/event1 0003 54 1142
sendevent /dev/input/event1 0001 330 00000001
sendevent /dev/input/event1 0000 0000 00000000
sendevent /dev/input/event1 0003 48 00000004
sendevent /dev/input/event1 0000 0000 00000000
sendevent /dev/input/event1 0001 330 00000000
sendevent /dev/input/event1 0000 0000 00000000

写完脚本touch.sh文件

使用命令afb push touch.sh /sdcard/把脚本导入手机

然后执行adb shell sh /sdcard/touch.sh

确认手机是否会出现同样操作

根据这个步骤也可以尝试写一些相关其他设备的输入,当我们需要重复点击时,之需要在脚本写个循环就可以实现自动压力测试了



猜你喜欢

转载自blog.csdn.net/wing12345678910/article/details/79170047