简体   繁体   English

UIAutomatorViewer 的替代品,用于在运行时检查 Android 应用程序

[英]Alternatives to UIAutomatorViewer to inspect an Android app while running it

The developers I'm working with in my team need to make automated integration tests and in some of them need to make actions on particular elements within specific pages of their app.在我的团队中与我一起工作的开发人员需要进行自动化集成测试,其中一些开发人员需要对他们应用程序特定页面中的特定元素进行操作。

To do so, they're using UI Automator, but the "uiautomatorviewer" is causing some problems due to uncovered Java versions (that's what it seemed to me).为此,他们使用了 UI Automator,但由于未发现 Java 版本(在我看来就是这样),“uiautomatorviewer”导致了一些问题。 They need a similar tool because, for example, if they want to catch a specific button and simulate the act of clicking it, for what I have understood until now, they have to call a method called resourceId(String) of UiSelector class, passing in it a string made of an "id", which some elements don't have explicitly declarated in the code, and so that's why they need to be able to debug the running app to see what is, for example, that id of that specific button.他们需要一个类似的工具,因为,例如,如果他们想要捕捉一个特定的按钮并模拟点击它的行为,据我到目前为止的理解,他们必须调用 UiSelector class 的一个名为 resourceId(String) 的方法,通过其中有一个由“id”组成的字符串,其中一些元素没有在代码中明确声明,因此这就是为什么他们需要能够调试正在运行的应用程序以查看什么是,例如,那个 id具体按钮。

I've seen this string is formed by what looks like a package (ex. com.android.vending:id/ the_id ).我已经看到这个字符串是由看起来像 package(例如 com.android.vending:id/ the_id )的字符串组成的。

I've done this technical example because they need something allowing them to know how to find the name of the id and how to find the name of the "package" to use.我已经完成了这个技术示例,因为他们需要一些东西让他们知道如何找到 id 的名称以及如何找到要使用的“包”的名称。 Are these informations available somewhere on Android Studio?这些信息可以在 Android Studio 的某个地方找到吗?

I've tried to use the Chrome DevTools but, for what I have understood about it, it doesn't work with native apps but only inspects web pages, correct me if I'm wrong.我尝试使用 Chrome DevTools,但据我了解,它不适用于本机应用程序,但仅检查 web 页面,如果我错了请纠正我。

I think also Genymotion works in the same way and doesn't allow to inspect apps.我认为 Genymotion 也以同样的方式工作,并且不允许检查应用程序。

If there is a simpler alternative allowing to get the strings to pass to the "resourceId" method without using "uiautomatorviewer" and similar softwares, could you suggest me how to do it?如果有更简单的替代方法允许在不使用“uiautomatorviewer”和类似软件的情况下将字符串传递给“resourceId”方法,你能建议我怎么做吗?

If not, could you suggest me a good alternative to "uiautomatorviewer"?如果没有,你能建议我一个很好的替代“uiautomatorviewer”的方法吗?

maybe this github repo help you to alternative way:也许这个 github 回购协议可以帮助您采用其他方式:

android inspector android 检验员

If you want to list the ID's and some other useful info to incorporate in your tests you can use AndroidViewClient 's dump :如果您想列出 ID 和一些其他有用的信息以合并到您的测试中,您可以使用AndroidViewClientdump

dump

and produces something like并产生类似的东西

android.widget.FrameLayout
   android.view.View com.google.android.apps.nexuslauncher:id/scrim_view
      android.view.View
   android.widget.ScrollView com.google.android.apps.nexuslauncher:id/workspace
      android.widget.FrameLayout com.google.android.apps.nexuslauncher:id/universal_smartspace_container
         android.widget.TextView com.google.android.apps.nexuslauncher:id/clock Friday, May 13
      com.android.launcher3.widget.LauncherAppWidgetHostView
         android.widget.LinearLayout com.google.android.deskclock:id/digital_widget
            android.widget.TextView com.google.android.deskclock:id/clock 12:41
            android.widget.TextView com.google.android.deskclock:id/date FRI, MAY 13
   android.widget.TextView  Messages
   android.widget.TextView  Play Store
   android.widget.TextView  Chrome
   android.widget.FrameLayout com.google.android.apps.nexuslauncher:id/search_container_all_apps
      android.view.View com.google.android.apps.nexuslauncher:id/mic_icon

Specifying command line options dump produces a wide variety of info:指定命令行选项dump会产生各种各样的信息:

usage: dump [OPTION]... [serialno]

Options:
  -H, --help                       prints this help
  -V, --verbose                    verbose comments
  -v, --version
  -I, --ignore-secure-device       ignore secure device
  -E, --ignore-version-check       ignores ADB version check
  -F, --force-view-server-use      force view server use (even if UiAutomator present)
  -S, --do-not-start-view-server   don't start ViewServer
  -k, --do-not-ignore-uiautomator-killed don't ignore UiAutomator killed
  -w, --window=WINDOW              dump WINDOW content (default: -1, all windows)
  -a, --all                        dump all information about Views
  -i, --uniqueId                   dump View unique IDs
  -x, --position                   dump View positions
  -b, --bounds                     dump View bounds
  -d, --content-description        dump View content descriptions
  -g, --tag                        dump View tags
  -c, --center                     dump View centers
  -f, --save-screenshot=FILE       save screenshot to file
  -W, --save-view-screenshots=DIR  save View screenshots to files in directory
  -D, --do-not-dump-views          don't dump views, only useful if you specified -f or -W
  -A, --device-art=MODEL           device art model to frame screenshot (auto: autodetected)
  -Z, --drop-shadow                drop shadow for device art screenshot
  -B, --glare                      screen glare over screenshot
  -h, --use-uiautomator-helper     use UiAutomatorHelper Android app
  -X, --debug=LIST                 debug options

However, if you want JSON output, you can use CulebraTester2-public and then但是,如果你想要 JSON output,你可以使用CulebraTester2-public然后

dump -ha

and you'll get你会得到

{
  "id": "hierarchy",
  "text": "Window Hierarchy",
  "timestamp": "2022-05-13T19:52:55.823Z",
  "children": [
    {
      "id": 0,
      "parent": -1,
      "text": "",
      "package": "com.google.android.apps.nexuslauncher",
      "checkable": false,
      "clickable": false,
      "index": 0,
      "content_description": "",
  ...

Finally, using culebra -G you can also automatically generate tests (in python).最后,使用culebra -G还可以自动生成测试(在 python 中)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM