03-UI自动化遍历工具-appcrawler

简介: 03-UI自动化遍历工具-appcrawler

appcrawler介绍

  • 一个基于自动遍历的app爬虫工具. 支持android和iOS, 支持真机和模拟器. 最大的特点是灵活性. 可通过配置来设定遍历的规则.

  优点

  • 跨平台性:AppCrawler是基于appium开发的,所以支持Android和IOS
  • 可控性:对测试的页面,控件类型的选择,测试的深度等都可自由控制
  • 可定制:可自定义操作,如输入,滑动等

   缺点

  • 运行速度较慢:AppCrawler是基于appium开发具备了跨平台的优点,但是也因为这层封装造成了运行速度相对较慢
  • 使用门槛高:正因为使用灵活性的问题,也造成了使用门槛的提高,主要基于yaml文件中使用appium的相关技术知识进行配置,这就对使用者有了一定的技术要求

下载与启动

   下载

   启动  

   说明:需要 java和appium环境

  • step1 :启动appium :  appium --session-override

  • step2:启动appcrawler :java -jar appcrawler-2.4.0-jar.jar --capability "appPackage=com.taobao.taobao,appActivity=com.taobao.tao.welcome.Welcome" -o result

  • 遍历原则:它的遍历原则是,找页面的里层次最深的元素,也就是处于中心位置元素会被优先遍历
  • 测试结果:如果没有使用-o参数指定log输出的路径,appcrawler就会在当前目录下生成以时间为命名的文件夹,里面保存了所有的数据,文件、截图、log
  • 测试报告:在测试log中有一个index.html文件,打开它会看到刚才运行的测试报告

 

配置文件启动

step1:生成配置文件模板:java -jar appcrawler-2.4.0-jar.jar --demo

  • 配置文件demo.yml如下
1. ---
2. pluginList: []
3. saveScreen: true
4. reportTitle: ""
5. resultDir: "20210307174024"
6. waitLoading: 500
7. waitLaunch: 6000
8. showCancel: true
9. maxTime: 10800
10. maxDepth: 10
11. capability:
12.   noReset: "true"
13.   fullReset: "false"
14.   appium: "http://127.0.0.1:4723/wd/hub"
15. testcase:
16.   name: "TesterHome AppCrawler"
17.   steps:
18.   - given: []
19.     when: null
20.     then: []
21.     xpath: "/*"
22.     action: "Thread.sleep(5000)"
23.     actions: []
24.     times: 0
25. selectedList:
26. - given: []
27.   when: null
28.   then: []
29.   xpath: "//*[contains(name(), 'Button')]"
30.   action: null
31.   actions: []
32.   times: 0
33. - given: []
34.   when: null
35.   then: []
36.   xpath: "//*[contains(name(), 'Text') and @clickable='true' and string-length(@text)<10]"
37.   action: null
38.   actions: []
39.   times: 0
40. - given: []
41.   when: null
42.   then: []
43.   xpath: "//*[@clickable='true']/*[contains(name(), 'Text') and string-length(@text)<10]"
44.   action: null
45.   actions: []
46.   times: 0
47. - given: []
48.   when: null
49.   then: []
50.   xpath: "//*[contains(name(), 'Image') and @clickable='true']"
51.   action: null
52.   actions: []
53.   times: 0
54. - given: []
55.   when: null
56.   then: []
57.   xpath: "//*[@clickable='true']/*[contains(name(), 'Image')]"
58.   action: null
59.   actions: []
60.   times: 0
61. - given: []
62.   when: null
63.   then: []
64.   xpath: "//*[contains(name(), 'Image') and @name!='']"
65.   action: null
66.   actions: []
67.   times: 0
68. - given: []
69.   when: null
70.   then: []
71.   xpath: "//*[contains(name(), 'Text') and @name!='' and string-length(@label)<10]"
72.   action: null
73.   actions: []
74.   times: 0
75. firstList: []
76. lastList:
77. - given: []
78.   when: null
79.   then: []
80.   xpath: "//*[@selected='true']/..//*"
81.   action: null
82.   actions: []
83.   times: 0
84. - given: []
85.   when: null
86.   then: []
87.   xpath: "//*[@selected='true']/../..//*"
88.   action: null
89.   actions: []
90.   times: 0
91. backButton:
92. - given: []
93.   when: null
94.   then: []
95.   xpath: "Navigate up"
96.   action: null
97.   actions: []
98.   times: 0
99. triggerActions:
100. - given: []
101.   when: null
102.   then: []
103.   xpath: "share_comment_guide_btn"
104.   action: null
105.   actions: []
106.   times: 0
107. xpathAttributes:
108. - "name"
109. - "label"
110. - "value"
111. - "resource-id"
112. - "content-desc"
113. - "instance"
114. - "text"
115. sortByAttribute:
116. - "depth"
117. - "list"
118. - "selected"
119. findBy: "default"
120. defineUrl: []
121. baseUrl: []
122. appWhiteList: []
123. urlBlackList: []
124. urlWhiteList: []
125. blackList:
126. - given: []
127.   when: null
128.   then: []
129.   xpath: ".*[0-9]{2}.*"
130.   action: null
131.   actions: []
132.   times: 0
133. beforeRestart: []
134. beforeElement:
135. - given: []
136.   when: null
137.   then: []
138.   xpath: "/*"
139.   action: "Thread.sleep(500)"
140.   actions: []
141.   times: 0
142. afterElement: []
143. afterPage: []
144. afterPageMax: 2
145. tagLimitMax: 2
146. tagLimit:
147. - given: []
148.   when: null
149.   then: []
150.   xpath: "确定"
151.   action: null
152.   actions: []
153.   times: 1000
154. - given: []
155.   when: null
156.   then: []
157.   xpath: "取消"
158.   action: null
159.   actions: []
160.   times: 1000
161. - given: []
162.   when: null
163.   then: []
164.   xpath: "share_comment_guide_btn_name"
165.   action: null
166.   actions: []
167.   times: 1000
168. assertGlobal: []

step2:配置参数

  • capability 配置如下
1. capability:
2.   noReset: "true"
3.   fullReset: "false"
4.   appium: "http://127.0.0.1:4723/wd/hub"
5.   appPackage: com.taobao.taobao
6.   appActivity: com.taobao.tao.welcome.Welcome
7.   automationName: uiautomator2
8.   autoGrantPermissions: true

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

  • given: 所有的先决条件,给定一个条件,只有条件成立的时候才完成后面的操作(实际用的较少)
  • when: 先决条件成立后的行为,对什么事件做什么事情
  • then: 断言集合,事件结束后对结果断言
1. testcase:
2.   name: "TesterHome AppCrawler"
3.   steps:
4.    - when: 
5.    xpath: //*
6.    action: click
7.    - when: 
8.    xpath: //*
9.    action: click
10.      then: 
11.      - //*[contains(@text, '文案')]

  action的动作支持

  • "" :只是截图记录
  • back:后退
  • backApp:回退到当前的App,默认等价于back行为 可定制
  • monkey:随机事件
  • xxx()执行代码:
  • Thread.sleep(1000)
  • driver.swipe(0.9,0.8,0.9,0.5)
  • click:点击事件
  • longTap:长按
  • 除以上所有行为外均视为输入行为

    selectedList:遍历范围设定,设置让其点击所有可点击的TextView和ImageView控件,修改完成如下:

1. selectedList:
2. - xpath: //android.widget.ImageView[@clickable='true']
3. - xpath: //*[@clickable='true' and contains(@class,"Text")]

   firstList:优先被点击

   lastList:最后执行,设置成点击确定按钮

1. lastList:
2. - { xpath: "//*[text()='确定']", action: click }
  • backButton:当所有元素都被点击后默认后退控件定位
  • blackList:黑名单
  • triggerAction: 特定条件出发执行动作的设置
  • agLimitMax: 全局设置,同类型的最多点击的次数;这里设置为2次
tagLimitMax: 2

    tagLimit: 自定义控件类型的点击次数,这里设置对于ListView类型的只点击一次;修改完成如下

- { xpath: "//*[contains(@class, 'List')]//*", times: 1 }

    maxDepth: 遍历的最大深度

    assertGlobal:设置一个全局断言,例如可设置断言在当前App,如果包名不符合,就可能发生了崩溃,便会报错

  配置文件:进入淘宝分类页面

1. ---
2. pluginList: []
3. saveScreen: true
4. reportTitle: ""
5. resultDir: "20210307174024"
6. waitLoading: 500
7. waitLaunch: 6000
8. showCancel: true
9. maxTime: 10800
10. maxDepth: 10
11. capability:
12.   noReset: "true"
13.   fullReset: "false"
14.   appium: "http://127.0.0.1:4723/wd/hub"
15.   appPackage: com.taobao.taobao
16.   appActivity: com.taobao.tao.welcome.Welcome
17.   automationName: uiautomator2
18.   autoGrantPermissions: true
19. testcase:
20.   name: "进入分类页面"
21.   steps:
22.   - given: []
23.     when: null
24.     then: []
25.     xpath: "//*[@text='分类']"
26.     action: click
27.     actions: []
28.     times: 0
29. 
30. selectedList:
31. - given: []
32.   when: null
33.   then: []
34.   xpath: "//*[contains(name(), 'Button')]"
35.   action: null
36.   actions: []
37.   times: 0
38. - given: []
39.   when: null
40.   then: []
41.   xpath: "//*[contains(name(), 'Text') and @clickable='true' and string-length(@text)<10]"
42.   action: null
43.   actions: []
44.   times: 0
45. - given: []
46.   when: null
47.   then: []
48.   xpath: "//*[@clickable='true']/*[contains(name(), 'Text') and string-length(@text)<10]"
49.   action: null
50.   actions: []
51.   times: 0
52. - given: []
53.   when: null
54.   then: []
55.   xpath: "//*[contains(name(), 'Image') and @clickable='true']"
56.   action: null
57.   actions: []
58.   times: 0
59. - given: []
60.   when: null
61.   then: []
62.   xpath: "//*[@clickable='true']/*[contains(name(), 'Image')]"
63.   action: null
64.   actions: []
65.   times: 0
66. - given: []
67.   when: null
68.   then: []
69.   xpath: "//*[contains(name(), 'Image') and @name!='']"
70.   action: null
71.   actions: []
72.   times: 0
73. - given: []
74.   when: null
75.   then: []
76.   xpath: "//*[contains(name(), 'Text') and @name!='' and string-length(@label)<10]"
77.   action: null
78.   actions: []
79.   times: 0
80. firstList: []
81. lastList:
82. - given: []
83.   when: null
84.   then: []
85.   xpath: "//*[@selected='true']/..//*"
86.   action: null
87.   actions: []
88.   times: 0
89. - given: []
90.   when: null
91.   then: []
92.   xpath: "//*[@selected='true']/../..//*"
93.   action: null
94.   actions: []
95.   times: 0
96. backButton:
97. - given: []
98.   when: null
99.   then: []
100.   xpath: "Navigate up"
101.   action: null
102.   actions: []
103.   times: 0
104. triggerActions:
105. - given: []
106.   when: null
107.   then: []
108.   xpath: 
109.   action: 
110.   actions: []
111.   times: 0
112. xpathAttributes:
113. - "name"
114. - "label"
115. - "value"
116. - "resource-id"
117. - "content-desc"
118. - "instance"
119. - "text"
120. sortByAttribute:
121. - "depth"
122. - "list"
123. - "selected"
124. findBy: "default"
125. defineUrl: []
126. baseUrl: []
127. appWhiteList: []
128. urlBlackList: []
129. urlWhiteList: []
130. blackList:
131. - given: []
132.   when: null
133.   then: []
134.   xpath: ".*[0-9]{2}.*"
135.   action: null
136.   actions: []
137.   times: 0
138. beforeRestart: []
139. beforeElement:
140. - given: []
141.   when: null
142.   then: []
143.   xpath: "/*"
144.   action: "Thread.sleep(500)"
145.   actions: []
146.   times: 0
147. afterElement: []
148. afterPage: []
149. afterPageMax: 2
150. tagLimitMax: 2
151. tagLimit:
152. - given: []
153.   when: null
154.   then: []
155.   xpath: "È·¶¨"
156.   action: null
157.   actions: []
158.   times: 1000
159. - given: []
160.   when: null
161.   then: []
162.   xpath: "È¡Ïû"
163.   action: null
164.   actions: []
165.   times: 1000
166. - given: []
167.   when: null
168.   then: []
169.   xpath: "share_comment_guide_btn_name"
170.   action: null
171.   actions: []
172.   times: 1000
173. assertGlobal: []

 step3:配置文件启动:java -jar appcrawler-2.4.0-jar.jar -c demo.yml

相关文章
|
运维 Prometheus 监控
3 年部署经验总结:用自动化工具轻松管理 300+ 服务器开源软件
三年前接手公司IT部门时,我满怀信心,却发现部署效率低下。尽管使用了GitLab、Jenkins、Zabbix等100+开源工具,部署仍耗时费力。文档厚重如百科,却难解实际困境。一次凌晨三点的加班让我下定决心改变现状。偶然看到一篇国外博客,介绍了自动化部署的高效方式,我深受启发。
534 0
|
机器学习/深度学习 人工智能 测试技术
EdgeMark:嵌入式人工智能工具的自动化与基准测试系统——论文阅读
EdgeMark是一个面向嵌入式AI的自动化部署与基准测试系统,支持TensorFlow Lite Micro、Edge Impulse等主流工具,通过模块化架构实现模型生成、优化、转换与部署全流程自动化,并提供跨平台性能对比,助力开发者在资源受限设备上高效选择与部署AI模型。
1140 9
EdgeMark:嵌入式人工智能工具的自动化与基准测试系统——论文阅读
|
人工智能 搜索推荐 UED
一个牛逼的国产AI自动化工具,开源了 !
AiPy是国产开源AI工具,结合大语言模型与Python,支持本地部署。用户只需用自然语言描述需求,即可自动生成并执行代码,轻松实现数据分析、清洗、可视化等任务,零基础也能玩转编程,被誉为程序员的智能助手。
|
人工智能 数据可视化 数据挖掘
团队日报不用愁!自动化生成工具亲测:任务进度实时同步
本文深入分析了传统手动日报在数据孤岛、格式混乱和时效性差三大痛点,并探讨了自动化日报带来的效率提升、决策优化等四大核心价值。通过对板栗看板、SmartBrief、n8n 等六款主流工具的功能、适用场景及实战效果进行测评,为企业提供科学的选型建议与实施路径。
团队日报不用愁!自动化生成工具亲测:任务进度实时同步
|
Java 测试技术 API
自动化测试工具集成及实践
自动化测试用例的覆盖度及关键点最佳实践、自动化测试工具、集成方法、自动化脚本编写等(兼容多语言(Java、Python、Go、C++、C#等)、多框架(Spring、React、Vue等))
1035 6
|
数据采集 人工智能 API
推荐一款Python开源的AI自动化工具:Browser Use
Browser Use 是一款基于 Python 的开源 AI 自动化工具,融合大型语言模型与浏览器自动化技术,支持网页导航、数据抓取、智能决策等操作,适用于测试、爬虫、信息提取等多种场景。
1821 4
推荐一款Python开源的AI自动化工具:Browser Use
|
人工智能 供应链 数据可视化
工作流梳理工具实战教程:手把手教你绘制第一张自动化流程图
本文剖析了团队因流程混乱导致重复劳动和效率低下的问题,提出通过工作流梳理提升协作效率的解决方案。总结了流程梳理的六大核心需求,并深度测评了6款主流工具,国内有板栗看板那,国外有kiss flow结合团队规模与需求提供选型建议,助力企业高效落地流程优化。
|
人工智能 缓存 自然语言处理
86_自动化提示:AutoPrompt工具
在当今人工智能领域,提示工程(Prompt Engineering)已成为释放大语言模型(LLM)潜能的关键技术。随着LLM规模和能力的不断增长,如何设计高效、精确的提示词成为研究和应用的焦点。然而,传统的手工提示工程面临着巨大挑战
828 0
|
运维 监控 持续交付
还在为部署开源工具烦恼?自动化部署工具 Websoft9一键部署 300+ 开源应用
在数字化时代,开源工具因免费、灵活、可定制等特性广受欢迎,但其部署过程却常因环境配置复杂、依赖繁琐、耗时长等问题令人头疼。本文介绍了传统部署的三大难点,并提出两种解决方案:传统手动部署与集成化控制台部署。
还在为部署开源工具烦恼?自动化部署工具 Websoft9一键部署 300+ 开源应用
|
运维 Kubernetes Devops
2025年10款主流开源自动化部署工具介绍
随着企业数字化转型加速,DevOps理念普及,自动化部署工具成为提升软件交付效率的关键。本文盘点2025年最具代表性的10款开源部署工具,涵盖从中小企业到大型企业的多样化需求,助力技术团队精准选型,打造高效、稳定的持续交付体系。
3356 1