Taking personal income tax APP as an example, this paper briefly introduces how to automate THE UI of APP from four aspects: introduction to Appium, setting up Appium environment, test execution and element positioning.

background

As for UI automation, the leader gave me three choices in May this year: WEB, PC client and APP. I immediately chose WEB, because I had tried it last year and I still remember it well. But the leader said APP>PC client >WEB was the main user, so I chose PC client. I thought the UI part would be over this year, but last month I announced that THE PC client would be reconfigured next year, so I still want to build the APP.

At that time, I chose to escape because I was afraid of difficulties, but now I have to start to be a real “warrior”.

Next, taking personal income tax APP as an example, I began to explore the road of UI automation of my APP.

The tool I used was Java+Appium+TestNg.

Appium profile

Appium introduction

Appium is an open source automated testing tool that supports native, Web, and hybrid apps on iOS and Android platforms.

Importantly, Appium is a cross-platform tool: it allows testers to write automated test scripts on different platforms (iOS, Android) using the same SET of apis, greatly increasing the reuse of code between iOS and Android test suites.

The Appium class library encapsulates the standard Selenium client class library while providing users with all the common Selenium commands in JSON format, as well as additional mobile device control-related commands, such as multi-touch gestures and screen orientation.

Operation Principle

The Test script:

This is our test program, is the implementation of the test logic part. Multiple languages can be used.

Appium Server:

This is a program implemented in javascript and running on Node.js. Node.js is the interpreter for JS programs.

Tested APP:

Running a real device or emulator.

Operation process:

The test program tells the Appium Server what to do.

For example, the application layer sends an HTTP request to the Appium Server by clicking on an interface element.

After Appium Server receives the program commands, it issues ADB commands to the control program running on the device (which is injected into the device by Appium Server), and the control program calls the corresponding automatic library methods to perform interface control.

Set up Appium environment

Install the JDK

Tools in the Android SDK, such as uiAutomatorViewer for viewing Android App interface elements, require a JDK to run. Baidu search JDK download and install, 1.8 version or later is recommended.

Install the Android SDK

  1. Download address jingyan.baidu.com/article/a3a…
  2. Double-click SDK Manager.exe to select the installation
  3. Check the API version you want to download and the corresponding Android version
  4. Configure the Android-SDK environment

My computer “right-click menu – > Properties – > Advanced – > Environment Variables – > System Variables – > New environment variables

ANDROID_HOME

D:\android\Android\sdk

Find PATH in the system variable and add the following PATH; %ANDROID_HOME%\platform-tools; %ANDROID_HOME%\tools;

  1. Install validation open CMD and type adb. If the command can be identified, the installation is successful.

Install Appium – the desktop

Appium mobile test has a very important component, Appium-Server, which is mainly used to listen on our mobile devices (real machine or emulator), parse the Appium test scripts written in different programming languages, and then drive the mobile devices to run the test.

So, the new tool appium-desktop is coming! It continues the mission of Appium-Server, which, of course, is still currently available. We’ll go straight to Appium-desktop here.

  1. Download and install jingyan.baidu.com/article/73c…
  2. Start the service

After downloading appium-desktop, open it as shown below:

Then click [Start Server], as shown below, and the Appium Server will Start.

Perform the test

Huawei Mate9 is used as an example to connect real devices.

Mobile phone to

  1. Connect to your computer with a USB cable
  2. Go to the phone Settings – System – Developer options
  3. Open developer options
  4. Enable USB debugging
  5. Execute adb command: ADB Devices -l on your computer

Note: Another way to open the developer option is:

2.2 Enter Mobile Phone Settings – System – About mobile phone

2.3 Continuously click the version number (more than 7 times) to enter the developer mode

2.4 Exit to the upper-level menu, developer mode, and open USB debugging

  1. Check whether the device is connected successfully

6.1 The following shows that the device is not connected successfully. How to operate in this case?

6.1.1 Unplug the cable, reconnect the USB, and see this logo on the computer

6.2.2 Click the Settings of the mobile phone to open the USB connection mode and switch from charging only to transferring files.

6.3.3 Enter mobile phone Settings – System – Developer option and open USB debugging (if there is still no USB debugging authorization, click Revoke USB debugging authorization, and then open USB debugging again until the popup window of whether TO allow USB debugging pops up, click OK).

6.2 Go to CMD and enter adb devices -l

Start to work

The preparatory work

  1. Download the application APK installation package of the tested app and place it locally. For example, my personal income tax APP

  1. Check whether the project configuration items (APK file directory, mobile phone version, and mobile phone model) are correct and consistent with running mobile phones.

Run the test

  1. Run Appium Server and click Record.

  1. Run the project test script code.

The script runs normally, and the logs in the Appium Server are observed.

  1. Perform log

Since I can’t upload a video, I can’t show you how it works, so I’ll show you some log pictures of how it works.

New projects need to be configured with key information

Configuration Information

  1. deviceName

For example: iPhone Simulator, iPad Simulator, iPhone Retina 4-inch, Android Emulator, Galaxy S4

  1. automationName

Which automation engine to use.

Appium (default) is still Selendroid.

  1. platformName

Which mobile platform to use. IOS, Android, orFirefoxOS.

  1. platformVersion

Specifies the system version of the platform. For example, the Android platform version is 8.0.0.

  1. appPackage

The Java package of the app to be tested is the unique authentication of the app.

  1. app

The address where the app installation package is saved on the computer. This way appium automatically installs the required packages each time it executes.

  1. appActivity

App entry information

How do I get the appPackage parameter?

  1. First, send the APK package from the PC to the phone
  2. Mobile phone installs personal income tax APP through APK package mobile phone click File Management, click Install.
  3. App has been installed on the phone, execute the command in CDM:

adb shell dumpsys activity recents|findstr “intent={“

(The above commands only support ADB6.0 or higher)

Element localization

Use the Appium Inspector to locate elements

  1. Start the Appium

  1. Making a New connection

  1. Set the “Capabilities

Click Save and you can repeat the request later.

  1. To establish a connection with the phone, click on Appium’s Start Session.

  1. Automatically start the personal income tax APP in the mobile phone, click the element you want to find in the left module on the interface of new session, and check the element location in the Source module on the right.

Tool use Tips:

Refresh the page in real time

You can use id, xpath, name, and other attributes in the window to find out if an element exists

This is the output for today, and the output for the next time is the buried log split test. Although the JMeter test also achieved the effect I wanted, the script test is a more reasonable test method, because the larger the base is calculated by hash, the more accurate it is.

Find out more next time!