如何通过MonkeyRunner单击android程序的视图?

Yin*_* Xu 9 android monkeyrunner

我想使用MonkeyRunner来测试我的android程序与具有不同屏幕分辨率的设备列表的兼容性.我需要单击一个视图,但视图对于不同的分辨率不在同一位置.我怎样才能获得它的位置或做点什么来点击它?需要你的帮助!

Gab*_*umb 7

我知道它有点晚了,但您可以在android sdk中使用hierarchyviewer来获取视图ID.

然后,在您的脚本中,使用:

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

device = MonkeyRunner.waitForConnection()  
easy_device = EasyMonkeyDevice(device)  

# Start your android app

# touch the view by id

easy_device.touch(By.id('view_id'), MonkeyDevice.DOWN_AND_UP)
Run Code Online (Sandbox Code Playgroud)

稍后编辑:感谢dtmilano和AndroidViewClient,我可以根据需要对视图进行点击.链接在这里:https://github.com/dtmilano/AndroidViewClient