Alipay non-invasive Android open source automated testing tool Soloπ

Soloπ (SoloPi) is a wireless technology Alipay open-source, non-invasive tool for automated testing of Android, Beta has recorded playback, performance testing, a machine control three main functions, can save valuable time for the test developer.

This article is SoloPi team depth explanation about the project,

Author: Qiaorui Kai, ants gold dress Advanced Wireless Development Engineer

Foreword

In recent years, with the rapid development of mobile Internet, mobile testing technology has also made considerable progress, from early on stand-alone automated test scripts, to the recording playback, image recognition, cloud test platform testing techniques fit the actual business application needs depth and innovation, in order to test the efficiency is raised again and again.

This paper describes a wireless payment, non-invasive, free Android Root of special test program Soloπ treasure implemented on the mobile side. Direct manipulation of the phone, you can automate the functionality, performance, compatibility, and stability testing work.

Mobile Test 1.0 times

Mobile test 1.0 times, it can also be called the exploration period. Tired of the day to day operation manual, how to improve testing efficiency has become the most important issue moving testing, during this period, in addition to tools Monkey, UiAutomator, Instruments and other official, the industry also emerged a number of outstanding open source automated testing tool / framework, based on the ability to drive automation, verification can be achieved not only basic functions can also be combined performance collection program, traversal algorithms to automate the various special tests. At this stage, a common form of automated testing is to deploy a test environment on a single machine or a few local stations PC, then use other tools to achieve Jenkins continuous integration.

Alipay non-invasive Android open source automated testing tool Soloπ

 

Mobile Test 2.0 era

With the continuous development of testing technology, and benefit from open source STF, the industry began to test the concept of the cloud platform, the real machine equipment, task management, test automation framework and special programs packaged in platform as a service, to make for users a one-stop testing experience. On the other hand, the introduction of remote debugging, equipment scheduling technology greatly improved utilization of equipment, lack of testers no longer need to test equipment or test time-consuming task queue to worry about. Test platform for cloud users, at this stage of testing common forms are: to develop test scripts on a local PC, then upload to cloud test platform to perform the last test report can be viewed in the platform, the testing process is simple and clear.

Alipay non-invasive Android open source automated testing tool Soloπ

 

移动测试 2.0+

在保留了上述“云测”的玩法之外,移动测试 2.0+ 时代下的测试技术提供的往往不再是某一个独立的小工具,更多的是带来一套完整的解决方案,例如为用户提供一套定制化的 IDE 环境,结合录制回放、图像识别等技术,用户可能只需要做一些简单的框选、拖拽就能完成测试脚本的开发。另一方面,由于办公环境、硬件条件等因素的限制,越来越多的测试人员希望可以在移动端上直接发起测试,做到移动测试“移动测”。当然,无论是云端、IDE 端、还是移动端,都应该做到能力互通,即“多端多通”,这样才能让测试方案更加灵活、适用于更多场景。

Alipay non-invasive Android open source automated testing tool Soloπ

 

Alipay non-invasive Android open source automated testing tool Soloπ

 

无线驱动的Android专项测试方案:Soloπ

“多端多通”的概念比较广,仅凭一篇文章可能无法阐述清楚,所以下面将会重点介绍为了迎接“移动 2.0+”时代,我们在移动端上实现的一套无线化、非侵入、免 Root 的 Android 专项测试方案 Soloπ。直接操控手机,即可实现自动化的功能、性能、兼容性、以及稳定性测试等工作。

整体架构

Alipay non-invasive Android open source automated testing tool Soloπ

 

这套方案中,底层依赖主要是“无线 ADB、系统辅助功能、Chrome 调试以及图像识别技术”,后文将会介绍它们具体的应用场景。同时,在底层依赖的基础上,我们封装了一套核心能力,由“控件定位、事件驱动、性能采集以及依赖注入”组成,并在服务层实现了录制、回放、数据处理等公共服务能力。在架构的最顶端,结合界面交互逻辑包装出了各个功能的入口。

无线 ADB

Alipay non-invasive Android open source automated testing tool Soloπ

 

大家都知道,对于 Android 自动化,ADB shell 的执行能力是一切的基础。

在 PC 上,通过 Android SDK 提供的ADB client 与同样运行于 PC 中的 ADB server 通信,再由 ADB server 通过 USB 与位于设备中的 Adbd 通信。要实现一套无线化的方案,必须要摆脱对 USB 线的依赖。好在 Android 系统还提供了一种基于 Socket 的 ADB 连接模式,既然是这样,那么只需要按照 ADB 通信协议在端上与本机的 5555 端口进行通信即可获得 ADB shell 的执行能力。

目前已经有一些实现 ADB 通信协议的 Java 开源项目,如 AdbLib ,他们封装了一套 ADB 的调试通信服务,能够替代 PC 上 ADB Server 的角色。我们在Soloπ应用中集成了 AdbLib 开源库,包装成一套 ADB 命令执行工具,为 Soloπ 后续各种专项测试能力的实现奠定了坚实的基础。下面将开始为大家介绍 Soloπ 的几大核心功能。

录制回放

录制回放功能基于 AccessibilityService、ChromeDevToolsProtocol、图像识别三种模式实现精确查找,可以在设备本地实现回放,也可以转换为 Appium/Macaca 等框架的脚本,对接云测平台。另外,为了降低用例维护的成本,我们在端上还提供了用例编辑、流程控制的功能。

Alipay non-invasive Android open source automated testing tool Soloπ

 

实现方案

Alipay non-invasive Android open source automated testing tool Soloπ

 

在录制过程中,Soloπ 会对用户的操作进行拦截,识别用户操作的位置,高亮当前操作的控件,记录用户当前要做的操作类型,在每一步操作后,将操作类型及目标控件的各种信息都记录下来。这里的控件信息包括控件的 ID、文字等基本信息,以及相对布局、截图信息等。

在回放时,Soloπ 会逐条解析之前录制的数据,通过智能查找算法,综合各种属性,定位目标控件,找到控件后,就会执行相应的操作,如点击、滑动等。在所有步骤执行后,会展示本次回放的结果,包括日志、截图等信息,作为本次回放的总结。

控件查找能力

对于传统的 Native 应用,通过 UiAutomator dump 获取的属性就足以实现自动化了。然而,随着移动端动态化能力的稳步发展,越来越多的应用采用了 “Native + H5/小程序” 这种混合开发的方案。再考虑到近年来手游行业的飞速发展,手机游戏自动化测试的需求也越来越多。为了尽可能的适配各种场景,Soloπ 提供了三种查找模式:

Alipay non-invasive Android open source automated testing tool Soloπ

 

  • 第一种方案不必多说,核心就是基于 AccessbilityService 生成当前控件视图树,并记录下id、文字等属性,适用于 Native 场景
  • 第二种方案基于 Chrome 的调试协议,通过注入js可以获得页面布局以及各元素属性,控件的定位思路与辅助功能这一套方案是一致的。适用于 H5/小程序场景。
  • 第三种方案是图像匹配方案,Soloπ 在端上实现了一套图像比对能力,结合了模板匹配、特征匹配等算法,并做了一定的适配和调优。适用于游戏自动化的场景。此外,在 Soloπ 目前的方案中,图像匹配能力还会作为前两种定位方式的兜底方案,进一步的提升控件查找的准确率。

回放能力

通过 Soloπ 录制的用例会以 JSON 的形式存储起来,用例不仅可以向上述视频演示的一样在设备本地直接回放,还可以通过 Soloπ 的解析器将用例转换为 Appium、Macaca 等目前主流自动化测试框架的脚本,轻松打通云测平台。另外,得益于文本抓取和图像识别能力,Soloπ 还实现了在 Android 端录制一遍用例,生成的脚本能够同时在 Android、iOS 双端回放的能力。

Alipay non-invasive Android open source automated testing tool Soloπ

 

更多功能

Soloπ 还提供了用例步骤的插入、删除、修改等用例编辑功能,可以有效降低用例的维护成本。另外,Soloπ 还引入了循环、条件等流程控制能力,若对用例进行合理编排,可轻松实现需要重复操作的工具脚本或是需要暴力回放的稳定性测试脚本。

Alipay non-invasive Android open source automated testing tool Soloπ

 

录制回放更多的能力还包括结合数据 Mock 解决用例回放不稳定的能力、打通性能测试的能力等等。

一机多控

在各类专项测试中,兼容性测试是最为耗时费力的一项,测试人员需要关注各种系统版本、各大手机厂商,各种类型的屏幕等等,想要通过纯人工测试来保证兼容性测试的质量成本是非常高的。

Soloπ 在录制回放能力的基础上实现了一套兼容性测试的解决方案。在录制回放的场景中,我们先是在一台设备上记录了用户的操作,然后再在任意一台设备上实现操作的回放。如果把场景扩展到多台设备上,就可以实现通过一台设备操控多台设备,我们把这套功能称为“一机多控”。具体说来就是主机与从机建立 Socket 连接,然后在主机上将用户的操作实时发送到各个从机,在从机上完成操作的回放。

Alipay non-invasive Android open source automated testing tool Soloπ

 

一机多控的环境搭建比较灵活,手边的手机在安装 Soloπ 后,通过简单的建联操作即可完成部署。一机多控适配了目前市面上主流机型和 ROM,并封装了一些提升测试效率的快捷功能,如应用安装、数据清理、设备信息查看等等。

Alipay non-invasive Android open source automated testing tool Soloπ

 

性能测试

提到专项测试,不得不提性能测试。近年来,手机应用成为了人们日常生活中不可或缺的一部分,这也对应用的使用体验提出了更高的要求。 为了给用户带来“丝般顺滑”的体验,仅仅实现功能是不够的,而性能测试,就是打造优质应用不可或缺的一个环节。然而,性能测试的开展并不是很容易,一方面,性能测试具有一定的门槛,很多时候需要开发脚本去实现,还要去处理各类兼容性问题。另一方面,大多数性能测试方案获取到的都是一些基本指标,难以发现深层次的问题。针对上述问题,Soloπ 实现了一套性能测试工具。包含常规性能指标获取、响应耗时计算以及移动 Lighthouse 三方面功能。

常规性能指标获取

Soloπ 支持 CPU、内存、fps、流量等常规指标的实时获取,同时支持将性能数据记录下来,存储到本地并通过报表形式展示。Soloπ 还提供了数据上传的功能,可以将数据发送给服务端做进一步的处理。整套性能工具支持手动触发和广播触发,可以和自动化测试轻松打通。

响应耗时计算

In addition to obtaining regular performance indicators, Soloπ also provides a response time consuming calculation functions. As we all know, a common method to calculate response time consuming is based on the code Buried or system log (such as activityDisplayed Time), but the results of this method calculated for asynchronous loading, it will be more practical and user interface of perception of a relatively large deviation.

Alipay non-invasive Android open source automated testing tool Soloπ

 

Soloπ screen framing based recording capability enables a user computing experience close response time of the program. Specifically, after opening screen recording, Soloπ will get event-based ADB shell of command click event monitor screen, it as a starting point to calculate the response time consuming, when the end of the recording screen, Soloπ will forward reverse video from comparing to find out the point of time to stabilize the interface, and as the end of calculation, subtraction is both time-consuming response.

Alipay non-invasive Android open source automated testing tool Soloπ

 

Lighthouse Mobile

H5 / applet technology in the proportion of mobile applications more and more, how to test the performance of such applications has become a new topic. Contact with the front-end performance of the students know, Lighthouse is a front-end performance testing tool, but it can not be applied directly on the phone. The Soloπ doing is based CDP protocol in the client implements a set of Lighthouse performance testing tool that can get start-up performance H5 / applet page, current consumption of resources, the quality of requests, JS quality, JSAPI call case page information, and built more than 30 front-end development best practices, aimed at discovering fine-grained performance problems.

Alipay non-invasive Android open source automated testing tool Soloπ

 

Specific implementation, and application of the test is to establish the basis Soloπ establish Websocket CDP protocol communication, listening to initiate a page request, receive data, such as callback event begins loading and collect error, Trace and other data. Then follow the startup performance, resource current consumption, required quality, JS quality, JSAPI call case where the page information 6 large dimensions classify and organize the data, followed by determining the collected results built-in rules, final reporting and interfaces in the show.

Alipay non-invasive Android open source automated testing tool Soloπ

 

More

As a complete special test program, in addition to playback recorded previously mentioned, a machine control, performance testing, Soloπ Mock data is also provided, pressing performance, network simulation, Monkey intelligent functions.

Guess you like

Origin www.cnblogs.com/cuiyubo/p/11297306.html