如何从adb shell运行UIAutomator2命令?

时间:2019-10-22 00:17:32

标签: android adb android-uiautomator uiautomatorviewer

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

一个人可以在不启动检测测试类的情况下从<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <div class="content-grid"> <div class="content-item"> 1 <img src="http://via.placeholder.com/350x150" alt=""> </div> <div class="content-item"> 2 <img src="http://via.placeholder.com/350x150" alt=""> </div> <div class="content-item"> <img src="http://via.placeholder.com/350x150" alt=""> </div> <div class="content-item"> <img src="http://via.placeholder.com/350x150" alt=""> </div> <div class="content-item"> <img src="http://via.placeholder.com/350x150" alt=""> </div> <div class="content-item"> <img src="http://via.placeholder.com/350x150" alt=""> </div> </div> </body> </html> .content-item { background-color: lightskyblue; } .content-grid .content-item:nth-child(2) { background-color: aliceblue; -ms-grid-column: 1; -ms-grid-column-span: 2; grid-column: 1 / span 2; -ms-grid-row: 1; grid-row: 1 } .content-grid .content-item:nth-child(1) { background-color: aliceblue; -ms-grid-column: 3; -ms-grid-column-span: 1; grid-column: 3 / span 1; } .content-item__image { height: 210px; width: 100%; background-size: cover; background-position: center center; background-repeat: no-repeat; } .content-item__description { padding: 16px 28px; } .content-grid { display: grid; display: -ms-grid; grid-template-columns: 400px 400px 400px; -ms-grid-columns: 400px 400px 400px; grid-gap: 1rem; } @supports (-ms-ime-align: auto) { .content-grid { display: block; } .content-item { float: left; width: 30%; } } @media all and (-ms-high-contrast: none), (-ms-high-contrast: active) { .content-grid { display: block; } .content-item { float: left; width: 30%; } } @media (max-width: 1100px) { .content-grid { display: grid; display: -ms-grid; grid-template-columns: 400px 400px; -ms-grid-columns: 400px 400px; grid-gap: 1rem; } } @media (max-width: 780px) { .content-grid { display: grid; display: -ms-grid; grid-template-columns: 400px; -ms-grid-columns: 400px; grid-gap: 1rem; } } 运行UIAutomator2命令吗?

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

1 个答案:

答案 0 :(得分: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