Как запустить команды UIAutomator2 из оболочки adb? - PullRequest
0 голосов
/ 22 октября 2019

Возможно, это глупый вопрос, но я хочу убедиться, что ответ отрицательный:

Можно ли запустить UIAutomator2 команды из adb shell без запуска инструментированного тестового класса?

Пока чтовсе, что я могу сделать, это сбросить XML и разобрать его, но мне интересно, могу ли я вызывать отдельные команды.

1 Ответ

0 голосов
/ 07 ноября 2019

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

Однако я нашел этот очень полезный Gist с большинством (если не со всеми) adb команд: https://gist.github.com/Pulimet/5013acf2cd5b28e55036c82c91bd56d8

Также вы можете сами проверить, какие команды доступны:

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

Если вам нужно взаимодействовать, посмотрите на adb shell sendevent

...