{
  "schemaVersion": "0.11.0",
  "canonical": "https://www.pystone.net/notes/airtest-project-knowledge-overview/",
  "atlas": "https://www.pystone.net/?node=airtest-project-knowledge-overview#knowledge-atlas",
  "markdown": "https://www.pystone.net/notes/airtest-project-knowledge-overview.md",
  "context": "https://www.pystone.net/notes/airtest-project-knowledge-overview.context.json",
  "knowledgeVersion": "224c990773de.5fa8af6e39fa",
  "build": {
    "siteCommit": "224c990773de166d23a886306577dd90379529ce",
    "notesCommit": "5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a",
    "builtAt": "1970-01-01T00:00:00.000Z",
    "version": "224c990773de.5fa8af6e39fa"
  },
  "id": "note:airtest-project-knowledge-overview",
  "slug": "airtest-project-knowledge-overview",
  "title": "【自动化测试】Airtest Project知识体系",
  "type": "note",
  "visibility": "public",
  "idStability": "rename-stable",
  "author": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "publisher": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "aliases": [],
  "summary": "【自动化测试】Airtest Project知识体系",
  "contentRole": "unspecified",
  "isMoc": false,
  "mocRecognition": "none",
  "generated": false,
  "attribution": "unspecified",
  "domain": "10-计算机、信息技术与工程",
  "tags": [],
  "mocs": [],
  "contentHash": "4e06f92ad69ea1c650e885192f8cd64fdbcfe7a66741ff1a89f78ee7d30fdf62",
  "assets": [
    {
      "reference": "assets/1620210507511.png",
      "url": "/media/2391eadca53bea7f902a.png",
      "mediaType": "image/png",
      "contentHash": "2391eadca53bea7f902af2049ff1f219d096e3ffba2d8d41effb8eef23563415",
      "byteLength": 92678,
      "width": 1172,
      "height": 1007
    },
    {
      "reference": "assets/1620206590873.png",
      "url": "/media/11879b9db111f13bdd78.png",
      "mediaType": "image/png",
      "contentHash": "11879b9db111f13bdd780a2c0964084f93805f2e802a37ef41695459a23f98a3",
      "byteLength": 35028,
      "width": 740,
      "height": 262
    },
    {
      "reference": "assets/1620210076038.png",
      "url": "/media/b13a289464c377959b6f.png",
      "mediaType": "image/png",
      "contentHash": "b13a289464c377959b6f993ede6fce34a6d3878bfc9f66729fa01b19c5db5ce0",
      "byteLength": 30743,
      "width": 621,
      "height": 203
    }
  ],
  "headings": [
    {
      "depth": 1,
      "text": "【自动化测试】Airtest Project知识体系",
      "anchor": "自动化测试airtest-project知识体系",
      "citation": "https://www.pystone.net/notes/airtest-project-knowledge-overview/#%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95airtest-project%E7%9F%A5%E8%AF%86%E4%BD%93%E7%B3%BB"
    },
    {
      "depth": 2,
      "text": "自动化测试概述",
      "anchor": "自动化测试概述",
      "citation": "https://www.pystone.net/notes/airtest-project-knowledge-overview/#%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E6%A6%82%E8%BF%B0"
    },
    {
      "depth": 3,
      "text": "为什么需要自动化测试",
      "anchor": "为什么需要自动化测试",
      "citation": "https://www.pystone.net/notes/airtest-project-knowledge-overview/#%E4%B8%BA%E4%BB%80%E4%B9%88%E9%9C%80%E8%A6%81%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95"
    },
    {
      "depth": 3,
      "text": "自动化测试的痛点",
      "anchor": "自动化测试的痛点",
      "citation": "https://www.pystone.net/notes/airtest-project-knowledge-overview/#%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E7%9A%84%E7%97%9B%E7%82%B9"
    },
    {
      "depth": 3,
      "text": "相关技术",
      "anchor": "相关技术",
      "citation": "https://www.pystone.net/notes/airtest-project-knowledge-overview/#%E7%9B%B8%E5%85%B3%E6%8A%80%E6%9C%AF"
    },
    {
      "depth": 2,
      "text": "Airtest测试套件",
      "anchor": "airtest测试套件",
      "citation": "https://www.pystone.net/notes/airtest-project-knowledge-overview/#airtest%E6%B5%8B%E8%AF%95%E5%A5%97%E4%BB%B6"
    },
    {
      "depth": 3,
      "text": "Airtest框架",
      "anchor": "airtest框架",
      "citation": "https://www.pystone.net/notes/airtest-project-knowledge-overview/#airtest%E6%A1%86%E6%9E%B6"
    },
    {
      "depth": 4,
      "text": "图像识别原理",
      "anchor": "图像识别原理",
      "citation": "https://www.pystone.net/notes/airtest-project-knowledge-overview/#%E5%9B%BE%E5%83%8F%E8%AF%86%E5%88%AB%E5%8E%9F%E7%90%86"
    },
    {
      "depth": 3,
      "text": "poco框架",
      "anchor": "poco框架",
      "citation": "https://www.pystone.net/notes/airtest-project-knowledge-overview/#poco%E6%A1%86%E6%9E%B6"
    },
    {
      "depth": 4,
      "text": "Poco原理",
      "anchor": "poco原理",
      "citation": "https://www.pystone.net/notes/airtest-project-knowledge-overview/#poco%E5%8E%9F%E7%90%86"
    },
    {
      "depth": 4,
      "text": "RPC协议",
      "anchor": "rpc协议",
      "citation": "https://www.pystone.net/notes/airtest-project-knowledge-overview/#rpc%E5%8D%8F%E8%AE%AE"
    },
    {
      "depth": 3,
      "text": "airtestIDE",
      "anchor": "airtestide",
      "citation": "https://www.pystone.net/notes/airtest-project-knowledge-overview/#airtestide"
    },
    {
      "depth": 3,
      "text": "多设备并行测试技术",
      "anchor": "多设备并行测试技术",
      "citation": "https://www.pystone.net/notes/airtest-project-knowledge-overview/#%E5%A4%9A%E8%AE%BE%E5%A4%87%E5%B9%B6%E8%A1%8C%E6%B5%8B%E8%AF%95%E6%8A%80%E6%9C%AF"
    },
    {
      "depth": 3,
      "text": "优缺点",
      "anchor": "优缺点",
      "citation": "https://www.pystone.net/notes/airtest-project-knowledge-overview/#%E4%BC%98%E7%BC%BA%E7%82%B9"
    },
    {
      "depth": 2,
      "text": "Ref",
      "anchor": "ref",
      "citation": "https://www.pystone.net/notes/airtest-project-knowledge-overview/#ref"
    }
  ],
  "claims": [],
  "outgoing": [],
  "incoming": [
    {
      "id": "note:software-engineering-and-quality",
      "title": "软件工程与质量保障",
      "url": "https://www.pystone.net/notes/software-engineering-and-quality/",
      "atlas": "https://www.pystone.net/?node=software-engineering-and-quality#knowledge-atlas",
      "label": "软件工程与质量保障",
      "origin": "explicit",
      "humanReviewed": true,
      "context": "CI-CD与质量保障/CI-CD工具链中的“【自动化测试】Airtest Project知识体系”导航项",
      "citation": "https://www.pystone.net/notes/software-engineering-and-quality/#ci-cd%E4%B8%8E%E8%B4%A8%E9%87%8F%E4%BF%9D%E9%9A%9Cci-cd%E5%B7%A5%E5%85%B7%E9%93%BE"
    },
    {
      "id": "note:software-delivery-automation-quality",
      "title": "软件交付、自动化与工程质量",
      "url": "https://www.pystone.net/notes/software-delivery-automation-quality/",
      "atlas": "https://www.pystone.net/?node=software-delivery-automation-quality#knowledge-atlas",
      "label": "软件交付、自动化与工程质量",
      "origin": "explicit",
      "humanReviewed": true,
      "context": "Airtest Project 知识体系是游戏自动化测试的工具与工程实践。",
      "citation": "https://www.pystone.net/notes/software-delivery-automation-quality/#%E8%87%AA%E5%8A%A8%E5%8C%96%E5%8F%8D%E9%A6%88"
    }
  ],
  "contentMarkdown": "# 【自动化测试】Airtest Project知识体系\n\n> 创建时间：2021/5/5 15:03\n\n  * 【自动化测试】Airtest Project知识体系\n    * 自动化测试概述\n      * 为什么需要自动化测试\n      * 自动化测试的痛点\n      * 相关技术\n    * Airtest测试套件\n      * Airtest框架\n        * 图像识别原理\n      * poco框架\n        * Poco原理\n        * RPC协议\n      * airtestIDE\n      * 多设备并行测试技术\n      * 优缺点\n    * Ref\n\n## 自动化测试概述\n\n游戏测试相关的资料与工具等：<https://github.com/jianbing/awesome-game-tester>\n\n自动化测试，就是把繁杂的人工测试用例利用自动化测试工具编写成代码，让机器代替人工自动跑用例的过程。实际上就是把以人为驱动的测试行为转化为机器执行的一种过程。\n\n节省人力、物力、时间、硬件资源等，提升测试效率，特别对于繁琐重复的测试用例，可以使测试人员更专注于新的测试模块的建立和开发，从而提高测试覆盖率。\n\n### 为什么需要自动化测试\n\n刘欣的回答：\n\n  * 安卓手机的碎片化问题非常严重，通常网易游戏出品的游戏上线前要测试200款型号的手机。人工来做兼容性测试非常痛苦，容易出错，耗时长，自动化在这里的作用非常明显。\n\n  * 游戏的迭代更新快，如何保证每周更新不会影响已有的内容，就需要用自动化的方式进行回归测试。通常我们的一个大型游戏每周更新前会运行数十个小时的自动化测试，如果不用自动化，那根本跟不上。\n\n### 自动化测试的痛点\n\n  * 游戏迭代太快，需要高效的脚本编写。\n\n  * 引擎及UI种类多，很难跨引擎实现通用。\n\n> Airtest框架本身基于图像识别所以平台无关。而poco框架在appium那里已经有了启发，为游戏引擎写一个SDK来dump控件树，只要协议对那么测试工具本身不需要修改，不依赖于具体的游戏引擎和UI实现。而Poco-sdk是开源的，意味着如果自己的UI实现方式比较特别还可以自己开发符合自己项目的SDK。\n\n  * 跨平台的模拟输入\n\n  * 游戏软件组成复杂。同时解决 原生android UI、游戏内UI的测试（游戏内你还得按情况决定是直接用图像识别还是直接定位物体，因为能交互的东西不一定是UI元素）。\n\n### 相关技术\n\n  * dump UI树的方式（poco）\n\n  * 基于OpenCV的图像识别技术（Airtest）\n\n  * 采用机器学习和强化学习结合的算法创造AI，可以与真是玩家进行对战。\n\n## Airtest测试套件\n\n![Alt text](assets/1620210507511.png)\n\n网易QA总监访谈：<https://www.oschina.net/question/3820517_2278684>\n\n### Airtest框架\n\n基于 **设备层模拟输入** 和 **图像识别** 的测试框架。基于图像识别，因此平台无关。\n\n> **Sikuli** \\- MIT的研究人员设计的图形脚本语言Sikuli，使用截图的方式组织程序。直基于图像识别控件而不是具体内存里的控件对象，因此不会产生不兼容的问题。\n>  **ATX(AutomatorX)** \\- 一款开源的自动化测试工具，支持测试iOS平台和Android平台的原生应用、游戏、Web应用。\n\n  * 网易的Airtest基于网易的ATX(<https://github.com/NetEaseGame/ATX>)\n\n  * ATX使用了基于opencv的图像识别库aircv\n\n  * ATX感谢了Sikuli语言(<http://sikulix-2014.readthedocs.org/en/latest/index.html>)\n\n![Alt text](assets/1620206590873.png)\n\n#### 图像识别原理\n\n![Alt text](assets/1620210076038.png)\n\n引用：<https://toutiao.io/posts/r7hdp1/preview>\n\n主要采用了 OpenCV 中的模板匹配和 SIFT 特征值匹配。其中模板匹配对于分辨率相同的输入效果非常完美，但是由于手机分辨率各不相同，我们需要采用 SIFT 特征值匹配来解决这个问题。\n\nSIFT 特征值具有的尺度不变性和旋转不变性满足了这个要求，但是运行效率和识别率都不够。于是我们进一步研究了常用游戏引擎的 UI 适配规则，内置了 Cocos 引擎的适配规则，同时暴露了 API 让游戏开发者明确指定自己游戏的分辨率适配算法。\n\nOpenCV模板匹配、特征点匹配知识：\n\n  * <https://blog.csdn.net/zhuisui_woxin/article/details/84400439>\n\n  * <https://blog.csdn.net/Amber_2015/article/details/108784345>\n\n  * <https://testerhome.com/articles/23816>\n\n### poco框架\n\n基于 **游戏引擎 UI 控件检索** 的测试框架。\n\n类似框架：\n\n  * Poco - 网易\n\n  * GAutomator - Tencent (<https://github.com/Tencent/GAutomator>)\n\n  * uiautomator for python-(<https://github.com/xiaocong/uiautomator>) 利用 Android 系统的控件结构来做自动化，通常是测试代码直接在安卓手机上运行。但是仅限于 Android，而且需要有 Android 开发经验，对技术水平要求较高。\n\n  * appium - (<https://github.com/appium/appium>) 被测应用通过 webdriver 协议与外部工具通信，再进行自动化测试。目前这套方案协议层做得不错，覆盖大部分的端，但是外部工具门槛较高，也不适合测试人员使用。\n\n> xiaocong的uiautomator只能抓取原生android的控件树，抓不了其他游戏引擎的，所以Poco和GAutomator就多做了一件事情那就是给各个游戏引擎开发SDK，把 **控件树** 数据 **dump** 出来然后回传，这样我们才能够在的Inspector工具里看到游戏内的控件树。而这个所谓的SDK本质上就是一个TCPServer跑在游戏里。\n\n#### Poco原理\n\n参考了安卓测试框架 UIAutomator 和 Web 测试框架 Selenium，获取到整个 UI 系统的树状结构，然后递归查找到需要操作的 UI 控件，再调用引擎或者设备接口进行模拟操作。\n\nSDK 在游戏内启动了一个 RpcServer，外部的 Python 测试框架通过 JSONRPC 调用 SDK 的方法抓取游戏的控件树。再通过 Airtest IDE 显示整个 UI 层次结构，通过模拟输入进行自动化操作。\n\n#### RPC协议\n\nRPC协议（Remote Procedure Call Protocol， **远程过程调用协议** ）：一种通过网络从远程计算机程序上请求服务，而不需要了解底层网络技术的协议。\n\nRPC协议假定某些传输协议的存在，如TCP或UDP，为通信程序之间携带信息数据。在OSI网络通信模型中，RPC跨越了传输层和应用层。RPC使得开发包括网络分布式多程序在内的应用程序更加容易。\nRPC采用客户机/服务器模式。请求程序就是一个客户机，而服务提供程序就是一个服务器。首先，调用进程发送一个有进程参数的调用信息到服务进程，然后等待应答信息。在服务器端，进程保持睡眠状态直到调用信息的到达为止。当一个调用信息到达，服务器获得进程参数，计算结果，发送答复信息，然后等待下一个调用信息，最后，客户端调用过程接收答复信息，获得进程结果，然后调用执行继续进行。\n\n### airtestIDE\n\nIDE整合了airtest和poco两大框架，提供了 adb工具、poco-inspector（抓ui控件）、设备屏录、图形化的脚本编辑器、便捷的ui截图工具等等一系列东西。\n\n### 多设备并行测试技术\n\n<https://github.com/AirtestProject/multi-device-runner>\n\n### 优缺点\n\n优点：\n跨平台、跨引擎\n上手门槛低、上限足够高\n灵活扩展、可规模化\n经过验证、有大量的最佳实践 - 在网易游戏内部，自动化技术已经应用在梦幻西游、大话西游、阴阳师等数十个产品，上千个自动化脚本累计运行上万小时\n\n  * 识别率不高，控件定位不够准确。如果存在控件\n\n## Ref\n\n<https://www.zhihu.com/question/269270386>\n<https://toutiao.io/posts/r7hdp1/preview>\n<https://blog.csdn.net/zhuisui_woxin/article/details/84400439>\n"
}
