CN113641574B - Android automation method and system - Google Patents

Android automation method and system Download PDF

Info

Publication number
CN113641574B
CN113641574B CN202110883968.3A CN202110883968A CN113641574B CN 113641574 B CN113641574 B CN 113641574B CN 202110883968 A CN202110883968 A CN 202110883968A CN 113641574 B CN113641574 B CN 113641574B
Authority
CN
China
Prior art keywords
android
root node
calling
current interface
instance
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202110883968.3A
Other languages
Chinese (zh)
Other versions
CN113641574A (en
Inventor
请求不公布姓名
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Individual
Original Assignee
Individual
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Individual filed Critical Individual
Priority to CN202110883968.3A priority Critical patent/CN113641574B/en
Publication of CN113641574A publication Critical patent/CN113641574A/en
Application granted granted Critical
Publication of CN113641574B publication Critical patent/CN113641574B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites

Abstract

The invention provides a method and a system for android automation, which belong to the technical field of android automation test, and the method for android automation firstly calls classes and methods to obtain UiAutomation examples according to APIs in a frame; then calling the instance to acquire a root node of the current interface; traversing all nodes according to the root node to obtain all element information of the current interface; calling the instance to monitor the change of the current interface; and finally, when the test is needed, calling a preset function to obtain an automatic test result. According to the method, the instance is obtained by calling the class and the method, all elements can be searched in a bottom layer mode, and the problem that many controls and flutter elements of the original frame cannot be identified is solved greatly. The invention further provides an android automation system.

Description

Android automation method and system
Technical Field
The invention belongs to the technical field of android automatic testing, and particularly relates to a method and a system for android automation.
Background
In the prior art, an automatic test of an App on an android operating system is mainly carried out by utilizing a appium framework or a uiautomatic framework, but when the appium framework or the uiautomatic framework is tested, the speed is not fast enough, a plurality of bottom events cannot be acquired quickly, and controls of the same machine type cannot be positioned accurately. With the popularization of flutter technology, mobile terminal pages are generally developed by partially or completely adopting flutter, and neither appium framework nor uiAutomator framework can fully support the testing of flutter and H5 pages. Although Google authorities have proposed Flutter driver and Integrationtest, the following problems exist in practical use: not suitable for the hybrid stack APP, although the driver is related in appium, the environment cannot be switched and the element positioning capability is relatively weak.
Disclosure of Invention
The invention aims to provide an android automation method and system, and aims to solve the problems that a plurality of bottom events cannot be acquired quickly and element positioning capability is weak when an App on an android operating system is automatically tested by utilizing a appium framework or a uiAutomation framework in the prior art.
In order to achieve the above purpose, the invention adopts the following technical scheme: a method of android automation comprising the steps of:
Step 1: acquiring a root node of a current interface;
step 2: traversing all nodes according to the root node to obtain all element information of the current interface;
Step 3: packaging preset logic as a function;
step 4: and when the test is needed, calling the function to obtain an automatic test result.
Preferably, the step 1: acquiring a root node of a current interface, including:
the process of calling getInstrumentation methods of android.test.platform.app.instrumentation registry to obtain Instrumentation is denoted as instance s;
Obtaining UiAutomation an instance by calling getUiAutomation methods of said instance s;
Performing capability configuration on UI Automator Service to obtain configured UI Automator Service;
the getRootInActiveWindow method of the UiAutomation instance is queried to obtain the root node of the current interface AccessibilityNodeInfo type.
Preferably, the step 2: traversing all nodes according to the root node to obtain all element information of the current interface, wherein the element information comprises:
Searching all leaf nodes and all non-leaf nodes according to the root node traversal to obtain all element information of the current interface; the element information comprises text attributes of the elements, classname attributes of the elements and id attributes of the elements; and when searching the text attribute of the element, calling the getContentDescription method or gettext method of the AccessbilityNodeInfo type root node to perform partial matching search.
Preferably, the step 4: when the test is needed, calling the function to obtain an automatic test result, wherein the automatic test result comprises the following steps:
And monitoring the change of the interface during the test by using an android event monitoring method.
The invention also provides an android event monitoring method, which comprises the following steps:
Calling setOnAccessibilityEventListener method of UiAutomation example to obtain onAccessibilityEvent class;
monitoring the change of the current interface according to the onAccessibilityEvent types.
The invention also provides an android automation system, which comprises:
The root node acquisition module is used for acquiring a root node of the current interface;
The node traversing module is used for traversing all the nodes according to the root node to obtain all the element information of the current interface;
The logic packaging module is used for packaging the preset logic into a function;
And the function calling module is used for calling the function when the test is needed to obtain an automatic test result.
Preferably, the root node obtaining module includes:
A calling unit, for calling getInstrumentation methods of android x.test.platform.app.instrumentation registry to obtain Instrumentation, and the process of obtaining Instrumentation is recorded as an instance s;
UiAutomation an instance acquisition unit, configured to acquire a UiAutomation instance by calling the getUiAutomation method of the instance s;
the capability configuration unit is used for carrying out capability configuration on UI Automator Service to obtain UI Automator Service after configuration;
And the node acquisition unit is used for inquiring the getRootInActiveWindow method of the UiAutomation example to acquire the root node of the current interface AccessibilityNodeInfo type.
Preferably, the node traversing module includes:
The traversing unit is used for traversing and searching all leaf nodes and all non-leaf nodes according to the root node to obtain all element information of the current interface; the element information comprises text attributes of the elements, classname attributes of the elements and id attributes of the elements; and when searching the text attribute of the element, calling the getContentDescription method or gettext method of the AccessbilityNodeInfo type root node to perform partial matching search.
The android automation method and system provided by the invention have the beneficial effects that: compared with the prior art, the android automation method comprises the steps of firstly obtaining a root node, and then traversing all nodes according to the root node to obtain all element information of a current interface; calling UiAutomation an instance to monitor the change of the current interface; and finally, when the test is needed, calling a preset function to obtain an automatic test result. According to the method, the class and method are called according to the API in the uiautomatic framework to obtain UiAutomation examples, the restriction of the uiautomatic on the bottom layer can be bypassed to obtain the root node, all the original controls and flutter elements can be identified through the root node, the problem that many controls of the original framework cannot be identified is greatly solved, and in addition, the method can also support all application scenes except games, such as H5 pages, weChat applets and the like.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings that are needed in the embodiments or the description of the prior art will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and that other drawings can be obtained according to these drawings without inventive effort for a person skilled in the art.
Fig. 1 is a flowchart of a method for android automation according to an embodiment of the present invention.
Fig. 2 is a schematic diagram of a system for android automation according to an embodiment of the present invention.
Detailed Description
In order to make the technical problems, technical schemes and beneficial effects to be solved more clear, the invention is further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the invention.
The invention aims to provide an android automation method and system, and aims to solve the problem that a plurality of bottom events cannot be acquired rapidly when an App on an android operating system is automatically tested by utilizing a appium framework or a uiAutomator framework in the prior art.
Referring to fig. 1, in order to achieve the above objective, the present invention adopts the following technical scheme: a method of android automation comprising the steps of:
S1: calling classes and methods to acquire UiAutomation examples according to APIs in the uiAutomator framework;
s1 specifically comprises:
the process of calling getInstrumentation methods of android.test.platform.app.instrumentation registry to obtain Instrumentation is denoted as instance s;
The UiAutomation instance is obtained by calling getUiAutomation methods of instance s.
In practical applications, an instance of Instrumentation obtained by getInstrumentation method of android. Test. Platform. Application. Instrumentation registry may be denoted as instance s;
an example of UiAutomation obtained by the getUiAutomation method of example s is denoted as u.
In the invention, the root node can be acquired by S1 bypassing the limitation of the uiAutomator to the bottom layer.
S2: invoking UiAutomation an instance to obtain a root node of the current interface;
S2 specifically comprises:
Performing capability configuration on UI Automator Service to obtain configured UI Automator Service;
the getRootInActiveWindow method of the UiAutomation instance is queried to obtain the root node of the current interface AccessibilityNodeInfo type.
In practice, a service configuration may be made to enhance its capabilities before the root node is acquired, for example, the capabilities are configured first in AccessbilityServiceInfo variables:
AccessibilityServiceInfo info=mUiAutomation.getServiceInfo();
info.flags|=AccessibilityServiceInfo.FLAG_RETRIEVE_INTERACTIVE_WI NDOWS;
info.flags|=AccessibilityServiceInfo.FLAG_REQUEST_ENHANCED_WEB_ACCESSIBILITY;
This variable is obtained by getServiceInfo method and then the flag in it is configured with capability, and the name of the package to be monitored can be specified by info.
S3: traversing all nodes according to the root node to obtain all element information of the current interface;
s3 specifically comprises:
Searching all leaf nodes and all non-leaf nodes according to the root node traversal to obtain all element information of the current interface; and when searching the text attribute of the element, calling the getContentDescription method or gettext method of the AccessbilityNodeInfo type root node to perform partial matching search.
This process is further described below:
In the invention, a root node of the current interface AccessibilityNodeInfo type is obtained in real time by querying the getRootInActiveWindow method of UiAutomation examples, and meanwhile, all element information (including the id, classname, text and other attributes of all elements) of the current interface can be traversed according to the root node.
In order to support flutter elements and elements of different models in the test process, all nodes need to be scanned, and normally, the elements of the control are generally leaf nodes of the control tree. In the invention, all elements need to be traversed, because attributes such as text and the like of a plurality of flutter elements exist on non-leaf nodes, the search is carried out according to the text, id and classname attributes of the elements when searching, the partial matching search is carried out by using a getContentDescription method and a gettext method of each AccessbilityNodeInfo type node when searching the text value, and if any method is matched, the click can be carried out by using a performAction method of AccessbilityNodeInfo or the region where the element is located can be obtained according to a getBoundsInScreen method of AccessbilityNodeInfo and the coordinate click is carried out. Partial matching is employed in the present invention because many element attribute values are displayed when elements are searched flutter. Such as a search mall, it is often more than displaying this text attribute in flutter elements, such as display of possibly mall index1, all the search flutter elements match more accurately with the used portion of the text search.
After the root node is provided, a plurality of methods can traverse all the nodes, one of the methods traversed according to the root node is exemplified in the invention, and text is searched for a control for designating characters or characters.
Variables defining an ArrayList < AccessibilityNodeInfo > type are denoted nodelist for storing normal nodes (collecting leaf nodes).
Variables defining an ArrayList < AccessibilityNodeInfo > type are denoted flutterlist for storing flutter element nodes or other abnormal nodes (collecting non-leaf nodes).
Acquiring a root node or acquiring a AccessibilityNodeInfo type root node of a current mobile phone interface by utilizing a getRootInActiveWindow () method of an instance u, and marking the root node as an instance root1;
A method is called in which the function name is B, the function name is interate, and the parameter type is AccessibilityNodeInfo type, and the method is named info 2.
The example root1 is transmitted into a function B, then child nodes are traversed by utilizing a recursion cycle, waiting is traversed, when the getChildCount method of info2 returns to a value of 0 and the isVisibleToUser method of info2 returns to a value of true, the getContentDescription method and the gettext method of the current node are called at the moment to perform partial matching search, and if one of the methods is matched, the searched node is added into nodelist even if the matching is successful; otherwise, invoking getContentDescription method and gettext method of the current node (non-leaf node) to perform partial matching search to see whether text to be searched is contained, if any method is matched, searching is successful, and adding nodelist the searched node; the recursive traversal (e.g., iterating the above process according to getChild () calling info 2) continues until all node searches are completed.
According to the invention, all flutter elements can be quickly and accurately found through S2-S3.
S4: packaging preset logic as a function;
s5: and when the test is needed, calling the function to obtain an automatic test result.
In the invention, the android event monitoring method can be utilized to monitor the change of the interface during the test.
The invention also provides an android event monitoring method, which comprises the following steps:
Calling setOnAccessibilityEventListener method of UiAutomation example to obtain onAccessibilityEvent class;
Monitoring the change of the current interface according to the onAccessibilityEvent types. Specifically, the invention can monitor the interface change by calling onAccessibilityEvent methods in new uiAutomation.
The following describes a method for monitoring an android event according to the present invention in combination with a specific embodiment:
public void onAccessibilityEvent(AccessibilityEvent event){
int eventType=event.getEventType();
switch(eventType){
case AccessibilityEvent.TYPE_VIEW_CLICKED:
case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
case AccessibilityEvent.TYPE_WINDOWS_CHANGED:
case AccessibilityEvent.TYPE_VIEW_SCROLLED:
case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED:
It should be noted that the above codes are only a preferred embodiment of the present invention, and are not intended to limit the present invention.
In the prior art, the problem that Appium frames cannot operate the Android toast component often exists, and the method can realize the change of a monitoring interface, further detect the interface change of the toast component and realize the operation of the toast component.
According to the invention, by acquiring the interface root node, traversing the text attribute of the current interface element, waiting to monitor whether the text information displayed in the toast appears or not, a function can be packaged based on the invention to achieve the purpose, for example: the eventtype of the int type is obtained through GETEVENTTYPE () in onAccessibilityEvent (AccessibilityEvent event).
When it is accessibilitiyevent. Type_windows_changed, it indicates that the interface is CHANGED. The foregoing is provided merely for the purpose of explanation and is in no way to be construed as limiting the scope of the application in any way in relation to its specific embodiments.
The invention can bypass the function of limiting to reach auxiliary service by using the android event monitoring method, so that based on the method, a plurality of things such as judging the loading time of the page, intelligent waiting and the like can be done. The invention can receive the event of page change by using the android event monitoring method, and can acquire the root node to search the elements of the current interface instead of continuously inquiring the root node.
After the android automation method is adopted, the UiAutomator frame can identify the original control and flutter elements, so that the problems that many controls of the original UiAutomator frame cannot be identified and some models cannot be identified are solved greatly, and all elements can be searched in a bottom layer mode.
In addition, the invention can bypass the function of limiting the realization of auxiliary service, and can accurately capture the event of the page without starting the auxiliary service. The method supports all application scenes except games, such as H5 pages, weChat applets and the like.
Referring to fig. 2, the present invention further provides a system for android automation, including:
The root node acquisition module is used for acquiring a root node of the current interface;
The node traversing module is used for traversing all the nodes according to the root node to obtain all the element information of the current interface;
The logic packaging module is used for packaging the preset logic into a function;
And the function calling module is used for calling the function when the test is needed to obtain an automatic test result.
Preferably, the root node obtaining module includes:
A calling unit, for calling getInstrumentation methods of android x.test.platform.app.instrumentation registry to obtain Instrumentation, and the process of obtaining Instrumentation is recorded as an instance s;
UiAutomation an instance acquisition unit, configured to acquire a UiAutomation instance by calling the getUiAutomation method of the instance s;
the capability configuration unit is used for carrying out capability configuration on UI Automator Service to obtain UI Automator Service after configuration;
And the node acquisition unit is used for inquiring the getRootInActiveWindow method of the UiAutomation example to acquire the root node of the current interface AccessibilityNodeInfo type.
Preferably, the node traversing module includes:
The traversing unit is used for traversing and searching all leaf nodes and all non-leaf nodes according to the root node in sequence according to the text attribute of the element, the id attribute of the element and the classname attribute of the element to obtain all element information of the current interface; and when searching the text attribute of the element, calling the getContentDescription method or gettext method of the AccessbilityNodeInfo type root node to perform partial matching search.
The invention discloses a method and a system for android automation, wherein the method for android automation provided by the invention comprises the steps of firstly, calling classes and methods to acquire UiAutomation examples according to an API in a uiAutomator frame; then, calling UiAutomation an instance to obtain a root node of the current interface; traversing all nodes according to the root node to obtain all element information of the current interface; calling UiAutomation an instance to monitor the change of the current interface; and finally, when the test is needed, calling a preset function to obtain an automatic test result. According to the method, the class and method are called according to the API in the uiautomatic framework to obtain UiAutomation examples, the restriction of the uiautomatic on the bottom layer can be bypassed to obtain the root node, all the original controls and flutter elements can be identified through the root node, the problem that many controls of the original framework cannot be identified is greatly solved, and in addition, the method can also support all application scenes except games, such as H5 pages, weChat applets and the like.
The foregoing description of the preferred embodiments of the invention is not intended to be limiting, but rather is intended to cover all modifications, equivalents, and alternatives falling within the spirit and principles of the invention.

Claims (1)

1. A method of android automation, comprising the steps of:
Step 1: acquiring a root node of a current interface;
step 2: traversing all nodes according to the root node to obtain all element information of the current interface;
Step 3: packaging preset logic as a function;
Step 4: when the test is needed, calling the function to obtain an automatic test result;
the step 1: acquiring a root node of a current interface, including:
the process of calling getInstrumentation methods of android.test.platform.app.instrumentation registry to obtain Instrumentation is denoted as instance s;
Obtaining UiAutomation an instance by calling getUiAutomation methods of said instance s;
Performing capability configuration on UI Automator Service to obtain configured UI Automator Service;
Querying getRootInActiveWindow methods of the UiAutomation instances to obtain a root node of the current interface AccessibilityNodeInfo type;
The step 2: traversing all nodes according to the root node to obtain all element information of the current interface, wherein the element information comprises:
Searching all leaf nodes and all non-leaf nodes according to the root node traversal to obtain all element information of the current interface; the element information comprises text attributes of the elements, classname attributes of the elements and id attributes of the elements; when searching text attributes of elements, calling a getContentDescription method or a gettext method of the AccessbilityNodeInfo type root node to perform partial matching search;
the step 4: when the test is needed, calling the function to obtain an automatic test result, wherein the automatic test result comprises the following steps:
monitoring the change of the interface during the test by using an android event monitoring method;
the android event monitoring method comprises the following steps:
Calling setOnAccessibilityEventListener method of UiAutomation example to obtain onAccessibilityEvent class;
monitoring the change of the current interface according to the onAccessibilityEvent types;
the android event monitoring method is applied to:
the common blank of the accessibility events,
Int event type = acquire event type;
The type of event is switched over and,
Case accessibility events, click event types;
case accessibility events, changed windows state:
case accessibility events, changed windows types;
Case accessibility events, type view scrolling;
Case accessibility events, more windows content categories;
And the android event monitoring method is utilized to bypass the limit to achieve the auxiliary service function.
CN202110883968.3A 2021-08-03 2021-08-03 Android automation method and system Active CN113641574B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110883968.3A CN113641574B (en) 2021-08-03 2021-08-03 Android automation method and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110883968.3A CN113641574B (en) 2021-08-03 2021-08-03 Android automation method and system

Publications (2)

Publication Number Publication Date
CN113641574A CN113641574A (en) 2021-11-12
CN113641574B true CN113641574B (en) 2024-04-19

Family

ID=78419460

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110883968.3A Active CN113641574B (en) 2021-08-03 2021-08-03 Android automation method and system

Country Status (1)

Country Link
CN (1) CN113641574B (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110287088A (en) * 2019-01-14 2019-09-27 南京大学 A kind of automated testing method based on dynamic UI model
CN111694744A (en) * 2020-06-11 2020-09-22 安然 Test open method based on monkey source code

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110287088A (en) * 2019-01-14 2019-09-27 南京大学 A kind of automated testing method based on dynamic UI model
CN111694744A (en) * 2020-06-11 2020-09-22 安然 Test open method based on monkey source code

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
An Infrastructure Approach to Improving Effectiveness of Android UI Testing Tools;Wenyu Wang et al.;《30th ACM SIGSOFT International Symposium on Software Testing and Analysis (ISSTA)》;第165-176页 *

Also Published As

Publication number Publication date
CN113641574A (en) 2021-11-12

Similar Documents

Publication Publication Date Title
CN107908541B (en) Interface testing method and device, computer equipment and storage medium
CN109783388B (en) UI (user interface) automatic testing method and device and electronic equipment
CN105868096B (en) For showing the method, device and equipment of web page test result in a browser
CN104699604B (en) Method and device for testing the Android application that kernel is browsed based on customization
CN104391797A (en) GUI (graphical user interface) widget identification method and device
CN103324728B (en) The application program search method and device of mobile terminal
CN110554962A (en) Regression testing process covering method, server and computer readable storage medium
CN111124371A (en) Game-based data processing method, device, equipment and storage medium
CA2786418C (en) Identifying equivalent javascript events
CN116302930A (en) Application testing method and device
CN113641574B (en) Android automation method and system
CN111508562A (en) Visual display method, device, equipment and medium of flow descriptive language
CN109684156B (en) Monitoring method, device, terminal and storage medium based on mixed mode application
CN110311806A (en) A kind of mobile applications interface operating lag diagnostic method, system and terminal
CN109144841B (en) Method and device for identifying advertisement application, computer equipment and storage medium
CN116303338A (en) Data migration method and device
CN111338709B (en) Method, device, equipment and storage medium for jumping target scene in client
CN117667663A (en) Control positioning path determining method, device, equipment, storage medium and product
CN111309558B (en) Method, device, equipment and storage medium for collecting vue event data in frame
CN113900950A (en) Page testing method, device, terminal and storage medium
CN114328180A (en) Interface automation test method, system, electronic equipment and storage medium
CN116628272B (en) Tree structure node rapid selection method based on vue framework
CN111309319A (en) Inheritable office data dynamic page configuration method and device
CN113934644B (en) Version difference comparison method and device, intelligent terminal and readable storage medium
CN104572743A (en) Quicklink information updating method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant