【问题标题】:How to run UIAutomator2 commands from adb shell?如何从 adb shell 运行 UIAutomator2 命令?
【发布时间】:2019-10-22 00:17:32
【问题描述】:

可能是一个愚蠢的问题,但我想验证答案是否定的:

可以在不启动检测测试类的情况下从adb shell 运行UIAutomator2 命令吗?

到目前为止,我似乎只能转储 XML 并对其进行解析,但我想知道我是否可以调用单个命令。

【问题讨论】:

    标签: android adb android-uiautomator uiautomatorviewer


    【解决方案1】:

    TLDR;不,对于UiAutomator2 拥有的几乎所有操作/可用方法,您都不能使用adb shell uiautomator xyzcommands

    运行adb shell uiautomator --help 将显示可用的子命令:

    adb shell uiautomator --help
    Usage: uiautomator <subcommand> [options]
    
    Available subcommands:
    
    help: displays help message
    
    runtest: executes UI automation tests
        runtest <class spec> [options]
        <class spec>: <JARS> < -c <CLASSES> | -e class <CLASSES> >
          <JARS>: a list of jar files containing test classes and dependencies. If
            the path is relative, it's assumed to be under /data/local/tmp. Use
            absolute path if the file is elsewhere. Multiple files can be
            specified, separated by space.
          <CLASSES>: a list of test class names to run, separated by comma. To
            a single method, use TestClass#testMethod format. The -e or -c option
            may be repeated. This option is not required and if not provided then
            all the tests in provided jars will be run automatically.
        options:
          --nohup: trap SIG_HUP, so test won't terminate even if parent process
                   is terminated, e.g. USB is disconnected.
          -e debug [true|false]: wait for debugger to connect before starting.
          -e runner [CLASS]: use specified test runner class instead. If
            unspecified, framework default runner will be used.
          -e <NAME> <VALUE>: other name-value pairs to be passed to test classes.
            May be repeated.
          -e outputFormat simple | -s: enabled less verbose JUnit style output.
    
    dump: creates an XML dump of current UI hierarchy
        dump [--verbose][file]
          [--compressed]: dumps compressed layout information.
          [file]: the location where the dumped XML should be stored, default is
          /sdcard/window_dump.xml
    
    events: prints out accessibility events until terminated
    
    

    但是我发现这个对大多数(如果不是全部)adb 命令非常有用的要点:https://gist.github.com/Pulimet/5013acf2cd5b28e55036c82c91bd56d8

    您还可以检查自己可以运行哪些命令:

    adb shell toybox --long | tr " " "\n"

    如果需要互动,请关注adb shell sendevent

    猜你喜欢
    • 1970-01-01
    • 2012-03-12
    • 2021-11-06
    • 2012-01-06
    • 2020-10-06
    • 2014-11-25
    • 2022-07-12
    • 2014-12-05
    • 1970-01-01
    相关资源
    最近更新 更多