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

#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)

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值