Appium-automated testing framework for mobile, how to get started?

insert image description here

Appium is an open source cross-platform mobile application automation testing framework.

Since we just want to learn how to get started with Appium, let's go straight to the topic. The article structure is as follows:

1、为什么要使用Appium?
2、如何搭建Appium工具环境?(超详细)
3、通过demo演示Appium的使用
4、Appium如何实现移动端UI自动化测试呢?
5、Appium视频类学习资源分享

ps: If you feel that the text and pictures are not as direct as the video, you can also directly read the fifth part, which is about "Appium video learning resource sharing".

1. Why use Appium on the mobile terminal?

In the field of UI automation, if Seleum is the first choice for the automation framework on the web side, then Appium is the first choice for the automation framework on the mobile side (mobile phone).

Why is Appium so high in mobile testing? Let's take a look at its 5 advantages:

1) Cross-platform support:

Appium supports automated testing for Android and iOS platforms, and cross-platform test scripts can be written using the same API.

2) Support multiple programming languages:

Appium can write test scripts in a variety of popular programming languages, including Java, Python, JavaScript, and more. It is convenient for testers to write automated test scripts in their familiar language.

3) Compatible with a variety of mobile application types:

Whether it is a native mobile application (APP), a hybrid application (Hybrid App) or a mobile web application (H5), Appium supports automated testing.

4) Openness and flexibility:

Appium is an open source project that allows developers to extend and customize it. It can be integrated with other testing frameworks and tools such as JUnit, TestNG and CI/CD tools, etc.

5) Using the standard WebDriver protocol:

Appium uses the WebDriver protocol to communicate with mobile devices, which allows developers to use familiar APIs and commands without having to learn a new testing framework.

In general, Appium provides a convenient and flexible way for testers to conduct UI automation testing of mobile applications, helping them improve testing efficiency, reduce manual repetitive work, and provide reliable test results, so this tool is for The first choice for mobile UI automation.

2. How to build the Appium tool environment? (super detailed)

To use Appium tools, you first need to build a tool environment, so how to build an Appium tool environment? Taking the Python development language as an example, it needs to be divided into five steps:

The first step: install jdk

Appium needs to use Android developer tools (adb and positioning tools) to test Android programs. It depends on jdk, so the first step is to install jdk (recommended to install 1.8)

1) First check whether JDK has been installed on your computer (probably it has been installed before).

Open the terminal with CMD and enter java -version. If you can see the version information, you can skip the second step of JDK installation.

picture

2) If you can't see the version information with java -version, download the JDK.

https://www.oracle.com/java/technologies/downloads/

picture

picture

  1. Double-click the exe file below to complete the installation.

Just click “Next” all the way. This process will install jdk and jre two contents. Wait patiently for the complete installation.

picture

  1. The installation is complete.

Restart cmd to open a new terminal. Enter java -version, you can see the version information, indicating that the installation is successful.

insert image description here

5) If you still cannot see the version information, then configure the environment variable: configure the JDK path: C:\Program Files\Java\jdk1.8.0_151\bin to the Path environment variable.

picture

6) Install the Android SDK tools

To test the Android program, you need to use adb to obtain the package name and interface name. You have used the built-in positioning tool UIAutomatorViewer, and you need to install the Android SDK tool

6.1) Download and unzip the Android SDK

picture

6.2) Configure environment variables

picture

Then add the path environment variable:

%ANDROID_HOME%/tools;   
%ANDROID_HOME%/platform-tools;

6.3) Verify adb

insert image description here

6.4) Install the appium desktop software tool directly

picture

6.5) Prepare simulator or real machine

You need to prepare an Android emulator (such as a thunderbolt emulator) or a real machine (for use at work) in advance

insert image description here

6.6) Install appium-python in pycharm

Install python's appium dependency package directly:

pip install Appium-Python-Client
 pip show Appium-Python-Client

3. Demonstrate the use of Appium through Demo

1. Start the appium server

insert image description here

2. The simulator/real machine connection is successful

picture

3. Obtain the package name and interface name of the application: adb shell dumpsys window | findstr mCurrentFocus

picture

4. Write code in pycharm, the following code is demo code, click to run in pycharm, the lightning simulator will automatically open the setting application

picture

4. How to implement Appium to realize mobile UI automation testing?

After completing the construction of the Appium environment and the use of the Demo, how to conduct Appium to realize the automated testing of the mobile UI? It takes a few steps:

1. Learn the use of Appium's basic Api

You can refer to the Chinese documentation to learn the basic API operations related to appium, including basic mobile phone operations, element positioning, element operations, obtaining element information, sliding, advanced gestures, mobile phone operations, etc.

Reference: https://www.kancloud.cn/testerhome/appium_docs_cn/2001595

2. Learn PO mode

PO pattern (Page Object pattern) is a software testing design pattern for managing application pages in automated testing.

Its main goal is to improve the readability, maintainability and reusability of test scripts, while reducing the coupling between test scripts and page implementation.

In PO mode, each page or interface is abstracted as an independent object, called "page object" (Page Object). Page objects encapsulate page-related elements, operations, and logic, and provide a set of methods for test scripts to use. Specifically, page object classes typically contain the following:

  1. Element positioning: The page object contains element locators on the page, such as ID, class, XPath, etc., which are used to locate elements on the page.

2) Element operation methods: the page object provides operation methods for page elements, such as click, input, and text acquisition, and encapsulates operations that interact with elements.

3) Page logic and business methods: The page object may contain some methods related to page logic and business, such as verifying the page title, submitting a form, and so on.

By encapsulating page objects, test scripts can describe test steps and operations at a higher level, without having to pay attention to the specific implementation and positioning of pages. The test script can directly call the method of the page object to interact with the page, which improves the readability and maintainability of the test script and reduces the duplication of code writing.

In short, PO mode is an effective design mode, which is suitable for the scene of managing and interacting with pages in automated testing. It provides a structured way to organize and manage test code, making test scripts more modular, reusable and maintainable.

3. Learn to build appium mobile automation testing framework

Combining the PO mode and the Pytest framework, learn and build a complete UI automation testing framework to realize UI automation testing and improve the efficiency of regression testing.

4. Summary

To implement automated testing of App, get started with Appium tools:

1-首先在windows下安装jdk,Android-sdk环境
2-安装appium桌面工具
3-安装模拟器(比如雷电模拟器),或者使用真机
4-安装python的依赖包(Appium-Python-Client)
5-启动appium服务器,启动模拟器,然后在pycharm中运行demo脚本,即可看到运行效果

Next, you can learn the commonly used appium api, learn how to locate elements, and then learn the packaging of PO mode to complete the introduction and use of appium tools.

Finally: The complete software testing video tutorial below has been sorted out and uploaded, and friends who need it can get the software testing interview documents by themselves【保100%免费】
insert image description here

We must study to find a high-paying job. The following interview questions are the latest interview materials from first-tier Internet companies such as Ali, Tencent, and Byte, and some Byte bosses have given authoritative answers. Finish this set The interview materials believe that everyone can find a satisfactory job.
insert image description here

insert image description here

Guess you like

Origin blog.csdn.net/m0_67695717/article/details/132208791