就我个人而言,我认为使用以下命令制作一个简单的 GUI 爬虫不会太难猴跑者 http://developer.android.com/tools/help/monkeyrunner_concepts.html and AndroidViewClient https://github.com/dtmilano/AndroidViewClient/wiki.
另外,您可能想了解一下用户界面自动化工具 http://developer.android.com/tools/help/uiautomator/index.html and 用户界面测试 http://developer.android.com/tools/testing/testing_ui.html
好是一个相对术语。我没有使用过Robotium,但是在这些圈子里经常提到它。
编辑 - 根据评论请求添加示例。
使用 MonkeyRunner 和 AndroidViewClient 您可以创建视图的层次结构。我认为 AndroidViewClient 有一个内置机制可以做到这一点,但我编写了自己的机制。此代码尝试生成与 Linux tree 命令使用的布局类似的布局。这space
and line
变量用于设置每行前面的“前缀”。当然,这段代码使用了深度优先的递归遍历。
def printViewListDepth(view, depth=0):
space = '|' * int(not depth == 0)
space += (' ' * 2 * (depth-1)) + '|' * int(not depth-1 <= 0)
line = '_' * int(not depth == 0) * 2
text = view.getText()
text = text[:10] + int(len(text) > 10) * '...'
print " [*] %s%s%s %s %s" % (
space, line, view.getUniqueId(),
view.getClass().replace('android.widget.', ''), text)
for ch in view.children:
printViewListDepth(ch, depth+1)
你打电话printViewListDepth
如下,使用ViewClient
AndroidViewClient 返回:
printViewListDepth(viewClient.root)
请注意,在上面的实现中,类View
通过删除“android.widget”来截断。和 a 的文本View
被截断为 10 个字符。您可以更改这些以满足您的需要。
Edit抓取 GUI
使用AndroidViewClient你可以查询View是否可点击,someView.isClickable()
。如果它是可点击的,您可以在其上调用触摸事件,someView.touch()
。假设大多数按钮单击都会打开不同的 Activity,您将需要想出一种获取机制back到你进行递归的地方。
我想这可以通过一些努力来完成,但您可能想从简单的事情开始,例如按下“后退”按钮,device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
。您可能需要处理出现的特定于应用程序的特殊情况,但这应该会让您有一个良好的开端。