『App自动化测试之Appium应用篇』| 元素定位工具uiautomatorviewer从简介、特点、启动到使用的完整过程

举报
虫无涯 发表于 2023/12/14 09:12:56 2023/12/14
【摘要】 1 uiautomatorviewer简介之前文章说明了Appium Inspector的定位使用方法;uiautomatorviewer是另一种定位工具;uiautomatorviewer是android-sdk自带的元素定位工具;它是通过截屏分析XML布局文件方式,来提供控件信息的查看服务。 2 uiautomatorviewer特点uiautomatorviewer和Appium I...

1 uiautomatorviewer简介

  • 之前文章说明了Appium Inspector的定位使用方法;
  • uiautomatorviewer是另一种定位工具;
  • uiautomatorviewerandroid-sdk自带的元素定位工具;
  • 它是通过截屏分析XML布局文件方式,来提供控件信息的查看服务。

2 uiautomatorviewer特点

  • uiautomatorviewerAppium Inspector有着明显的区别;
  • Appium Inspector功能相对比较强大;
  • uiautomatorviewer只能用于安卓系统;
  • 另外uiautomatorviewer只能用于元素定位,不支持通过该工具操作APP,也不支持录制功能等。

3 uiautomatorviewer启用

  • uiautomatorviewer位于SDK目录下的tools\目录下;
  • 比如我的是:D:\android-sdk-windows\tools
    在这里插入图片描述
  • 双击uiautomatorviewer.bat进行启动即可:
    在这里插入图片描述

4 Work Bar

  • Work Bar即工作栏,工作栏中有4个按钮,如图所示:
    在这里插入图片描述

  • 从左到右依次为:

图标 名称 说明
1 Open 打开已保存的布局
2 Device Screenshot(uiautomator dump) 获取详细布局
3 Device Screenshot with Cpmpressed Hierarchy (uiautomator dump) 获取简介布局
4 Save 保存布局
  • 其中4保存时将保存两个文件,一个是图片,一个是.uix文件;
    在这里插入图片描述
  • 可以查看图片显示:
    在这里插入图片描述
  • 也可以查看XML格式内容:
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<hierarchy rotation="0">
    <node index="0" text="" resource-id="" class="android.widget.FrameLayout" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][768,1184]">
        <node index="0" text="" resource-id="" class="android.widget.LinearLayout" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][768,1184]">
            <node index="0" text="" resource-id="android:id/content" class="android.widget.FrameLayout" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][768,1184]">
                <node index="0" text="" resource-id="com.android.launcher3:id/launcher" class="android.widget.FrameLayout" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][768,1184]">
                    <node index="0" text="" resource-id="com.android.launcher3:id/drag_layer" class="android.widget.FrameLayout" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][768,1184]">
                        <node index="0" text="" resource-id="com.android.launcher3:id/workspace" class="com.android.launcher3.Workspace" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="true" long-clickable="false" password="false" selected="false" bounds="[0,0][768,1184]">
                            <node index="1" text="" resource-id="" class="android.view.ViewGroup" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="true" password="false" selected="false" bounds="[8,184][760,976]">
                                <node index="0" text="" resource-id="" class="android.view.ViewGroup" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[8,184][760,976]">
                                    <node index="0" text="QQi" resource-id="" class="android.widget.TextView" package="com.android.launcher3" content-desc="QQi" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="true" password="false" selected="false" bounds="[8,184][196,382]" />
                                    <node index="1" text="Settings" resource-id="" class="android.widget.TextView" package="com.android.launcher3" content-desc="Settings" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="true" password="false" selected="false" bounds="[384,778][572,976]" /></node>
                                <node index="1" text="" resource-id="" class="android.view.View" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[8,184][220,406]" /></node>
                        </node>
                        <node index="1" text="" resource-id="com.android.launcher3:id/search_drop_target_bar" class="android.widget.FrameLayout" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,48][768,184]">
                            <node index="0" text="" resource-id="" class="android.appwidget.AppWidgetHostView" package="com.android.launcher3" content-desc="Search" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,48][768,184]">
                                <node index="0" text="" resource-id="" class="android.widget.RelativeLayout" package="com.android.quicksearchbox" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,48][768,184]">
                                    <node index="0" text="" resource-id="com.android.quicksearchbox:id/search_plate" class="android.widget.LinearLayout" package="com.android.quicksearchbox" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,48][768,184]">
                                        <node NAF="true" index="0" text="" resource-id="com.android.quicksearchbox:id/search_icon" class="android.widget.ImageView" package="com.android.quicksearchbox" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[19,68][115,164]" />
                                        <node NAF="true" index="1" text="" resource-id="com.android.quicksearchbox:id/search_widget_text" class="android.widget.TextView" package="com.android.quicksearchbox" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[115,79][740,153]" /></node>
                                </node>
                            </node>
                        </node>
                        <node index="3" text="" resource-id="com.android.launcher3:id/page_indicator" class="android.widget.LinearLayout" package="com.android.launcher3" content-desc="Home screen 2 of 2, Settings" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[360,992][408,1016]">
                            <node index="0" text="" resource-id="" class="android.widget.FrameLayout" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[360,992][384,1016]">
                                <node index="1" text="" resource-id="com.android.launcher3:id/inactive" class="android.widget.ImageView" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[360,992][384,1016]" /></node>
                            <node index="1" text="" resource-id="" class="android.widget.FrameLayout" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[384,992][408,1016]">
                                <node index="0" text="" resource-id="com.android.launcher3:id/active" class="android.widget.ImageView" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[384,992][408,1016]" /></node>
                        </node>
                        <node index="4" text="" resource-id="com.android.launcher3:id/hotseat" class="android.widget.FrameLayout" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,1016][768,1184]">
                            <node index="0" text="" resource-id="com.android.launcher3:id/layout" class="android.view.ViewGroup" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="true" password="false" selected="false" bounds="[0,1016][768,1184]">
                                <node index="0" text="" resource-id="" class="android.view.View" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[24,1016][192,1184]" />
                                <node index="1" text="" resource-id="" class="android.view.ViewGroup" package="com.android.launcher3" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[24,1016][768,1184]">
                                    <node index="0" text="Phone" resource-id="" class="android.widget.TextView" package="com.android.launcher3" content-desc="Phone" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="true" password="false" selected="false" bounds="[29,1022][163,1178]" />
                                    <node index="1" text="Contacts" resource-id="" class="android.widget.TextView" package="com.android.launcher3" content-desc="Contacts" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="true" password="false" selected="false" bounds="[173,1022][307,1178]" />
                                    <node index="2" text="" resource-id="" class="android.widget.TextView" package="com.android.launcher3" content-desc="Apps" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="true" password="false" selected="false" bounds="[317,1022][451,1178]" />
                                    <node index="3" text="Messaging" resource-id="" class="android.widget.TextView" package="com.android.launcher3" content-desc="Messaging" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="true" password="false" selected="false" bounds="[461,1022][595,1178]" />
                                    <node index="4" text="Browser" resource-id="" class="android.widget.TextView" package="com.android.launcher3" content-desc="Browser" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="true" password="false" selected="false" bounds="[605,1022][739,1178]" /></node>
                            </node>
                        </node>
                    </node>
                </node>
            </node>
        </node>
    </node>
</hierarchy>
  • 其中2会显示全部布局;
  • 其中3只显示部分有用的控件布局。

5 Screenshot

  • screenshot是截图区域,在图中的左侧部分;
  • 主要是显示当前屏幕的布局图片:
    在这里插入图片描述

6 控件布局

  • 控件布局内容主要在右上方显示,以XML格式展示;
    在这里插入图片描述

7 控件属性

  • 控件属性显示在右下方,当点击一个控件时,将会在这显示其属性信息:
    在这里插入图片描述

8 连接设备

  • 直接点击工作栏中的第二个或第三个按钮即可连接到设备;
  • 我们这里点击的是第二个按钮Device Screenshot
    在这里插入图片描述

9 Error while obtaining UI问题排查

  • 当我们点击第二个按钮Device Screenshot时出现以下界面:
    在这里插入图片描述
  • 这个说明报错了,没有连接上,那我们看下详细信息,点击【Details】:
Error while obtaining UI hierarchy XML file: com.android.ddmlib.SyncException: Remote object doesn't exist!
  • 大概意思是Remote object doesn't exist,就是说已经存在了一个连接,那我们就需要断开已经连接的才行;
  • 我们检查发现使用了Appium-Inspector已经连接了,我们点击【×】断开这个会话连接:

在这里插入图片描述

  • 重新再连接就可以使用uiautomatorviewer连接上了。
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。