基于坐标monkey runner自动化

#coding=utf-8
#!/usr/bin/env monkeyrunner  
# Copyright 2010, The Android Open Source Project  
#  
# Licensed under the Apache License, Version 2.0 (the "License");  
# you may not use this file except in compliance with the License.  
# You may obtain a copy of the License at  
#  
#     http://www.apache.org/licenses/LICENSE-2.0  
#  
# Unless required by applicable law or agreed to in writing, software  
# distributed under the License is distributed on an "AS IS" BASIS,  
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
# See the License for the specific language governing permissions and  
# limitations under the License.  
  
import sys     
from com.android.monkeyrunner import MonkeyRunner as MR
from com.android.monkeyrunner import MonkeyDevice as MD
from com.android.monkeyrunner import MonkeyImage as MI
from com.android.monkeyrunner.easy import EasyMonkeyDevice,By
device=MR.waitForConnection(10)
if device:
    print("Connect device successful!")
else:
    print("Connect device failed!")




a=0
b=0
for j in range(1,100):
    Package = 'baoming'
    Activity ='Activity'
    runComponent = Package + '/' + Activity
    device.startActivity(component=runComponent)
    MR.sleep(5.0)
    # i=j%10
    # for x in xrange(0,i):
    #     device.drag((951,595),(951,0,),1.0,1)
    #     MR.sleep(2.0)
    #     print 'dragtime:'+str(x)
    # else:
    #     print 'enddrag'
    # MR.sleep(3.0)
    image = device.takeSnapshot()
    image.writeToFile('/Users/Downloads/LIST.png','png') 
    device.touch(121,1843,'DOWN_AND_UP')
    MR.sleep(2.0)
    image = device.takeSnapshot()
    image.writeToFile('/Users/Downloads/detail.png','png')
    result = MR.loadImageFromFile('/Users/Downloads/LIST.png')
    MR.sleep(2.0)
    if image.sameAs(result,0.9):
        pass
    else:
        device.touch(548,1813,'DOWN_AND_UP')
        MR.sleep(15.0)
        image = device.takeSnapshot()
        image.writeToFile('/Users/Downloads/play.png','png')
        result = MR.loadImageFromFile('/Users/Downloads/detail.png')
        MR.sleep(2.0)
        if image.sameAs(result,0.9):
            a=a+1
            anum='第'+str(a)+'次连接失败'
            image.writeToFile(anum+'.png','png')
            print  anum
            MR.sleep(2.0) 
        else:
            MR.sleep(2.0) 
            b=b+1
            bnum ='第'+str(b)+'次连接成功'
            print  bnum
            MR.sleep(2.0)           
    device.press('KEYCODE_BACK')
    device.press('KEYCODE_BACK')
    MR.sleep(2.0)
    device.press('KEYCODE_BACK')
    device.press('KEYCODE_BACK')
    MR.sleep(5.0)
    print '第'+str(j)+'次连接'
else:
    print ' end' ;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值