完整教程:深入解析AppCrawler:开源自动遍历测试工具配置指南

news/2025/10/24 13:05:52/文章来源:https://www.cnblogs.com/slgkaifa/p/19162990

完整教程:深入解析AppCrawler:开源自动遍历测试工具配置指南

Appcrawler是一个基于自动遍历的App爬虫工具,支持Android和IOS,支持真机和模拟器。最大的特点是灵活性高,可通过配置来设定遍历的规则。

配置文件格式

执行参数与配置文件

  • capability设置:与appium完全一致

  • testcase:用于启动app后的基础测试用例

  • selectedList:遍历范围设定

  • triggerActions:特定条件触发执行动作的设置

  • selectedList:需要被遍历的元素范围

  • firstList:优先被点击

  • lastList:最后被点击

  • tagLimitMax:同祖先(同类型)的元素最多点击多少次

  • backButton:当所有元素都被点击后默认后退控件定位

  • blackList:黑名单

  • maxDepth: 遍历的最大深度

配置的最小单元 测试用例模型

testcase的完整形态
  • given:所有的先决条件

  • when:先决条件成立后的行为

  • then:断言集合

testcase的简写形态
  • xpath:对应when里的xpath

  • action:对应when的action

执行参数比配置文件优先级别高
  • given 前提条件

  • when 执行动作

  • then 写断言

简写形态

  • xpath xpath支持xpath表达式、正则、包含

  • action 支持

xpath定义

  • xpath - //[@resource-id=‘xxxx’] - //[contains(@text, ‘密码’)]

  • 正则 - ^确定$ - ^.*输入密码

  • 包含 - 密码 - 输入 - 请

action定义

  • "" 只是截图记录

  • back 后退

  • backApp 回退到当前的app 默认等价于back行为 可定制

  • monkey 随机事件

  • click

  • longTap

  • xxx() 执行scala或者java代码 - Thread.sleep(3000) - driver.swipe(0.9, 0.5, 0.1, 0.5)

  • 非以上所有行为是输入 xx ddd

完整配置文件

---
maxTimeDescription: "最大运行时间"
maxTime: 10800
maxDepthDescription: "默认的最大深度10, 结合baseUrl可很好的控制遍历的范围"
maxDepth: 10
capabilityDescription: "appium的capability通用配置,其中automationName代表自动化的驱动引擎,除了支持appium的\
  所有引擎外,额外增加了adb和selenium的支持"
capability:
  appActivity: ".ApiDemos"
  appium: "http://127.0.0.1:4723/wd/hub"
  noReset: "true"
  appPackage: "io.appium.android.apis"
  fullReset: "false"
testcaseDescription: "测试用例设置,用于遍历开始之前的一些前置操作,比如自动登录"
testcase:
  name: "AppCrawler TestCase"
  steps:
    - given: []
      when: null
      then: []
      xpath: "/*/*"
      action: "Thread.sleep(1000)"
      actions: []
      times: -1
triggerActionsDescription: "在遍历过程中需要随时处理的一些操作,比如弹框、登录等"
triggerActions:
  - given: []
    when: null
    then: []
    xpath: "permission_allow_button"
    action: ""
    actions: []
    times: 3
  - given: []
    when: null
    then: []
    xpath: "允许"
    action: ""
    actions: []
    times: 3
selectedListDescription: "默认遍历列表,只有出现在这个列表里的控件范围才会被遍历"
selectedList:
  - given: []
    when: null
    then: []
    xpath: "//*[contains(name(), 'Button')]"
    action: ""
    actions: []
    times: -1
  - given: []
    when: null
    then: []
    xpath: "//*[contains(name(), 'Text') and @clickable='true' and string-length(@text)<10]"
    action: ""
    actions: []
    times: -1
  - given: []
    when: null
    then: []
    xpath: "//*[@clickable='true']//*[contains(name(), 'Text') and string-length(@text)<10]"
    action: ""
    actions: []
    times: -1
  - given: []
    when: null
    then: []
    xpath: "//*[contains(name(), 'Image') and @clickable='true']"
    action: ""
    actions: []
    times: -1
  - given: []
    when: null
    then: []
    xpath: "//*[@clickable='true']/*[contains(name(), 'Image')]"
    action: ""
    actions: []
    times: -1
  - given: []
    when: null
    then: []
    xpath: "//*[contains(name(), 'Image') and @name!='']"
    action: ""
    actions: []
    times: -1
  - given: []
    when: null
    then: []
    xpath: "//*[contains(name(), 'Text') and @name!='' and string-length(@label)<10]"
    action: ""
    actions: []
    times: -1
  - given: []
    when: null
    then: []
    xpath: "//a"
    action: ""
    actions: []
    times: -1
  - given: []
    when: null
    then: []
    xpath: "//*[contains(@class, 'Text') and @clickable='true' and string-length(@text)<10]"
    action: ""
    actions: []
    times: -1
  - given: []
    when: null
    then: []
    xpath: "//*[@clickable='true']//*[contains(@class, 'Text') and string-length(@text)<10]"
    action: ""
    actions: []
    times: -1
  - given: []
    when: null
    then: []
    xpath: "//*[contains(@class, 'Image') and @clickable='true']"
    action: ""
    actions: []
    times: -1
  - given: []
    when: null
    then: []
    xpath: "//*[@clickable='true']/*[contains(@class, 'Image')]"
    action: ""
    actions: []
    times: -1
  - given: []
    when: null
    then: []
    xpath: "//*[@clickable='true' and contains(@class, 'Button')]"
    action: ""
    actions: []
    times: -1
blackListDescription: "黑名单列表 matches风格, 默认排除内容包含2个数字的控件"
blackList:
  - given: []
    when: null
    then: []
    xpath: ".*[0-9]{2}.*"
    action: ""
    actions: []
    times: -1
firstListDescription: "优先遍历列表,同时出现在selectedList与firstList中的控件会被优先遍历"
firstList: []
lastListDescription: "最后遍历列表,同时出现在selectedList与lastList中的控件会被最后遍历"
lastList:
  - given: []
    when: null
    then: []
    xpath: "//*[@selected='true']/..//*"
    action: ""
    actions: []
    times: -1
  - given: []
    when: null
    then: []
    xpath: "//*[@selected='true']/../..//*"
    action: ""
    actions: []
    times: -1
backButtonDescription: "后退按钮列表,默认在所有控件遍历完成后,才会最后点击后退按钮。目前具备了自动判断返回按钮的能力,默认不需要配置"
backButton:
  - given: []
    when: null
    then: []
    xpath: "Navigate up"
    action: ""
    actions: []
    times: -1
xpathAttributesDescription: "在生成一个控件的唯一定位符中应该包含的关键属性"
xpathAttributes:
  - "name()"
  - "name"
  - "label"
  - "value"
  - "resource-id"
  - "content-desc"
  - "text"
  - "id"
  - "name"
  - "innerText"
  - "tag"
  - "class"
sortByAttributeDescription: "陆续根据属性进行遍历排序微调,depth表示从dom中最深层的控件开始遍历,list表示dom中列表优先,\
  selected表示菜单最后遍历,这是默认规则,一般不需要改变"
sortByAttribute:
  - "depth"
  - "list"
  - "selected"
findByDescription: "默认生成控件唯一定位符的表达式风格,可选项 default|android|id|xpath,默认会自动判断是否使用android定\
  位或者ios定位"
findBy: "xpath"
baseUrlDescription: "设置一个起始点,从这个起始点开始计算深度,比如默认从登录后的界面开始计算"
baseUrl: []
appWhiteListDescription: "app白名单,允许在这些app里进行遍历"
appWhiteList: []
urlBlackListDescription: "url黑名单,用于排除某些页面的遍历"
urlBlackList: []
urlWhiteListDescription: "url白名单,仅在这些界面内遍历"
urlWhiteList: []
beforeStartWaitDescription: "启动一个app默认等待的时间"
beforeStartWait: 6000
beforeRestart: []
beforeElementDescription: "在遍历每个控件之前默认执行的动作"
beforeElement: []
afterElementDescription: "在遍历每个控件之后默认执行的动作"
afterElement: []
afterElementWaitDescription: "在遍历每个控件之后默认等待的时间,用于等待新页面加载"
afterElementWait: 500
afterAllDescription: "在遍历完当前页面内的所有控件后,是否需要刷新或者滑动"
afterAll: []
afterAllMaxDescription: "afterAll的最大重试次数,比如连续滑动2次都没新元素即取消"
afterAllMax: 2
tagLimitMaxDescription: "相似控件最多点击几次"
tagLimitMax: 2
tagLimitDescription: "设置部分相似控件的最大遍历次数"
tagLimit:
  - given: []
    when: null
    then: []
    xpath: "确定"
    action: ""
    actions: []
    times: 1000
  - given: []
    when: null
    then: []
    xpath: "取消"
    action: ""
    actions: []
    times: 1000
  - given: []
    when: null
    then: []
    xpath: "share_comment_guide_btn_name"
    action: ""
    actions: []
    times: 1000
assertGlobalDescription: "全局断言"
assertGlobal: []
suiteNameDescription: "报告中的测试套件名字可以由列表内的控件内容替换,增强报告中关键界面的辨识度"
suiteName:
  - "//*[@selected='true']//android.widget.TextView/@text"
screenshotDescription: "是否截图"
screenshot: true
reportTitleDescription: "报告的title"
reportTitle: "AppCrawler"
resultDirDescription: "结果目录,如果为空会自动创建对应时间戳_报名的结果目录"
resultDir: ""
showCancelDescription: "是否展示跳过的控件记录"
showCancel: true
pluginListDescription: "插件列表,暂时禁用,太高级了,很多人不会用"
Description: "。在selectedList firstList lastList等很多配置中,需要填充的是测试步骤Step类型。Step类型由given(\
  满足条件)when(条件满足的行为)then(断言)三部分组成。Step可以简化为xpath(定位表达式,支持xpath 正则 包含关系)与action(点击\
  \ 输入等行为)。"
pluginList: []

金牌赞助商(Gold Sponsor)

图片

霍格沃兹测试开发学社 是 测吧(北京)科技有限公司 旗下业界领先的测试开发技术高端教育品牌。 学院课程均由名企一线测试大牛设计,提供实战驱动的系列课程。涵盖移动app自动化测试、接口自动化测试、性能测试、持续集成/持续交付/DevOps 、测试左移、测试右移、测试管理等课程。

测吧(北京)科技有限公司 是一家服务于测试领域的高科技公司,为企业提供全方位的自动化测试技术支持、测试平台开发定制、测试效能提升等咨询与科研合作服务。 先后服务于华为、工信部、信通院等知名企业与机构。

编译

mvn clean package

技术交流

由霍格沃兹测试开发学社维护,技术交流与issue提交请移步 https://ceshiren.com/c/opensource/appcrawler/ 

测试开发全景图:AI测试、智能驱动、自动化、测试开发、左移右移与DevOps的持续交付 


推荐阅读

精选技术干货

精选文章

  • 打造高效极简工作流
  • Playwright MCP浏览器自动化指南
  • 新手轻松上手:零基础搭建Qwen智能体指南
  • 大模型部署实战:四大工具赋能个人探索与企业级应用
  • Playwright MCP 实现小红书全自动发布的全流程指南
  • AI 测试平台新功能揭秘:自动化测试用例运行的奥秘

学社精选

  • 测试开发之路 大厂面试总结

  • 【面试】分享面试题总结

  • 测试人生 | 从外包菜鸟到测试开发,薪资一年翻三倍,连自己都不敢信!(附面试真题与答案)

  • 人工智能与自动化测试结合实战-探索人工智能在测试领域中的应用

  • 爱测智能化测试平台

  • 自动化测试平台

  • 精准测试平台

  • AI测试开发企业技术咨询服务

人工智能测试开发学习专区

  • 人工智能/AI/为什么测试工程师需要掌握AI

  • 人工智能在音频、视觉、多模态领域的应用

  • 从0到1打造AI工作流:测试用例/测试架构图/测试报告/简历/PPT全自动生成

  • 视觉识别在自动化测试中的应用-UI测试与游戏测试

  • 人工智能产品测试:从理论到实战

  • AI驱动的全栈测试自动化与智能体开发

  • 大语言模型应用开发框架 LangChain

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/945195.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

解释 EIP-4337

简单来说,EIP-4337 旨在实现“账户抽象”,让智能合约钱包成为用户的默认和主流钱包,从而极大地改善用户体验和安全性。 下面我将从几个方面详细解释 EIP-4337: 1. 核心问题:以太坊的两种账户 在理解 EIP-4337 之前…

数论常见结论及例题

数论常见结论及例题 常见结论 球盒模型(八种) 参考链接。给定 \(n\) 个小球 \(m\) 个盒子。球同,盒不同、不能空隔板法: \(N\) 个小球即一共 \(N-1\) 个空,分成 \(M\) 堆即 \(M-1\) 个隔板,答案为 \(\dbinom{n-1…

材料包含与下载漏洞

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

N8N Workflow Collection - 专业级自动化工作流库 - 详解

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

完整教程:Elasticsearch面试精讲 Day 23:安全认证与权限控制

完整教程:Elasticsearch面试精讲 Day 23:安全认证与权限控制pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Con…

Min25 筛

Min25 筛 求解 \(1-N\) 的质数和,其中 \(N \le 10^{10}\) 。 namespace min25{const int N = 1000000 + 10;int prime[N], id1[N], id2[N], flag[N], ncnt, m;LL g[N], sum[N], a[N], T;LL n;LL mod;inline LL ps(LL …

莫比乌斯函数/反演

莫比乌斯函数/反演 莫比乌斯函数定义:\(\displaystyle {\mu(n) = \begin{cases} 1 &n = 1 \\ (-1)^k &n = \prod_{i = 1}^k p_i \text{ 且 } p_i \text{ 互质 } \\ 0 &else \end{cases}}\) 。莫比乌斯函数…

同余方程组、拓展中国剩余定理 excrt

同余方程组、拓展中国剩余定理 excrt 公式:\(x \equiv b_i(\bmod\ a_i)\) ,即 \((x - b_i) \mid a_i\) 。 int n; LL ai[maxn], bi[maxn]; inline int mypow(int n, int k, int p) {int r = 1;for (; k; k >>=…

完整教程:微软2025教育AI报告:教育群体采用AI的比例显著提升

完整教程:微软2025教育AI报告:教育群体采用AI的比例显著提升pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Con…

康拓展开

康拓展开 正向展开普通解法 将一个字典序排列转换成序号。例如:12345->1,12354->2。 int f[20]; void jie_cheng(int n) { // 打出1-n的阶乘表f[0] = f[1] = 1; // 0的阶乘为1for (int i = 2; i <= n; i++)…

求解连续数字的正约数集合——倍数法

求解连续数字的正约数集合——倍数法 使用规律递推优化,时间复杂度为 \(\mathcal{O}(N\log N)\) ,如果不需要详细的输出集合,则直接将 vector 换为普通数组即可(时间更快) 。 #include <bits/stdc++.h> usi…

git回滚代码

回滚上一次提交是指撤销最近一次的git提交操作。在实际使用中,有两种常见的方法可以实现这个操作: 方法一:使用git revert命令回滚 1. 首先,通过命令`git log`查看提交记录,找到要回滚的提交的hash值。 2. 使用命…

Apache POI 在 Linux 无图形界面环境下因字体配置问题导致Excel导出失败的解决方案 - 详解

Apache POI 在 Linux 无图形界面环境下因字体配置问题导致Excel导出失败的解决方案 - 详解2025-10-24 12:52 tlnshuju 阅读(0) 评论(0) 收藏 举报pre { white-space: pre !important; word-wrap: normal !importan…

扩展欧几里得 exgcd

扩展欧几里得 exgcd 求解形如 \(a\cdot x + b\cdot y = \gcd(a,b)\) 的不定方程的任意一组解。 int exgcd(int a, int b, int &x, int &y) {if (!b) {x = 1, y = 0;return a;}int d = exgcd(b, a % b, y, x);y…

离散对数 bsgs 与 exbsgs

离散对数 bsgs 与 exbsgs 以 \(\mathcal O(\sqrt {P})\) 的复杂度求解 \(a^x \equiv b(\bmod P)\) 。其中标准 \(\tt BSGS\) 算法不能计算 \(a\) 与 \(MOD\) 互质的情况,而 exbsgs 则可以。 namespace BSGS { LL a, …

防爆模乘

防爆模乘 借助浮点数实现 以 \(\mathcal O(1)\) 计算 \(a\cdot b\bmod p\) ,由于不取模,常数比 int128 法小很多。其中 \(1 \le n, k, p \le 10^{18}\) 。 int mul(int a, int b, int m) {int r = a * b - m * (int)…

欧拉筛(线性筛)

欧拉筛(线性筛) 时间复杂度为 \(\mathcal{O}(N\log\log N)\) 。 vector<int> prime; // 这里储存筛出来的全部质数 auto euler_Prime = [&](int n) -> void {vector<int> v(n + 1);for (int i = …

常见数列

常见数列 调和级数 满足调和级数 \(\mathcal O\left( \dfrac{N}{1} +\dfrac{N}{2}+\dfrac{N}{3}+\dots + \dfrac{N}{N} \right)\),可以用 $ \approx N\ln N$ 来拟合,但是会略小,误差量级在 \(10\%\) 左右。本地可以…

20232314 2025-2026-1 《网络与系统攻防技术》实验三实验报告

一.实验内容(1)正确使用msf编码器,veil-evasion,自己利用shellcode编程等免杀工具或技巧。正确使用msf编码器,使用msfvenom生成如jar之类的其他文件 veil,加壳工具 使用C + shellcode编程 (2)通过组合应用各种技术…

【LTDC】LTDC 简介

前言 此篇文章仅作笔记分享,内容来源为:【正点原子】全是干货 | 手把手教你学STM32的LTDC这一节课目的就是了解一下 LTDC 的各种特点,方便后面学习。 LTDC 简介控制器框图信号线 注意不同芯片会有不同的引脚对应。 …