如何在Android中进行UI自动化?

bla*_*yre 5 automation android monkeyrunner

是否有任何指南可以执行以下UI自动化,例如选择项目,编写文本,在Android中按下按钮.请列出集成此UI自动化的上述步骤之一的步骤.

谢谢

Pep*_*lac 7

你应该像python脚本一样使用它.例:

import sys
import os
import time
import shlex
import subprocess

from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
device = MonkeyRunner.waitForConnection(99, ANDROID_SERIAL_NUMBER)

def Click(device, left, top, duration = 0):
    if duration == 0:
        device.touch(left, top, MonkeyDevice.DOWN_AND_UP)
    else:
        device.touch(left, top, MonkeyDevice.DOWN)
        time.sleep(duration)
        device.touch(left, top, MonkeyDevice.UP)

def Drag_example():
    device.drag((100, 200), (1500, 150), 1, 10) 

def Settings_menu():
    package='com.android.settings'
    activity='.Settings'
    component_name=package + "/" + activity
    device.startActivity(component=component_name)
Settings_menu();
Run Code Online (Sandbox Code Playgroud)

对于运行脚本使用: monkeyrunner script_name

这是: Click它是在x和y位置点击屏幕的功能;
Drag_example拖动
Settings_menu运行活动的简单示例的简单示例

不要忘记更改ANDROID_SERIAL_NUMBER序列号.
你可以通过adb devices命令获得它.

有关更多信息,您可以阅读谷歌文档.

在Java中使用时请阅读这篇文章