码迷,mamicode.com
首页 > 其他好文 > 详细

【monkeyrunner】monkeyrunner 实例

时间:2016-02-22 16:45:55      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:

import time
import os
import re
from com.android.monkeyrunner import MonkeyRunner as mr
from com.android.monkeyrunner import MonkeyDevice as md
from com.android.monkeyrunner import MonkeyImage as mi


regrex=r"(.*)\.apk"
dir="E:\howdoTest\marketLogoTest\packages"
activity="com.howdo.commonschool/com.howdo.commonschool.activities.WelcomeActivity"
device=mr.waitForConnection()
if  os.path.exists(dir) and  os.path.isdir(dir) :
    for packageFile in os.listdir(dir):
        if re.match(regrex, packageFile):
            packageFilePath = os.path.join(dir,packageFile)
            device.installPackage(packageFilePath)
            time.sleep(2)
            print "APK finish setup...."
            time.sleep(1)
            print "Start testing...."
            device.startActivity(component=activity)
            mr.sleep(1)
            snapshotLogo=device.takeSnapshot()
            #snapshotLogoName="e:\\"+packageFile+"snapshotLogo.png"
            snapshotLogo.writeToFile(‘E:\howdoTest\marketLogoTest\snapshots\\‘+packageFile+‘snapshotLogo.png‘,‘png‘)
            mr.sleep(10)
            device.touch(195,1174,"DOWN_AND_UP")
            mr.sleep(1)
            device.type("*****")
            mr.sleep(1)
            device.touch(134,395,"DOWN_AND_UP")
            mr.sleep(1)
            device.type("*****")
            mr.sleep(1)
            device.touch(348,600,"DOWN_AND_UP")
            mr.sleep(5)
            device.touch(51,107,"DOWN_AND_UP")
            mr.sleep(2)
            device.touch(158,805,"DOWN_AND_UP")
            mr.sleep(2)
            device.touch(195,335,"DOWN_AND_UP")
            time.sleep(1)
            snapshotIsnew=device.takeSnapshot()
            snapshotIsnew.writeToFile(‘E:\howdoTest\marketLogoTest\snapshots\\‘+packageFile+‘snapshotIsnew.png‘,‘png‘)
            mr.sleep(1)
            device.touch(184,555,"DOWN_AND_UP")
            mr.sleep(1)
            snapshotVersion=device.takeSnapshot()
            snapshotVersion.writeToFile(‘E:\howdoTest\marketLogoTest\snapshots\\‘+packageFile+‘snapshotVersion.png‘,‘png‘)
            time.sleep(1)
            print "Finish testing..."
            device.removePackage("com.howdo.commonschool")
            time.sleep(2)
            print packageFile+" finish unsetup...."

else:
    print ‘path %s is not existed or is not a directory‘ %dir

  

【monkeyrunner】monkeyrunner 实例

标签:

原文地址:http://www.cnblogs.com/paulwinflo/p/5207252.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!