from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice,MonkeyImage
device= MonkeyRunner.waitForConnection() #连接设备
device.startActivity('com.android.calendar/.AllInOneActivity') #启动app
MonkeyRunner.sleep(1)
device.press('KEYCODE_MENU',MonkeyDevice.DOWN_AND_UP) #点击菜单键
MonkeyRunner.sleep(1)
device.touch(80,264,MonkeyDevice.DOWN_AND_UP) #定位选择
MonkeyRunner.sleep(2)
device.touch(65,166,MonkeyDevice.DOWN_AND_UP) #定位光标
MonkeyRunner.sleep(2)
device.press('KEYCODE_BACK',MonkeyDevice.DOWN_AND_UP) #按Back键,这里是去掉键盘显示
MonkeyRunner.sleep(1)
device.drag((170,390),(170,191),1,10) #拖动屏幕
MonkeyRunner.sleep(1)
device.touch(78,342,MonkeyDevice.DOWN_AND_UP) #定位光标
MonkeyRunner.sleep(2)
import random #引入随机的方法
import string #定义
str1="1234567890abcdefghijklmnopqrstuvwxyz" #定义一个要随机输入的字符串,随机的内容就从这里选择
strList=[] #定义一个数组
for i in range(100):
strList.append(random.choice(str1)) #随机获取字符放到一个列表,append表示放在字符后面
str2="".join(strList) #转换成字符串
print (str2) #输出资格字符串
for j in range(200):
device.type(str2)
MonkeyRunner.sleep(1)
print (j) #循环输入随机的字符串,并且打印出循环次数