MonkeyRunner_MonkeryRunner圖片對比代碼

來源:互聯網
上載者:User

轉載自: http://www.51testing.com/?uid-225927-action-viewspace-itemid-249291

************** picCompare.py
from __future__ import division
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage
log=open("F:\\demo\\demo.txt","w")
#this function used for pic compare
#the variables is base-pic,compare-pic,pic-width,pic-high,pic similarity
def picCompare(imageA,imageB,width,high,factor):
    i=0
    Rc=Gc=Bc=0
    Total=255*width*high/4
    while i<width:
        j=0
        while j<high:
            cc=imageA.getRawPixel(i,j)
            dd=imageB.getRawPixel(i,j)
            Rc=Rc+abs(cc[1]-dd[1])
            Gc=Gc+abs(cc[2]-dd[2])
            Bc=Bc+abs(cc[3]-dd[3])
            j=j+2
        i=i+2
    Rsub=Rc/Total
    Gsub=Gc/Total
    Bsub=Bc/Total
    picSame=1-(Rsub+Gsub+Bsub)/3
    if picSame>factor:
        return 1
    else:
        return 0
**********測試指令碼
import sys
sys.path.append("E:\\android-sdk-windows\\tools")
import picCompare as COM
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage
log=open("F:\\demo\\demo.txt","w")
imageA=MonkeyRunner.loadImageFromFile("F:\\demo\\sougou.png")
#judge connection
device = MonkeyRunner.waitForConnection()
#
imageB=device.takeSnapshot()
imageB=imageB.getSubImage((20,320,60,60))
if COM.picCompare(imageA,imageB,60,60,0.8):
    log.write("OK,the will do action Click\n")
    device.touch(20,320,"DOWN_AND_UP")
else:
    imageB.writeToFile("F:\\demo\\errorSogou.png","png")
    log.write("couldn't find sogou item,please check")
log.close()  ******************************使用說明,andorid手機自動化 測試過程中,如果UE能提前確定,則使用MonkeyRunner Recorder捕獲全部的測試控制項,然後通過映像對比,執行對應的Activity。這個是基於SeeTest基礎上個人改編的,歡迎討論~~

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.