zoukankan      html  css  js  c++  java
  • 安卓自动化测试案例(跑在MonkeyRunner上)

    首先文件所在目录:

    MonkeyRunner所在目录:

    运行命令(通过cd 命令  进入Tools目录下):

    运行脚本:monkeyrunner.bat ..honeywelljsq.py

    源文件代码为:

    # coding=utf-8
    
    import sys
    from com.android.monkeyrunner import MonkeyRunner as mr,MonkeyDevice
    from com.android.monkeyrunner.easy import EasyMonkeyDevice,By
    from com.android.chimpchat.hierarchyviewer import HierarchyViewer
    
    #连接设备
    device = mr.waitForConnection(30,"emulator-5554")
    if not device:
         print >> sys.stderr,"fail"
         sys.exit(1)
    #连接设备完成
    mr.sleep(2.0)
    #打开主屏幕-根据ResourceId
    #
    
    #
    upArrow="id/all_apps_handle"
    easy_device = EasyMonkeyDevice(device)
    easy_device.touch(By.id(upArrow), MonkeyDevice.DOWN_AND_UP)
    mr.sleep(2.0)
    #启动Activity 打开拨号键
    activityName="com.android.dialer/.DialtactsActivity"
    device.startActivity(component = activityName)
    #等待时间,防止操作太快,设备反应不及时
    mr.sleep(2.0)
    
    #点击添加拨号动作
    action_button="id/floating_action_button"
    
    easy_device.touch(By.id(action_button), MonkeyDevice.DOWN_AND_UP)
    mr.sleep(2.0)
    #开始拨号
    button_1="id/one"
    button_2="id/two"
    button_3="id/three"
    button_4="id/four"
    button_5="id/five"
    button_6="id/six"
    button_7="id/seven"
    button_8="id/eight"
    button_9="id/nine"
    button_0="id/zero"
    easy_device.touch(By.id(button_1), MonkeyDevice.DOWN_AND_UP)
    
    easy_device.touch(By.id(button_8), MonkeyDevice.DOWN_AND_UP)
    
    easy_device.touch(By.id(button_9), MonkeyDevice.DOWN_AND_UP)
    
    easy_device.touch(By.id(button_1), MonkeyDevice.DOWN_AND_UP)
    
    easy_device.touch(By.id(button_1), MonkeyDevice.DOWN_AND_UP)
    
    easy_device.touch(By.id(button_6), MonkeyDevice.DOWN_AND_UP)
    
    easy_device.touch(By.id(button_9), MonkeyDevice.DOWN_AND_UP)
    
    easy_device.touch(By.id(button_5), MonkeyDevice.DOWN_AND_UP)
    
    easy_device.touch(By.id(button_0), MonkeyDevice.DOWN_AND_UP)
    
    easy_device.touch(By.id(button_8), MonkeyDevice.DOWN_AND_UP)
    
    easy_device.touch(By.id(button_7), MonkeyDevice.DOWN_AND_UP)
    mr.sleep(2.0)
    #添加联系人
    createNewId="id/cliv_name_textview"
    easy_device.touch(By.id(createNewId), MonkeyDevice.DOWN_AND_UP)
    mr.sleep(2.0)
    #姓名输入  获取焦点
    device.touch(300,1060,'DOWN_AND_UP')
    mr.sleep(1.0)
    #输入
    device.type('JackChen')
    mr.sleep(2.0)
    #关闭键盘
    device.press('KEYCODE_BACK',MonkeyDevice.DOWN_AND_UP)
    #保存联系人
    mr.sleep(2.0)
    menu_save="id/menu_save"
    easy_device.touch(By.id(menu_save), MonkeyDevice.DOWN_AND_UP)
    mr.sleep(2.0)
    device.press('KEYCODE_HOME',MonkeyDevice.DOWN_AND_UP)
    mr.sleep(2.0)
    componentName='com.google.android.apps.messaging/.ui.ConversationListActivity'
    #启动特定的Activity
    device.startActivity(component = componentName)
    mr.sleep(2.0)
    #新建信息
    messageAdd="id/start_new_conversation_button"
    easy_device.touch(By.id(messageAdd), MonkeyDevice.DOWN_AND_UP)
    mr.sleep(2.0)
    numText="id/recipient_text_view"
    easy_device.touch(By.id(numText), MonkeyDevice.DOWN_AND_UP)
    mr.sleep(1.0)
    
    device.type('18911695087')
    mr.sleep(3.0)
    #点击10086
    device.touch(301,300,'DOWN_AND_UP')
    mr.sleep(2.0)
    device.press('KEYCODE_BACK',MonkeyDevice.DOWN_AND_UP)
    mr.sleep(1.0)
    messageTxt="id/compose_message_text"
    easy_device.touch(By.id(messageTxt), MonkeyDevice.DOWN_AND_UP)
    mr.sleep(1.0)
    device.type('Hello,jack')
    
    #等待时间,防止操作太快,设备反应不及时
    mr.sleep(1.0)
    btn_send="id/self_send_icon"
    easy_device.touch(By.id(btn_send), MonkeyDevice.DOWN_AND_UP)
    
    mr.sleep(3.0)
    conversationImg = device.takeSnapshot()
    conversationImg.writeToFile('d:\SendMessage.png','png');

    @陈卧龙的博客

  • 相关阅读:
    Junit单元测试
    win7的6个网络命令
    WOJ1024 (POJ1985+POJ2631) Exploration 树/BFS
    WOJ1022 Competition of Programming 贪心 WOJ1023 Division dp
    woj1019 Curriculum Schedule 输入输出 woj1020 Adjacent Difference 排序
    woj1018(HDU4384)KING KONG 循环群
    woj1016 cherry blossom woj1017 Billiard ball 几何
    woj1013 Barcelet 字符串 woj1014 Doraemon's Flashlight 几何
    woj1012 Thingk and Count DP好题
    woj1010 alternate sum 数学 woj1011 Finding Teamates 数学
  • 原文地址:https://www.cnblogs.com/chenwolong/p/6588888.html
Copyright © 2011-2022 走看看