Android自动化测试, Feature phone自动化测试, Robotium, Monkey Runner, Android Robot
Android自动化测试 - Getevent 脚本
上一篇 /
下一篇 2012-09-11 13:09:21
我们采用Getevent事件给
android发送动作命令:
#!/system/bin/sh
# Script. to execute automatical test.
# By using: adb shell sendevent [device] [type] [code] [value]
#
# @author GuoLin
# Click on a point
click()
{
press $1 $2
release $1 $2
}
# Long click on a point
longclick()
{
press $1 $2
press $1 $2
sleep 1
}
# Fling from a point to another
fling()
{
move $1 $2 $3 $4
release $3 $4
}
# Drag and drop
dad()
{
longclick $1 $2
move $1 $2 $3 $4
release $3 $4
}
# Move from a point to another
move()
{
for i in 1 2 3 4;
do
x=$(( ($3 - $1) * $i / 3 + $1 ))
y=$(( ($4 - $2) * $i / 3 + $2 ))
press $x $y
done;
}
# Press a point
press()
{
sendevent $EVENT 3 $((0x35)) $1
sendevent $EVENT 3 $((0x36)) $2
sendevent $EVENT 3 $((0x30)) $((0x44))
sendevent $EVENT 3 $((0x32)) $((0x04))
sendevent $EVENT 3 $((0x39)) $((0x00))
sendevent $EVENT 0 $((0x02)) $((0x00))
sendevent $EVENT 0 $((0x00)) $((0x00))
}
# Release on a point
release()
{
sendevent $EVENT 3 $((0x35)) $1
sendevent $EVENT 3 $((0x36)) $2
sendevent $EVENT 3 $((0x30)) $((0x00))
sendevent $EVENT 3 $((0x32)) $((0x04))
sendevent $EVENT 3 $((0x39)) $((0x00))
sendevent $EVENT 0 $((0x02)) $((0x00))
sendevent $EVENT 0 $((0x00)) $((0x00))
}
# Samples
# Click on icon on cell 1,4
#click $((0x8b)) $((0x2c0))
# Scroll screen
#fling $((0x8b)) $((0x2c0)) $((0x222)) $((0x2c0))
# Drag and drop
#dad $((0x8b)) $((0x2c0)) $((0x8b)) $((0x200))
最底部的Samples例举了几种常用操作。
当然Shell自动化测试内容远不止一个脚本这么简单,但这是一个基础,有了这个脚本我们就可以开始进行各种内存、电量等测试了。下期介绍更高级的Android Shell内容
迈测(上海)信息科技有限公司 提供
AndroidRobot自动化测试工具免费下载
http://www.mtester.cn/content/?83.html
收藏
举报
TAG: