This is the study note for the Hogwarts Test House Cadet course


1. Introduction

1.1 the profile

AppCrawler is a project developed by Hogwarts Testing Institute Headmaster John Smith, and we can probably guess the direction from the name.

The official GitHub explanation for the tool reads:

An App crawler based on automatic traversal. Support Android and iOS, support real machine and emulator. The most important feature is flexibility, which can be configured to set the traversal rules.

By the way, Google has also released an automatic traversal tool with the same name, App Crawler (minus one space) and the same design idea. However, this tool is still under development.

Google App Crawler link:

Developer.android.com/training/te…

Let’s take a look at the role and value of AppCrawler.


1.2 Requirement Background

Background of Internet business requirements:

  • Rapid business change
  • Numerous lines of business
  • Complex business processes
  • Many third-party interfaces are required

FAQ for testing work:

  • UI automation only covers core business logic, leaving no time for new functionality to be automated
  • After the release of the new version, the old functions are not fully regressive, so it is easy to miss the test
  • After long and intense work, people tend to get tired and become less sensitive to error information such as the number of digits and text display
  • The product’s interface is deep and contains a lot of display information
  • Specific test regression is difficult: there are too many memory leaks, robustness tests, weak network tests, etc

At this point we need a tool that can do both things:

  • Code less: Minimizes maintenance costs for UI automation use cases
  • Automate: Automate as much as possible to cover regression operations


Automatic traversal can meet our requirements for the above business; Next, let’s look at some of our requirements for automatic traversal tests. Since we want to use automatic traversal, what kind of effect do we need to wait for?

2. Select tools

2.1 Traversal Tool Requirements


Requirements for automatic traversal:

  • Controllable: You can define traversal paths and specify services to be tested to ensure coverage priority of core services
  • Customizable: can realize automatic input, automatic sliding and other basic behavior

Results analysis:

  • Click the before and after screenshot comparison
  • Data modeling of the results

2.2 Tool Comparison

2.2.1 Monkey

Let’s start with an early and often heard tool called Monkey


Reference links:

Monkey official link:

Developer.android.com/studio/test…

Monkey Script:

Github.com/gb112211/An…


This is a tool provided by Android official website, we can see the explanation of this tool as follows:


Yes, Google originally designed this tool to stress test apps, not automatically traverse tests. Note that the stress test here is not on the server side in the usual sense, but on the front end of the App. Here is sihan’s explanation of the App’s stress test:

In Google’s early design of Android, Android needed to respond to events such as sliding, input, volume, and phone calls. In the early stage of activity design, Google wanted to test activity performance and output all data to activity in batches. See how much data your activity can process in a second. So early Monkey was a stress test tool for Android.

Because Monkey is “random” during testing, it can be used for automatic traversal testing, but the downside of Monkey is that it doesn’t meet two of our automatic traversal needs: controllability and customizability.


  • Disadvantages: It does not support business behavior customization and cannot be flexibly controlled. It often points to external App and cannot revert to the original test App. Or click logout and exit, resulting in unable to continue the subsequent test; Therefore, monkey did not become our first choice for automatic traversal testing after research and understanding.

2.2.2 Maxim


Maxim is also an automatic traversal tool, developed by a Domestic engineer named Zhangzhao. The official definition is:

An efficient Android Monkey Tester, available for emulators and Real Devices, Suitable for real machine/simulator APP UI pressure test.


Official GitHub address:

Github.com/zhangzhao44…

TesterHome address: testerhome.com/topics/1171…


Let’s look at the pros and cons of this tool:


Advantages:

  • Based on Monkey secondary development, also used some AppCrawler design ideas, with customized functions;
  • Because the bottom layer is based on Monkey, so it is relatively fast;

Disadvantages:

  • Because it is Monkey based, it is not cross-platform. It can only test Android, but not iOS, Web, etc.


This tool is not open source, but you can use it directly. You can download it on GitHub and follow the official instructions. There is no emphasis here.


Let’s focus on tool features and options:


– Configuration file, an example of the configuration file is provided in json format:


If you look at AppCrawler, it’s written very similarly, except that AppCrawler is written in YAML files.


Options:

This is also an excellent tool that can be customized to a certain extent. If you only test Android, you can consider using Maxim for automatic traversal, which is relatively fast. If you want to cross-platform or re-develop open source tools, enter AppCrawler.

2.2.3 AppCrawler

Let’s go back to today’s hero
AppCrawlerTo see how it meets our testing needs and what its strengths and weaknesses are.

Let’s look at the structure of its relationship to other frameworks

  • Relationships with other frameworks


Advantages:

  • Cross-platform:AppCrawler Is based on Appium Developed, so supportAndroid And the IOS.
  • Controllability: the page of the test, the choice of control type, the depth of the test can be freely controlled;
  • Customizable: Customizable operations, such as input, sliding, etc.


Disadvantages:

  • Running speed is slow:AppCrawler Is based on Appium Development has the advantage of being cross-platform, but it is also relatively slow because of this layer of encapsulation;
  • High barriers to use: Because of the flexibility issue, the barriers to use are also increased, mainly based on the use of A in YAML filesppium The relevant technical knowledge to configure, which has certain technical requirements for users;

Installation and startup


3.1 download


Because of the larger, the official also gave the package after baidu network disk download address

Download the latest version:

pan.baidu.com/s/1dE0JDCH


Take the latest 2.4.0 as an example

How to compile and package yourself:

Clone source code from GitHub. The latest version of 2.4.0 corresponds to 2.3.1 AppCrawler.

Github.com/seveniruby/…

Git Checkout 2.3.1

3) Run MVN clean compile

4) Build with Maven: Execute MVN Assembly :single command to compile

Installation:

AppCrawler itself is a JAR package that does not need to be installed. What you need to install is the environment that the runtime depends on:

Java version: Java8, Java10 (not tested, author says support)

Appium: Above Appium 1.8 because AppCrawler is based on Appium,

So the Appium environment is essential to Appium installation way can refer to another blog: Windows (Win10), Mac install Appium;

View the help documentation:

Run the java-jar appcrawler-2.4.0-jar-with-dependencies. Jar command to view the help documents as follows:

$java-jar appcrawler dependencies. Jar ---------------- appcrawler dependencies Java8 Tested App crawler for automated iteration tests Support for Android and iOS, support true machine and simulator project address: https://github.com/seveniruby/AppCrawler mobile test technical communication: https://testerhome.com to contact the author: [email protected] (cold) thanks: xiaoguang spring dragon Yang Rong thermostatic mikezhou yaming116 MuMu -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the Usage: appcrawler [options]-a--app <value> Android or iOS file address, can be a network address, assigned to the app option of Appium# Install App, rarely used in practice
  -e, --encoding <value>   set encoding, such as UTF-8 GBK # On Windows, garbled characters may be generated-c, --conf <value> Configuration file address# Complex and important, at the heart of AppCrawler customization-p, --platform <value> Platform type. The system automatically determines the platform type based on the app name extension by default. -t, --maxTime <value> Maximum running time. The unit is seconds. If this value is exceeded, the system exits. -u, --appium <value> Appium URLUse the default appium address port without this parameter-o, --output <value> Save directory for traversal results. Capability k1=v1,k2=v2... capability k1=v1,k2=v2...Appium has the same capability as appiumThe appium capability option overrides the configuration template parameter specified by -c, which is used to fine-tune the parameters on the template configuration. --report <value> Output HTML and XML report --template <value> Output code template --master <value> master diff. Yml file address --candidate <value> Candidate environment diff. Yml file --diff Perform diff comparison -vv, --verbose Whether to display more debug information --demo Generate demo configuration file learn how to use it --help example appcrawler-a xueqiu.apk
appcrawler -a xueqiu.apk --capability noReset=trueAppcrawler -c conf/xueqiu. Json -p android -o result/ xueqiu. Json -- Capability udid=[udid]-a Snowball.app
appcrawler -c xueqiu.json -a Snowball.app -u 4730
appcrawler -c xueqiu.json -aOperates. The app - u http://127.0.0.1:4730/wd/hub# generate demo examples
appcrawler --demo

Start the app you already have installed
appcrawler --capability "appPackage=com.xueqiu.android,appActivity=.view.WelcomeActivityAlias"

Rebuild the report from the finished result
appcrawler --report result/

# Comparison between old and new versions
appcrawler --candidate result/ --master pre/ --report ./Copy the code

By the way, the function of the current version of DIff is not perfect and relatively complex, so we will not do in-depth research for now

Quick Start:

1) Start appium

$ appium
[Appium] Welcome to Appium v1.14.1
[Appium] Appium REST http interface listener started on 0.0.0.0:4723Copy the code

2) Start the emulator or real machine to ensure that ADB Devices can find your device

$ adb devices
List of devices attached
FKFBB19120151100  deviceCopy the code

3) Start traversing an already installed App (snowball App in the example) by following the command in the reference documentation:

Java jar appcrawler - 2.4.0 - jar - with - dependencies. The jar - capability"appPackage=com.xueqiu.android,appActivity=.view.WelcomeActivityAlias"Copy the code

This command executes the use case in the default manner and then iterates

  • Rule of traversal: The rule of traversal is to find the deepest element on the page, i.e. the element in the center is traversed first
  • Part of traversal effect display:



The test results

If the -o parameter is not used to specify the path to log output, AppCrawler will generate a time-named folder in the current directory that holds all data, files, screenshots, and logs

$20191129154742 appcrawler ls - 2.4.0 - jar - with - dependencies. The jarCopy the code

When you open the folder, you’ll see the following, screenshots are taken for each step (which is one of the reasons for the slow speed) and for the DOM file, you’ll see several steps files, which just randomly click on an action to let the user know that the action is being performed, and the actual steps start from there.

  • The test report has an index. HTML file in the test log. If you open it, you’ll see the test report that just ran. AppCrawler treats each click as a test case, and no page as a test suite. The interface and the controls in the interface click to simulate the relationship between test suite and test case;

Canceled is a control that was found to be clickable during traversal but didn’t end up traversed.

You can also view screenshots of operation events on the corresponding page in the report

  • The test log

    In the generated folder is appcrawler.log, which records log information about the detailed execution steps (plus-vv Parameter runs to get more log information.

Part of the captured log is shown as follows:

 2019-11-29 15:48:10 INFO [Crawler.996.doElementAction] current element = MainActivity.tag=ImageView.depth=24
2019-11-29 15:48:10 INFO [Crawler.997.doElementAction] current index = 2
2019-11-29 15:48:10 INFO [Crawler.998.doElementAction] current action = click
2019-11-29 15:48:10 INFO [Crawler.999.doElementAction] current xpath = //*[@resource-id="com.xueqiu.android:id/decor_content_parent"]//*[@resource-id="android:id/content"]//*[@resource-
id="com.xueqiu.android:id/mainContent"]//*[@resource-id="com.xueqiu.android:id/main_content"]//*[@resource-
id="com.xueqiu.android:id/pager"]//*[@resource-id="com.xueqiu.android:id/layout_refresh"]//*[@resource-
id="com.xueqiu.android:id/list"]//*[@resource-id="com.xueqiu.android:id/today_topic_container"]//*[@resource-
id="com.xueqiu.android:id/time_line_topic_item_case2"]//*[@resource-
id="com.xueqiu.android:id/today_topic_container"]//*[@resource-
id="com.xueqiu.android:id/time_line_topic_footer"]//*[@resource-id="com.xueqiu.android:id/feedback"] 2019-11-29 15:48:10 INFO [Crawler.1000.doElementAction] current url = MainActivity 2019-11-29 15:48:10 INFO [Crawler.1001.doElementAction] current tag path = hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/andro id.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.R elativeLayout/android.view.ViewGroup/androidx.viewpager.widget.ViewPager/android.widget.RelativeLayout/android.view.View Group/androidx.recyclerview.widget.RecyclerView/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.Fr ameLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.widget.RelativeLa yout/android.widget.FrameLayout/android.widget.ImageView 2019-11-29 15:48:10 INFO [Crawler.1002.doElementAction] current  file name = MainActivity.tag=ImageView.depth=24 2019-11-29 15:48:10 INFO [Crawler.1071.doElementAction] need input click 2019-11-29 15:48:10 INFO [AppiumClient.53.findElementByURI] find by uri element= MainActivity.tag=ImageView.depth=24 2019-11-29 15:48:10 INFO [AppiumClient.245.findElementsByURI] findElementByAndroidUIAutomator new UiSelector().className("android.widget.ImageView")
2019-11-29 15:48:10 INFO [AppiumClient.60.findElementByURI] find by xpath success
2019-11-29 15:48:10 INFO [Crawler.1080.doElementAction] mark 20191129154742/1_Steps.tag=.name=NOT_FOUND.clicked.png to 20191129154742/2_MainActivity.tag=ImageView.depth=24.click.png
2019-11-29 15:48:10 INFO [AppiumClient.141.mark] read from 20191129154742/1_Steps.tag=.name=NOT_FOUND.clicked.png
2019-11-29 15:48:11 INFO [AppiumClient.154.mark] write png 20191129154742/1_Steps.tag=.name=NOT_FOUND.clicked.png
2019-11-29 15:48:11 INFO [AppiumClient.161.mark] ImageIO.write newImageName 20191129154742/2_MainActivity.tag=ImageView.depth=24.click.png
2019-11-29 15:48:11 INFO [Crawler.1095.$anonfun$doElementActionA $5] click element
Copy the code

Index equals the number of events, action represents the current operation, and xpath represents the xpath expression for the element being operated on.


4. Supplementary notes

AppCrawler is always said to be slow, while other tools are relatively fast. Why

- AppCrawler-appium, ATX-APpium on Uiautomator2 Server, ATX on Uiautomator2, Maxim, ADB shell Uiautomator2 server - Uiautomator2 - AccessibilityServiceCopy the code

There’s an underlying thing called AccessibleServices, and it gets all the Android widgets, and that’s how UIAutomator gets the widgets to do things, and then it gets the AccessibleServices, Uiautomator just wraps it up;


Based on UIAutomator, Appium developed a UIAutomator server, and ATX developed a UIAutomator2. Maxim is in this layer.


Appium uses HTTP protocol, ATX uses JSON-RPC protocol, AppCrawler is at the top, so AppCrawler has two more layers of encapsulation, and screenshots are added in the running process (which can be cancelled in the configuration, but it is not conducive to view the results after cancellation). It’s going to be slow.


  • Improvement expectation: The late expectation is that the AppCrawler team will be able to specify the underlying operations as required, bypassing many unnecessary processes to increase efficiency, so that the functionality is complete and efficiency is maintained


(Article from Hogwarts Testing Institute)

Welfare benefits:

Front-line Internet famous enterprises test development position internal promotion channel

Test development internal communication circle, expand your test network

For free: Interface testing + Performance testing + Automated testing + Test development + Test cases + resume template + test documentation