monkeyrunner实例太少了,自己研究了下,写了个简单的例子,或许对大家有所帮助,该代码在模拟器上没有问题,但是在真机上,有的代码命令不能通过

首先:导入Notepad源码,然后运行该程序

然后:使用monkeyrunner工具进行测试:

#使用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_AND_UP"')
MonkeyRunner.sleep(2)

d.touch(160,430)

d.press("KEYCODE_HOME",'DOWN_AND_UP')

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()

更多相关文章

  1. android中apk反编译
  2. Android——Notification 通知类 (适配 Android(安卓)9.0)
  3. [Android] 单独编译生成boot.img时mkbootfs: No such file or di
  4. OpenGL.Shader:1-重新认识Android上OpenGL(纯Cpp)
  5. 类加载器
  6. Android(Java):对应用进行单元测试
  7. Android之MVP 模式:简单易懂的介绍方式
  8. Android(安卓)使用Glide加载图片
  9. android Aspectj实践问题

随机推荐

  1. Simulate android behaviors on win32
  2. android,No Launcher activity found!
  3. Android事件分发机制
  4. Android(安卓)结束进程的方法
  5. android中的震动
  6. Android(安卓)Studio 之 View组件常用属
  7. Error running app: Instant Run require
  8. Android全屏Activity的几种方式
  9. 【Android】Activity知识点
  10. android中的震动