1, the introduction of

1.1 the profile

  • AppCrawler is a project opened by TesterHome co-founder Huang Yansheng (Si Han). We can probably guess the direction from the name, Crawler means Crawler, Crawler of App, traversing App; 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 biggest feature is flexibility. You can configure 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 links: developer.android.com/training/te…

After that, let’s take a look at the role and value of AppCrawler:

1.2 Requirement Background

  • Internet business requirements background:
    • Rapid business change
    • Numerous lines of business
    • Complex business processes
    • Many third-party interfaces are required
  • Frequently asked Questions about 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. Tool selection

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… The 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:

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 underlying layer is based on the Monkey, it is still relatively fast
  • Disadvantages:
    • Because it is Monkey based, it is not cross-platform. It can only test Android, 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 fileschoose:

    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 take a look at today’s main character, AppCrawler, and see why it meets our testing needs. What are its advantages and disadvantages

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

  • Relationships with other frameworks
    • Appcrawler underlying engine
      • appium
        • wda
        • uiautomator2
      • adb
      • Macaca (not maintained, obsolete)
      • Selenium (not open source yet)
  • advantages:
    • Cross-platform:AppCrawlerIs based onappiumDeveloped, so supportAndroidandIOS
    • Controllability: you can freely control the page of the test, the choice of control type, the depth of the test, etc
    • Customizable: Customizable operations, such as input, sliding, etc
  • disadvantages:
    • Running speed is slow:AppCrawlerIs based onappiumDevelopment has the advantage of being cross-platform, but it is also relatively slow because of this layer of encapsulation
    • High threshold of use: Precisely because of the problem of flexibility of use, also caused the increase of threshold of use, mainly based onyamlUse in filesappiumThe relevant technical knowledge to configure, which has certain technical requirements for users

3. Installation and startup

  • Download because of the large, the official baidu web disk after the package download address: the latest version download address: pan.baidu.com/s/1dE0JDCH here is the latest 2.4.0 as an example

    How to compile and package yourself:

    Clone source code from GitHub. The latest open source version 2.4.0 corresponds to branch 2.3.1

    AppCrawler GitHub address:Github.com/seveniruby/…

    2) Switch to branch:Git checkout 2.3.1

    3) Build with Maven: Executemvn assembly:singleCommand to compile

  • * Java version: Java8, Java10(not tested) * appium: Because AppCrawler is based on Appium development, so the Appium environment is essential

  • Run the java-jar appcrawler-2.4.0-jar-with-dependencies. Jar command to view the help document, you can view the following information about the help document:

    $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

  • 1) Start appium

    $ appium
    [Appium] Welcome to Appium v1.14.1
    [Appium] Appium REST http interface listener started on 0.0.0.0:4723
    Copy 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	device
    Copy 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. = the WelcomeActivityAlias” after the command execution can be carried in the default way to use cases, and then traverse

  • The rule of traversal is to find the deepest element on the page, that is, the element in the center will be traversed first

  • Part of the traversal effect display

  • 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 within the interface are clicked to simulate the relationship between the test suite and the test case

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

  • The test log is in the generated folder appcrawler.log, which contains detailed log information about the execution steps (running with the -vv parameter yields more and 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, AND ATX uses JSON-RPC protocol. Appcrawler is the top layer, so appCrawler runs slowly because of two more layers of encapsulation and screenshots (which can be removed from the configuration, but will make it difficult to view the results).

  • 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

Write at the end

This is just a basic understanding of appCrawler, since it mentioned the characteristics of customization, it needs to be completed through the configuration file, the next article will be introduced in detail, please refer to the blog: AppCrawler configuration file to complete the automatic traversal test customization (basic)-01