User Tools

Site Tools


android:monkey-script

Android monkey 自动化测试 script

参考:

http://www.linuxidc.com/Linux/2011-10/45152.htm

http://developer.android.com/reference/android/view/KeyEvent.html

http://www.eoeandroid.com/thread-161933-1-1.html

http://qatesttech.wordpress.com/category/android-monkey-script/

http://blog.csdn.net/quaful/article/details/6863914

Example:

# Start of Script
type= point
count= 8
speed= 1.0
start data >>
LaunchActivity(com.snda.cloudary, com.snda.cloudary.CloudaryMobile)
#LaunchActivity(com.snda.cloudary, com.snda.cloudary.bookreader.BookReaderActivity)
#KeyEvent参考:http://developer.android.com/reference/android/view/KeyEvent.html
#ACTION_DOWN:0
#ACTION_UP:1

#启动书架
UserWait(5000)
captureDispatchPointer(0,0,0,82,1116,0,0,0,0,0,0,0);
captureDispatchPointer(0,0,1,82,1116,0,0,0,0,0,0,0);


#退出程序
#返回事件
UserWait(2000)
DispatchPress(KEYCODE_BACK)
#确认退出
UserWait(1000)
captureDispatchPointer(0,0,0,193,719,0,0,0,0,0,0,0);
captureDispatchPointer(0,0,1,193,719,0,0,0,0,0,0,0);

#重新启动程序
UserWait(1000)
LaunchActivity(com.snda.cloudary, com.snda.cloudary.CloudaryMobile)

#启动书架
UserWait(4000)
captureDispatchPointer(0,0,0,82,1116,0,0,0,0,0,0,0);
captureDispatchPointer(0,0,1,82,1116,0,0,0,0,0,0,0);

#启动书架设置
UserWait(1000)
captureDispatchPointer(0,0,0,63,104,0,0,0,0,0,0,0);
captureDispatchPointer(0,0,1,63,104,0,0,0,0,0,0,0);

#返回事件
UserWait(2000)
DispatchPress(KEYCODE_BACK)

#启动书城
UserWait(1000)
captureDispatchPointer(0,0,0,231,1116,0,0,0,0,0,0,0);
captureDispatchPointer(0,0,1,231,1116,0,0,0,0,0,0,0);

#启动帐户
UserWait(1000)
captureDispatchPointer(0,0,0,447,1116,0,0,0,0,0,0,0);
captureDispatchPointer(0,0,1,447,1116,0,0,0,0,0,0,0);

#启动设置
UserWait(1000)
captureDispatchPointer(0,0,0,638,1116,0,0,0,0,0,0,0);
captureDispatchPointer(0,0,1,638,1116,0,0,0,0,0,0,0);

#启动书架
UserWait(1000)
captureDispatchPointer(0,0,0,82,1116,0,0,0,0,0,0,0);
captureDispatchPointer(0,0,1,82,1116,0,0,0,0,0,0,0);


#启动书城
UserWait(200)
captureDispatchPointer(0,0,0,231,1116,0,0,0,0,0,0,0);
captureDispatchPointer(0,0,1,231,1116,0,0,0,0,0,0,0);

#启动帐户
UserWait(200)
captureDispatchPointer(0,0,0,447,1116,0,0,0,0,0,0,0);
captureDispatchPointer(0,0,1,447,1116,0,0,0,0,0,0,0);

#启动设置
UserWait(200)
captureDispatchPointer(0,0,0,638,1116,0,0,0,0,0,0,0);
captureDispatchPointer(0,0,1,638,1116,0,0,0,0,0,0,0);

#启动书架
UserWait(200)
captureDispatchPointer(0,0,0,82,1116,0,0,0,0,0,0,0);
captureDispatchPointer(0,0,1,82,1116,0,0,0,0,0,0,0);

#打开书架第一本书
UserWait(1000)
captureDispatchPointer(0,0,0,347,289,0,0,0,0,0,0,0);
captureDispatchPointer(0,0,1,347,289,0,0,0,0,0,0,0);

#弹出阅读页面菜单
UserWait(1000)
captureDispatchPointer(0,0,0,376,600,0,0,0,0,0,0,0);
captureDispatchPointer(0,0,1,376,600,0,0,0,0,0,0,0);
#隐藏阅读页面菜单
UserWait(1000)
captureDispatchPointer(0,0,0,376,600,0,0,0,0,0,0,0);
captureDispatchPointer(0,0,1,376,600,0,0,0,0,0,0,0);

#翻页事件,右上角
UserWait(1000)
captureDispatchPointer(0,0,0,624,219,0,0,0,0,0,0,0);
captureDispatchPointer(0,0,1,624,219,0,0,0,0,0,0,0);

#翻页事件,左上角
UserWait(2000)
captureDispatchPointer(0,0,0,96,219,0,0,0,0,0,0,0);
captureDispatchPointer(0,0,1,96,219,0,0,0,0,0,0,0);

#翻页事件,右下角
UserWait(2000)
captureDispatchPointer(0,0,0,624,1024,0,0,0,0,0,0,0);
captureDispatchPointer(0,0,1,624,1024,0,0,0,0,0,0,0);

#翻页事件,左下角
UserWait(2000)
captureDispatchPointer(0,0,0,96,1024,0,0,0,0,0,0,0);
captureDispatchPointer(0,0,1,96,1024,0,0,0,0,0,0,0);

#返回事件
UserWait(2000)
DispatchPress(KEYCODE_BACK)

#退出程序
#返回事件
UserWait(2000)
DispatchPress(KEYCODE_BACK)
#确认退出
UserWait(1000)
captureDispatchPointer(0,0,0,193,719,0,0,0,0,0,0,0);
captureDispatchPointer(0,0,1,193,719,0,0,0,0,0,0,0);

/var/www/dokuwiki/wiki/data/pages/android/monkey-script.txt · Last modified: 2016/05/05 13:07 by 127.0.0.1