首页 > 移动平台 > 详细

Android自动化测试 - MonkeyRunner(三) 随手练习测试脚本

时间:2015-04-03 18:50:37      阅读:1137      评论:0      收藏:0      [点我收藏+]
#coding=utf-8
import os
import time

#import MonkeyRunner three module
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage
runComponent = "com.dest.mr/.ui.home.HomeLauncherNew"

path = d:/pic/
logpath = d:/log/

#new log file.txt
log = open(logpath + dest  + ".txt",w)

#connection device
device = MonkeyRunner.waitForConnection()

if not device:
    log.write(connection failed  \n )
    sys.exit(1)
else:
    log.write(connection passed  \n)

device.startActivity(component = runComponent)
time.sleep(5)

#device.shell("logcat | grep ‘com.dest.mr‘ > sdcard/destlog.txt")
#os.system(‘‘‘adb logcat | findstr "com.dest.mr" >> d:/log/logcat.txt‘‘‘)

for i in range(3):
        #save log to file.txt 
        log.write(start app.... + str(i) + \n)
        desthome = device.takeSnapshot()
        desthome.writeToFile(path + desthome + str(i) + .png,png)
        #import home pictures for comparing the results
        homeTure = MonkeyRunner.loadImageFromFile(d:/pic/Tdesthome.png)
        
        if(desthome.sameAs(homeTure,0.9)):
                print desthome pic is the same \n
                log.write (test passed \n)
        else:
                print test byebye \n
                log.write (test failed \n)
        
        #open userinfo
        device.touch(850,68,DOWN_AND_UP)
        time.sleep(2)
        userinfo = device.takeSnapshot()
        userinfo.writeToFile(path + userinfo + str(i) + .png,png)
        
        ufoTure = MonkeyRunner.loadImageFromFile(d:/pic/Tuserinfo.png)
        
        if(userinfo.sameAs(ufoTure,0.75)):
                print userinfo pic is the same \n
                log.write (userinfo test passed \n)
        else:
                print userinfo pic is not the same
                log.write (userinfo test failed \n)

        #click mobile, into myinfo page
        device.touch(550,200,DOWN_AND_UP)
        time.sleep(2)
        myinfo = device.takeSnapshot()
        myinfo.writeToFile(path + myinfo + str(i) + .png,png)
        device.drag((500,550),(300,250),0.5)
        time.sleep(2)
        
        
        device.press(KEYCODE_BACK,DOWN_AND_UP)
        time.sleep(2)
        device.touch(60,80,DOWN_AND_UP)
        time.sleep(2)

 

Android自动化测试 - MonkeyRunner(三) 随手练习测试脚本

原文:http://www.cnblogs.com/dtest/p/4390689.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!