Software Testing - How App Automation Appium works!

question

What do you use for app-side automation at work?

Have you used the Appium framework?

Are you familiar with Appium?

How does the underlying principle of Appium drive mobile phones to operate?

Inspection point

The interviewer wants to know:

  • Have you used the Appium framework?
  • Are you familiar with the common APIs of the Appium framework?
  • Is there any solution for special controls and special operations on mobile terminals?
  • Have you seen the source code of Appium?
  • Do you understand the underlying working principle of the Appium framework?

Technical points

Technical points involved:

  • App API
  • Appium underlying communication protocol
  • Appium framework principle

answer

First, introduce the Appium framework and explain the characteristics of the corresponding framework; then draw a communication schematic diagram to explain; explain the API of common operations; and finally make an overall summary.

Appium framework introduction

What is Appium?

First of all, Appium is an open source framework with a rich ecosystem, a strong community, and has been maintained by developers;

It is a flexible cross-platform test automation tool that can perform automated test runs on mobile applications on iOS, Android, Windows, and Mac devices, and can use the same API to write test scripts for multiple platforms;

Appium, similar to Selenium, is a cross-language automation framework and can be combined with any testing framework; test scripts can be written in different programming languages, including Java, JavaScript, PHP, Ruby, Python and C#.

现在我也找了很多测试的朋友,做了一个分享技术的交流群,共享了很多我们收集的技术文档和视频教程。
如果你不想再体验自学时找不到资源,没人解答问题,坚持几天便放弃的感受
可以加入我们一起交流。而且还有很多在自动化,性能,安全,测试开发等等方面有一定建树的技术大牛
分享他们的经验,还会分享很多直播讲座和技术沙龙
可以免费学习!划重点!开源的!!!
qq群号:110685036

Appium Communication-Introduction to Each Terminal

The client sends automated instructions to the Appium Server. After receiving the instructions sent by the client, the Appium Server converts them into instructions that the mobile terminal can recognize, and then sends them to the mobile device. The mobile device operates according to the instructions.

The following figure shows automated communication interaction:

Client

The client is to run the written automation project code and use the API provided by Appium-client to write use cases.
Among them, declare the DesiredCapabilities object and specify the relevant information of the device and app under test; the value of automationName specified in the DesiredCapabilities object is UiAutomator2, so that an Android session can be created through Appium Server.

In the automation project code, you first request to create an AndroidDriver instance, and you need to pass in the URL of the Appium Server and the DesiredCapabilities object.

App Server

The default port number occupied by Appium Server when it is started is 4723. Its main function is to monitor API requests.
Receive commands sent by the client, convert them into instructions that can be recognized by the mobile terminal, and send them to the mobile device for operation, and then wait for the mobile device to return the operation results.
The Appium Server receives the results returned by the mobile device and then sends the operation results to the Client.

Among them, Appium server can be placed on the client side together with the automation project code, or it can be placed on the cloud.
If it is placed on the client side together with the code, the IP address of Appium Server is 127.0.0.1;
if it is placed on the cloud, the IP address of Appium Server is the IP address of the cloud server.

Android mobile terminal

Appium is based on the JSON Wire protocol and implements automated testing of APP by calling the UIAutomatior command.
Among them, the UIAutomator test framework is the APP UI automation testing Java library that comes with the Android SDK.

Summarize

The client sends a request to Appium Server, and Appium Server converts the request to the mobile terminal. After the mobile terminal operation is completed, the response content is returned to Appium Server, and Appium Server returns the result to the client.

Appium communication-end to end

Client and Appium Server

The client requests to create a driver session and passes the declared capabilities startup parameters to the Appium Server through port 4723;

Appium Server redirects to the corresponding driver module based on the automationName attribute in capabilities.
If automationName is uiautomator2, Appium Server redirects to UIAutomator2 Driver, then creates a session and generates the corresponding sessionID.

Appium Server and Android mobile terminal

APK installation

  • appium settings

In order to run applications on Android phones, Appium requires certain permissions to control system settings.
Appium installs a small application io.appium.settings. After successful installation, Appium Settings runs in the background.

  • uiautomator2 server

Since you are using the UIAutomator2 Driver, you need to install the Driver-related apk on your Android phone, namely
appium-uiautomator2-server-xx.apk.

After the installation is completed, the 8200 port of the Appium Server and the 6790 port of the Android device are mapped, and communication is carried out through the mapped link.

Summarize

  1. Client sends operation instructions to Appium Server
  2. Appium Server sends JWP protocol requests to Android's appium-uiautomator2-server through appium-uiautomator2-driver
  3. appium-uiautomator2-server calls Google UIAutomator2 of the Android system to perform specific automation operations
  4. After the operation is completed, the result object AppiumResponse is returned to appium-uiautomator2-driver, and AppiumServer returns it to the client. The client gets the final result of the operation.

Notice

  • The communication protocol between appium-uiautomator2 driver and server is JWP protocol
  • The AndroidDriver is created following the W3C protocol.

Finally, I would like to thank everyone who read my article carefully. Looking at the increase in fans and attention, there is always some courtesy. Although it is not a very valuable thing, if you can use it, you can take it directly!

Software Testing Interview Document

We must study to find a high-paying job. The following interview questions are from the latest interview materials from first-tier Internet companies such as Alibaba, Tencent, Byte, etc., and some Byte bosses have given authoritative answers. After finishing this set I believe everyone can find a satisfactory job based on the interview information.
 

Insert image description here

Guess you like

Origin blog.csdn.net/jiangjunsss/article/details/132817345