Method and system for completing interface automatic use case generation and execution based on traffic collection
By conducting secondary development on the JVM Sandbox Repeater tool, using Python scripts to parse and assemble interface request traffic and generate detailed test reports, the problems of low interface request playback success rate and inflexible automation use case design of existing tools were solved, and efficient interface automation testing was achieved.
Patent Information
- Application Number
- CN202211221071.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-08
- Publication Date
- 2025-09-09
- Estimated Expiration
- 2042-10-08
AI Technical Summary
Existing JVM sandbox repeater tools only support traffic recording and single playback, and cannot download interface details. This results in a low request playback success rate, inflexible automated use case design, and a lack of detailed test reporting capabilities.
Based on the JVM sandbox repeater tool, Python scripts are used to parse interface request traffic, generate interface automation use cases, and use the Jinja2 library to render test reports, thereby realizing the download, parsing, assembly and test report generation of interface requests.
It achieves the diversity and simulation of interface requests, reduces the time for manually writing automated use cases, solves the problem of precise regression under system reconstruction and rapid iteration, and improves test efficiency and coverage.
Smart Images

Figure CN115629967B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing, and in particular to a method and system for completing interface automated use case generation and execution based on traffic collection. Background Art
[0002] The JVM Sandbox Repeater tool only records and replays traffic for a single session. It doesn't support downloading detailed interface information, doesn't process recorded traffic parameters, and doesn't parse or assemble unique parameters. Therefore, it can't guarantee the success rate of request replays or the flexibility of automated use case design. After replaying traffic, the results can only be viewed in real time, and detailed test reports are not available.
[0003] This invention uses the open source tool JVM Sandbox Repeater to record request traffic, implements the download of interface request traffic through secondary development, uses Python scripts to parse interface information and flexibly assemble interface automation use cases, and uses the Jenkins library in Python to render and display detailed test reports after test execution, providing a complete testing solution.
[0004] Patent document CN113709003A (application number: 202111027405.0) discloses a system, method and medium for automatically generating test cases through network traffic data, including: a network traffic data acquisition module: collecting network traffic data from a real environment through a bypass mirroring method, and processing the collected network traffic data; a playback parsing module: filtering and parsing the collected network traffic data according to the configuration file to obtain parsed data, and formatting the parsed data, converting the configuration file according to the formatted data format, and converting the parsed data into a playback file for playback testing in a test environment. Summary of the Invention
[0005] In view of the defects in the prior art, the purpose of the present invention is to provide a method and system for completing interface automatic use case generation and execution based on traffic collection.
[0006] According to the present invention, a method for completing interface automation use case generation and execution based on traffic collection is provided, comprising:
[0007] Step S1: Deploy the JVM Sandbox Repeater tool on the front end of the application and add configuration information to the target interface;
[0008] Step S2: After the configuration is completed, the traffic of the target service module is monitored and recorded to obtain the interface request information;
[0009] Step S3: Provide a download function for the recorded interface traffic information, and complete the traffic download of the target request interface through the configuration information;
[0010] Step S4: assemble and generate interface test automation use cases by parsing basic information of download traffic;
[0011] Step S5: Execute the interface test automation case, record the execution results, and compare the execution results with the expected results;
[0012] Step S6: Interface automation use case execution report display.
[0013] Preferably, the step S1 adopts:
[0014] Step S1.1: Deploy the JVM sandbox repeater module to the application server, mount the business processing module, and implement monitoring of the business request interface;
[0015] Step S1.2: Configure the target environment, target application, and target interface information to be monitored, and establish a heartbeat after the configuration is complete.
[0016] Preferably, the step S2 adopts:
[0017] Step S2.1: Send a request to the target interface and record the request data sent and received;
[0018] Step S2.2: Store relevant traffic data packets, process and filter the traffic, obtain the request parameters of the request interface and return result information.
[0019] Preferably, the step S3 adopts:
[0020] Step S3.1: Filter the recorded requests based on the configured environment parameters, application parameters, and interface parameter information, and select the data that successfully returns information;
[0021] Step S3.2: Download the screening results to obtain the interface traffic information table, including the traffic recording environment, application name, interface request path, request address, request method, request header, request body, status code and response body information.
[0022] Preferably, the step S4 adopts:
[0023] Step S4.1: Parse the downloaded interface traffic information table using the Python language extension package xlrd to obtain table cell data, including the request address, request header, and request method;
[0024] Step S4.2: Assemble the interface automation test case through the request method of the Python language extension package requests, including the interface request method, request address, and request header information.
[0025] Preferably, the step S5 adopts:
[0026] Step S5.1: Obtain the successfully assembled interface automation use case, send the interface request in a loop through the request method, and obtain the relevant interface response results, including the returned response body and response code information;
[0027] Step S5.2: Use the return result data of the traffic download as the expected result and the result of the interface automation execution as the actual result. Use the deepdiff library in Python to perform a differential comparison of the return result json to obtain the difference result.
[0028] Preferably, the step S6 adopts: using the jinja2 extension library in python to complete the rendering of the test report, the test report includes the pass rate, interface response time, interface list and interface differentiation result information;
[0029] The pass rate is determined by the response result, and a response code of 200 indicates that the test has passed;
[0030] The interface response time is the time taken from the interface request to the interface return;
[0031] The interface list includes: request address, request method and status code; the interface list is displayed in the order of loop requests;
[0032] The differentiated result is a differentiated comparison between the expected result of the display interface and the automated execution result.
[0033] According to the present invention, a system for automatically generating and executing interface use cases based on traffic collection is provided, comprising:
[0034] Module M1: Deploy the JVM Sandbox Repeater tool on the front end of the application and add configuration information to the target interface;
[0035] Module M2: After configuration is completed, it monitors and records the traffic of the target business module and obtains interface request information;
[0036] Module M3: provides a download function for the recorded interface traffic information, and completes the traffic download of the target request interface through configuration information;
[0037] Module M4: assembles and generates interface test automation cases by parsing basic information of download traffic;
[0038] Module M5: Execute interface test automation cases, record the execution results, and compare the execution results with the expected results;
[0039] Module M6: Interface automation use case execution report presentation.
[0040] Preferably, the module M1 adopts:
[0041] Module M1.1: Deploy the JVM sandbox repeater module to the application server, mount the business processing module, and implement monitoring of the business request interface;
[0042] Module M1.2: Configure the target environment, target application, and target interface information to be monitored, and establish a heartbeat after the configuration is complete;
[0043] The module M2 adopts:
[0044] Module M2.1: Sends a request to the target interface and records the request data sent and received;
[0045] Module M2.2: stores relevant traffic data packets, processes and filters the traffic, obtains the request parameters of the request interface, and returns result information.
[0046] Preferably, the module M3 adopts:
[0047] Module M3.1: Filter recorded requests based on configured environment parameters, application parameters, and interface parameters, and select the data that successfully returns information;
[0048] Module M3.2: Download the filtering results to obtain the interface traffic information table, including the traffic recording environment, application name, interface request path, request address, request method, request header, request body, status code, and response body information;
[0049] The module M4 adopts:
[0050] Module M4.1: Use the Python language extension package xlrd to parse the downloaded interface traffic information table and obtain the table cell data, including the request address, request header, and request method;
[0051] Module M4.2: Assemble interface automation test cases through the request method of the Python language extension package requests, including the interface request method, request address, and request header information;
[0052] The module M5 adopts:
[0053] Module M5.1: Obtain the successfully assembled interface automation use case, send interface requests cyclically through the request method, and obtain the relevant interface response results, including the returned response body and response code information;
[0054] Module M5.2: Use the return result data of the traffic download as the expected result and the result of the interface automation execution as the actual result. Use the deepdiff library in Python to perform a differential comparison of the return result JSON to obtain the difference result;
[0055] The module M6 uses the jinja2 extension library in Python to complete the rendering of the test report, which includes the pass rate, interface response time, interface list and interface differentiation result information.
[0056] Compared with the prior art, the present invention has the following beneficial effects:
[0057] 1. The present invention locally stores and downloads the real traffic of system interface requests, parses and reorganizes the interface requests, and replaces unique parameters and random parameters to ensure the diversity and simulation of automation use cases;
[0058] 2. After the test case is executed, the test report is automatically generated by recording the differences between the actual and test scenarios, achieving accurate regression of the system interface under the development rhythm of service reconstruction or rapid iteration. At the same time, it reduces the time for manually writing automated use cases and allows for more flexible test case generation. It can also solve the pain point of some online bugs that cannot be reproduced. BRIEF DESCRIPTION OF THE DRAWINGS
[0059] Other features, objects and advantages of the present invention will become more apparent upon reading the detailed description of non-limiting embodiments with reference to the following drawings:
[0060] Figure 1 A system diagram for automatically generating and executing interface use cases based on traffic collection. DETAILED DESCRIPTION
[0061] The present invention will be described in detail below with reference to specific embodiments. The following examples will help those skilled in the art to further understand the present invention, but are not intended to limit the present invention in any form. It should be noted that, for those skilled in the art, several changes and improvements can be made without departing from the scope of the present invention. These all fall within the scope of protection of the present invention.
[0062] Example 1
[0063] The present invention provides a method and system for completing interface automatic use case generation and execution based on traffic collection, including: mounting the Jvm Sandbox Repeater module to the business module of the Java type application to complete the monitoring of the relevant business request interface, including collecting and recording traffic data such as the input parameters and return values of the http, java, and dubbo type interfaces; providing a traffic download function, in the Jvm Sandbox The download function is developed based on Repeater, which records and saves the data monitored by the business module, provides a download address and supports downloading and saving as an Excel spreadsheet; the interface traffic information of the application is obtained by parsing the Excel spreadsheet through code, including its request address, request method, request body, status code, response body and other information; the interface test case is automatically generated, and the program loop is used through the requests library in Python to obtain the interface related information, and the request address, request method and request header are used to assemble the relevant interface test case for the get type request; the interface test case is executed through the code loop and the request function is used to complete the execution of the relevant interface test case. The downloaded interface return data is used as the expected result, and the execution result of the assembled case is used as the actual result. The two execution results are compared differentially; a test report is generated, and a test report template is prepared. The results of the interface test case execution are rendered into a test report through the jinja2 library in Python. The main display indicators are pass rate, response time, interface list, differential results and other information.
[0064] The present invention mounts a JVM sandbox repeater on an application to monitor program interface requests and store data, and automatically generates and executes interface automation use cases by splitting and reorganizing the downloaded results. This solves the problem of fast and accurate regression testing under system reconstruction and fast-paced version delivery, and achieves effective regression testing with high efficiency and wide coverage.
[0065] The present invention provides a method for completing interface automation use case generation and execution based on traffic collection, comprising:
[0066] Step 1: Deploy the JVM Sandbox Repeater tool on the application front end and add configuration information to the target interface.
[0067] Step 2: After the configuration is complete, monitor and record the traffic of the target business module to obtain interface request information;
[0068] Step 3: Provide a download function for the recorded interface traffic information. By configuring the environment parameters, application parameters, and interface parameters, complete the traffic download of the target request interface.
[0069] Step 4: Analyze the basic information of the download traffic and assemble and generate interface test automation cases;
[0070] Step 5: Execute the automated test cases for the interface test and compare the results.
[0071] Step 6: Interface automation use case execution report presentation.
[0072] Specifically, step 1 includes the following steps:
[0073] Step 1.1: Deploy the JVM Sandbox Repeater module to the application server, mount the business processing module, and implement monitoring of the business request interface;
[0074] Step 1.2: Configure the target environment, target application, target interface, and other information to be monitored, and establish a heartbeat after the configuration is complete.
[0075] Specifically, step 2 includes the following steps:
[0076] Step 2.1: Send a request to the target interface and record the request data sent and received;
[0077] Step 2.2: Store relevant traffic data packets, process and filter the traffic, and obtain the request parameters, return results and other information of the request interface.
[0078] Specifically, step 3 includes the following steps:
[0079] Step 3.1: Filter the recorded requests based on the configured environment parameters, application parameters, interface parameters, and other information, and select the data that successfully returns information;
[0080] Step 3.2: Download the filtered results, including information such as the traffic recording environment, application name, interface request path, method, request header, request body, status code, and response body.
[0081] Specifically, step 4 includes the following steps:
[0082] Step 4.1: Use the Python language extension package xlrd to parse the downloaded interface traffic information table and obtain the table cell data. The program obtains the request address, request header, request method, request header and other information;
[0083] Step 4.2: Assemble interface automation test cases through the request method of the Python language extension package requests. The test cases mainly include the interface request method, request address, and request header information.
[0084] Specifically, step 5 includes the following steps:
[0085] Step 5.1: Obtain the successfully assembled interface automation use case, send interface requests in a loop through the request method, and obtain the relevant interface response results, including key information such as the returned response body and response code;
[0086] Step 5.2: Use the return result data of the traffic download as the expected result and the result of the interface automation execution as the actual result. Use the deepdiff library in Python to perform a differential comparison of the return result JSON to obtain the difference result.
[0087] Specifically, step 6 includes the following steps:
[0088] Step 6.1: Use the Jinja2 extension library in Python to render the test report. The test report mainly contains information such as pass rate, interface response time, interface list, and interface differentiation results.
[0089] Step 6.2: The interface execution pass rate is mainly determined by the response result. A response code of 200 indicates that the test has passed. The interface response time mainly refers to the time taken from the interface request to the interface return. The interface list mainly includes the request address, request method, status code, and the interface list is displayed in the order of the loop request. The differentiated results mainly show the differentiated comparison between the expected results of the interface and the automated execution results.
[0090] The present invention provides a system for completing interface automation use case generation and execution based on traffic collection, such as Figure 1 As shown, including:
[0091] Module 1: Deploy the JVM Sandbox Repeater tool on the front end of the application and add configuration information to the target interface;
[0092] Module 2: After configuration is complete, monitor and record the traffic of the target business module to obtain interface request information;
[0093] Module 3: Provides a download function for recorded interface traffic information. By configuring environment parameters, application parameters, and interface parameters, it completes the traffic download of the target request interface.
[0094] Module 4: Analyze the basic information of download traffic and assemble and generate interface test automation cases;
[0095] Module 5: Execute automated test cases for interface testing and compare the results;
[0096] Module 6: Interface automation use case execution report presentation.
[0097] Specifically, the module 1 includes the following modules:
[0098] Module 1.1: Deploy the JVM Sandbox Repeater module to the application server, mount the business processing module, and implement monitoring of the business request interface;
[0099] Module 1.2: Configure the target environment, target application, target interface and other information to be monitored, and establish a heartbeat after the configuration is complete.
[0100] Specifically, the module 2 includes the following modules:
[0101] Module 2.1: Send a request to the target interface and record the request data sent and received;
[0102] Module 2.2: Store relevant traffic data packets, process and filter the traffic, and obtain request parameters, return results and other information of the request interface.
[0103] Specifically, the module 3 includes the following modules:
[0104] Module 3.1: Filter recorded requests based on configured environment parameters, application parameters, interface parameters, and other information, and select the data that successfully returns information;
[0105] Module 3.2: Download the screening results, including information such as traffic recording environment, application name, interface request path, method, request header, request body, status code, response body, etc.
[0106] Specifically, the module 4 includes the following modules:
[0107] Module 4.1: Use the Python language extension package xlrd to parse the downloaded interface traffic information table, obtain the table cell data, and the program obtains the request address, request header, request method, request header and other information;
[0108] Module 4.2: Assemble interface automation test cases through the request method of the Python language extension package requests. The test cases mainly include the interface request method, request address, and request header information.
[0109] Specifically, the module 5 includes the following modules:
[0110] Module 5.1: Obtain the successfully assembled interface automation use case, send interface requests in a loop through the request method, and obtain the relevant interface response results, including key information such as the returned response body and response code;
[0111] Module 5.2: Use the return result data of traffic download as the expected result and the result of interface automation execution as the actual result. Use the deepdiff library in Python to perform differential comparison of the return result JSON to obtain the difference result.
[0112] Specifically, the module 6 includes the following modules:
[0113] Module 6.1: Use the Jinja2 extension library in Python to render the test report. The test report mainly contains information such as pass rate, interface response time, interface list, interface differentiation results, etc.
[0114] Module 6.2: The interface execution pass rate is mainly determined by the response result. A response code of 200 indicates that the test has passed. The interface response time mainly refers to the time taken from the interface request to the interface return. The interface list mainly includes the request address, request method, status code, and the interface list is displayed in the order of the loop request. The differentiated results mainly show the differentiated comparison between the expected results of the interface and the automated execution results.
[0115] Those skilled in the art will appreciate that, in addition to implementing the system, device, and various modules provided by the present invention in purely computer-readable program code, it is entirely possible to implement the same program in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, embedded microcontrollers, and the like by logically programming the method steps. Therefore, the system, device, and various modules provided by the present invention can be considered a hardware component, and the modules included therein for implementing various programs can also be considered structures within the hardware component; the modules for implementing various functions can also be considered both software programs for implementing the method and structures within the hardware component.
[0116] The above describes specific embodiments of the present invention. It should be understood that the present invention is not limited to the specific embodiments described above, and those skilled in the art may make various changes or modifications within the scope of the claims, which do not affect the essence of the present invention. The embodiments of this application and the features in the embodiments may be combined with each other in any manner unless there is a conflict.
Claims
1. A method for completing interface automation use case generation and execution based on traffic collection, characterized in that: include: Step S1: Deploy the JVM Sandbox Repeater tool on the front end of the application and add configuration information to the target interface; Step S2: After the configuration is completed, the traffic of the target service module is monitored and recorded to obtain the interface request information; Step S3: Provide a download function for the recorded interface traffic information, and complete the traffic download of the target request interface through the configuration information; Step S4: assemble and generate interface test automation use cases by parsing basic information of download traffic; Step S5: Execute the interface test automation case, record the execution results, and compare the execution results with the expected results; Step S6: Interface automation use case execution report display; The step S5 adopts: Step S5.1: Obtain the successfully assembled interface automation use case, send the interface request in a loop through the request method, and obtain the relevant interface response results, including the returned response body and response code information; Step S5.2: Use the returned result data of the traffic download as the expected result and the result of the interface automation execution as the actual result. Use the deepdiff library in Python to perform a differential comparison of the returned result JSON to obtain the difference result; The step S6 adopts: using the jinja2 extension library in Python to complete the rendering of the test report, the test report includes the pass rate, interface response time, interface list and interface differentiation result information; The pass rate is determined by the response result, and a response code of 200 indicates that the test has passed; The interface response time is the time taken from the interface request to the interface return; The interface list includes: request address, request method and status code; the interface list is displayed in the order of loop requests; The differentiated result is a differentiated comparison between the expected result of the display interface and the automated execution result.
2. The method for completing interface automation use case generation and execution based on traffic collection according to claim 1 is characterized in that: The step S1 adopts: Step S1.1: Deploy the JVM sandbox repeater module to the application server, mount the business processing module, and implement monitoring of the business request interface; Step S1.2: Configure the target environment, target application, and target interface information to be monitored, and establish a heartbeat after the configuration is complete.
3. The method for completing interface automation use case generation and execution based on traffic collection according to claim 1 is characterized in that: The step S2 adopts: Step S2.1: Send a request to the target interface and record the request data sent and received; Step S2.2: Store relevant traffic data packets, process and filter the traffic, obtain the request parameters of the request interface and return result information.
4. The method for completing interface automation use case generation and execution based on traffic collection according to claim 1 is characterized in that: The step S3 adopts: Step S3.1: Filter the recorded requests based on the configured environment parameters, application parameters, and interface parameter information, and select the data that successfully returns information; Step S3.2: Download the screening results to obtain the interface traffic information table, including the traffic recording environment, application name, interface request path, request address, request method, request header, request body, status code and response body information.
5. The method for completing interface automation use case generation and execution based on traffic collection according to claim 1 is characterized in that: The step S4 adopts: Step S4.1: Parse the downloaded interface traffic information table using the Python language extension package xlrd to obtain table cell data, including the request address, request header, and request method; Step S4.2: Assemble the interface automation test case through the request method of the Python language extension package requests, including the interface request method, request address, and request header information.
6. A system for automatically generating and executing interface use cases based on traffic collection, characterized in that: include: Module M1: Deploy the JVM Sandbox Repeater tool on the front end of the application and add configuration information to the target interface; Module M2: After configuration is completed, it monitors and records the traffic of the target business module and obtains interface request information; Module M3: provides a download function for the recorded interface traffic information, and completes the traffic download of the target request interface through configuration information; Module M4: assembles and generates interface test automation cases by parsing basic information of download traffic; Module M5: Execute interface test automation cases, record the execution results, and compare the execution results with the expected results; Module M6: Interface automation use case execution report presentation; The module M3 adopts: Module M3.1: Filter recorded requests based on configured environment parameters, application parameters, and interface parameters, and select the data that successfully returns information; Module M3.2: Download the filtering results to obtain the interface traffic information table, including the traffic recording environment, application name, interface request path, request address, request method, request header, request body, status code, and response body information; The module M4 adopts: Module M4.1: Use the Python language extension package xlrd to parse the downloaded interface traffic information table and obtain the table cell data, including the request address, request header, and request method; Module M4.2: Assemble interface automation test cases through the request method of the Python language extension package requests, including the interface request method, request address, and request header information; The module M5 adopts: Module M5.1: Obtain the successfully assembled interface automation use case, send interface requests cyclically through the request method, and obtain the relevant interface response results, including the returned response body and response code information; Module M5.2: Use the return result data of the traffic download as the expected result and the result of the interface automation execution as the actual result. Use the deepdiff library in Python to perform a differential comparison of the return result JSON to obtain the difference result; The module M6 uses the jinja2 extension library in Python to complete the rendering of the test report, which includes the pass rate, interface response time, interface list and interface differentiation result information.
7. The system for automatically generating and executing interface use cases based on traffic collection according to claim 6 is characterized in that: The module M1 adopts: Module M1.1: Deploy the JVM sandbox repeater module to the application server, mount the business processing module, and implement monitoring of the business request interface; Module M1.2: Configure the target environment, target application, and target interface information to be monitored, and establish a heartbeat after the configuration is complete; The module M2 adopts: Module M2.1: Sends a request to the target interface and records the request data sent and received; Module M2.2: stores relevant traffic data packets, processes and filters the traffic, obtains the request parameters of the request interface, and returns result information.
Citation Information
Patent Citations
System and method for automatically generating test case through network flow data and medium
CN113709003A
Method for generating automatic test case based on traffic recording
CN112749100A
Automatic test system and automatic test server
CN113704090A