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)
  • 相关阅读:
    New-SAN-FENG-YUN-三
    San丰-Cloud
    SpringBoot+MySQL+MyBatis+Shiro+AdminLTE
    SanFeng-Clound
    SanFengClound
    传奇音乐设置
    热血传奇GOM引擎问题集锦
    app测试
    接口测试
    题目
  • 原文地址:https://www.cnblogs.com/dtest/p/4390689.html
Copyright © 2011-2022 走看看