Mobile phone APP automatic testing method and device

By using J2V8 engine and WebSocket technology in the automated testing of mobile APPs, the test scripts are directly run on the target device, which solves the problems of low communication efficiency and low development efficiency in the existing test methods, and achieves an efficient and stable automated testing process.

CN119865842APending Publication Date: 2025-04-22ZIXUN TECHNOLOGY (FUJIAN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411808513.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-10
Publication Date
2025-04-22

AI Technical Summary

Technical Problem

The existing mobile APP automation testing methods have problems such as low communication efficiency, degraded concurrent testing performance, poor script expansion, low development efficiency and functional limitations.

Method used

Using J2V8 engine and WebSocket technology, the test scripts are implemented to directly run on the target device. The host side is only responsible for task management and script distribution, and improves test efficiency and stability through two-way real-time communication.

Benefits of technology

It significantly improves the efficiency of test execution, simplifies the configuration of the test environment, and improves the isolation of the equipment environment and the stability and real-timeness of the test process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119865842A_ABST
    Figure CN119865842A_ABST
Patent Text Reader

Abstract

The invention provides a mobile phone APP automatic test method and device, and the method comprises the steps: initializing a test device, connecting at least one Android device to a host end, and installing a set test APK to the Android device; the host side issues the test task script and the corresponding configuration file to the target equipment through Spring BootWebSocket service; the WebSocket client of the test APK receives a test task script and a corresponding configuration file issued by the host end, and loads the test task script and the corresponding configuration file to J2V8; injecting a function interface of a script execution environment into an execution environment of J2V8; a test task script is loaded and executed through J2V8, and error information in the execution process is captured and recorded to a log module; afterwards, error information is fed back to a host end in real time through WebSocket, so that a user can automatically complete APP testing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of testing technology, and in particular to a method and device for automatic testing of mobile phone APPs. Background Art

[0002] After developing a mobile APP, it needs to be tested by testers; the commonly used testing methods are as follows:

[0003] 1. Appium, the test script is written and run on the host side, communicating with the device under test through a specific protocol to achieve automated operation. The main communication protocol is Webdriver;

[0004] 2. Airtest, similar to writing python scripts on the Appium host side, interacts with the mobile phone through the Android ADB tool to perform specific test requirements at runtime;

[0005] 3. UI Automator, write test scripts in Java, simulate user operations, locate and operate UI elements through the device UI hierarchy, and run the specified Java test script on the target device.

[0006] The above test methods have the following disadvantages:

[0007] 1. Appium: It relies on the WebDriver protocol, and has low communication efficiency. High concurrency and simultaneous testing of multiple devices will cause the overall execution performance of the host machine and mobile phone to decline. The script has poor extensibility and is difficult to flexibly inject custom APIs.

[0008] 2. Airtest: The element positioning solution relies more on image recognition; the Python language is not easy to inject custom API capabilities. It relies on ADB for screenshot positioning, and the performance is poor in high-frequency testing scenarios;

[0009] 3. UI Automator: Written in Java, it has low development efficiency and scripts are difficult to dynamically expand and iterate; its functions are limited to the Accessibility API and its testing support for complex functions is insufficient. Summary of the invention

[0010] The technical problem to be solved by the present invention is to provide a method and device for automated testing of mobile phone APPs, in which the host side is only responsible for task management and script distribution, which simplifies the configuration requirements of the test environment and improves the environmental isolation of the target device.

[0011] In a first aspect, the present invention provides a method for automated testing of a mobile phone APP, comprising the following steps:

[0012] Step 1: Initialize the test device, connect at least one Android device to the host, install the set test APK to the Android device, the test APK integrates J2V8 and implements the WebSocket client to establish two-way communication with the Spring Boot WebSocket service on the host; install the tested APP to the Android device at the same time; start the test APP, register the Android device with the host, and send the device information of the Android device to the host;

[0013] Step 2: The host listens to the test task request through the Spring Boot WebSocket service; the host classifies the captured test task request according to the settings, and selects the target device according to the task priority and Android device status; the host sends the test task script and the corresponding configuration file to the target device through the Spring Boot WebSocket service;

[0014] Step 3: The WebSocket client of the test APK receives the test task script and the corresponding configuration file sent by the host, and loads them into J2V8; injects the functional interface of the script execution environment into the J2V8 execution environment;

[0015] Step 4: Load and execute the test task script through J2V8, capture the error information during the execution process and record it in the log module; then feed back the error information to the host side in real time through WebSocket for testers to view and analyze.

[0016] In a second aspect, the present invention provides a mobile phone APP automatic testing device, comprising:

[0017] Initialization module, test device initialization, connect at least one Android device to the host, install the set test APK to the Android device, the test APK integrates J2V8 and implements the WebSocket client to establish two-way communication with the Spring Boot WebSocket service on the host; at the same time, install the tested APP to the Android device; start the test APP, register the Android device to the host, and send the device information of the Android device to the host;

[0018] In the task delivery module, the host side listens to the test task request through the Spring Boot WebSocket service; the host side classifies the captured test task request according to the settings, and selects the target device according to the task priority and Android device status; the host side delivers the test task script and the corresponding configuration file to the target device through the Spring Boot WebSocket service;

[0019] Load the injection module, test that the WebSocket client of the APK receives the test task script and the corresponding configuration file sent by the host, and loads them into J2V8; inject the functional interface of the script execution environment into the J2V8 execution environment;

[0020] The test feedback module loads and executes the test task script through J2V8, captures the error information during the execution process and records it in the log module; then the error information is fed back to the host side in real time through WebSocket for testers to view and analyze.

[0021] One or more technical solutions provided by the present invention have at least the following technical effects or advantages:

[0022] The test script of the present invention is directly run in the target device through J2V8, and the script logic and the operating environment are embedded in the device, thus avoiding frequent communication between the host and the device and significantly improving the execution efficiency.

[0023] By embedding J2V8 and SDK API in the device, the target device has the ability to independently parse and run test scripts. The host side is only responsible for task management and script distribution, which simplifies the configuration requirements of the test environment and improves the environmental isolation of the target device.

[0024] The present invention uses WebSocket to achieve two-way real-time communication between the host and the device. This mechanism can reliably and quickly distribute test script tasks and feed back the execution results to the host in a timely manner, thereby improving the stability and real-time performance of the test process.

[0025] The present invention exposes the specific functional capabilities of the device to the JavaScript execution environment of J2V8 by dynamically injecting SDK API. The test script can directly call these built-in capabilities, quickly adapt to diverse test requirements, and realize flexible expansion of the script.

[0026] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented according to the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] The present invention will be further described below in conjunction with embodiments with reference to the accompanying drawings.

[0028] Figure 1 is a flow chart of the method in Embodiment 1 of the present invention;

[0029] Figure 2 It is a schematic diagram of the structure of the device in the second embodiment of the present invention. DETAILED DESCRIPTION

[0030] The technical solution in the embodiment of the present application has the following general idea:

[0031] Step 1: Initialize the test equipment

[0032] 1. Equipment preparation:

[0033] Connect multiple Android devices to the host via USB.

[0034] 2. Test APK installation:

[0035] The host uses the ADB tool to batch install the test APK containing the J2V8 engine to the target device.

[0036] At the same time, install the APP to be tested on the target device;

[0037] 3. Device registration:

[0038] Launch the test APK on the target device.

[0039] Implement the WebSocket client in the test APK and establish two-way communication through the Spring Boot WebSocket service on the host side.

[0040] The host receives the device registration request and records the unique identification of the device (such as device ID, status, etc.) to ensure that the device can correctly participate in task allocation.

[0041] Step 2: Task distribution

[0042] 1. Task monitoring:

[0043] The host listens to test task requests through the Spring Boot WebSocket service.

[0044] 2. Task organization:

[0045] The task management module on the host side classifies and organizes the captured tasks and selects the appropriate target device based on the task priority and device status.

[0046] 3. Task issuance:

[0047] The host sends the test task script and its related configuration to the target device through the Spring Boot WebSocket service.

[0048] Supported script delivery methods:

[0049] Single JavaScript file: Directly deliver a single .js script file, suitable for simple tasks.

[0050] Modular project files: A compressed package (.zip) of project files that complies with the CommonJS specification is sent, which contains multiple module files. After receiving the compressed package, the target device will decompress it and load it into the J2V8 engine.

[0051] Task verification: When a task is issued, the file integrity will be verified and the receipt status will be confirmed.

[0052] Step 3: Test script loading and execution

[0053] 1. Task reception and bridging:

[0054] The WebSocket client of the test APK receives the test task script sent by the host.

[0055] Single file mode: For a single script file, it is directly loaded into the J2V8 executor and prepared for execution.

[0056] Modular mode: For compressed package files, first decompress them to a temporary directory on the target device, load the project directory, and parse CommonJS module dependencies.

[0057] The test task script in JavaScript format is run by the J2V8 execution environment and is bound to the execution context of the device (information of the execution environment).

[0058] 2. SDK API injection:

[0059] The J2V8 injector of the test APK is responsible for dynamically injecting the functional interface of the script execution environment into the J2V8 execution environment, including the following two injection schemes:

[0060] Solution 1: Dynamically call the host interface through WebSocket+ADB

[0061] When a test task script needs to call complex device functions (such as advanced system commands), the script sends a request to the host through WebSocket.

[0062] The host uses the ADB tool to call the device's functions, and after completion, returns the results to the test task script through WebSocket.

[0063] Solution 2: Providing device UI operation capabilities through the Accessibility API

[0064] The test APK is configured as an Accessibility service, allowing direct manipulation of the target device's interface and its UI elements.

[0065] The script calls the dynamically injected interface to perform operations such as UI element search, click, and slide.

[0066] Step 4: Execution of automated operations

[0067] 1. Start the script execution:

[0068] The J2V8 executor in the test APK starts the J2V8 engine, loads and executes the encapsulated test task script.

[0069] 2.Automation capability call:

[0070] The test task script calls the injected SDK API according to the logic to complete the following typical operations:

[0071] UI element operation: Use the Accessibility API to simulate user interaction behaviors such as clicking and sliding.

[0072] Advanced system commands: Request the host-side ADB tool through WebSocket to execute Shell commands or other device function operations.

[0073] File and screenshot operations: directly call the injected file management and screenshot interfaces to access device files and capture images.

[0074] Business interface call: For specific business scenarios (such as TikTok functions), the test logic is implemented through dynamically injected business interfaces.

[0075] 3. Error capture and handling:

[0076] During the execution process, the system captures errors in the script and records them in the log module.

[0077] Error information is fed back to the host in real time via WebSocket, making it easier for testers to view and analyze it.

[0078] Step 5: Real-time feedback and result reporting

[0079] 1. Real-time log upload:

[0080] The WebSocket client of the test APK uploads the real-time log of task execution to the host through the Spring Boot WebSocket service.

[0081] 2. Task Completion Report:

[0082] After the script is executed, the test APK summarizes the following data: execution status (success / failure), error log (if any), and screenshot files or test output files.

[0083] Upload the above report to the host service through WebSocket communication.

[0084] 3. Result storage and analysis:

[0085] The host side stores the received logs, screenshots, and result files, providing data support for subsequent generation of test reports or troubleshooting.

[0086] Step 6: Scheduling subsequent tasks

[0087] 1. Task closed-loop management:

[0088] The host marks the task completion status and updates the device status to "idle", ready to assign new tasks.

[0089] 2. Exception handling:

[0090] If the task fails to execute, the host side reallocates the task by analyzing the error log, or adjusts the script and sends it again.

[0091] 3. Global log summary:

[0092] The host side uniformly collects the execution logs and exception records of all tasks to provide a reference for subsequent test optimization.

[0093] Embodiment 1

[0094] like Figure 1 As shown, this embodiment provides a mobile phone APP automated testing method, including the following steps:

[0095] Step 1: Initialize the test device, connect at least one Android device to the host, install the set test APK to the Android device, the test APK integrates J2V8 and implements the WebSocket client to establish two-way communication with the Spring Boot WebSocket service on the host; install the tested APP to the Android device at the same time; start the test APP, register the Android device with the host, and send the device information of the Android device to the host;

[0096] Step 2: The host listens to the test task request through the Spring Boot WebSocket service; the host classifies the captured test task request according to the settings, and selects the target device according to the task priority and Android device status; the host sends the test task script and the corresponding configuration file to the target device through the Spring Boot WebSocket service;

[0097] Step 3: The WebSocket client of the test APK receives the test task script and the corresponding configuration file sent by the host, and loads them into J2V8; injects the functional interface of the script execution environment into the J2V8 execution environment;

[0098] Step 4: Load and execute the test task script through J2V8, capture the error information during the execution process and record it in the log module; then feed back the error information to the host side in real time through WebSocket for testers to view and analyze.

[0099] In this embodiment, preferably, the step 2 is specifically as follows: the host side listens to the test task request through the Spring Boot WebSocket service; the host side classifies the captured test task request according to the settings, and selects the target device according to the task priority and the Android device status; the host side sends the test task script and the corresponding configuration file to the target device through the Spring Boot WebSocket service; the test task script is sent to the target device in the form of a single JavaScript file, or is sent to the target device in the form of a modular engineering file.

[0100] In this embodiment, preferably, the step 3 is specifically as follows: the WebSocket client of the test APK receives the test task script and the corresponding configuration file sent by the host side, and loads them into J2V8;

[0101] If it is a JavaScript file, it is directly loaded into J2V8; if it is a modular project file, the modular project file is unzipped to the temporary directory of the target device, the project directory is loaded and the CommonJS module dependencies are parsed;

[0102] Inject the functional interface of the script execution environment into the J2V8 execution environment, and the injection includes: when the test task script needs to call the function of the set Android device, send a request to the host side through WebSocket; the host side calls the corresponding function of the Android device through the ADB tool, and after completion, returns the running result to the test task script through WebSocket; or, provide Android device UI operation capabilities through the Accessibility API, configure the test APK as an Accessibility service, and allow the test task script to directly operate the interface of the Android device and its UI elements.

[0103] In this embodiment, preferably, step 4 is specifically as follows: load and execute the test task script through J2V8, capture the error information during the execution process and record it in the log module; then feed back the error information to the host side in real time through WebSocket for testers to view and analyze; after the test task script is executed, upload all test information to the host side, and the host side receives and stores it.

[0104] This embodiment preferably further includes step 5: when the Android device completes the test task script, the host side marks the state of the Android device as idle, in preparation for allocating a new test task script.

[0105] Based on the same inventive concept, the present application also provides a device corresponding to the method in Example 1, see Example 2 for details.

[0106] Embodiment 2

[0107] like Figure 2 As shown, in this embodiment, a mobile phone APP automatic testing device is provided, including:

[0108] Initialization module, test device initialization, connect at least one Android device to the host, install the set test APK to the Android device, the test APK integrates J2V8 and implements the WebSocket client to establish two-way communication with the Spring Boot WebSocket service on the host; at the same time, install the tested APP to the Android device; start the test APP, register the Android device to the host, and send the device information of the Android device to the host;

[0109] In the task delivery module, the host side listens to the test task request through the Spring Boot WebSocket service; the host side classifies the captured test task request according to the settings, and selects the target device according to the task priority and Android device status; the host side delivers the test task script and the corresponding configuration file to the target device through the Spring Boot WebSocket service;

[0110] Load the injection module, test that the WebSocket client of the APK receives the test task script and the corresponding configuration file sent by the host, and loads them into J2V8; inject the functional interface of the script execution environment into the J2V8 execution environment;

[0111] The test feedback module loads and executes the test task script through J2V8, captures the error information during the execution process and records it in the log module; then the error information is fed back to the host side in real time through WebSocket for testers to view and analyze.

[0112] In this embodiment, preferably, the task issuing module is specifically as follows: the host side listens to the test task request through the Spring Boot WebSocket service; the host side classifies the captured test task request according to the settings, and selects the target device according to the task priority and the Android device status; the host side sends the test task script and the corresponding configuration file to the target device through the Spring Boot WebSocket service; the test task script is sent to the target device in the form of a single JavaScript file, or is sent to the target device in the form of a modular engineering file.

[0113] In this embodiment, preferably, the loading and injection module is specifically as follows: the WebSocket client of the test APK receives the test task script and the corresponding configuration file sent by the host side, and loads them into J2V8;

[0114] If it is a JavaScript file, it is directly loaded into J2V8; if it is a modular project file, the modular project file is unzipped to the temporary directory of the target device, the project directory is loaded and the CommonJS module dependencies are parsed;

[0115] Inject the functional interface of the script execution environment into the J2V8 execution environment, and the injection includes: when the test task script needs to call the function of the set Android device, send a request to the host side through WebSocket; the host side calls the corresponding function of the Android device through the ADB tool, and after completion, returns the running result to the test task script through WebSocket; or, provide Android device UI operation capabilities through the Accessibility API, configure the test APK as an Accessibility service, and allow the test task script to directly operate the interface of the Android device and its UI elements.

[0116] In this embodiment, preferably, the test feedback module is specifically: loading and executing the test task script through J2V8, capturing the error information during the execution process and recording it in the log module; then feeding back the error information to the host side in real time through WebSocket for testers to view and analyze; after the test task script is executed, all test information is uploaded to the host side, and the host side receives and stores it.

[0117] This embodiment preferably further includes a marking module, and when the Android device completes the test task script, the host side marks the state of the Android device as idle, in preparation for allocating a new test task script.

[0118] Since the device introduced in the second embodiment of the present invention is a device used to implement the method of the first embodiment of the present invention, those skilled in the art can understand the specific structure and deformation of the device based on the method introduced in the first embodiment of the present invention, so it is not described here in detail. All devices used in the method of the first embodiment of the present invention belong to the scope of protection of the present invention.

[0119] The technical solution provided in the embodiments of the present application has at least the following technical effects or advantages:

[0120] The test script task of this embodiment is directly executed in the target device through the J2V8 engine, and the script logic and the operating environment are embedded in the device, thus avoiding frequent communication between the host and the device and significantly improving the execution efficiency.

[0121] In this embodiment, the host side is only responsible for task management and script distribution, which simplifies the configuration requirements of the test environment and improves the environmental isolation of the target device.

[0122] This embodiment uses WebSocket to achieve two-way real-time communication between the host and the device. This mechanism can reliably and quickly distribute test script tasks and promptly feed back the execution results to the host, improving the stability and real-time performance of the test process.

[0123] Although the specific implementation modes of the present invention are described above, those skilled in the art should understand that the specific implementation modes described are only illustrative and are not intended to limit the scope of the present invention. Equivalent modifications and changes made by those skilled in the art in accordance with the spirit of the present invention should be included in the scope of protection of the claims of the present invention.

Claims

1. A mobile phone APP automated testing method, characterized in that: The steps include: Step 1: Initialize the test device, connect at least one Android device to the host, install the set test APK to the Android device, the test APK integrates J2V8 and implements the WebSocket client to establish two-way communication with the Spring Boot WebSocket service on the host; at the same time, install the tested APP to the Android device; Start the test APP, register the Android device with the host, and send the device information of the Android device to the host; Step 2: The host listens to the test task request through the Spring Boot WebSocket service; The host classifies the captured test task requests according to the settings and selects the target device according to the task priority and Android device status; the host sends the test task script and the corresponding configuration file to the target device through the Spring Boot WebSocket service; Step 3: The WebSocket client of the test APK receives the test task script and the corresponding configuration file sent by the host, and loads them into J2V8; Inject the functional interface of the script execution environment into the J2V8 execution environment; Step 4: Load and execute the test task script through J2V8, capture the error information during the execution process and record it in the log module; then feed back the error information to the host side in real time through WebSocket for testers to view and analyze.

2. According to claim 1, a mobile phone APP automated testing method is characterized in that: The step 2 is specifically as follows: the host side listens to the test task request through the Spring Boot WebSocket service; the host side classifies the captured test task request according to the settings, and selects the target device according to the task priority and the Android device status; the host side sends the test task script and the corresponding configuration file to the target device through the Spring Boot WebSocket service; the test task script is sent to the target device in the form of a single JavaScript file, or in the form of a modular engineering file.

3. According to claim 1, a mobile phone APP automated testing method is characterized in that: The step 3 is specifically as follows: the WebSocket client of the test APK receives the test task script and the corresponding configuration file sent by the host, and loads them into J2V8; If it is a JavaScript file, it is directly loaded into J2V8; if it is a modular project file, the modular project file is unzipped to the temporary directory of the target device, the project directory is loaded and the CommonJS module dependencies are parsed; Injecting the function interface of the script execution environment into the J2V8 execution environment, wherein the injection includes: when the test task script needs to call the function of the set Android device, sending a request to the host side through WebSocket; The host side calls the corresponding functions of the Android device through the ADB tool, and returns the running results to the test task script through WebSocket after completion; or, through the Accessibility API, the Android device UI operation capability is provided, and the test APK is configured as an Accessibility service, allowing the test task script to directly operate the interface of the Android device and its UI elements.

4. According to claim 1, a mobile phone APP automated testing method is characterized in that: The step 4 is specifically as follows: load and execute the test task script through J2V8, capture the error information during the execution process and record it in the log module; then feed back the error information to the host side in real time through WebSocket for testers to view and analyze; after the test task script is executed, upload all test information to the host side, and the host side receives and stores it.

5. According to claim 1, a mobile phone APP automated testing method is characterized in that: The method also includes step 5: when the Android device completes the test task script, the host marks the state of the Android device as idle to prepare for allocating a new test task script.

6. A mobile phone APP automated testing device, characterized in that: include: Initialization module, test device initialization, connect at least one Android device to the host, install the set test APK to the Android device, the test APK integrates J2V8 and implements the WebSocket client to establish two-way communication with the Spring Boot WebSocket service on the host; at the same time, install the tested APP to the Android device; Start the test APP, register the Android device with the host, and send the device information of the Android device to the host; In the task delivery module, the host side listens to the test task request through the Spring Boot WebSocket service; The host classifies the captured test task requests according to the settings and selects the target device according to the task priority and Android device status; the host sends the test task script and the corresponding configuration file to the target device through the Spring Boot WebSocket service; Load the injection module, test the APK's WebSocket client to receive the test task script and corresponding configuration file sent by the host, and load them into J2V8; Inject the functional interface of the script execution environment into the J2V8 execution environment; The test feedback module loads and executes the test task script through J2V8, captures the error information during the execution process and records it in the log module; then the error information is fed back to the host side in real time through WebSocket for testers to view and analyze.

7. A mobile phone APP automatic testing device according to claim 6, characterized in that: The task sending module is specifically as follows: the host side listens to the test task request through the Spring BootWebSocket service; the host side classifies the captured test task request according to the settings, and selects the target device according to the task priority and the Android device status; the host side sends the test task script and the corresponding configuration file to the target device through the Spring BootWebSocket service; the test task script is sent to the target device in the form of a single JavaScript file, or in the form of a modular engineering file.

8. A mobile phone APP automated testing device according to claim 6, characterized in that: The loading and injection module is specifically as follows: the WebSocket client of the test APK receives the test task script and the corresponding configuration file sent by the host, and loads them into J2V8; If it is a JavaScript file, it is directly loaded into J2V8; if it is a modular project file, the modular project file is unzipped to the temporary directory of the target device, the project directory is loaded and the CommonJS module dependencies are parsed; Injecting the function interface of the script execution environment into the J2V8 execution environment, wherein the injection includes: when the test task script needs to call the function of the set Android device, sending a request to the host side through WebSocket; The host side calls the corresponding functions of the Android device through the ADB tool, and returns the running results to the test task script through WebSocket after completion; or, through the Accessibility API, the Android device UI operation capability is provided, and the test APK is configured as an Accessibility service, allowing the test task script to directly operate the interface of the Android device and its UI elements.

9. A mobile phone APP automatic testing device according to claim 6, characterized in that: The test feedback module specifically loads and executes the test task script through J2V8, captures error information during the execution process and records it in the log module; then feeds back the error information to the host side in real time through WebSocket for testers to view and analyze; after the test task script is executed, all test information is uploaded to the host side, and the host side receives and stores it.

10. A mobile phone APP automatic testing device according to claim 6, characterized in that: It also includes a marking module. When the Android device completes the test task script, the host side marks the state of the Android device as idle, in preparation for allocating a new test task script.