Automated Testing Based on Multiple Scripts and Method and System for Modifying Dynamic Variables

Through the combination of batch processing and shell scripts, dynamic variable modification is performed using regular expressions, which solves the problems of automated execution and variable modification of multi-script tests in the existing technology, and realizes efficient and reliable test process management and result analysis.

CN120256315BActive Publication Date: 2025-08-01ZHEJIANG SHUXIN NETWORK CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510726872.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-06-03
Publication Date
2025-08-01
Estimated Expiration
2045-06-03

AI Technical Summary

Technical Problem

Existing performance testing methods lack automation when processing multiple test scripts. Testers need to manually start each script and collect results, and it is difficult to implement dynamic modification of variables in the test script, increasing testing complexity and maintenance costs.

Method used

Through the combination of batch scripts and shell scripts, regular expressions are used to match variable node information in the test script, dynamic modification is made with external configuration files, and automated testing process is achieved through continuous integration tools.

Benefits of technology

It realizes the automated execution and management of multiple test scripts, improves testing efficiency, enhances testing flexibility and adaptability, reduces the risks of manual intervention and errors, and provides comprehensive test results analysis capabilities.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120256315B_ABST
    Figure CN120256315B_ABST
Patent Text Reader

Abstract

The present invention provides an automated testing and dynamic variable modification method and system based on multiple scripts, which relates to the technical field of script testing. It includes calling the command-line tool of a performance testing tool through a batch script to execute multiple test scripts, and using a Shell script to preprocess the test scripts and dynamically modify the variable node information, and finally integrating and generating a unified test report. The present invention realizes the rapid switching of the test environment, the batch execution of test scripts, and the automatic integration of test results, improves the test efficiency, and reduces the manual operation error rate.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of script testing, and particularly to an automated testing and dynamic variable modification method and system based on multiple scripts. Background Art

[0002] In the fields of software development and testing, performance testing is an important link to ensure the quality of software systems. With the continuous improvement of the complexity of software systems, the number of test scripts to be executed is also increasing, making the testing work more onerous. Traditional performance testing usually requires testers to manually execute multiple test scripts and integrate and analyze the test results, which is inefficient and error-prone.

[0003] Currently, there are various performance testing tools on the market, such as JMeter, LoadRunner, etc. These tools provide rich functions to support the execution of performance testing. However, when multiple test scripts need to be executed, testers usually need to manually start each script and modify test parameters in different environments, which greatly increases the complexity and workload of testing.

[0004] Defects and deficiencies of the prior art:

[0005] Existing performance testing methods lack an automated mechanism when dealing with multiple test scripts. Testers need to manually start each script and collect results, which is not only time-consuming but also error-prone and difficult to meet the needs of large-scale testing.

[0006] It is difficult for the prior art to achieve dynamic modification of variables in test scripts. When the test environment changes, testers need to manually modify relevant parameters in each test script, such as server addresses, port numbers, etc., which increases the maintenance cost and reduces the testing efficiency. Summary of the Invention

[0007] Embodiments of the present invention provide an automated testing and dynamic variable modification method and system based on multiple scripts, which can solve the problems in the prior art.

[0008] In the first aspect of the embodiments of the present invention, an automated testing and dynamic variable modification method based on multiple scripts is provided, including:

[0009] Calling the command-line tool of the performance testing tool through a batch script, where the batch script is configured with the path information of the performance testing tool, the path information of multiple test script files, and the storage path information of the test result file;

[0010] Using the batch script to loop through and read the path information of the multiple test script files, and calling the command-line tool of the performance testing tool to sequentially execute the multiple test script files;

[0011] Preprocess the multiple test script files through a Shell script, where the preprocessing includes detecting the existence of the multiple test script files and cleaning historical test result files;

[0012] The Shell script uses regular expressions to match variable node information in the multiple test script files, and dynamically modifies the variable node information based on parameter information in an external configuration file. The variable node information includes server address information, port information, user authentication information, and communication protocol information;

[0013] The Shell script calls the command-line tool of the performance testing tool to integrate the test results of the multiple test script files to generate a unified test report, where the test report includes execution result information of the multiple test script files;

[0014] The batch script and the Shell script combine to form a test process, and the test process is called through the interface of a continuous integration tool to realize automatic execution of the test process in the continuous integration tool.

[0015] Using the batch script to loop through and read the path information of the multiple test script files, and calling the command-line tool of the performance testing tool to execute the multiple test script files in sequence includes:

[0016] A file path storage array is set in the batch script, and the file path storage array is used to store the path information of the multiple test script files;

[0017] The batch script obtains the path information of each test script file by traversing the file path storage array, and uses the obtained path information as the input parameter of the command-line tool of the performance testing tool;

[0018] The batch script determines the number of loop executions according to the length of the file path storage array, and generates independent test result files for each test script file.

[0019] The Shell script uses regular expressions to match variable node information in the multiple test script files, and dynamically modifies the variable node information based on parameter information in an external configuration file includes:

[0020] [[ID=NO=]]The Shell script reads a parameter configuration matrix in an external configuration file. The parameter configuration matrix includes multiple groups of parameter combinations, and each group of parameter combinations contains a parameter identifier, a current parameter value, a target parameter value, and a parameter verification rule;

[0021] The Shell script constructs a hierarchical regular expression matching rule. The regular expression matching rule includes a parameter positioning expression and a parameter extraction expression. The parameter positioning expression is used to locate the position of the XML node where the parameter is located, and the parameter extraction expression is used to obtain specific parameter value information;

[0022] The Shell script performs a two-way scan on the test script file based on the regular expression matching rule, and establishes a parameter mapping table during the scan. The parameter mapping table records the correspondence between the parameter identifier and the XML node; The Shell script locates the position of the parameter to be modified according to the parameter mapping table, replaces the current parameter value with the target parameter value, and uses the parameter verification rule to verify the correctness of the format of the modified parameter value.

[0023] The Shell script performs a two-way scan on the test script file based on the regular expression matching rule, and establishing a parameter mapping table during the scan includes:

[0024] The Shell script constructs a two-way traversal pointer, which includes a forward traversal pointer and a backward traversal pointer; The forward traversal pointer scans backward from the starting position of the test script file, and the backward traversal pointer scans forward from the end position of the test script file;

[0025] The Shell script extracts the hierarchical depth value and node attribute information of each XML node during the two-way scan, and stores the hierarchical depth value and the node attribute information in a temporary buffer; The Shell script constructs a parameter mapping table based on the information in the temporary buffer. The parameter mapping table stores the mapping relationship between the parameter identifier and the XML node in a hash structure, and the mapping relationship includes the absolute position information, relative position information of the node in the file, and the parent-child relationship information of the node;

[0026] The Shell script calculates the parameter positioning coordinates according to the absolute position information and the relative position information, and performs a modification operation on the target parameter value based on the parameter positioning coordinates; The Shell script uses a preset parameter verification rule to perform format verification and validity verification on the modified parameter value.

[0027] The method further includes:

[0028] Receiving a parameter modification instruction, the parameter modification instruction includes a target parameter identifier, a modified parameter value, and modification reason information; Obtaining a parameter historical version chain from a parameter version library based on the target parameter identifier, and the parameter historical version chain includes multiple historical version nodes corresponding to the target parameter identifier;

[0029] Extract parameter dependency information from the parameter historical version chain, where the parameter dependency information records the association rules between the target parameter identifier and other associated parameter identifiers; construct a parameter dependency graph based on the parameter dependency information, and the parameter dependency graph uses a tree structure to record the upstream and downstream associated parameters of the target parameter identifier.

[0030] For the modified parameter value, verify the association rules in the parameter dependency graph, and generate a parameter change impact assessment report, where the parameter change impact assessment report includes the information of the affected associated parameters in the parameter dependency graph.

[0031] After verifying the association rules in the parameter dependency graph for the modified parameter value and generating a parameter change impact assessment report, the method further includes:

[0032] Submit the modified parameter value and the parameter change impact assessment report to a parameter review module for review to generate review result information; when the review result information is passed, create a new version node, where the new version node includes a version identifier, the modified parameter value, the modification reason information, and timestamp information.

[0033] Insert the new version node into the parameter historical version chain, and synchronously update the affected associated parameter version nodes based on the parameter dependency graph; the parameter historical version chain supports rollback operations based on the version identifier or the timestamp information, and the rollback operation includes the consistent rollback of the target parameter and its associated parameters.

[0034] In the second aspect of the embodiments of the present invention, an automated testing and dynamic variable modification system based on multiple scripts is provided, including:

[0035] A first unit for calling a command-line tool of a performance testing tool through a batch script, where the batch script is configured with the path information of the performance testing tool, the path information of multiple test script files, and the storage path information of a test result file.

[0036] A second unit for using the batch script to loop through and read the path information of the multiple test script files, and calling the command-line tool of the performance testing tool to sequentially execute the multiple test script files.

[0037] A third unit for preprocessing the multiple test script files through a Shell script, where the preprocessing includes detecting whether the multiple test script files exist and cleaning historical test result files.

[0038] A fourth unit for the Shell script to use regular expressions to match variable node information in the multiple test script files, and dynamically modify the variable node information based on parameter information in an external configuration file, where the variable node information includes server address information, port information, user authentication information, and communication protocol information;

[0039] A fifth unit for the Shell script to call the command-line tool of the performance testing tool, and integrate the test results of the multiple test script files to generate a unified test report, where the test report includes execution result information of the multiple test script files;

[0040] A sixth unit for the batch script and the Shell script to form a test process, and the test process is called through an interface of a continuous integration tool to realize automatic execution of the test process in the continuous integration tool.

[0041] In a third aspect of an embodiment of the present invention, an electronic device is provided, including:

[0042] A processor; [[ID=!4]]

[0043] A memory for storing instructions executable by the processor;

[0044] Wherein, the processor is configured to call the instructions stored in the memory to execute the method described above.

[0045] In a fourth aspect of an embodiment of the present invention, a computer-readable storage medium is provided, on which computer program instructions are stored, and when the computer program instructions are executed by a processor, the method described above is implemented.

[0046] The beneficial effects of this application are as follows:

[0047] Through the combined application of a batch script and a Shell script, the present invention realizes the automatic execution and management of multiple test scripts, greatly improves the test efficiency, reduces the need for manual intervention, and makes the test process more efficient and reliable.

[0048] The present invention uses Shell script and regular expression technologies to dynamically modify variable node information in test scripts, enabling test scripts to adapt to different test environments and parameter configurations, enhancing the flexibility and adaptability of testing, and avoiding the error risk caused by manual modification of scripts.

[0049] The present invention seamlessly integrates the test process with a continuous integration tool, realizes the automatic triggering and execution of the test process, and at the same time provides comprehensive test result analysis capabilities through a unified test report generation mechanism, effectively improving the quality assurance level and test coverage rate in the software development process. Description of the Drawings

[0050] Figure 1 This is a flowchart showing the automated testing and dynamic variable modification method based on multiple scripts in an embodiment of the present invention;

[0051] Figure 2 This is a flowchart showing the dynamic modification of variable node information based on parameter information in an external configuration file. Detailed implementation manners

[0052] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Apparently, the described embodiments are only some, rather than all, of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.

[0053] The technical solutions of the present invention will be described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments.

[0054] Refer to Figure 1 and Figure 2 The automated testing and dynamic variable modification method based on multiple scripts in an embodiment of the present invention includes:

[0055] Call the command-line tool of the performance testing tool through a batch script, and the batch script is configured with the path information of the performance testing tool, the path information of multiple test script files, and the storage path information of the test result file;

[0056] Use the batch script to loop through and read the path information of the multiple test script files, and call the command-line tool of the performance testing tool to execute the multiple test script files in sequence;

[0057] Preprocess the multiple test script files through a Shell script, and the preprocessing includes detecting whether the multiple test script files exist and clearing the historical test result files;

[0058] The Shell script uses regular expressions to match the variable node information in the multiple test script files, and dynamically modifies the variable node information based on the parameter information in the external configuration file. The variable node information includes server address information, port information, user authentication information, and communication protocol information;

[0059] The Shell script calls the command-line tool of the performance testing tool to integrate the test results of the multiple test script files to generate a unified test report, and the test report includes the execution result information of the multiple test script files;

[0060] The batch script and the Shell script are combined to form a test process, and the test process is called through the interface of the continuous integration tool to realize the automatic execution of the test process in the continuous integration tool.

[0061] In an optional implementation manner, using the batch script to loop through the path information of the multiple test script files and calling the command-line tool of the performance testing tool to sequentially execute the multiple test script files includes:

[0062] A file path storage array is set in the batch script, and the file path storage array is used to store the path information of the multiple test script files;

[0063] The batch script obtains the path information of each test script file by traversing the file path storage array, and uses the obtained path information as the input parameter of the command-line tool of the performance testing tool;

[0064] The batch script determines the number of loop executions according to the length of the file path storage array, and generates an independent test result file for each test script file.

[0065] Exemplarily, a file path storage array is set in the batch script, and the file path storage array is used to store the path information of multiple test script files. In practical applications, the file path storage array can be defined as an array variable of string type. For example, in a Windows batch script, it can be defined in the following way: SET scriptPaths=(), where scriptPaths is the name of the file path storage array. The elements of the file path storage array can be the absolute path or relative path of the test script file, such as "D:\TestProject\scripts\test1.jmx", "D:\TestProject\scripts\test2.jmx", etc., or can be all script file paths in a specific directory matched by a regular expression.

[0066] In the initialization phase of the batch script, the file path storage array can be populated in various ways. One way is to hard-code the paths of the test script files directly in the batch script. For example: SET scriptPaths[0]=D:\TestProject\scripts\test1.jmx; SET scriptPaths[1]=D:\TestProject\scripts\test2.jmx; SET scriptPaths[2]=D:\TestProject\scripts\test3.jmx. Another way is to dynamically obtain all the test script files in a specific directory through file system commands. For example, in a Windows batch script, the dir command combined with a for loop can be used to achieve this: FOR / F "tokens=*" %G IN ('dir / b / s "D:\TestProject\scripts\*.jmx"') DO (SET scriptPaths[!index!]=%G&SET / A index+=1). In this way, the paths of all files with the.jmx extension in the "D:\TestProject\scripts" directory can be added to the file path storage array.

[0067] After the file path storage array is populated, the batch script obtains the path information of each test script file by traversing the array. The traversal process can be implemented using a loop statement. For example, in a Windows batch script, a for loop can be used: FOR / L %I IN (0,1,%arrayLength%) DO (process scriptPaths[%I]), where arrayLength represents the length of the file path storage array minus 1. In each loop, the batch script obtains an element in the array, that is, the path information of a test script file.

[0068] After obtaining the path information of the test script file, the batch script uses this path information as the input parameter of the command-line tool of the performance testing tool. Assuming that the command-line tool of the performance testing tool is jmeter, and the command format for executing the test script is "jmeter -n -t [script path] -l [result file path]", then in the batch script, a complete command can be constructed by concatenating command strings. For example: SET cmd=jmeter -n -t %scriptPath% -l %resultPath%, where scriptPath is the path of the test script file obtained in the current loop, and resultPath is the path of the generated test result file. After the command string is constructed, the batch script executes this command through the system command. For example, in a Windows batch script, the call command can be used: CALL %cmd%, thus realizing the execution of the test script by invoking the command-line tool of the performance testing tool.

[0069] The batch script determines the number of loop executions based on the length of the array storing the file paths, and generates an independent test result file for each test script file. The length of the array storing the file paths can be recorded by a counting variable, such as obtaining it by incrementing the index variable when filling the array, or by using a specific command to get the size of the array. The number of loop executions is equal to the length of the array storing the file paths, that is, the loop will be executed as many times as there are test script files.

[0070] In each loop, the batch script needs to generate an independent test result file for the currently executed test script file. The path of the test result file can be generated based on the path or name of the test script file. For example, the extension of the test script file can be replaced from.jmx to.jtl or.csv as the path of the test result file, or information such as a timestamp can be added after the test script file name to ensure the uniqueness of the result file. For example, for the test script file "D:\TestProject\scripts\test1.jmx", the test result file "D:\TestProject\results\test1_20230524120000.jtl" can be generated.

[0071] In a specific example, assume that there are three test script files, namely "D:\TestProject\scripts\login_test.jmx", "D:\TestProject\scripts\search_test.jmx", and "D:\TestProject\scripts\payment_test.jmx". The batch script first stores these three paths in an array for storing file paths, and then performs three loops to execute these three test script files respectively. In the first loop, the batch script obtains "D:\TestProject\scripts\login_test.jmx", constructs the command "jmeter -n -t D:\TestProject\scripts\login_test.jmx -l D:\TestProject\results\login_test_result.jtl", and executes this command. In the second loop, the batch script obtains "D:\TestProject\scripts\search_test.jmx", constructs the command "jmeter -n -t D:\TestProject\scripts\search_test.jmx -l D:\TestProject\results\search_test_result.jtl", and executes this command. In the third loop, the batch script obtains "D:\TestProject\scripts\payment_test.jmx", constructs the command "jmeter -n -tD:\TestProject\scripts\payment_test.jmx -l D:\TestProject\results\payment_test_result.jtl", and executes this command. Finally, the batch script generates three independent test result files, corresponding to the execution results of the three test script files respectively.

[0072] In an alternative embodiment, the Shell script uses regular expressions to match variable node information in the multiple test script files, and dynamically modifies the variable node information based on parameter information in an external configuration file, including:

[0073] The Shell script reads a parameter configuration matrix in an external configuration file, where the parameter configuration matrix includes multiple groups of parameter combinations, and each group of parameter combinations contains a parameter identifier, a current parameter value, a target parameter value, and a parameter verification rule;

[0074] The Shell script constructs a hierarchical regular expression matching rule, which includes a parameter location expression and a parameter extraction expression. The parameter location expression is used to locate the XML node position where the parameter is located, and the parameter extraction expression is used to obtain specific parameter value information;

[0075] The Shell script performs a two-way scan of the test script file based on the regular expression matching rule, and establishes a parameter mapping table during the scan. The parameter mapping table records the correspondence between the parameter identifier and the XML node; the Shell script locates the position of the parameter to be modified according to the parameter mapping table, replaces the current parameter value with the target parameter value, and uses the parameter verification rule to verify the correctness of the format of the modified parameter value.

[0076] In this embodiment, a method for dynamically modifying variable node information in a test script file using a Shell script is provided. This method reads a parameter configuration matrix in an external configuration file through a Shell script, constructs a hierarchical regular expression matching rule, and performs a two-way scan of the test script file based on this rule, thereby establishing a parameter mapping table, and finally realizing dynamic replacement and verification of parameter values.

[0077] The Shell script first reads the parameter configuration matrix in the external configuration file. The parameter configuration matrix is stored in JSON format and contains multiple parameter combinations. Each parameter combination includes four key attributes: parameter identifier (param_id), current parameter value (current_value), target parameter value (target_value), and parameter verification rule (validation_rule).

[0078] The Shell script parses the JSON file through the jq tool, extracts each group of parameter information and stores it in an associative array for subsequent processing. During the parsing process, a loop is used to traverse each parameter combination, and its attribute values are stored in the corresponding array variables.

[0079] The Shell script constructs a hierarchical regular expression matching rule. These rules are divided into two levels: a parameter location expression and a parameter extraction expression. The parameter location expression is used to locate the node position containing the target parameter in the XML structure, while the parameter extraction expression is used to extract the specific parameter value from the located node. The regular expression rule is designed according to the XML structure characteristics of the test script file, considering factors such as the nested level of XML nodes, the attribute definition method, and the value format.

[0080] For example, for the timeout_value parameter, the location expression can be `<timeout[^>]*>`, which is used to match all timeout tags; the parameter extraction expression can be `value="([^"]+)"`, which is used to extract the specific timeout value from the tag attributes. This hierarchical design enables the script to accurately locate and extract parameters of various different structures, improving the accuracy and flexibility of matching.

[0081] The Shell script uses tools such as grep, sed, and awk in combination with the above regular expressions to perform a two-way scan of the test script file. By two-way scan, it means that the script first scans the file from top to bottom to locate XML nodes that may contain the target parameters; then it performs a detailed left-to-right analysis on each located node to extract the parameter values and match them with the parameters in the configuration matrix. During this process, the script will establish a parameter mapping table to record information such as the line number, position offset, etc. of each parameter identifier (param_id) and the corresponding XML node.

[0082] The parameter mapping table is implemented using an associative array, and its structure is as follows:

[0083] mapping_table["timeout_value"]="line:42,offset:15,length:4,xpath: / config / server / timeout";

[0084] mapping_table["retry_count"]="line:78,offset:12,length:1,xpath: / config / retry / max";

[0085] This mapping relationship records the exact location of the parameter in the file, including the line number, character offset, value length, and XML path, providing a location basis for subsequent parameter replacement operations.

[0086] After completing the scan and mapping, the Shell script locates the positions of the parameters that need to be modified according to the parameter mapping table. For each parameter that needs to be modified, the script first obtains its location information from the mapping table, and then uses the sed command to perform an exact text replacement, replacing the current parameter value with the target parameter value. The replacement operation uses an in-line directed replacement method, ensuring that only the target parameter is replaced without affecting other content by combining the line number and regular expression.

[0087] After the parameter substitution is completed, the Shell script immediately validates whether the format of the modified parameter value is correct using the parameter validation rules. The validation process is carried out through the grep command in combination with the validation rules (validation_rule) defined in the parameter configuration matrix. If the substituted parameter value does not conform to the validation rules, the script will record an error log and may roll back this modification.

[0088] Through this strict validation mechanism, the legality and security of parameter modification are ensured, and the risk of test script execution failure caused by incorrect parameter formats is avoided.

[0089] The Shell script also implements batch processing capabilities and can process multiple test script files at once. The script defines the set of script files to be processed through the find command or a file list variable, and then executes the above-mentioned parameter scanning, mapping, substitution, and validation processes on each file one by one through a loop. This batch processing mechanism greatly improves the efficiency of parameter modification, especially in large-scale test environments.

[0090] To improve processing efficiency, the Shell script adopts various optimization techniques, such as using file caching to reduce repeated I / O operations, using hash tables to accelerate parameter lookup, and performing multiple substitutions using a single sed command. These optimization measures ensure that the script can maintain good execution efficiency even when processing a large number of test script files.

[0091] Through the above methods, the Shell script can efficiently and accurately use regular expressions to match the variable node information in the test script file and dynamically modify the variable nodes based on the parameter information in the external configuration file. This automated parameter adjustment mechanism greatly improves the flexibility and efficiency of the test process and reduces the errors that may be introduced by manual parameter modification.

[0092] In an optional implementation manner, the Shell script performs a two-way scan of the test script file based on the regular expression matching rules, and establishes a parameter mapping table during the scan, including:

[0093] The Shell script constructs a two-way traversal pointer, which includes a forward traversal pointer and a backward traversal pointer; the forward traversal pointer scans backward from the starting position of the test script file, and the backward traversal pointer scans forward from the end position of the test script file.

[0094] The Shell script extracts the hierarchical depth value and node attribute information of each XML node during the two-way scanning process, and stores the hierarchical depth value and the node attribute information in a temporary buffer; the Shell script constructs a parameter mapping table based on the information in the temporary buffer, and the parameter mapping table stores the mapping relationship between the parameter identifier and the XML node in a hash structure, and the mapping relationship includes the absolute position information, relative position information of the node in the file, and the parent-child relationship information of the node;

[0095] The Shell script calculates the parameter positioning coordinates according to the absolute position information and the relative position information, and performs a modification operation on the target parameter value based on the parameter positioning coordinates; the Shell script uses a preset parameter verification rule to perform format verification and validity verification on the modified parameter value.

[0096] Exemplarily, when the Shell script performs two-way scanning, it creates two file handle pointers, which are used for forward and reverse scanning respectively. The forward traversal pointer is initialized at the starting position of the file, 0 bytes, and the reverse traversal pointer is initialized at the end position of the file. The forward traversal pointer reads a 4096-byte data block each time, and the reverse traversal pointer reads a 4096-byte data block each time, and the scanning speeds of the two pointers are kept synchronized.

[0097] During the two-way scanning process, the Shell script uses the regular expression " / (<.*?>) / " to match the XML node tags. For each matched XML node, the hierarchical depth value of the node is recorded through a counter. Taking the user authentication configuration in the test script as an example, when scanning to " <authentication>"The hierarchical depth value of the node is 1, and its child node is scanned." <username>"The hierarchical depth value at this time is 2. The collection of node attribute information includes key information such as node name, node value, and node type.

[0098] The Shell script stores the collected information in a temporary buffer area, and the temporary buffer area organizes data in the form of key-value pairs. Taking the user authentication configuration as an example, the cache data structure is "{node path: / Authentication / Username, depth value: 2, node value: admin, node type: string}". The size of the temporary buffer area is set to 32MB, and when the data volume exceeds the threshold, a data persistence operation is triggered.

[0099] When constructing a parameter mapping table based on the data in the temporary buffer area, a hash table structure is used to improve the retrieval efficiency. The key of the hash table is the parameter identifier, which is generated by the complete path of the node, and the value is a JSON object of the detailed node information. The absolute position information of the node records the byte offset of the node in the file, and the relative position information records the distance between the node and the adjacent node. For the above example, the absolute position may be 1024 bytes after the start of the file, and the relative position records that the distance from the previous node is 256 bytes.

[0100] The calculation of the parameter positioning coordinates comprehensively considers the absolute position and relative position information. When modifying the username parameter value, the Shell script first uses the absolute position for quick positioning. If the absolute position becomes invalid due to file content changes, the relative position information is used for calibration positioning. After positioning, the sed command is used for parameter value replacement operations.

[0101] The parameter verification rules contain verification logics in multiple dimensions. The data type rule verifies whether the parameter value conforms to the expected type. For example, the username must be of string type. The value range rule verifies whether the parameter value is within the legal range. For example, the port number must be between 1 and 65535. The dependency rule verifies whether the parameter value meets the constraint relationship between nodes. For example, the server address format must match the protocol type.

[0102] Taking the modification of server configuration parameters as an example: The original parameter value is "http: / / serverA:8080", and the modified parameter value is "https: / / serverB:443". The Shell script first locates the protocol configuration node through the parameter mapping table and changes "http" to "https"; then locates the server address node and changes "serverA" to "serverB"; finally locates the port number node and changes "8080" to "443". The verification rule will check whether the https protocol matches the 443 port number to ensure the validity of the modified configuration.

[0103] When the validation rule detects an illegal modification, the Shell script will roll back the parameter value and record the error information. The error information includes the parameter identifier, the original value, the target value, the reason for failure, etc., which is used for subsequent analysis and processing. The parameter modifications that pass the validation will be submitted to the test script file to complete the parameter update operation.

[0104] In an alternative embodiment, the method further includes:

[0105] Receiving a parameter modification instruction, the parameter modification instruction includes a target parameter identifier, a modified parameter value, and modification reason information; obtaining a parameter historical version chain from a parameter version library based on the target parameter identifier, the parameter historical version chain includes multiple historical version nodes corresponding to the target parameter identifier;

[0106] Extracting parameter dependency information from the parameter historical version chain, the parameter dependency information records the association rules between the target parameter identifier and other associated parameter identifiers; constructing a parameter dependency graph based on the parameter dependency information, the parameter dependency graph uses a tree structure to record the upstream and downstream associated parameters of the target parameter identifier;

[0107] Validating the association rules in the parameter dependency graph for the modified parameter value, generating a parameter change impact assessment report, the parameter change impact assessment report includes the affected associated parameter information in the parameter dependency graph;

[0108] Submitting the modified parameter value and the parameter change impact assessment report to a parameter review module for review, generating review result information; when the review result information is passed, creating a new version node, the new version node includes a version identifier, the modified parameter value, the modification reason information, and timestamp information;

[0109] Inserting the new version node into the parameter historical version chain, and synchronously updating the affected associated parameter version nodes based on the parameter dependency graph; the parameter historical version chain supports rollback operations based on the version identifier or the timestamp information, and the rollback operation includes the consistency rollback of the target parameter and its associated parameters.

[0110] Exemplarily, the parameter modification instruction is received through a message queue. The message body is encapsulated in JSON format and contains a type field to identify the instruction type, a paramId field to identify the target parameter, a value field to store the modified value, and a reason field to record the reason for the modification. A typical example of a parameter modification instruction is: {"type": "MODIFY", "paramId": "server.protocol", "value": "https", "reason": "Security upgrade"}.

[0111] The system maintains a distributed parameter version library, using a key-value storage structure. The key is the parameter identifier, and the value is a linked list of historical versions. Each node in the version linked list contains attributes such as version, value, and timestamp. Taking the server protocol parameter as an example, its historical version chain contains three version nodes: {"version": "v1.0", "value": "http", "timestamp": "1621234567"}, {"version": "v1.1", "value": "https", "timestamp": "1621345678"}, {"version": "v1.2", "value": "http2", "timestamp": "1621456789"}.

[0112] The parameter dependency relationship information is stored in a relational database, and an association table is used to record the dependency rules between parameters. The dependency rules include fields such as sourceParam (source parameter), targetParam (target parameter), ruleType (rule type), and ruleContent (rule content). Taking the server configuration as an example, there are the following records in the rule table: The source parameter is "server.protocol", the target parameter is "server.port", the rule type is "VALUE_MAPPING", and the rule content is "https->443;http->80", indicating the correspondence between the protocol and the port.

[0113] The parameter dependency graph is constructed using a tree data structure. Each node contains four basic attributes: paramId, value, children, and parent. The tree construction process starts from the target parameter and recursively queries the dependency relationship table to obtain the upstream and downstream parameters. For the server configuration example, the constructed dependency tree includes: The root node is the protocol parameter, and the child nodes include the port parameter and the security parameter. Each node records the current value and version information.

[0114] The impact assessment of parameter changes is based on a depth - first traversal of the dependency graph. The assessment process checks the rule constraints of each associated node and records the parameters that need to be synchronously changed. The generated assessment report includes: changed parameter information (parameter identifier, original value, new value), scope of impact (list of affected parameters), and risk level (determined based on the scope of impact). Taking protocol switching as an example, the assessment report shows that switching to the https protocol will affect the port number (which needs to be changed to 443) and the security configuration (which needs to enable SSL).

[0115] The parameter review module implements a three - level review mechanism. Reviewers view the change content and the impact assessment report and can choose to approve, reject, or request modification. The review results are recorded in the review log table, which includes information such as the reviewer, review time, and review comments. When the review is passed, a new version node is created for the target parameter, and the version number is incremented in the format of major.minor.patch, such as "v1.2.0" -> "v1.2.1".

[0116] The insertion of the version node adopts an atomic operation to ensure the consistency of the version chain. When synchronously updating associated parameters based on the dependency graph, transactions are used to ensure that all update operations either succeed or roll back completely. For rollback operations, it is supported to locate the target version by version number or timestamp. During the rollback process, the system automatically processes the dependency relationships between parameters to ensure that the associated parameters are synchronously rolled back to a consistent state. Taking the rollback of server configuration as an example: when rolling back the protocol to the http version, the system automatically rolls back the port number to 80 and closes the SSL configuration at the same time.

[0117] The complete version control process is recorded in the operation log table, which includes information such as the operation type, operation time, operator, and scope of impact. Each version node is linked to the corresponding assessment report and review record, forming a complete change link to support subsequent change tracking and problem location. The system regularly performs garbage collection on the version library to clean up expired historical versions, and by default, retains version records for the last 90 days.

[0118] In the second aspect of the embodiments of the present invention, an automated testing and dynamic variable modification system based on multiple scripts is provided, including:

[0119] The first unit is used to call the command - line tool of the performance testing tool through a batch script. The batch script is configured with the path information of the performance testing tool, the path information of multiple test script files, and the storage path information of the test result file;

[0120] The second unit is used to use the batch script to loop through and read the path information of the multiple test script files, and call the command - line tool of the performance testing tool to sequentially execute the multiple test script files;

[0121] A third unit for preprocessing the multiple test script files through a Shell script, where the preprocessing includes detecting the existence of the multiple test script files and cleaning historical test result files;

[0122] A fourth unit for the Shell script to match variable node information in the multiple test script files using regular expressions and dynamically modify the variable node information based on parameter information in an external configuration file, where the variable node information includes server address information, port information, user authentication information, and communication protocol information;

[0123] A fifth unit for the Shell script to call the command-line tool of the performance testing tool and integrate the test results of the multiple test script files to generate a unified test report, where the test report includes execution result information of the multiple test script files;

[0124] A sixth unit for the batch script and the Shell script to form a test process, where the test process is called through an interface of a continuous integration tool to implement automatic execution of the test process in the continuous integration tool.

[0125] In a third aspect of the embodiments of the present invention, an electronic device is provided, including:

[0126] A processor;

[0127] A memory for storing instructions executable by the processor;

[0128] Wherein, the processor is configured to call the instructions stored in the memory to execute the method described above.

[0129] In a fourth aspect of the embodiments of the present invention, a computer-readable storage medium is provided, on which computer program instructions are stored, and when the computer program instructions are executed by a processor, the method described above is implemented.

[0130] The present invention can be a method, device, system, and / or computer program product. The computer program product may include a computer-readable storage medium on which computer-readable program instructions for executing various aspects of the present invention are uploaded.

[0131] Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements on some or all of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present invention.< / username> < / authentication>

Claims

1. An automated testing and dynamic variable modification method based on multiple scripts, characterized in that Including: A command-line tool that calls a performance testing tool through a batch script, where the batch script is configured with the path information of the performance testing tool, the path information of multiple test script files, and the storage path information of a test result file; Using the batch script to loop through and read the path information of the multiple test script files, and calling the command-line tool of the performance testing tool to sequentially execute the multiple test script files; Preprocessing the multiple test script files through a Shell script, where the preprocessing includes detecting whether the multiple test script files exist and clearing historical test result files; The Shell script uses a regular expression to match variable node information in the multiple test script files, and dynamically modifies the variable node information based on parameter information in an external configuration file. The variable node information includes server address information, port information, user authentication information, and communication protocol information; The Shell script calls the command-line tool of the performance testing tool, integrates the test results of the multiple test script files to generate a unified test report, and the test report includes the execution result information of the multiple test script files; The batch script and the Shell script are combined to form a test process, and the test process is called through an interface of a continuous integration tool to achieve automatic execution of the test process in the continuous integration tool.

2. The method according to claim 1, wherein Using the batch script to loop through and read the path information of the multiple test script files, and calling the command-line tool of the performance testing tool to sequentially execute the multiple test script files includes: A file path storage array is set in the batch script, and the file path storage array is used to store the path information of the multiple test script files; The batch script obtains the path information of each test script file by traversing the file path storage array, and uses the obtained path information as the input parameter of the command-line tool of the performance testing tool; The batch script determines the number of loop executions according to the length of the file path storage array, and generates an independent test result file for each test script file.

3. The method according to claim 1, characterized in that, The Shell script uses a regular expression to match variable node information in the multiple test script files, and dynamically modifies the variable node information based on parameter information in an external configuration file includes: The Shell script reads a parameter configuration matrix in an external configuration file, and the parameter configuration matrix includes multiple groups of parameter combinations. Each group of parameter combinations contains a parameter identifier, a current parameter value, a target parameter value, and a parameter verification rule; The Shell script constructs a hierarchical regular expression matching rule, and the regular expression matching rule includes a parameter positioning expression and a parameter extraction expression. The parameter positioning expression is used to locate the XML node position where the parameter is located, and the parameter extraction expression is used to obtain specific parameter value information; The Shell script performs a two-way scan on the test script file based on the regular expression matching rule, and establishes a parameter mapping table during the scan. The parameter mapping table records the correspondence between parameter identifiers and XML nodes. The Shell script locates the positions of the parameters to be modified according to the parameter mapping table, replaces the current parameter values with the target parameter values, and uses the parameter verification rule to verify the correctness of the format of the modified parameter values.

4. The method according to claim 3, wherein The Shell script performs a two-way scan on the test script file based on the regular expression matching rule, and establishing a parameter mapping table during the scan includes: The Shell script constructs a two-way traversal pointer, which includes a forward traversal pointer and a backward traversal pointer. The forward traversal pointer scans backward from the starting position of the test script file, and the backward traversal pointer scans forward from the ending position of the test script file. The Shell script extracts the hierarchical depth value and node attribute information of each XML node during the two-way scan, and stores the hierarchical depth value and the node attribute information in a temporary buffer. The Shell script constructs a parameter mapping table based on the information in the temporary buffer. The parameter mapping table stores the mapping relationship between parameter identifiers and XML nodes in a hash structure, and the mapping relationship includes the absolute position information, relative position information of the node in the file, and the parent-child relationship information of the node. The Shell script calculates the parameter positioning coordinates according to the absolute position information and the relative position information, and performs a modification operation on the target parameter value based on the parameter positioning coordinates. The Shell script uses a preset parameter verification rule to perform format verification and validity verification on the modified parameter value.

5. The method according to claim 1, wherein The method further includes: Receiving a parameter modification instruction, the parameter modification instruction includes a target parameter identifier, a modified parameter value, and modification reason information. Obtaining a parameter historical version chain from a parameter version library based on the target parameter identifier, and the parameter historical version chain includes multiple historical version nodes corresponding to the target parameter identifier. Extracting parameter dependency relationship information from the parameter historical version chain, and the parameter dependency relationship information records the association rule between the target parameter identifier and other associated parameter identifiers. Constructing a parameter dependency graph based on the parameter dependency relationship information, and the parameter dependency graph uses a tree structure to record the upstream and downstream associated parameters of the target parameter identifier. For the modified parameter value, verifying the association rules in the parameter dependency graph, and generating a parameter change impact assessment report, and the parameter change impact assessment report includes the affected associated parameter information in the parameter dependency graph.

6. The method according to claim 5, wherein After verifying the association rules in the parameter dependency graph and generating a parameter change impact assessment report for the modified parameter value, the method further includes: Submit the modified parameter value and the parameter change impact assessment report to the parameter review module for review to generate review result information; when the review result information is passed, create a new version node, and the new version node includes a version identifier, the modified parameter value, the modification reason information, and timestamp information; Insert the new version node into the parameter historical version chain, and synchronously update the affected associated parameter version nodes based on the parameter dependency graph; the parameter historical version chain supports rollback operations based on the version identifier or the timestamp information, and the rollback operation includes consistent rollback of the target parameter and its associated parameters.

7. An automated testing and dynamic variable modification system based on multiple scripts, for implementing the method according to any one of claims 1-6, characterized in that, Including: The first unit is used to call the command-line tool of the performance testing tool through a batch script, and the batch script is configured with the path information of the performance testing tool, the path information of multiple test script files, and the storage path information of the test result file; The second unit is used to loop through the path information of the multiple test script files by using the batch script, and call the command-line tool of the performance testing tool to execute the multiple test script files in sequence; The third unit is used to preprocess the multiple test script files through a Shell script, and the preprocessing includes detecting whether the multiple test script files exist and cleaning historical test result files; The fourth unit is used for the Shell script to match variable node information in the multiple test script files by using a regular expression, and dynamically modify the variable node information based on parameter information in an external configuration file, and the variable node information includes server address information, port information, user authentication information, and communication protocol information; The fifth unit is used for the Shell script to call the command-line tool of the performance testing tool to integrate the test results of the multiple test script files to generate a unified test report, and the test report includes the execution result information of the multiple test script files; The sixth unit is used for the batch script and the Shell script to form a test process, and the test process is called through the interface of a continuous integration tool to realize automatic execution of the test process in the continuous integration tool.

8. An electronic device, characterized in that, Including: A processor; A memory for storing instructions executable by the processor; Wherein, the processor is configured to call the instructions stored in the memory to execute the method according to any one of claims 1 to 6.

9. A computer-readable storage medium having computer program instructions stored thereon, characterized in that, When the computer program instructions are executed by the processor, the method according to any one of claims 1 to 6 is implemented.

Citation Information

Patent Citations

  • Script execution method, device, equipment, system, medium and product

    CN119003589A

  • Web automatic testing method and system based on parameterized input

    CN119829437A