1 # -*- coding: UTF-8 -*- 2 #手机分辨率为1080*1920 3 import sys 4 from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice,MonkeyImage 5 6 def install(d): 7 MonkeyRunner.sleep(3) 8 d.removePackage('com.xxx.phone') 9 print "uninstall success!!" 10 MonkeyRunner.sleep(2) 11 d.installPackage('d:mkxxxphone.apk') 12 print "install success!!" 13 MonkeyRunner.sleep(2) 14 15 d.wake() 16 d.touch(800,1900,'DOWN_AND_UP') 17 MonkeyRunner.sleep(2) 18 d.startActivity(component="com.xxx.phone/com.xxx.phone.activity.WelcomeActivity") 19 MonkeyRunner.sleep(5) 20 d.wake() 21 d.drag((800,600),(400,600),0.1,10) 22 d.wake() 23 MonkeyRunner.sleep(2) 24 d.drag((800,600),(300,600),0.1,10) 25 MonkeyRunner.sleep(2) 26 d.touch(530,1600,'DOWN_AND_UP') 27 MonkeyRunner.sleep(3) 28 d.touch(533,1007,'DOWN_AND_UP') 29 MonkeyRunner.sleep(2) 30 d.touch(533,1800,'DOWN_AND_UP') 31 32 def main(): 33 print "Start" 34 device=MonkeyRunner.waitForConnection() 35 if not device: 36 print "Couldn't connect the device" 37 sys.exit() 38 print "Conneted device" 39 install(device) 40 41 42 if __name__ == '__main__': 43 main()
1.因为在Notepad默认编码为Ascll,所以在首行加入编码注释(必须放在第一行或者第二行),# -*- coding:utf-8 -*-
2.因为是按坐标执行,代码只支持对应的分辨率,手机分辨率可在设置中查看或者画图软件中查看最大坐标值,#手机分辨率为1080*1920
3. 每个用例可以封装为一个函数 def