zoukankan      html  css  js  c++  java
  • MonkeyRunner使用小结

    最近在用MonkeyRunner做自动化测试。现把个人心得记录下来。

    MonkeyRunner在mysdk/tools/目录下,为了方便,可以加到坏境变量PATH里.这里不再赘述。

    关键命令使用方法如下:

    #MonkeyRunner  
    # Imports the monkeyrunner modules used by this program  
    from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage  
    # Connects to the current device, returning a MonkeyDevice object  
    device = MonkeyRunner.waitForConnection()  
      
    # Installs the Android package. Notice that this method returns a boolean, so you can test  
    # to see if the installation worked.  
    device.installPackage('myproject/bin/MyApplication.apk')  
      
    # sets a variable with the package's internal name  
    package = 'com.example.android.myapplication'  
      
    # sets a variable with the name of an Activity in the package  
    activity = 'com.example.android.myapplication.MainActivity'  
      
    # sets the name of the component to start  
    runComponent = package + '/' + activity  
      
    # Runs the component  
    device.startActivity(component=runComponent)  
      
    # Presses the Menu button  
    device.press('KEYCODE_MENU', MonkeyDevice.DOWN_AND_UP)  
      
    # Takes a screenshot  
    result = device.takeSnapshot()  
      
    # Writes the screenshot to a file  
    result.writeToFile('myproject/shot1.png','png')  
      
    # 输入a s d  
    device.type('asd')  
      
    #如果不记得那么多的命令,可以使用recorder把可视化界面记录下来。  
    #Monkey Recorder  
    from com.android.monkeyrunner.recorder import MonkeyRecorder as recorder  
    recorder.start(device)  

    adb shell常用命令:
    按下OK键	device.press('KEYCODE_DPAD_CENTER','DOWN_AND_UP')
    长按某个按键:  device.drag((236,440),(236,440),2,10)
    相应的按键对应的名称如下:
    home键:KEYCODE_HOME
    back键:KEYCODE_BACK
    send键:KEYCODE_CALL
    End键:	KEYCODE_ENDCALL
    上导航键:KEYCODE_DPAD_UP
    下导航键:KEYCODE_DPAD_DOWN
    左导航	:KEYCODE_DPAD_LEFT
    右导航键:KEYCODE_DPAD_RIGHT
    OK键	:KEYCODE_DPAD_CENTER
    上音量键:KEYCODE_VOLUME_UP
    下音量键:KEYCODE_VOLUME_DOWN
    power键	:KEYCODE_POWER
    camera键:KEYCODE_CAMERA
    meun键	:KEYCODE_MENU

    参考文献:

    http://developer.android.com/tools/help/monkeyrunner_concepts.html

  • 相关阅读:
    记一次 contentInsetAdjustmentBehavior 引发的bug
    Android埋点技术概览
    Android开发快速入门iOS开发概览
    工作项目遇到的一些问题
    ruby操作项目.xcodeproj
    关于performSelector afterDelay:0 的使用
    谷歌Python代码风格指南 中文翻译
    最大子矩阵问题--悬线法dp
    tarjan
    SDU CSPT3模拟
  • 原文地址:https://www.cnblogs.com/chengliu/p/3636405.html
Copyright © 2011-2022 走看看