██Harrow travel automated test order grabbing test program

Preface:

 

This blog only uses Android AccessibilityService to implement the API of the automatic order grabbing test program Demo. It does not provide a detailed explanation of the class structure and related configuration information of AccessibilityService. If you need to know more, please refer to the documentation of Google Android AccessibilityService.

Google Android official website AccessibilityService documentation:AccessibilityService | Android Developers

I first wanted to make a script on Harrow Travel to grab/find orders, and I was thinking about how to implement such a function. Use lua script? Use Android Monkey? Obviously, these have limitations and cannot be achieved. One day, I thought of a scene on a certain TV station: On a certain TV station, it was talking about the Xiaomi Group (Xiaomi mobile phone). There were thousands or even tens of thousands of mobile phones neatly placed on the racks in a work room. of mobile phones, and the screens of each mobile phone were flashing crazily. Later I found out that it was doing automated interactive testing. I’m thinking: Is this required function of mine also a technical point in automated interactive testing? I searched Baidu and came into contact with Android AccessibilityService.

public abstract class AccessibilityService
extends Service

java.lang.Object
   ↳android.content.Context
    ↳android.content.ContextWrapper
     ↳android.app.Service
      ↳android.accessibilityservice.AccessibilityService

Service, which is inherited from the four major components of Android, is basically used in the same way as service. But it is a system-level “listener” service that can monitor small and large changes caused by all applications on the phone (such as click events of a monitored application, changes in control text content, message notifications, etc.). In addition, it has its own independent life cycle (the idea is somewhat similar to the processing of messages and events in WeChat public account development), as follows:

onCreate()
onServiceConnected()
onAccessibilityEvent(AccessibilityEvent event)//Thread blocking
onInterrupt()

 

Let’s enter the topic:

Step 1. Register for service 

1.1 Register the service in the manifest file

<service
    android:name=".service.HaloAccessibilityServiceV5"
    android:enabled="true"
    android:exported="true"
    android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
    <intent-filter>
        <action android:name="android.accessibilityservice.AccessibilityService" />
    </intent-filter>
    <meta-data
        android:name="android.accessibilityservice"
        android:resource="@xml/accessibilityservice_setting" />
</service>

1.2meta-data introduction configuration

<meta-data
        android:name="android.accessibilityservice"
        android:resource="@xml/accessibilityservice_setting" />

1.3accessibilityservice.xml configuration information items

<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
    android:accessibilityEventTypes="typeAllMask"
    android:accessibilityFeedbackType="feedbackGeneric"
    android:accessibilityFlags="flagReportViewIds|flagRetrieveInteractiveWindows"
    android:canPerformGestures="true"
    android:canRetrieveWindowContent="true"
    android:description="@string/accessibilityservice_setting"
    android:notificationTimeout="100"
    android:packageNames="Fill in the complete package name of the application you want to monitor, separated by commas and multiple entries"></accessibility-service>

1.4 You must manually turn on the accessibility permission switch for the apk application.

Go to Settings->Shortcuts and Accessibility->Accessibility, find your own apk auxiliary program application, and manually turn on the switch.

 

Step 2. Implement auxiliary functions

Idea: The key to realizing auxiliary functions isevent received, and use AccessibilityService related api toGet application control information,as well asrespond to appropriate events, to complete the “auxiliary” function.

1.1 Let’s first take a look at what events AccessibilityService, as a “system-level” service, can monitor for a specified application, or what changes in the application it can monitor.

Event types Supported event types (comprehensive)
AccessibilityEvent#TYPE_VIEW_CLICKED//View control click event
AccessibilityEvent#TYPE_VIEW_LONG_CLICKED//Long press event
AccessibilityEvent#TYPE_VIEW_FOCUSED//Focused Event
AccessibilityEvent#TYPE_VIEW_SELECTED//Select event
AccessibilityEvent#TYPE_VIEW_TEXT_CHANGED//Text changes
AccessibilityEvent#TYPE_WINDOW_STATE_CHANGED//Window status changes
AccessibilityEvent#TYPE_NOTIFICATION_STATE_CHANGED//Message notification status change
AccessibilityEvent#TYPE_TOUCH_EXPLORATION_GESTURE_START// Gesture START
AccessibilityEvent#TYPE_TOUCH_EXPLORATION_GESTURE_END// Gesture END
Accessibilityeventure #TYPE_VIEW_HOVER_ENTER// Hover
Accessibilityeventure #TYPE_VIEW_HOVER_EXIT// Hover
AccessibilityEvent#TYPE_VIEW_SCROLLED// Roll
AccessibilityEvent#TYPE_VIEW_TEXT_SELECTION_CHANGED//Text selection changes
AccessibilityEvent#TYPE_WINDOW_CONTENT_CHANGED//Window connection changes
AccessibilityEvent#TYPE_ANNOUNCEMENT// Announcement
AccessibilityEvent#TYPE_GESTURE_DETECTION_START//Finger detection START
AccessibilityEvent#TYPE_GESTURE_DETECTION_END//Finger detectionEND
AccessibilityEvent#TYPE_TOUCH_INTERACTION_START//Touch interaction START
AccessibilityEvent#TYPE_TOUCH_INTERACTION_END//Touch interactionEND
AccessibilityEvent#TYPE_VIEW_ACCESSIBILITY_FOCUSED//Accessibility
AccessibilityEvent#TYPE_WINDOWS_CHANGED//Window changes
AccessibilityEvent#TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED//Accessibility clear

1.2 There are two ways to obtain application control information.

1). Search for controls by id. The id format is: (package name: id/+specify the id of the control), which is invalid for third-party applications. A tool is introduced here, which is the monitor tool that comes with Android Sdk. You can use it to initially analyze the page control structure of third-party applications, such as id, control text, hierarchical relationships and other information. ~/Android/Sdk/tools$ ./monitor.

List<AccessibilityNodeInfo> list = rowNode.findAccessibilityNodeInfosByViewId("com.jingyao.easybike:id/tvAmount");

2).Find the control through the text of the control

List<AccessibilityNodeInfo> list = rowNode.findAccessibilityNodeInfosByText("No carpooling");

1.3.Responsive events
1) The node can respond to the operations performed

android.view.accessibility.AccessibilityNodeInfo#performAction(int action)
have

android.view.accessibility.AccessibilityNodeInfo#ACTION_CLICK//Node click
android.view.accessibility.AccessibilityNodeInfo#ACTION_FOCUS
android.view.accessibility.AccessibilityNodeInfo#ACTION_CLEAR_FOCUS
android.view.accessibility.AccessibilityNodeInfo#ACTION_SELECT
android.view.accessibility.AccessibilityNodeInfo#ACTION_CLEAR_SELECTION
android.view.accessibility.AccessibilityNodeInfo#ACTION_CLICK
android.view.accessibility.AccessibilityNodeInfo#ACTION_LONG_CLICK
android.view.accessibility.AccessibilityNodeInfo#ACTION_ACCESSIBILITY_FOCUS
android.view.accessibility.AccessibilityNodeInfo#ACTION_CLEAR_ACCESSIBILITY_FOCUS
android.view.accessibility.AccessibilityNodeInfo#ACTION_NEXT_AT_MOVEMENT_GRANULARITY
android.view.accessibility.AccessibilityNodeInfo#ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY
android.view.accessibility.AccessibilityNodeInfo#ACTION_NEXT_HTML_ELEMENT
android.view.accessibility.AccessibilityNodeInfo#ACTION_PREVIOUS_HTML_ELEMENT
android.view.accessibility.AccessibilityNodeInfo#ACTION_SCROLL_FORWARD
android.view.accessibility.AccessibilityNodeInfo#ACTION_SCROLL_BACKWARD
Android. View. The org.eclipse.swt.accessibility. AccessibilityNodeInfo# ACTION_COPY / / copy
Android. View. The org.eclipse.swt.accessibility. AccessibilityNodeInfo# ACTION_PASTE / / paste
Android. View. The org.eclipse.swt.accessibility. AccessibilityNodeInfo# ACTION_CUT / / shear
android.view.accessibility.AccessibilityNodeInfo#ACTION_SET_SELECTION
android.view.accessibility.AccessibilityNodeInfo#ACTION_EXPAND
android.view.accessibility.AccessibilityNodeInfo#ACTION_COLLAPSE
android.view.accessibility.AccessibilityNodeInfo#ACTION_DISMISS
android.view.accessibility.AccessibilityNodeInfo#ACTION_SET_TEXT
android.view.accessibility.AccessibilityNodeInfo#LAST_LEGACY_STANDARD_ACTION
android.view.accessibility.AccessibilityNodeInfo#ACTION_TYPE_MASK
android.view.accessibility.AccessibilityNodeInfo#ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT
android.view.accessibility.AccessibilityNodeInfo#ACTION_ARGUMENT_HTML_ELEMENT_STRING
android.view.accessibility.AccessibilityNodeInfo#ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN
android.view.accessibility.AccessibilityNodeInfo#ACTION_ARGUMENT_SELECTION_START_INT
android.view.accessibility.AccessibilityNodeInfo#ACTION_ARGUMENT_SELECTION_END_INT
android.view.accessibility.AccessibilityNodeInfo#ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE
android.view.accessibility.AccessibilityNodeInfo#ACTION_ARGUMENT_ROW_INT
android.view.accessibility.AccessibilityNodeInfo#ACTION_ARGUMENT_COLUMN_INT
android.view.accessibility.AccessibilityNodeInfo#ACTION_ARGUMENT_PROGRESS_VALUE
android.view.accessibility.AccessibilityNodeInfo#ACTION_ARGUMENT_MOVE_WINDOW_X
android.view.accessibility.AccessibilityNodeInfo#ACTION_ARGUMENT_MOVE_WINDOW_Y
android.view.accessibility.AccessibilityNodeInfo#ACTION_ARGUMENT_ACCESSIBLE_CLICKABLE_SPAN

2) Global response to executable operations
android.accessibilityservice.AccessibilityService#performGlobalAction(int action)
have

android.accessibilityservice.AccessibilityService#GLOBAL_ACTION_BACK//Back, equivalent to the back button on the mobile phone
android.accessibilityservice.AccessibilityService#GLOBAL_ACTION_HOME//Return to the phone HOME screen
android.accessibilityservice.AccessibilityService#GLOBAL_ACTION_RECENTS
android.accessibilityservice.AccessibilityService#GLOBAL_ACTION_NOTIFICATIONS
android.accessibilityservice.AccessibilityService#GLOBAL_ACTION_QUICK_SETTINGS
android.accessibilityservice.AccessibilityService#GLOBAL_ACTION_POWER_DIALOG
android.accessibilityservice.AccessibilityService#GLOBAL_ACTION_TOGGLE_SPLIT_SCREEN
android.accessibilityservice.AccessibilityService#GLOBAL_ACTION_LOCK_SCREEN
android.accessibilityservice.AccessibilityService#GLOBAL_ACTION_TAKE_SCREENSHOT

 

Step 3. Write an automated test DEMO application.

Posted below are some of the main logic codes for Halo Travel’s automated test of order grabbing/finding, HaloAccessibilityServiceV5.java

 

 

the fourth step.running result

Part of the Log log and running screenshots (if necessaryComplete source codePlease contact the blogger at [email protected] to install the package):

intercity routes
02 2021-10-06 22973-22973 / com. 04.218 example. Driverslanguage I/HaloAccessibilityServiceV5: [0] on October 12, 10 to 15
2021-10-06 02 04.224 22973-22973/com.example.driverslanguage I/HaloAccessibilityServiceV5: [1] Dongguan City·Huawei (Fenggang Store)
2021-10-06 02:51:04.234 22973-22973/com.example.driverslanguage I/HaloAccessibilityServiceV5: [2]61.4km
2021-10-06 02 04.238 22973-22973/com.example.driverslanguage I/HaloAccessibilityServiceV5: [3] Shenzhen·Shenzhen North and South Xiaozhu Inn
2021-10-06 02:51:04.243 22973-22973/com.example.driverslanguage I/HaloAccessibilityServiceV5: [4]93.1
02 2021-10-06 22973-22973 / com. 04.252 example. Driverslanguage I/HaloAccessibilityServiceV5: [5]
02 2021-10-06 22973-22973 / com. 04.266 example. Driverslanguage I/HaloAccessibilityServiceV5: [6] three people
2021-10-06 02 04.266 22973-22973/com.example.driverslanguage I/HaloAccessibilityServiceV5: [7] No carpooling
2021-10-06 02 04.269 22973-22973/com.example.driverslanguage I/HaloAccessibilityServiceV5: FreerideOrder{insertTime='1633459864266', pointoftime='October 12th 10 15', begin='Dongguan City·Huawei (Fenggang Store) )', end='Shenzhen·Shenzhen North and South Xiaozhu Inn', fromkm=61.4, price=93.1, peopleNum=3, type='No carpooling'}


Inner city route
02 2021-10-06 22973-22973 / com. 32.808 example. Driverslanguage I/HaloAccessibilityServiceV5: [0] 40 15 tomorrow
02 2021-10-06 22973-22973 / com. 32.818 example. Driverslanguage I/HaloAccessibilityServiceV5: [1] from you 12.6 km
2021-10-06 02 32.822 22973-22973/com.example.driverslanguage I/HaloAccessibilityServiceV5: [2]Shilong Plaza
2021-10-06 02 32.827 22973-22973/com.example.driverslanguage I/HaloAccessibilityServiceV5: [3] Dongguan City·Nangang
2021-10-06 02 32.833 22973-22973/com.example.driverslanguage I/HaloAccessibilityServiceV5: [4]Guangzhou Xinhua University Dongguan Campus (West Gate)
2021-10-06 02:52:32.837 22973-22973/com.example.driverslanguage I/HaloAccessibilityServiceV5: [5]62.7
02 2021-10-06 22973-22973 / com. 32.841 example. Driverslanguage I/HaloAccessibilityServiceV5: [6]
2021-10-06 02 32.849 22973-22973/com.example.driverslanguage I/HaloAccessibilityServiceV5: [7] Prepaid
02 2021-10-06 22973-22973 / com. 32.852 example. Driverslanguage I/HaloAccessibilityServiceV5:2 [8]
2021-10-06 02 32.852 22973-22973/com.example.driverslanguage I/HaloAccessibilityServiceV5: [9] No carpooling

 

Recorded and summarized here, Wednesday, October 06, 2021, 02-23 CST.

Disclaimer:This program is only used for communication and learning between auxiliary click tools and IT developers and testers. It does not have any black technology functions. It is prohibited to be used for any illegal activities. Otherwise, you will be responsible for the consequences. Please abide by the law.

 

UPDATE2, final version

UPDATE2, final version, Friday, October 29, 2021 03-36 CST

Some software screenshots

 

 

 

 

 

 

UPDATE3,derivative version

UPDATE3, derivative version, Thursday, November 04, 2021 20-33 CST

v2.0.3.2

 

v2.0.3.2 installation package download

Program update address:
Link: https://pan.baidu.com/s/1D_q_43XaLQZtRCgQ6U-T5Q Password: pu1s, gif recording effect picture:

 

bilibili short video [Noah’s Ark-Bilibili]https://b23.tv/Eht88x0

Noah’s Ark 2.1.5

Short video added Tuesday, December 28, 2021 at 03:03 CST.

 

Related Posts

Postman installation and getting started simple tutorial

[Android] The most complete analysis of relative layout (RelativeLayout)

Efficient Agile Testing Lesson 13 Automated testing, use case testing, interface testing, big data testing

Mouse operation in selenium: ActionChains class

selenium.common.exceptions.WebDriverException: Message: ‘chromedriver‘ executable needs to be in PAT

android view animation (ViewAnimation animation)

How to solve the problem of network abnormality when the app captures packets?

Android set Padding and Margin (dynamic/static)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*