9月 122017
 

1. adb shell input text

向文本框中输入文本,如将光标定位到一个输入框后执行下面的命令:

貌似不能输入中文

输入特殊字符时需要在特殊字符前加上“\”,比如空格(在Mac下测试)

2. adb shell input keyevent

模拟按键,可以是数字、符键或者是功能按键,keyevent后可以是按键的码值或者按键的名称,按键列表见文末的介绍,举例如下:

3. adb shell input [touchscreen|touchpad] tap x y

touchscreen – 触摸屏幕,touchpad – 不知道是啥
tap 点击的意思,和下面的swipe相对应
x,y – 要点击的位置的横纵轴坐标,举例如下:

4. adb shell input [touchscreen|touchpad] swipe x1 y1 x2 y2

touchscreen – 触摸屏幕,touchpad – 不知道是啥
swipe – 滑动、滑屏操作
x1 y1 x2 y2 – 滑动起始和终止位置的横纵轴坐标,举例如下:

5. adb shell input trackball press

模拟轨迹球按下(未测试过)
 

6. adb shell input trackball roll <dx> <dy>

模拟轨迹球滚动(未测试过)
 
附一:按键码列表:

 

1月 042017
 

  Android提供一个命令行工具monkey可以对安卓程序进行测试,monkey会对应用生成随机的动作流,包括点击、触摸、手势、文字录入等,模拟人工操作应用,并在发生错误后发送报告给用户。使用方法:首先在avd manager中打开一个模拟器或者使用USB线连上真机,打开命令行窗口,输入下面的命令:

  其中com.bcoder.testapp是你的包的名字,5000代表要测试的次数

  如果你的命令行中不能执行adb命令,请找度娘给你配置一下adb

  monkey支持很多参数,下面是一个详细的参数列表:

类别 参数 描述
常规 --help 打印一个简单的使用向导(确实很简单!)。
-v

每增加一个-v就会增加输出的测试信息的详细度,共分为级别0、1、2,也就是最多输入两个-v

事件 -s <seed>

此参数后边可以跟随一个数字值,这个值用于生成随机操作的种子,当你下一次再用这个种子值操作时,会重复上一次一样的操作。

比如:你执行 adb shell monkey -p com.bcoder.testapp -s 10 1000后发现了程序的一个报错

可以在修复问题后重新执行上面的命令,monkey还会按和上次一样的顺序生成随机事件

作者注:貌似不是每次的操作完全一样

--throttle <milliseconds> 为每次的事件增加一个延时,用于放慢monkey的执行速度,单位毫秒
--pct-touch <percent> 设置触屏操作所占的百分比
--pct-motion <percent> 设置划屏操作所占的百分比
--pct-trackball <percent> 设置轨迹球操作所占的百分比
--pct-nav <percent>

设置方向键操作所占的百分比

Adjust percentage of “basic” navigation events. (Navigation events consist of up/down/left/right, as input from a directional input device.)

--pct-majornav <percent>

设置back键、menu键所占的百分比

Adjust percentage of “major” navigation events. (These are navigation events that will typically cause actions within your UI, such as the center button in a 5-way pad, the back key, or the menu key.)

--pct-syskeys <percent>

设置系统键所占的百分比

Adjust percentage of “system” key events. (These are keys that are generally reserved for use by the system, such as Home, Back, Start Call, End Call, or Volume controls.)

--pct-appswitch <percent>

Adjust percentage of activity launches. At random intervals, the Monkey will issue a startActivity() call, as a way of maximizing coverage of all activities within your package.

--pct-anyevent <percent> Adjust percentage of other types of events. This is a catch-all for all other types of events such as keypresses, other less-used buttons on the device, and so forth.
约束 -p <allowed-package-name>

指定一个或者多个包进行测试,比如-p com.bcoder.testapp,如果要指定多个包进行测试就要使用多个-p参数,比如adb shell monkey -p com.bcoder.testapp -p com.bcoder.testapp2 1000

If you specify one or more packages this way, the Monkey will only allow the system to visit activities within those packages. If your application requires access to activities in other packages (e.g. to select a contact) you’ll need to specify those packages as well. If you don’t specify any packages, the Monkey will allow the system to launch activities in all packages. To specify multiple packages, use the -p option multiple times — one -p option per package.

-c <main-category> If you specify one or more categories this way, the Monkey will only allow the system to visit activities that are listed with one of the specified categories. If you don’t specify any categories, the Monkey will select activities listed with the category Intent.CATEGORY_LAUNCHER or Intent.CATEGORY_MONKEY. To specify multiple categories, use the -c option multiple times — one -c option per category.
调试 --dbg-no-events When specified, the Monkey will perform the initial launch into a test activity, but will not generate any further events. For best results, combine with -v, one or more package constraints, and a non-zero throttle to keep the Monkey running for 30 seconds or more. This provides an environment in which you can monitor package transitions invoked by your application.
--hprof If set, this option will generate profiling reports immediately before and after the Monkey event sequence. This will generate large (~5Mb) files in data/misc, so use with care. See Traceview for more information on trace files.
--ignore-crashes

正常情况下,当测试遇到应用崩溃时,monkey就停止测试,如果使用了此参数,monkey将继续给系统发送事件直到运行完count所设定的值。

Normally, the Monkey will stop when the application crashes or experiences any type of unhandled exception. If you specify this option, the Monkey will continue to send events to the system, until the count is completed.

--ignore-timeouts

正常情况下,当遇到ANR错误时,monkey就会停止测试,加上此参数后,monkey将会继续进行测试直到运行完所设定的count值。

Normally, the Monkey will stop when the application experiences any type of timeout error such as a “Application Not Responding” dialog. If you specify this option, the Monkey will continue to send events to the system, until the count is completed.

-f

指定测试脚本文件,示例文件见文末尾

如:adb shell monkey -v -v -f /mnt/sdcard/monkey_click.txt 1000

--ignore-security-exceptions

同上,忽略安全性异常错误。

Normally, the Monkey will stop when the application experiences any type of permissions error, for example if it attempts to launch an activity that requires certain permissions. If you specify this option, the Monkey will continue to send events to the system, until the count is completed.

--kill-process-after-error Normally, when the Monkey stops due to an error, the application that failed will be left running. When this option is set, it will signal the system to stop the process in which the error occurred. Note, under a normal (successful) completion, the launched process(es) are not stopped, and the device is simply left in the last state after the final event.
--monitor-native-crashes Watches for and reports crashes occurring in the Android system native code. If –kill-process-after-error is set, the system will stop.
--wait-dbg Stops the Monkey from executing until a debugger is attached to it.

 

-f参数脚本示例

注意事项:

  1. count参数一定要放到最后面
8月 162016
 

  要给app做一个定时提醒的功能,使用到了AlarmManager,因为涉及到很多天以后的提醒,所以不好测试,但是通过adb是可以查看系统已保存的AlarmManager 的,具体命令如下:

  如果我们只想看我们自己的应用的情况,则用linux的过滤器也可以(MAC下使用未在Windows下测试),命令如下:

 

2月 242013
 

原来一直在想,既然手机都有了无线网络或者蓝牙技术,为什么调试的时候还需要用数据线来弄,来回插拔麻烦不说,还得一直拖着个数据线。前几天在网上搜罗了一下,终于找到可以省掉数据线而用Wifi来调试的方法了。

据说在手机或者平板没有root的情况下也可以实现Wifi调试,但是笔者试验未成功,但是还是把办法来讲一下吧。

测试环境:手机HTC EVO 3d(HTC g17),Android版本4.0.3

没有Root系统时进行wifi连接调试的办法:

1、需要先插上数据线
2、打开一个命令行窗口,将目录切换到android-sdkplatform-tools目录下,执行adb tcpip 5555,将adb的连接方式切换到wifi
3、假设你手机的ip地址为192.168.0.100,在命令行窗口中执行adb connect 192.168.0.100,如果后面不加”:portnumber”则默认端口号为5555,如果成功会显示connected to 192.168.0.100:5555
4、使用adb devices命令可以显示已连接的设备。192.168.0.100:5555      device表示连接成功,192.168.0.100:5555      offline表示连接有问题。
5、如果需要用usb进行调试则执行adb usb命令

本人用上述方法未能成功连上wifi调试,没办法只能把手机系统root

Root后进行wifi连接调试的办法:

1、在手机上下载adbWireless,打开并开启wifi调试
2、 打开一个命令行窗口,将目录切换到android-sdkplatform-tools目录下,执行adb tcpip 5555,将adb的连接方式切换到wifi
3、 假设你手机的ip地址为192.168.0.100,在命令行窗口中执行adb connect 192.168.0.100,如果后面不加”:portnumber”则默认端口号为5555,如果成功会显示connected to 192.168.0.100:5555
4、使用adb devices命令可以显示已连接的设备。192.168.0.100:5555      device表示连接成功,192.168.0.100:5555      offline表示连接有问题。
5、如果需要用usb进行调试则执行adb usb命令

Eclipse插件支持

有一个插件可以用在Eclipse中以快速连接wifi调试,插件地址为http://ppareit.github.com/AdbConnect/,安装方法为打开菜单“帮助-〉安装新软件”,输入http://ppareit.github.com/AdbConnect/做为更新站点,安装完毕后在菜单“窗口-〉首选项-〉Android-〉Adb Connect”中设置手机的ip地址和端口号,在工具栏上会多一个图标按钮用于快速连接