• monkeyrunner脚本实例(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()

    转载于:http://www.51testing.com/?uid-402328-action-viewspace-itemid-249091

  • 相关阅读:
    OCP-1Z0-053-V12.02-614题
    OCP-1Z0-053-V12.02-615题
    OCP-1Z0-053-V12.02-218题
    OCP-1Z0-053-V12.02-377题
    文件内存映射CreateFileMapping和GlobalAlloc内存分配
    为什么C++不提供override这个关键字呀
    OCP-1Z0-052-V8.02-74题
    OCP-1Z0-053-V12.02-558题
    OCP-1Z0-053-V12.02-559题
    OCP-1Z0-053-V12.02-33题
  • 原文地址:https://www.cnblogs.com/ccxniit2004/p/2325822.html
Copyright © 2020-2023  润新知