Introduction to Android automated testing

This article will give a brief overview of Android automated testing content and testing framework, hoping to let everyone have a general understanding of Android automated testing, and then take Appium as an example to introduce its environment construction and basic use.

Automated test content

Android can be tested automatically through an automation framework or a cloud testing platform. The test content includes the following aspects

  • Compatibility testing: Install, start, uninstall
  • Function test: gesture operation, function verification
  • Stability test: whether the APP is prone to flashback and other phenomena
  • Scenario test: Simulated real network scenarios, including 2G, 3G, 4G, and wifi network switching

Automated testing framework

  • Espresso is an open source Android automation testing framework for Android platform, mainly for Android App UI automation testing, using Java to write test code, Glide and Android Studio support, the test runs fairly fast (no waiting, no sleeping)

  • UI Automator is also a simple UI automation test tool officially issued by Google. It can be tested across apps. Only Android4.0 or above can be used. Uiautomatorviewer is a built-in tool of the Android SDK. By taking screen shots and analyzing XML layout files, the control information viewing service is provided for users. The tool is located in the tools\bin subdirectory of the SDK directory

  • Appium is an open source, cross-platform testing framework that can be used to test Native apps, hybrid apps, mobile Web apps (H5 apps), and more

    Appium: Is the core of the Appium system. As it is also a Web interface service, it is also called Appium Server. Multiple ports including 4723 are enabled externally by default.

    Appium-desktop: in order to make Appium better to use, so that the white entry easier, so that debugging and interface analysis more convenient, the official development of the GUI tool APpium-desktop.

    Appium Client: Appium is just a Web interface that accepts HTTP requests, so each language can encapsulate and send requests by itself, and there are various subprojects under Appium

Apppium Installation and Configuration (Mac Version)

Basic environment construction

1 install the Java environment, Git, Ruby, Brew, and Android SDK environment

Java -version git --version ruby -v brew -v adbCopy the code

2 Configure environment variables

Installing Appium and related packages (Java version)

1 Appium download

Select the Java Client and download the Related Selenium package in the Compile Dependencies section on its details page. When writing Java automated test scripts, download the package in Compile Dependencies, such as Commons-lang3, as needed.

Apppium is basically used

Video tutorial

The adb command

  • Use TCPIP to connect mobile phones (computer and mobile phone need to be in the same LOCAL area network)
Adb tcpIP 5555 // Disconnect the USB, Adb Connect 10.33.70.165:5555 // Disconnect ADB disconnect 10.33.70.165:5555Copy the code
  • Get App information
Adb shell Dumpsys Activity top adb shell Dumpsys activity Activities App ADB shell am start - W - n com. Xueqiu. Android /. The WelcomeActivityAlias -s / / get the current interface elements adb shell dumpsys activity to the topCopy the code
  • Operating the phone (typing, pressing, clicking, sliding)
adb shell text/keyevent/tapswipe/press/roll 
Copy the code