'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). 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.
I've seen this string is formed by what looks like a package (ex. 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. Are these informations available somewhere on 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.
I think also Genymotion works in the same way and doesn't allow to inspect apps.
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?
If not, could you suggest me a good alternative to "uiautomatorviewer"?
Solution 1:[1]
Solution 2:[2]
If you want to list the ID's and some other useful info to incorporate in your tests you can use AndroidViewClient's dump
:
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:
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
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).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | h__g |
Solution 2 | Diego Torres Milano |