使用 MonkeyRunner 进行自动化测试(3)
,time.localtime(time.time())) #获取日期 def getToday () : return time.strftime( %Y_%m_%d ,time.localtime(time.time())) #截图并保存 def shotPhoto () : newimage = device.takeSnapshot() newimage
,time.localtime(time.time()))
def getToday():
return time.strftime(
"%Y_%m_%d",time.localtime(time.time()))
def shotPhoto():
newimage = device.takeSnapshot()
newimage.writeToFile (
"ImageFile/" + getToday() + getNowTimeUnderline() +
".png" ,
"png")
time.sleep(
1.0)
def mkdirPath(path):
if not os.path.exists(path):
os.mkdir(path)
mkdirPath(
"ImageFile")
device.startActivity(component = mRunComponent)
time.sleep(
3.0)
for slipCount
in range(
1,
3):
device.drag( (
385,
1032), (
385,
700),
1.0,
10 )
time.sleep(
2.0)
shotPhoto()
device.touch(
399,
73,
"DOWN_AND_UP")
time.sleep(
1.0)
shotPhoto()
device.type(
'https://shlurenjia.github.io')
time.sleep(
1.0)
device.press(
'KEYCODE_ENTER', MonkeyDevice.DOWN_AND_UP)
time.sleep(
5.0)
shotPhoto()
device.touch(
325,
357,
"DOWN_AND_UP")
time.sleep(
1.0)
shotPhoto()
device.press(
'KEYCODE_BACK',
'DOWN_AND_UP')
time.sleep(
2.0)
shotPhoto()
device.press(
'KEYCODE_BACK',
'DOWN_AND_UP')
time.sleep(
2.0)
shotPhoto()
截图可以让你挂完脚本之后自己比对效果。每个动作后面加上 sleep 因为要考虑到手机响应的时间。不然脚本执行下去很容易报错 Error sending xxx event
效果
由于加了sleep,所以看起来比较慢
自动化测试.gif
?