zoukankan      html  css  js  c++  java
  • MonkeyRunner及MonkeyRunner模块简介

    ●MonkeyRunner简介

    MonkeyRunner:Android SDK中自带的一个黑盒测试工具,在PC端通过Android API控制设备的运行或者自动化测试的执行。支持Python脚本,可以实现Monkey无法实现的一些逻辑控制。

    注意: 前一章面讲的Monkey是运行在abd shell中的、运行在设备上,MonkeyRunner是在PC端运行,通过PC端提供的API来执行自动化测试的。

    ●MonkeyRunner API 3大模块组成

    ·MonkeyRunner //通用的一些方法的模块

    ·MonkeyDevice //控制设备和模拟器的模块

    ·MonkeyImage  //与屏幕图像相关的模块

    官方文档:https://developer.android.com/studio/test/monkeyrunner/index.html

    官网上说:MonkeyRunner是一个和Monkey没有关系的工具,虽然名称相似,是两个完全不同的工具。MonkeyRunner提供了一些在Android测试中独有的特性,包括多设备的控制、支持功能测试、支持回归测试、在脚本中支持对结果截屏、可扩展API。

    ●MonkeyRunner模块的方法

    ●MonkeyRunner各个模块中主要API的使用方法

    首先在adt-bundle...sdk ools双击monkeyrunner.bat或者cmd里敲monkeyrunner.bat

    •第一步:导入模块这一步必须做,才能下面的操作monkeyrunner

    from com.android.monkeyrunner import +模块名 //导入模块的方法

    from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice,MonkeyImage

    ●帮助文档的方法  

    ①MonkeyRunner.help("text") //text格式

    报错原因是因为monkeyrunner在集成到sdk中并没有把相应的资源放到sdk版本中来,如果要执行help命令的话,需要把百度云的resources文件包拷贝到sdk/tools/lib中

    再次执行一下MonkeyRunner.help("text")

    ②MonkeyRunner.help("html") //html格式可以把生成的help信息写到文件中方便阅读

    content=MonkeyRunner.help("html") //help信息放到content里面

    f=open("help.html","w") //定义文件,把content变量保存的内容写到文件中

    f.write(content)//写入content变量

    f.close()

    adt-bundlesdk ools会生成help.html文件

    打开此文件会看到生成monkeyrunner的help文件并且有相应的方法,并且有每个方法的具体说明:返回值、对应的参数、参数的含义。

    ●MonkeyRunner.alert('对话框信息','对话框标题','对话框确定按钮文字')

    MonkeyRunner.alert('MonkeyRunner alert','imooc','OK')

    ●MonkeyRunner.choice('显示的信息','选择的清单','标题')

    MonkeyRunner.choice(' MonkeyRunner choice ',['test1','test2'],'imooc')

    选择test1点击确定,返回值为0,说明这个选择清单的返回值是根据选择项的选择的数组中的index值是choice返回的,返回值从0开始的。

    ●MonkeyRunner.input('信息','初始化值','标题','ok按钮','cancel按钮')

    MonkeyRunner.input('MonkeyRunner input','init str','imooc','OK','Cancel')

    在输入框输入test again,命令行返回test again

    ●MonkeyRunner.sleep(秒) //脚本中断执行的命令

    MonkeyRunner.sleep(4)

    4秒钟应用暂停才会结束

    ●MonkeyRunner.waitForConnection(超时时间,deviceid)//建立和设备连接

    如果不指定,默认连接当前已经连接的设备

    首先打开avd

    MonkeyRunner.waitForConnection()

    返回monkeyrunner一个device对象,表示monkeyrunner和设备已建立了通信

  • 相关阅读:
    scrapy 多个爬虫运行
    scrapy不抓取重复的网页解决办法
    centos7 安装mysql
    20个免费和开源数据可视化工具
    转载 CSDN 谈谈我对证券公司一些部门的理解(前、中、后台)
    scrapy 教程
    django 常见错误汇总
    python 常见错误
    python 基础知识整理
    使用SQL语法来查询Elasticsearch:Elasticsearch-SQL插件
  • 原文地址:https://www.cnblogs.com/ljf-hero/p/6625345.html
Copyright © 2011-2022 走看看