android自动化测试工具monkeyrunner脚本实例(notepad)

上一篇 / 下一篇  2011-11-16 17:02:25

一个对notepad基本操作的实例,希望对大家有所帮助
 
#使用320*480分辨率android屏幕
import sys
from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice,MonkeyImage
#添加一个新的note
def insertnote(d):                  
 d.startActivity(component="com.example.android.notepad/.NotesList")
 print "insert a new note"
 MonkeyRunner.sleep(2)
 d.press("KEYCODE_MENU",'DOWN')
 MonkeyRunner.sleep(2)
 d.touch(58,430)
 MonkeyRunner.sleep(2)
 d.type("hello")
 d.press("KEYCODE_BACK",'DOWN')
 d.press("KEYCODE_HOME",'DOWN')
 print "insert Successfully"
 MonkeyRunner.sleep(5)
#对之前添加的note做更改
def updatenote(d):
 d.startActivity(component="com.example.android.notepad/.NotesList")
 print "update the note"
 MonkeyRunner.sleep(2)
 result = d.takeSnapshot()
 result.writeToFile('noteslist.png','png')

 d.touch(58,100)
 MonkeyRunner.sleep(2)
 result = d.takeSnapshot()
 result.writeToFile('opennote.png','png')

 d.press("KEYCODE_MENU",'DOWN')
 MonkeyRunner.sleep(2)
 result = d.takeSnapshot()
 result.writeToFile('pressmenu.png','png')

 d.touch(300,430)
 MonkeyRunner.sleep(3)
 result = d.takeSnapshot()
 result.writeToFile('edittitle.png','png')

 y=250
 x1=300
 x2=50
 duration=1
 steps=10
 start=(x1,y)
 end=(x2,y)
 d.drag(start,end,duration,steps)
 result = d.takeSnapshot()
 result.writeToFile('cut.png','png')
 d.touch(100,265)
 MonkeyRunner.sleep(2)
 d.type("note1")
 MonkeyRunner.sleep(2)
 result = d.takeSnapshot()
 result.writeToFile('printnewname.png','png')

 d.touch(285,305)
 MonkeyRunner.sleep(2)
 d.type("world")
 MonkeyRunner.sleep(1)
 d.press('KEYCODE_BACK','DOWN')
 d.press("KEYCODE_HOME",'DOWN')
 MonkeyRunner.sleep(5)
#删除该条note
def deletenote(d):
 d.startActivity(component="com.example.android.notepad/.NotesList")
 print "delete the note"
 MonkeyRunner.sleep(2)
 d.touch(58,100)
 MonkeyRunner.sleep(2)
 d.press("KEYCODE_MENU",'DOWN')
 MonkeyRunner.sleep(2)
 d.touch(160,430)
 d.press("KEYCODE_HOME",'DOWN')
def main():
        print "Start"
        device = MonkeyRunner.waitForConnection()
       
        if not device:
            print "Couldn't get connection"
            sys.exit()
   
        print "Found device"
 
 insertnote(device)
 updatenote(device)
 deletenote(device)
if __name__ == '__main__':
 main()
 
 
 
 

 

TAG: Monkeyrunner monkeyRunner monkeyrunner

zhangliming@ich的个人空间 引用 删除 zhangliming@ich   /   2012-07-30 11:00:24
请问monkeyrunner 有办法模拟来电测试吗
zhangliming@ich的个人空间 引用 删除 zhangliming@ich   /   2012-07-30 10:55:20
lz  触摸屏的坐标是怎么的到的?请赐教
a420344的个人空间 引用 删除 a420344   /   2012-03-30 14:26:26
写的不错,顺便问一下,怎么可以在SDK的tools目录下的脚本里import其他脚本的内容,谢谢
引用 删除 xiaolongqi   /   2011-11-30 11:49:26
很好,学习了
引用 删除 xiaolongqi   /   2011-11-30 11:49:25
3
引用 删除 xiaolongqi   /   2011-11-30 11:49:16
很好,学习了
 

评分:0

我来说两句

日历

« 2024-05-03  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 3877
  • 日志数: 3
  • 建立时间: 2011-05-31
  • 更新时间: 2012-04-13

RSS订阅

Open Toolbar