zoukankan      html  css  js  c++  java
  • Android自动化测试

    #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  
    ' )
        sys.exit(1)
    else:
        log.write('connection passed  
    ')
    
    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) + '
    ')
            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 
    '
                    log.write ('test passed 
    ')
            else:
                    print 'test byebye 
    '
                    log.write ('test failed 
    ')
            
            #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 
    '
                    log.write ('userinfo test passed 
    ')
            else:
                    print 'userinfo pic is not the same'
                    log.write ('userinfo test failed 
    ')
    
            #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)
  • 相关阅读:
    HasnMap的一种遍历方式:Map.Entry 和 Map.entrySet()
    Java中常见的几个乱码问题以及解决方法
    浅谈JavaScript--this指向
    数据挖掘深入理解和学习路径
    数据分析学习路线
    C#索引器
    浅谈浅拷贝与深拷贝
    词频统计(统计两个连在一起的词出现的频数)
    第一周 词频统计
    莫比乌斯反演总结
  • 原文地址:https://www.cnblogs.com/dtest/p/4390689.html
Copyright © 2011-2022 走看看