MonkeyRunner创建一个Note的实例

之前的系列给出了Appium,Robotium,Instrumentation和UIAutomator创建一个Note实例的例子:

那么用MonkeyRunner又是如何实现这些功能的呢?今天花了点时间学习了下MonkeyRunner的基本API然后尝试实现了该功能,给我作为一个初学者的感触如下:

  • MonkeyRunner可以通过坐标点击对象,在引入EasyMonkeyDevice后可以根据ID进行点击
  • Eclipse上Jython代码很多对象没有成员函数提示(jar包以导入),如MonkeyRunner.waitForConnection获得device对象后,后面devie.不能自动提示可用成员函数
  • 感觉脚本跑得很慢
  • 没有任何junit的继承,应该可以通过Junit4框架来使用MonkeyRunner,下次有时间再尝试下
  • 也许是不熟悉,感觉跟Robotium,UIAutomator等的编写效率差一些

from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice
from com.android.monkeyrunner.easy import EasyMonkeyDevice,By

#Connect to the target device
device = MonkeyRunner.waitForConnection("10000", "emulator-5554")
easy_device = EasyMonkeyDevice(device)  #touch a button by id would need this
device.startActivity(component="com.example.android.notepad/com.example.android.notepad.NotesList")
#time.sleep(2000)

#invoke the menu options
MonkeyRunner.sleep(3)
device.press('KEYCODE_MENU', MonkeyDevice.DOWN_AND_UP);

#Touch on the "Add note" menu entry by coordinate
MonkeyRunner.sleep(3)
device.touch(118,253,MonkeyDevice.DOWN_AND_UP)

#Type in the text for the note
MonkeyRunner.sleep(3)
device.type('Note1')
#easy_device.type(By.id('id/note'),'Note2')

#invoke the menu options
MonkeyRunner.sleep(3)
device.press('KEYCODE_MENU', MonkeyDevice.DOWN_AND_UP);

#Touch on the "save" menu entry by coordinate
MonkeyRunner.sleep(3)
device.touch(59,257,MonkeyDevice.DOWN_AND_UP)

#Simulate long press on the new added note by id with EasyMonkeyDevice
MonkeyRunner.sleep(3)
easy_device.touch(By.id('id/text1'),MonkeyDevice.DOWN) #Touch down for 10 seconds
MonkeyRunner.sleep(10)
easy_device.touch(By.id('id/text1'),MonkeyDevice.UP) #Then release the touch

#Touch on the "delete" menu entry of the context menu options to delete the note
MonkeyRunner.sleep(6)
device.touch(84,172,MonkeyDevice.DOWN_AND_UP)
时间: 2024-07-31 13:50:02

MonkeyRunner创建一个Note的实例的相关文章

SDK Instrumentation创建一个Note的实例

除了高层框架如Robotium的solo,我们也可以直接调用SDK底层的提供的Instrumentation的API来实现如前几篇文章描述的创建一个note的功能.总所周知之Robotium就是基于Instrumentation的框架高层抽象实现的一个项目,所以对比<Robotium创建一个Note的实例>,我们可以看到robotium的实现比起直接调用Instrumetnation简介了很多.这就好比你用文本编辑器直接编写调用WIN32 API和通过Visual Studio调用高层封装的M

Java创建一个类的实例的方法

创建一个类的实例的方法有以下四种 一.通过new 来实现,也是最常用的 二.通过反射机制来实现 Class c = Class.forName("路径"): (1)java.lang.newInstance User use = (User)c.java.newInstance(); (2)java.lang.reflect.Constructor类的newInstance方法 Constructor con = c.getConstructor(String.class); User

AWS探索及创建一个aws EC2实例

一.AWS登陆 1.百度搜索aws 2.输入账户及密码登陆(注册流程按照提示走即可) 二.创建EC2实例(相当于阿里云的ecs) 1.找到EC2 2.创建实例 3.选择系统类型(个人习惯用CentOS,根据情况选择吧) 系统版本 4.选择配置(新用户有免费一年的实例类型) 5.配置实例 6.可以选择添加数据盘 7.添加服务器标签 8.配置安全组信息 9.确认信息 10.查看实例 至此.一个aws的EC2实例就购买完成了!! 原文地址:https://www.cnblogs.com/hei-ma/

Swift创建一个单例实例

假设一个ZLAnimal类. 我需要创建ta的时候保持单例 在oc中的做法 static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ _instance = [[ZLAnimal alloc] init]; }); 在swift中的做法其实也类似,这里新建一个类,ZLAnimal类,提供快捷方法 class ZLAnimal: NSObject { class var sharedManager: ZLAnimal { stru

Java中通过类名创建一个类的实例

Java中通过类名创建类的实例,此类必须是默认的构造方法,不能自己写构造方法. 方法1: UserDao userDao=null; Properties prop=new Properties();    InputStream inStream=DaoFactory.class.getClassLoader().getResourceAsStream("daoconfig.properties");    prop.load(inStream);    String userDao

Spring Boot 使用IntelliJ IDEA创建一个web开发实例(一)

.新建项目File-->New-->Project-->Spring Initializr 点击Finish,一个Spring Boot web应用就创建好了. 原文地址:https://www.cnblogs.com/zsg88/p/9161685.html

Spring Boot 使用IntelliJ IDEA创建一个web开发实例(三)

属性配置 1.配置application.properties文件 配置web访问端口和context path server.port = 8081 server.servlet.context-path = /demo 运行 2. 用application.yml进行配置 server: port : 8082 servlet: context-path: /demo2 启动,访问 注意,application.properties 比application.yml的优先级高 原文地址:ht

创建一个实例&amp;创建一个线程。。

1 using System; 2 using System.Threading; 3 4 5 namespace WorkerThread02 6 { 7 class ThreadTest 8 { 9 bool done; 10 static void Main() 11 { 12 ThreadTest tt=new ThreadTest();//创建一个类的实例 13 Thread t=new Thread(WriteY);//创建一个线程. 14 .............. 15 ...

Recreating an Activity 重新创建一个活动

There are a few scenarios in which your activity is destroyed due to normal app behavior, such as when the user presses theBack button or your activity signals its own destruction by calling finish(). The system may also destroy your activity if it's