Intelligent alarm lamp application program automatic test method and system based on Airtest framework
Through the automated testing method of the Airtest framework, the problem of cumbersome and inefficient testing of the intelligent police lamp APP is solved, and efficient and reliable automated testing is achieved, and detailed reports are generated to improve the visualization and analysis capabilities of the test results.
Patent Information
- Application Number
- CN202510595014.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-09
- Publication Date
- 2025-08-05
AI Technical Summary
In the prior art, the testing process of intelligent police lamp APP is cumbersome, inefficient, high cost and error-prone, and lacks efficient automated testing methods.
Using an automated test method based on the Airtest framework, we write automated test scripts through image recognition and UI control operation, combining multi-machine communication and detailed test report generation to realize automated testing of the intelligent alarm light APP.
It improves testing efficiency, reduces development costs, reduces manual testing workload and error rate, and enhances the visualization and analysis capabilities of test results.
Smart Images

Figure CN120429236A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of automated testing, and in particular to an automatic testing method and system for an intelligent police light application program based on an Airtest framework. Background Art
[0002] With the rapid development of intelligent terminal systems, such as smartphones and tablets, their functionality and complexity continue to increase. Testing has become crucial to ensuring the quality and stability of these intelligent terminal systems. However, traditional manual testing methods are inefficient and prone to errors when faced with the massive testing workload.
[0003] Currently, the testing process of smart police light apps relies on manual clicks for simulation testing, which is cumbersome, inefficient, costly, and prone to errors. Therefore, it is necessary to provide an automated testing method based on image recognition and UI control operations to achieve efficient automated testing of smart police light apps, improve testing efficiency, and reduce testing costs. Summary of the Invention
[0004] One of the purposes of the present invention is to provide an automatic testing method for smart police light applications based on the Airtest framework to solve the problems in the prior art of cumbersome testing process, low efficiency, high cost and prone to errors.
[0005] The present invention is implemented through the following technical solution, a method for automatically testing an intelligent police light application based on the Airtest framework, comprising the following steps: S100, installing and deploying a test environment to ensure that the test environment enables the Airtest framework to execute automated scripts; S200, writing an automated test script based on the Airtest framework that meets the requirements of automated testing of intelligent police lights, and implementing automatic testing through the automated test script; S300, calling a script execution module, running the test script, generating a detailed and formatted test report, and recording the test results and exception logs.
[0006] Furthermore, the test environment also includes building multi-machine communication functions through ADB tools, connecting multiple devices through ADB tools, assigning a unique device ID to each device, listing all currently connected devices through ADB commands, and specifying the target device for operation through device ID in the Airtest framework to ensure that different devices can operate independently.
[0007] Furthermore, the automated test script includes the following sub-steps:
[0008] S210. Locate interactive elements on the screen through image recognition algorithms. In the automated testing of smart police lights, image recognition technology is used to locate and identify interactive elements on the screen by comparing screenshots with stored template images, and to locate specific controls on the interface or the status of the police light. S220. The script directly operates the UI control hierarchy by calling the Poco sub-framework in the Airtest framework, and identifies and operates controls through the Poco sub-framework. S230. Support for loop execution logic and multi-scenario branch judgment is added to the script, and multi-scenario execution of automated tests is achieved through loops and conditional judgments.
[0009] Furthermore, the loop execution logic includes: when the test scenario requires executing a certain operation multiple times, the loop logic is used to implement the repeated switching operation multiple times.
[0010] Furthermore, multi-scenario branch judgment includes: when different modes are selected, the script needs to perform different operations or verify different results according to the different modes. Through if-else condition judgment, the script branches according to different modes and states.
[0011] Furthermore, the test report includes: taking screenshots of each step of the operation and comparing the expected results with the actual results. The screenshot comparison is generated by the screenshot() function provided by the Airtest framework. The screenshot file is saved in the specified path and embedded in the final test report; it also records the status of each test step, and provides execution time, pass rate statistics and coverage analysis to comprehensively evaluate the efficiency and effectiveness of test execution.
[0012] Further, the execution time includes: recording the time consumed in the entire test execution so that the tester can evaluate the execution efficiency of the script; the pass rate statistics include: the test report statistics the pass rate of all executed use cases, showing the number of passed use cases, the number of failed use cases and the reasons for failure; the coverage analysis includes: the report needs to analyze the coverage of the script to help testers determine whether all key functions have been covered.
[0013] On the other hand, the invention provides an automatic testing system for smart police light applications based on the Airtest framework, including a memory, a processor, and a computer program stored in the memory and runnable on the processor. When the processor executes the program, it implements any of the automatic testing methods for smart police light applications based on the Airtest framework described above.
[0014] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the above-described automatic testing methods for smart police light applications based on the Airtest framework.
[0015] Compared with the prior art, the present invention has the following advantages and beneficial effects:
[0016] 1. The present invention provides an efficient and flexible automated testing method based on the characteristics of the smart police light APP, which fully meets the testing needs of the smart police light APP and improves the testing efficiency. In addition, through the image recognition algorithm and the Poco sub-framework, it realizes the precise positioning and operation of the screen interactive elements and the UI control hierarchy, and improves the accuracy of element positioning and control operation.
[0017] 2. The present invention adopts loop execution logic and multi-scenario branch judgment to enhance the flexibility and adaptability of test scripts, and can effectively cope with complex test scenarios. By generating detailed test reports, including screenshot comparison, execution time, pass rate statistics and coverage analysis, the visualization and analysis capabilities of test results are improved.
[0018] 3. The present invention reduces development costs, improves test reliability, reduces the workload and error rate of manual testing, and thus reduces testing costs. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The drawings described herein are used to provide a further understanding of the embodiments of the present invention, constitute a part of this application, and do not constitute a limitation of the embodiments of the present invention. In the drawings:
[0020] Figure 1 This is a flow chart of the method provided in Example 1 of the present invention. DETAILED DESCRIPTION
[0021] To make the objectives, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions of the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings herein can be arranged and designed in various different configurations.
[0022] Example 1
[0023] Currently, during the testing process of smart police light apps, manual clicks are used for simulation testing, which is cumbersome. This embodiment discloses an automatic testing method for smart police light applications based on the Airtest framework. By using the Python + Airtest IDE platform, an automated police light app UI testing method is developed, realizing intelligent and automated testing of the smart police light app.
[0024] Figure 1 The flowchart of the method in this embodiment is shown. It can be seen from the figure that this embodiment includes the following steps:
[0025] Step 1: Deploy the test environment to establish the foundation for intelligent testing. First, install the Python interpreter. Python is the foundation of the Airtest framework, and all automated scripts and tools rely on Python to run. Airtest is a framework for automated testing that provides a graphical interface, making it easier to write test scripts, execute tests, and view test results.
[0026] Connect your test device using the Airtest IDE and begin writing or executing test scripts. Airtest communicates with Android devices using the Android SDK and ADB tools. Therefore, configuring the Android SDK and ADB debugging tools is crucial for setting up your test environment.
[0027] It is important to note that the Airtest framework relies on multiple Python third-party libraries to perform automated testing. Specifically, they include:
[0028] Airtest, the core library of the Airtest framework, provides various automated testing functions such as image recognition and UI operations.
[0029] PocoUI is an important extension of Airtest, used to enhance image recognition and UI operation capabilities, and is especially useful on smart devices and in-vehicle terminals.
[0030] Jinja2, Jinja2 is a template engine that is often used to generate output content such as test reports.
[0031] The above three libraries are required for Airtest to execute automated scripts, so ensuring they are correctly installed is an important step in setting up the test environment. Of course, those skilled in the art can install dependent libraries that support other functions according to actual needs.
[0032] It should also be noted that smart police lights are currently usually installed on police cars and often need to be used with on-board terminal devices, so you may encounter automated testing of on-board terminal devices. For automated testing of on-board terminals, it is often necessary to test multiple devices at the same time. In this case, it is necessary to configure the multi-machine communication function of the device. You can connect to multiple devices using the ADB tool. Each device has a unique device ID, and all currently connected devices are listed using the ADB command. In Airtest, the target device for the operation is specified by the device ID. This ensures that different devices can be operated independently. In addition, different devices can be selected for testing as needed, and multiple devices can be operated simultaneously. It supports synchronous testing between devices, which facilitates parallel verification of multiple systems or functions in the vehicle environment.
[0033] Step 2: After deploying the test environment, consider the unique characteristics of smart police lights, such as interacting with the device's interface, switching states, and controlling police light modes. Airtest's image recognition and Poco control recognition frameworks can be used to develop automated test scripts tailored to the specific needs of smart police light automation testing. For smart police light devices, testing focuses primarily on the light's state, mode switching, and interface control responsiveness. Based on the specific characteristics of the smart police light device, refine the test script.
[0034] Specifically, writing automated test scripts that meet the requirements of automated testing of smart police lights includes:
[0035] 1) Locating interactive elements on the screen through image recognition algorithms. In the automated testing of smart police lights, image recognition technology can be used to locate and identify interactive elements on the screen by comparing screenshots with stored template images, and locate specific controls on the interface or the status of the police light (such as on / off, flashing mode, police light color, etc.).
[0036] For example, the operating interface of a smart police light may have an "on / off" button, different police light mode options, status indicator lights, etc. Through image recognition algorithms, the test script can determine the location of these elements and perform corresponding operations. Assuming that the police light has a button for turning on the police light, image recognition can locate the button by comparing it with a screenshot of the button and perform a click operation. By using the image recognition algorithm to identify the "on" or "off" button in the interface, the test script can perform a click operation. And by comparing the screenshot of the police light status, it can verify whether the color of the police light has changed to ensure that it is as expected (for example, flashing red, blue, etc.). The image recognition algorithm helps detect whether the police light on the screen displays relevant prompt information, allowing the script to automatically perform click, verification, judgment and other operations on these interactive elements.
[0037] 2) The script directly operates the UI control hierarchy by calling the Poco sub-framework in the Airtest framework, and identifies and operates the controls through the Poco sub-framework.
[0038] For example, the control interface of a smart police light contains a "Police Light Mode Selection Box." The Poco subframework can help locate this control and perform selection operations (such as selecting "Flashing Mode," "Constant Light Mode," or "Emergency Mode.") Application scenarios for the Poco subframework include: Mode selection: Through Poco, scripts can directly interact with the mode selection box to select different police light modes (for example, after selecting "Flashing Mode," the script can verify whether the police light starts flashing). Button click mode: Use Poco to locate and click the "On" or "Off" button to test the on / off function of the police light. State control mode: Use the Poco operation interface control to verify whether the state changes of the police light are as expected, such as color changes when turned on and light off when turned off.
[0039] 3) Considering that the test scripts of smart police lights often need to support multiple operation scenarios, it is also possible to add support for loop execution logic and multi-scenario branch judgment in the script to achieve multi-scenario execution of automated testing through loops and conditional judgments.
[0040] Loop execution logic includes: When a test scenario requires multiple executions of a certain operation (such as repeatedly switching a police light on or off or in different modes), loop logic can be used to implement this repeated switching operation. For example, to test different police light modes, repeatedly switch each mode and verify the light status.
[0041] Multi-scenario branching judgment includes: Different police light control scenarios may require different operations. When the user selects different modes, the script needs to perform different operations or verify different results based on the mode. Through if-else conditional judgment, the script can branch processing according to different modes and states. For example, in the smart police light interface, if the user selects "flashing mode", the test script can determine the current mode and perform corresponding verification operations, such as detecting whether the police light is flashing. If "steady on mode" is selected, it verifies that the light is always on.
[0042] It should be noted that in this embodiment, based on the characteristics of the smart police light device, the writing of the test script needs to make full use of Airtest's image recognition and the control recognition technology of the Poco sub-framework to verify the various functions of the police light. Through image recognition, the script can locate interactive elements on the screen, such as switch buttons, status indicators, etc., and perform operations and verifications. Through the Poco sub-framework, you can directly operate the controls in the interface to perform more precise operations. And combined with the functions of loop execution and multi-scenario branch judgment, the script can be made more flexible and adaptable to different test scenarios to ensure that all functions of the smart police light can be fully verified.
[0043] Step 3: Call the script execution module to run the test script and generate a detailed and formatted test report that records the test results and exception logs.
[0044] The Airtest framework provides a flexible execution module to simulate user clicks, input, and function verification on the vehicle terminal screen. When the script is executed, in addition to simulating clicks and input operations, it also requires interface verification. For example, image recognition can be used to determine button status, or Poco control controls can be used to verify the different states of the warning light (on / off, flashing, etc.). These verification operations can be combined with assert statements to ensure that each step meets expectations.
[0045] The execution of the test script is the core step in the automated testing process in this embodiment. The test script can simulate click operations and simulate the user clicking on interactive elements such as buttons and menu items on the screen through image recognition and Poco control operations. Specifically, these operations can be implemented through functions such as touch() and swipe() in the script of the Airtest framework. In particular, for the input box on the vehicle terminal screen, the script can simulate user input, such as selecting a text box, entering a string, selecting a drop-down menu, etc. The Airtest framework provides a text() method for simulating input.
[0046] For example, in a test of a smart police light, the script might perform the following operations:
[0047] 1. Click the "Turn on police lights" button.
[0048] 2. Enter the police light mode selection (such as selecting "flashing mode").
[0049] 3. Use image recognition or Poco to verify that the police lights switch to flashing mode as expected.
[0050] During execution, the Airtest framework runs the script line by line and provides real-time feedback on the test execution status. If an exception occurs, the test framework will throw an error message for subsequent analysis.
[0051] After the script is executed, a formatted test report is generated and output. Test reports are a crucial part of automated testing. They help developers and testers quickly understand the test execution status, result analysis, and potential problems. Specifically, the report should include the following:
[0052] 1) The test report should include a screenshot for each step and compare the expected results with the actual results. For example, every time the test script simulates a user clicking the "Turn on lights" button, the report should include a screenshot showing the interface changes after the button is clicked. If a step fails, the report should include a screenshot of that step and compare it to the expected image to facilitate analysis of the cause of the problem. Screenshot comparison is typically generated using the screenshot() function provided by the Airtest framework. The screenshot file can be saved to a specified path and embedded in the final test report.
[0053] 2) The test report should not only record the status of each test step, but also provide execution time, pass rate statistics, and coverage analysis to comprehensively evaluate the efficiency and effectiveness of test execution.
[0054] The execution time report should record the duration of the entire test execution, allowing testers to evaluate the efficiency of the script. Especially in multi-scenario testing, execution time is a key indicator for evaluating the performance of the test framework.
[0055] Pass rate statistics: The test report should count the pass rates of all executed use cases, showing the number of passed use cases, the number of failed use cases and the reasons for failure.
[0056] Coverage analysis: The report needs to analyze the coverage of the script, especially for multi-mode and multi-functional devices such as smart police lights. Coverage analysis can help testers determine whether all key functions have been covered.
[0057] The specific implementation methods described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific implementation method of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. An automatic testing method for smart police light applications based on the Airtest framework, characterized in that: The automatic testing method comprises: S100. Install and deploy the test environment to ensure that the test environment enables the Airtest framework to execute automated scripts; S200, based on the Airtest framework, write automated test scripts that meet the requirements of automated testing of smart police lights, and implement automatic testing through automated test scripts; S300: Call the script execution module, run the test script, generate a detailed and formatted test report, and record the test results and exception log.
2. The automatic testing method for smart police light application based on Airtest framework according to claim 1 is characterized in that: The test environment also includes building a multi-machine communication function through the ADB tool, connecting multiple devices through the ADB tool, And assign a unique device ID to each device, list all currently connected devices through ADB commands, and in the Airtest framework, specify the target device for operation through device ID to ensure that different devices can operate independently.
3. The automatic testing method for smart police light application based on Airtest framework according to claim 1 is characterized in that: The automated test script includes the following sub-steps: S210. Locating interactive screen elements using an image recognition algorithm. In the automated testing of intelligent police lights, image recognition technology is used to locate and identify interactive elements on the screen by comparing screenshots with stored template images, thereby locating specific controls on the interface or the status of the police light. S220. The script directly operates the UI control hierarchy by calling the Poco subframework in the Airtest framework, and identifies and operates the controls through the Poco subframework. S230. Add support for loop execution logic and multi-scenario branch judgment in the script, and realize multi-scenario execution of automated testing through loop and conditional judgment.
4. The automatic testing method for the smart police light application based on the Airtest framework according to claim 3 is characterized in that: The loop execution logic includes: when the test scenario requires executing a certain operation multiple times, implementing the repeated switching operation multiple times through loop logic.
5. The automatic testing method for smart police light application based on Airtest framework according to claim 3 is characterized in that: The multi-scenario branch judgment includes: when different modes are selected, the script needs to perform different operations or verify different results according to the different modes, Through if-else conditional judgment, the script branches according to different modes and states.
6. The automatic testing method for smart police light application based on Airtest framework according to claim 1 is characterized in that: The test report includes: Take a screenshot of each step and compare the expected results with the actual results. The screenshot comparison is generated by the screenshot() function provided by the Airtest framework. The screenshot file is saved in the specified path and embedded in the final test report. It also records the status of each test step and provides execution time, pass rate statistics, and coverage analysis to comprehensively evaluate the efficiency and effectiveness of test execution.
7. The automatic testing method for the smart police light application based on the Airtest framework according to claim 6 is characterized in that: The execution time includes: recording the time taken for the entire test execution so that the tester can evaluate the execution efficiency of the script; The pass rate statistics include: the test report statistics the pass rate of all executed use cases, showing the number of passed use cases, the number of failed use cases and the reasons for failure; The coverage analysis includes: reporting the coverage of the scripts that need to be analyzed to help testers determine whether all key functions have been covered.
8. An automatic testing system for smart police light applications based on the Airtest framework, characterized in that: The automatic testing system comprises: processor; A memory stores a computer program, which, when executed by a processor, implements the automatic testing method for an intelligent police light application based on the Airtest framework as described in any one of claims 1 to 7.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the automatic testing method for a smart police light application based on the Airtest framework as described in any one of claims 1 to 7.