Appium Mobile Automation Framework

Introduction: Appium is an open source tool for automated testing on the mobile side, which can write test cases with a set of APIs for different platforms. This article provides an overview of the capabilities of the Appium automated testing framework. This article is selected from "Software Automation Test Development".

Features of the Appium Framework

(1) Support iOS and Android, can automate App automation on multiple machines in parallel, and test model adaptation. 
(2) The code implements keyword-driven:

  • Test Sets: Associate Excel test cases and script configurations.
  • Test data: Excel stores input data, control elements, test results.
  • Test script: Written by Java and TestNG, the hierarchical structure includes case, log, config, report, and data.

(3) Automatic test case execution:

  • Extract the main functions that need to be repeatedly executed from the functional test cases for use case coverage.
  • Automatically take screenshots when the support use case fails.
  • The failed test case is automatically repeated several times.

(4) Continuous integration environment Jenkins, which automatically builds and executes test tasks regularly.

  • Test result report display, automatic mail display.

The basic process of Appium's automated testing of an app is as follows:

The basic process of testing the app

  Based on the Appium automated testing framework, what we need to do is connect the computer, connect the mobile phone, unlock, install the app, uninstall the app, start the app, element positioning, element operation, screen operation, page waiting, exception handling screenshots, data verification, The detailed process of a series of automated test executions such as logs and reports. 
Appium automates the capture of frame element controls and performs corresponding operations based on the captured element controls. 
  Appium element controls have a variety of positioning methods, the most commonly used are the ID of the element (ie By.id) and the value of the element (ie By.name). You can also perform positioning operations through element type TagName, element location XPath, and coordinates of mobile devices. Android element controls can be recorded and captured through the uiautomatorviewer.bat file in the SDK, as shown in the figure below. 
图片描述
图片描述
图片描述
  In the above figure, the resource-id com.test.seller:id/phone_edit1 under Node Detail corresponds to the positioning method By.id in Excel and the code, the control element data text 13798359580 corresponds to the operation method sendkeys() in Excel and the code, and the control The element assignment data is 13798359580. 
  It can be understood like this: first find the text box, and then enter data into the text box. That is, through the ID attribute value com.test.seller:id/phone_edit1, find the control element of the user name text box, and then enter the user name data 13798359580 into the user name text through the sendkeys() method. The positioning methods, control elements, and operation methods of other automated test steps are also similar. In fact, automated testing is the process of simulating manual testing through program code. 
  The sendkeys() method for inputting the user name text box is introduced above, so what are the operation methods of other elements? Element operation methods generally include click (click), input (sendkeys), element sliding, page sliding, long press, drop-down, pop-up, screen zoom in and out, etc. The most commonly used are click and input. 
  Data validation. In fact, the element itself is a data check. When the program cannot find the element, the use case will fail. 
  In addition, one or more assertions can be added to verify the data when testing the case, and the delay time of step waiting can also be set. 
  Test Results. The test case records the test results after running, such as pass, failed or skip. (This part will be explained in detail in Chapter 4 of "Software Automation Test Development")

Appium introduction (refer to Appium official information)

  Appium is an open source tool for automated testing on the mobile side. It supports iOS and Android platforms, and languages ​​such as Python and Java. That is, the same set of Java or Python scripts can run on iOS and Android platforms at the same time. 
  Appium is cross-platform, that is, you can use a set of APIs to write test cases for different platforms. 
  Appium is a C/S architecture, the core of which is a Web server, which provides a set of REST interfaces. When the client's connection is received, commands are listened for, then executed on the mobile device, and finally returned to the client in an HTTP response.

Session

  Automation always revolves around a Session. The client initiates a Session to interact with the server. Different languages ​​have different implementations, but they all ultimately send a POST request to the server. The request contains a JSON object, which is called "Desired Capabilities". At this point, the server will open an automated session, and then return a session ID, which will be sent by the user for subsequent commands.

Desired Capabilities

  Desired Capabilities 是一些键值对的集合(比如一个 map 或者 hash)。客户端将这些键值对发送给服务端,告诉服务端我们想要怎样测试。比如,我们可以把platformName capability 设置为 iOS,告诉Appium 服务端,我们想要一个iOS 的session,而不是一个 Android 的session。

Appium Server 服务端

  Appium Server 是用 Node.js 写的,我们既可以用源码编译,也可以从 NPM 直接安装。 
  Appium 服务端有很多语言库,如 Java、Ruby、Python、PHP、JavaScript 以及C#等,这些库都实现了 Appium 对 WebDriver 协议的扩展。当使用 Appium 的时候,你只需使用这些库代替常规的 WebDriver 库就可以了。

Appium Clients 客户端

  此客户端的概念不是我们传统意义上的客户端,更好的理解方式是一个扩展的WebDriver 协议库,当你用自己喜欢的语言写case 时,会将该语言扩展的WebDrvier库添加到自己的环境中,这时你可以把它理解为这就是个客户端。 
  Appium Clients 客户端的安装包如下。 
  Mac 机器上直接运行Appium.dmg;Windows 机器上运行Appium.exe。

Appium Android/iOS 工作原理

  API 接口调用Selenium 的接口,Appium Server 接收WebDriver 标准请求,解析请求内容,调用对应的框架响应操作。代码将DesiredCapability 中的键值对组合成一个JSON,然后通过HTTP 协议发送到Appium服务器创建一个session。代码与Appium的所有交互都是围绕着这个session 进行的。session 创建成功后,Appium 再通过USB接口与手机之间创建TCP 连接,先安装一些服务端App,比如Android API 4.2+是uiautomator,Android 2.3+是Instrumentation;如果是iOS,则是UiAutomation。手机的操作都是由Appium 发送指令到uiautomator,然后再由uiautomator 进行控制的。 
  Appium 原理图如下。 
图片描述
  Appium 的核心是一个遵守REST 设计风格的Web 服务器,它接收客户端的连接和命令,在手机设备上执行命令,然后通过HTTP 的响应收集命令执行的结果。这种架构给我们提供了很好的开放特性:只要某种语言有HTTP 客户端的API,我们就可以通过这个语言写自己的测试代码。 
  本文选自《软件自动化测试开发》,点此链接可在博文视点官网查看。 
  图片描述

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326448501&siteId=291194637