0

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

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

到目前为止,我似乎所能做的就是转储 XML 并解析它,但我想知道我是否可以调用单个命令。

4

1 回答 1

0

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

于 2019-11-07T10:23:11.457 回答