引入頭文件
fromcom.android.monkeyrunnerimportMonkeyRunner, MonkeyDevice, MonkeyImage, MonkeyView
連接設備
device_name ='192.168.58.101:5555'
device = MonkeyRunner.waitForConnection(0.5, device_name)
常用的幾個事件
1 press
device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
2 touch
device.touch((858+1082) /2, (1336+1504) /2,"DOWN_AND_UP")
3 sleep
MonkeyRunner.sleep(0.5)
4 啟動Activity
device.startActivity('com.genertech.atlb/com.gener_tech.tlb.LoginActivity')
5 截屏保存
image = device.takeSnapshot()
image.writeToFile(path+imageName+"."+type, type)
下一節(jié)結合android做一個簡單的登陸的自動化測試