MonkeyRunner创建一个Note的实例

发表于:2015-11-11 11:19

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:天地会珠海分舵    来源:51Testing软件测试网采编

  之前的系列给出了Appium,Robotium,Instrumentation和UIAutomator创建一个Note实例的例子:
  《Appium创建一个Note的实例》
  《Robotium创建一个Note的实例》
  《UIAutomator创建一个Note的实例》
  《SDK Instrumentation创建一个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)
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号