使用 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
?