Lightweight message detection system, method and equipment based on hybrid strategy and medium
This lightweight message detection system employs a hybrid strategy to address the reliability and efficiency issues of Toast message detection in automated testing of mobile applications. It achieves high coverage, low anomaly rate, and efficient detection results, and is suitable for Android, iOS, and cross-platform mobile applications.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-02
- Publication Date
- 2026-04-03
AI Technical Summary
Existing technologies for automated testing of mobile applications suffer from problems such as high failure rates, interruptions due to their short duration, insufficient adaptability to dynamic content, and excessive performance overhead, failing to meet the reliability and efficiency requirements of cross-platform applications.
A lightweight message detection system based on a hybrid strategy is adopted, which combines native detection, page source code analysis and intelligent element search. Through a multi-level detection decision module, intelligent text matching, anti-transient disappearance module and efficient source code analysis module, it achieves high coverage and low anomaly rate for Toast message text detection.
Significantly improves detection success rate, reduces anomaly rate, optimizes detection efficiency, supports dynamic matching and historical records, facilitates system expansion, reduces testing and maintenance costs, and is compatible with mainstream frameworks.
Smart Images

Figure CN121785904A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of automated testing technology for mobile applications. Specifically, this invention is applied to the Toast message detection scenario of Android, iOS and cross-platform mobile applications, and particularly relates to a lightweight message detection system, method, device and medium based on a hybrid strategy. Background Technology
[0002] In mobile application automated testing, Toast messages, as lightweight notification components that are briefly displayed (usually 1-2 seconds), are a key element in verifying application operation feedback; existing Toast detection technologies have the following shortcomings:
[0003] (1) The single detection strategy has significant limitations: the traditional method of relying solely on Appium native API or DOM element search has a high failure rate in cross-platform applications, custom style Toast, or complex UI overlay scenarios;
[0004] (2) The short duration of Toast displays can easily cause StaleElementReferenceException (element failure exception), which can lead to detection interruption.
[0005] (3) The dynamic content adaptation capability is insufficient, and it cannot effectively identify Toasts containing variables and dynamic text, nor does it support some text matching scenarios;
[0006] (4) Excessive performance loss, frequent acquisition of page source code or repeated DOM traversal, resulting in increased detection time and excessive test resources.
[0007] With the increasing complexity of mobile applications and the widespread adoption of cross-platform development, traditional Toast detection technology can no longer meet the reliability and efficiency requirements of automated testing. There is an urgent need for an intelligent detection system that integrates multiple strategies, is resistant to interference, and has high performance. Summary of the Invention
[0008] The purpose of this invention is to provide a lightweight message detection system, method, device, and medium based on a hybrid strategy to address the aforementioned problems in the prior art, thereby solving all or one of the aforementioned problems in the prior art.
[0009] To solve the above-mentioned technical problems, the specific technical solution of the present invention is as follows:
[0010] On one hand, the present invention provides a lightweight message detection system based on a hybrid strategy, comprising:
[0011] The multi-level detection decision module is used to: respond to a Toast detection request, perform Toast message text detection based on the native detection strategy, and obtain the native detection result; start a page source code analysis thread and a smart element search thread to perform Toast message text detection using a hybrid strategy according to the native detection result; and end the detection task in response to the successful detection by the page source code analysis thread or the smart element search thread.
[0012] The intelligent text matching module is used to: respond to the Toast message text detection task of the intelligent element search thread;
[0013] The high-efficiency source code analysis module is used to: respond to the Toast message text detection task of the page source code analysis thread;
[0014] The anti-transient disappearance module is used for: configuring loop detection, handling anomaly capture, and dynamically adjusting the frequency in the Toast message text detection task;
[0015] The historical tracking and analysis module is used to record and analyze information on successfully detected tasks.
[0016] As an improved solution, the multi-level detection decision module is further configured to: upon receiving the Toast detection request, call the Appium framework's mobile:toastContainsText native interface and pass in the Toast message text to be detected.
[0017] As an improved solution, the multi-level detection decision module is further configured to: record the detection result and terminate the process when the native interface returns a result indicating existence; and simultaneously start the page source code analysis thread and the intelligent element search thread to enter the hybrid detection phase in parallel when the native interface returns a result indicating non-existence or triggers an abnormal interface call result.
[0018] As an improved solution, the intelligent text matching module is further configured to: in response to the mixed detection stage, convert the Toast message text to be detected to lowercase and perform {message_lower} matching detection.
[0019] As an improved solution, the high-efficiency source code analysis module is further configured to: in response to the hybrid detection stage, obtain the complete page source code and store it in the local cache, read the lowercase source code from the local cache, and match {message_lower} through string inclusion judgment logic.
[0020] As an improved solution, the anti-transient disappearance module is further configured to: set the number of loop detections and the timeout threshold; if a StaleElementReferenceException is captured during the element search process, a retry mechanism is immediately triggered; and if no element is captured in two consecutive detections, the detection interval is shortened.
[0021] As an improved solution, the historical tracking and analysis module is further used to: automatically record relevant detection data each time a Toast message is successfully captured during the detection process; support record clearing and export; and periodically scan the log records to perform statistical analysis of detection performance.
[0022] On the other hand, the present invention also provides a lightweight message detection method based on a hybrid strategy, comprising the following steps:
[0023] Multi-level detection decision-making:
[0024] In response to a Toast detection request, Toast message text detection is performed based on the native detection strategy to obtain the native detection result; based on the native detection result, a page source code analysis thread and a smart element search thread are started to perform Toast message text detection using a hybrid strategy; in response to the page source code analysis thread or the smart element search thread successfully detecting the message, the detection task ends.
[0025] Intelligent text matching:
[0026] The Toast message text detection task of the intelligent element search thread is responded to;
[0027] High-efficiency source code analysis:
[0028] Respond to the Toast message text detection task of the page source code analysis thread;
[0029] Anti-transient disappearance:
[0030] In the Toast message text detection task, cyclic detection configuration, anomaly capture processing, and dynamic frequency adjustment are performed.
[0031] Historical tracking and analysis:
[0032] Record and analyze information on successfully completed testing tasks.
[0033] On the other hand, the present invention also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the lightweight message detection method based on a hybrid strategy.
[0034] On the other hand, the present invention also provides a computer device, the computer device including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; wherein:
[0035] The memory is used to store computer programs;
[0036] The processor is configured to execute the steps of the lightweight message detection method based on the hybrid strategy by running a program stored in the memory.
[0037] The beneficial effects of the technical solution of this invention are:
[0038] 1. The lightweight message detection system based on a hybrid strategy described in this invention can achieve a high detection coverage rate and significantly improve the success rate of traditional methods through the cooperation of system modules; it reduces the anomaly rate based on the anti-transient mechanism and optimizes the efficiency of single source code acquisition; it is based on partial and dynamic matching, and historical records are easy to trace; it is based on modular design for easy expansion, is compatible with mainstream frameworks, reduces testing and maintenance costs, and efficiently solves the pain points of Toast detection.
[0039] 2. The lightweight message detection method based on a hybrid strategy described in this invention can make orderly calls to system modules, thereby realizing the system logic of the lightweight message detection system based on a hybrid strategy described in this invention.
[0040] 3. The computer-readable storage medium of the present invention can enable the boot system module to cooperate in order to realize the lightweight message detection method based on the hybrid strategy of the present invention. Furthermore, the computer-readable storage medium of the present invention can effectively improve the operability of the lightweight message detection method based on the hybrid strategy.
[0041] 4. The computer device described in this invention can store and execute the computer-readable storage medium, thereby realizing the lightweight message detection method based on a hybrid strategy described in this invention. Attached Figure Description
[0042] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0043] Figure 1 This is a schematic diagram of the architecture of the lightweight message detection system based on a hybrid strategy described in Embodiment 1 of the present invention;
[0044] Figure 2 This is a schematic diagram of the logic principle of the lightweight message detection system based on a hybrid strategy described in Embodiment 1 of the present invention;
[0045] Figure 3 This is a flowchart illustrating the lightweight message detection method based on a hybrid strategy as described in Embodiment 2 of the present invention.
[0046] Figure 4 This is a schematic diagram of the structure of the computer device described in Embodiment 4 of the present invention;
[0047] The markings in the attached diagram are explained as follows:
[0048] 1501. Processor; 1502. Communication interface; 1503. Memory; 1504. Communication bus. Detailed Implementation
[0049] The preferred embodiments of the present invention will now be described in detail with reference to the accompanying drawings, so that the advantages and features of the present invention can be more easily understood by those skilled in the art, thereby providing a clearer and more explicit definition of the scope of protection of the present invention.
[0050] In the description of this invention, it should be noted that the embodiments described in this invention are only some embodiments of this invention, not all embodiments; based on the embodiments of this invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this invention.
[0051] The terms "first," "second," etc., used in this specification, claims, and accompanying drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, apparatus, product, or device that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or devices.
[0052] Example 1
[0053] This embodiment provides a lightweight message detection system based on a hybrid strategy, such as... Figure 1 and Figure 2 As shown, it includes:
[0054] The core technology of this invention lies in its priority-driven + multi-module collaborative architecture. It coordinates the detection process through a three-level detection strategy module, linking intelligent text matching, anti-transient disappearance, and efficient source code analysis modules to address the core pain points of Toast detection. Finally, a historical tracking and analysis module enables traceability and analysis of detection results. The invention is compatible with mainstream testing frameworks such as Appium and Selenium, and supports API-level integration into automated testing platforms, as detailed below:
[0055] (1) Multi-level detection decision module, used for:
[0056] (1.1) Native interface priority detection: When a Toast detection request is received, the system calls the mobile:toastContainsText native interface of the Appium framework, passes in the Toast message text to be detected, and if the interface returns "exists" (True), the detection result is recorded and the process is terminated; if it returns "does not exist" (False) or triggers an interface call exception, it enters the mixed detection stage.
[0057] (1.2) Parallel Triggering of Hybrid Detection: The page source code analysis thread and the intelligent element search thread are started simultaneously; the page source code analysis thread calls the efficient source code analysis module to obtain and process the source code, and the intelligent element search thread calls the intelligent text matching module to perform XPath positioning. The two threads are executed in parallel to shorten the detection time.
[0058] (1.3) Result aggregation and judgment: If either thread detects the target Toast message, the other thread is immediately terminated and the result "Detection successful" is output; if both threads have finished executing without detection and no timeout is triggered, the retry logic of the anti-transient disappearance module is executed; if a timeout is triggered, the result "Detection failed" is output.
[0059] (2) Intelligent text matching module, used for:
[0060] (2.1) Text preprocessing: Convert the Toast message text to be detected to lowercase using a string conversion function and determine the {message_lower} parameter;
[0061] (2.2) XPath expression construction: dynamically generate XPath expressions containing the translate() and contain() functions, where the translate() function normalizes the text attribute value of the page element to lowercase, and the contain() function matches the contain / match relationship between {message_lower} and the normalized text;
[0062] (2.3) Dynamic content adaptation: For Toast messages containing variables, only a fixed text portion needs to be passed as {message_lower}, and detection can be achieved through partial matching.
[0063] (3) Anti-transient disappearance module, used for:
[0064] (3.1) Loop detection configuration: Set the number of loop detections and the timeout threshold; optional, the default loop interval is 200ms and the timeout time is set to 3 seconds, thus overriding the normal Toast display duration;
[0065] (3.2) Exception handling: If a StaleElementReferenceException is caught during the element search process, the retry mechanism is triggered immediately. The number of retries shall not exceed 3, and there shall be a 50ms interval before each retry to avoid the problem of elements not being refreshed.
[0066] (3.3) Dynamic frequency adjustment: If no element is captured in two consecutive detections, the detection interval will be automatically shortened to 150ms; if an element is detected but no text is matched, the interval will be extended to 250ms to balance detection accuracy and resource consumption.
[0067] (4) High-efficiency source code analysis module, used for:
[0068] (4.1) Source code acquisition and caching: Call the page source code acquisition interface of the test framework, obtain the complete page source code once, and then store it in the local cache;
[0069] (4.2) Fast matching: Read lowercase source code from the cache and match {message_lower} by string inclusion judgment (in keyword), without parsing the DOM structure, and the matching time is reduced to milliseconds;
[0070] (4.3) Cache invalidation mechanism: If more than 5 seconds have passed since the last source code retrieval, the source code will be automatically retrieved again and the cache will be updated to ensure the timeliness of the source code.
[0071] (5) Historical tracking and analysis module, used for:
[0072] (5.1) Recording and storage: During the detection process, for each Toast message successfully captured, the "Detection time - message content - detection time" data is automatically recorded and stored in a local JSON file;
[0073] (5.2) Record Management: Provides record clearing and export interfaces;
[0074] (5.3) Statistical analysis: Regularly scan the record files, such as calculating the daily detection success rate (number of successful tests / total number of tests), average detection time (total time / number of successful tests) and abnormal frequency, and generate simple statistical reports.
[0075] It should be noted that the above examples are merely for explaining the present invention and should not be construed as limiting the scope of protection of the present invention.
[0076] Example 2
[0077] This embodiment is based on the same inventive concept as the lightweight message detection system based on a hybrid strategy described in Embodiment 1, and provides a lightweight message detection method based on a hybrid strategy, such as... Figure 3 As shown, it includes the following steps:
[0078] S100, Multi-level Detection Decision:
[0079] In response to a Toast detection request, Toast message text detection is performed based on the native detection strategy to obtain the native detection result; based on the native detection result, a page source code analysis thread and a smart element search thread are started to perform Toast message text detection using a hybrid strategy; in response to the page source code analysis thread or the smart element search thread successfully detecting the message, the detection task ends.
[0080] S200, Intelligent Text Matching:
[0081] The Toast message text detection task of the intelligent element search thread is responded to;
[0082] S300, High-Efficiency Source Code Analysis:
[0083] Respond to the Toast message text detection task of the page source code analysis thread;
[0084] S400, resistance to transient loss:
[0085] In the Toast message text detection task, cyclic detection configuration, anomaly capture processing, and dynamic frequency adjustment are performed.
[0086] S500, Historical Tracking Analysis:
[0087] Record and analyze information on successfully completed testing tasks.
[0088] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific logical process of the method described above can be referred to the corresponding working process of the system, device and unit in the foregoing method embodiments, and will not be repeated here.
[0089] Example 3
[0090] This embodiment provides a computer-readable storage medium, including:
[0091] The storage medium is used to store computer software instructions used to implement the lightweight message detection method based on the hybrid strategy described in Embodiment 2 above. It includes a program for executing the program set up for the lightweight message detection method based on the hybrid strategy described above. Specifically, the executable program can be built into the lightweight message detection system based on the hybrid strategy described in Embodiment 1. In this way, the lightweight message detection system based on the hybrid strategy can implement the lightweight message detection method based on the hybrid strategy described in Embodiment 2 by executing the built-in executable program.
[0092] Furthermore, the computer-readable storage medium in this embodiment can be any combination of one or more readable storage media, wherein the readable storage medium includes an electrical, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof.
[0093] Example 4
[0094] This embodiment provides an electronic device, such as... Figure 4 As shown, the electronic device may include: a processor 1501, a communication interface 1502, a memory 1503, and a communication bus 1504, wherein the processor 1501, the communication interface 1502, and the memory 1503 communicate with each other through the communication bus 1504.
[0095] Memory 1503 is used to store computer programs;
[0096] When the processor 1501 executes the computer program stored in the memory 1503, it implements the steps of the lightweight message detection method based on a hybrid strategy described in Embodiment 1 above.
[0097] As one embodiment of the present invention, the communication bus mentioned in the terminal above can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 4 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.
[0098] As one embodiment of the present invention, the communication interface is used for communication between the aforementioned terminal and other devices.
[0099] In one embodiment of the present invention, the memory may include random access memory (RAM) or non-volatile memory, such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.
[0100] As one embodiment of the present invention, the processor described above may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0101] It should be understood that in the various embodiments of this document, the sequence number of each process does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this document.
[0102] It should also be understood that, in the embodiments herein, the term "and / or" is merely a description of the relationship between associated objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Additionally, the character " / " in this document generally indicates that the preceding and following associated objects have an "or" relationship.
[0103] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this document.
[0104] In the embodiments provided herein, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the couplings or direct couplings or communication connections shown or discussed may be indirect couplings or communication connections through some interfaces, devices, or units, or they may be electrical, mechanical, or other forms of connection.
[0105] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of the embodiments described herein, depending on actual needs.
[0106] Furthermore, the functional units in the various embodiments of this document can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0107] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this paper, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this paper. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0108] The above description is merely an embodiment of the present invention and does not limit the patent scope of the present invention. Any equivalent structural or procedural transformations made based on the content of the present invention's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of the present invention.
Claims
1. A lightweight message detection system based on a hybrid strategy, characterized in that, include: The multi-level detection decision module is used to: respond to a Toast detection request, perform Toast message text detection based on the native detection strategy, and obtain the native detection result; start a page source code analysis thread and a smart element search thread to perform Toast message text detection using a hybrid strategy according to the native detection result; and end the detection task in response to the successful detection by the page source code analysis thread or the smart element search thread. The intelligent text matching module is used to: respond to the Toast message text detection task of the intelligent element search thread; The high-efficiency source code analysis module is used to: respond to the Toast message text detection task of the page source code analysis thread; The anti-transient disappearance module is used for: configuring loop detection, handling anomaly capture, and dynamically adjusting the frequency in the Toast message text detection task; The historical tracking and analysis module is used to record and analyze information on successfully detected tasks.
2. The lightweight message detection system based on a hybrid strategy according to claim 1, characterized in that: The multi-level detection decision module is further configured to: upon receiving the Toast detection request, call the Appium framework's mobile:toastContainsText native interface and pass in the Toast message text to be detected.
3. The lightweight message detection system based on a hybrid strategy according to claim 1, characterized in that: The multi-level detection decision module is further configured to: record the detection result and terminate the process when the native interface returns a result indicating existence; and simultaneously start the page source code analysis thread and the intelligent element search thread to enter the hybrid detection stage in parallel when the native interface returns a result indicating non-existence or triggers an abnormal interface call result.
4. The lightweight message detection system based on a hybrid strategy according to claim 3, characterized in that: The intelligent text matching module is further configured to: in response to the mixed detection stage, convert the Toast message text to be detected to lowercase and perform {message_lower} matching detection.
5. The lightweight message detection system based on a hybrid strategy according to claim 3, characterized in that: The high-efficiency source code analysis module is further configured to: in response to the hybrid detection phase, obtain the complete page source code and store it in the local cache, read the lowercase source code from the local cache, and match {message_lower} through string inclusion judgment logic.
6. The lightweight message detection system based on a hybrid strategy according to claim 1, characterized in that: The anti-transient disappearance module is further configured to: set the number of loop detections and the timeout threshold; if a StaleElementReferenceException is captured during the element search process, a retry mechanism is immediately triggered; and if no element is captured in two consecutive detections, the detection interval is shortened.
7. The lightweight message detection system based on a hybrid strategy according to claim 1, characterized in that: The historical tracking and analysis module is also specifically used for: automatically recording relevant detection data each time a Toast message is successfully captured during the detection process; supporting record clearing and export; periodically scanning the log records to perform statistical analysis of detection performance.
8. A lightweight message detection method based on a hybrid strategy, based on the lightweight message detection system based on a hybrid strategy according to any one of claims 1 to 7, characterized in that, The method includes the following steps: Multi-level detection decision-making: In response to a Toast detection request, Toast message text detection is performed based on the native detection strategy to obtain the native detection result; based on the native detection result, a page source code analysis thread and a smart element search thread are started to perform Toast message text detection using a hybrid strategy; in response to the page source code analysis thread or the smart element search thread successfully detecting the message, the detection task ends. Intelligent text matching: The Toast message text detection task of the intelligent element search thread is responded to; High-efficiency source code analysis: Respond to the Toast message text detection task of the page source code analysis thread; Anti-transient disappearance: In the Toast message text detection task, cyclic detection configuration, anomaly capture processing, and dynamic frequency adjustment are performed. Historical tracking and analysis: Record and analyze information on successfully completed testing tasks.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the lightweight message detection method based on a hybrid strategy as described in claim 8.
10. A computer device, characterized in that, It includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; wherein: The memory is used to store computer programs; The processor is configured to execute the steps of the lightweight message detection method based on a hybrid strategy as described in claim 8 by running a program stored in the memory.