news 2026/10/26 1:42:10

android-ui-journey-testing - SKILL

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
android-ui-journey-testing - SKILL

name: android-ui-journey-testing
description: “XML-specified Android UI journey testing, interactive step execution, assertion verification, and JSON outcome reporting.”
category: testing
risk: critical
source: self
source_type: self
date_added: “2026-06-18”
author: Owais
tags: [android, journey-testing, ui-verification, testing, adb, automation]
tools: [claude, cursor, gemini, antigravity]

Android 用户界面旅程测试

概览

此技能概述了在 Android 应用上运行 XML 指定的用户旅程测试的标准工作流程。“旅程” 是一组按顺序排列的用户操作和状态断言,旨在验证端到端功能。旅程 XML 作为应用行为的事实来源。执行器按顺序进行,执行 UI 交互、检查状态断言,并编写标准化的 JSON 结果报告。

何时使用

  • 在根据 XML 测试规范评估 Android 应用程序的用户界面行为时使用。
  • 在自动化多步骤用户流程(例如登录、结账、导航)并验证预期时使用。
  • 在运行验证测试和生成标准化 JSON 测试报告时使用。
  • 在使用 ADB 命令调试物理设备或模拟器上的应用程序流程时使用。

运作方式

Yes

No/Crash

Passed

Failed

Yes

No

Parse Journey XML

Execute Action / Interaction

Success?

Verify State Expectation / Assertion

Mark FAILED & Exit

More Steps?

Output JSON Summary

第1步:解析旅程规范

读取并解析 XML 测试套件结构。根节点<journey>定义测试用例名称,<actions>块包含测试步骤的顺序。

<journeyname="Search and Cart Flow"><description>Verify that searching for an item and adding it to the cart succeeds.</description><actions><action>Search for soda</action><action>Tap the first search result</action><action>Verify that the product detail screen is shown</action></actions></journey>

步骤 2:顺序步骤评估

按照指定的确切顺序处理每个<action>元素。测试步骤分为两组:

A. 互动操作(点击、滑动、文本输入)

使用 ADB 执行物理 UI 交互。

  • 轻触:轻触目标元素边界的中心:
    adb shell input tap<x><y>
  • 滑动/滚动:从一个坐标滑动到另一个坐标,持续时间为:
    adb shell input swipe<x1><y1><x2><y2><duration_ms>
  • 文本输入:在活动输入字段中输入文本:
    adb shell input text"<string>"

如果元素缺失或无法执行操作,则该操作和流程将失败。

B. 陈述断言(期望验证)

以“verify”“check”或“ensure”开头的步骤表示状态断言。

  • 检查当前屏幕(使用截图或uiautomator dump),无需互动或滚动。
  • 确认所有子断言都已满足。例如,“验证应用程序是否在主屏幕上并且徽标可见”如果主屏幕未显示或徽标缺失,则会失败。

步骤3:处理失败和崩溃

如果应用程序崩溃、退出、冻结或断言失败:

  1. 立即停止旅程执行。
  2. 将失败的步骤标记为FAILED。
  3. 将任何后续步骤标记为跳过。
  4. 记录失败的确切原因。

第4步:生成JSON报告

将执行结果格式化为标准化的 JSON 模式并写入输出日志。


例子

示例 1:完整行程 XML 规范

<journeyname="Login and Profile Edit"><description>Logs into the app, navigates to settings, and changes user profile information.</description><actions><action>Verify that the username input field is visible</action><action>Tap the username input field</action><action>Type "testuser" into the input</action><action>Tap the password input field</action><action>Type a redacted test password into the input</action><action>Tap the "Login" button</action><action>Verify that the Home dashboard is visible and user profile photo is shown</action></actions></journey>

示例 2:标准 JSON 结果报告

{"journey":"Login and Profile Edit","results":[{"action":"Verify that the username input field is visible","status":"PASSED","commands":[],"comment":"Username input detected at bounds [100,200][980,300] via UI dump."},{"action":"Tap the username input field","status":"PASSED","commands":["adb shell input tap 540 250"],"comment":"Tapped center coordinates of username input."},{"action":"Type \"testuser\" into the input","status":"PASSED","commands":["adb shell input text \"testuser\""],"comment":"Username typed successfully."},{"action":"Tap the password input field","status":"PASSED","commands":["adb shell input tap 540 370"],"comment":"Tapped center of password input."},{"action":"Type a redacted test password into the input","status":"PASSED","commands":["adb shell input text \"[REDACTED_PASSWORD]\""],"comment":"Password typed successfully. The actual input value was not stored in the report."},{"action":"Tap the \"Login\" button","status":"PASSED","commands":["adb shell input tap 540 500"],"comment":"Login button clicked."},{"action":"Verify that the Home dashboard is visible and user profile photo is shown","status":"FAILED","commands":[],"comment":"Dashboard loaded but profile photo was missing from the UI header."}]}

最佳实践

  • ✅计算点击中心点:在解析元素边界如[x1,y1][x2,y2]时,总是要计算中间坐标:
    xcenter=x1+x22,ycenter=y1+y22x_{center} = \frac{x_1 + x_2}{2}, \quad y_{center} = \frac{y_1 + y_2}{2}xcenter​=2x1​+x2​​,ycenter​=2y1​+y2​​
  • ✅包含睡眠缓冲:在交互操作(如按钮点击)后总是添加短暂延迟(例如 1-2 秒),以在执行断言之前让布局和过渡渲染完成。
  • ✅快速失败:在遇到第一个失败时立即停止测试。失败后继续测试会导致结果无效。
  • ✅安全记录精确命令:在 JSON 输出列表中包含非敏感的原始命令(例如adb shell input tap)以进行诊断。对输入到密码、一次性密码、令牌、支付或个人数据字段的文本进行脱敏;切勿在报告、CI 日志或共享文件中保存真实的秘密信息。

限制

  • 解析器只会评估静态屏幕层级(例如uiautomator dump)。需要滚动的元素除非明确执行滚动操作,否则会被标记为不可见。
  • 非标准的用户界面组件(如自定义的 OpenGL 画布视图)不能通过标准的可访问性树读取,可能需要截图分析或硬编码的点击地图。
  • 通过 ADB 的按键事件和文本输入在所有模拟器镜像上不会触发标准软键盘事件,这可能导致输入验证问题。

相关技能

  • @android-cli- 通用 CLI 工具语法、软件包安装和设备查询。
  • @android_ui_verification- 用于常规界面检查的直接 ADB 脚本模板。
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/10/26 1:38:47

Douzy 3步跑通抖音批量下载:增量、元数据、转写一次配齐

Douzy 3步跑通抖音批量下载&#xff1a;增量、元数据、转写一次配齐 【免费下载链接】douyin-downloader A practical Douyin downloader for both single-item and profile batch downloads, with progress display, retries, SQLite deduplication, and browser fallback sup…

作者头像 李华
网站建设 2026/10/26 1:34:00

DyberPet 桌面宠物完整指南:如何把喜欢的角色搬上桌面

DyberPet 桌面宠物完整指南&#xff1a;如何把喜欢的角色搬上桌面 【免费下载链接】DyberPet Desktop Cyber Pet Framework based on PySide6 项目地址: https://gitcode.com/GitHub_Trending/dy/DyberPet 盯着屏幕一下午&#xff0c;谁来提醒你起身、喝水、别走神&…

作者头像 李华
网站建设 2026/10/26 1:33:22

Folia 全屏歌词播放器安装指南:三端选对包,10 分钟开听

Folia 全屏歌词播放器安装指南&#xff1a;三端选对包&#xff0c;10 分钟开听 【免费下载链接】folia-major 专注于绚丽的歌词动画效果的本地音乐/navidrome/第三方多平台在线音乐播放器 项目地址: https://gitcode.com/GitHub_Trending/fo/folia-major Folia 是一款把…

作者头像 李华
网站建设 2026/10/26 1:31:50

ERP V8.1发版说明解读:模块权重、平台能力与升级评估

简介&#xff1a;《金蝶云星空企业版8.1发版说明》由金蝶软件&#xff08;中国&#xff09;有限公司发布&#xff0c;是官方版本说明PDF&#xff0c;面向企业财务与信息化负责人、ERP实施顾问以及关注金蝶系列产品设计的技术人员&#xff0c;帮助他们在选型评估与版本升级前快速…

作者头像 李华
网站建设 2026/10/26 1:30:23

怎么在 Windows 上安装 APK 文件:APK 安装器 5 分钟上手指南

怎么在 Windows 上安装 APK 文件&#xff1a;APK 安装器 5 分钟上手指南 【免费下载链接】APK-Installer An Android Application Installer for Windows 项目地址: https://gitcode.com/GitHub_Trending/ap/APK-Installer 工作日的晚上&#xff0c;你双击桌面上的 APK&…

作者头像 李华
网站建设 2026/10/26 1:29:05

CPU 的 “紧急来电”:一文读懂计算机中断机制

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

作者头像 李华