A method and device for generating test scripts

By combining pattern recognition and code positioning methods, and using genetic algorithms to generate test scripts, the problem of high product version requirements and sensitive interface element changes in the existing technology is solved, and a test script with high flexibility and accuracy is achieved, reducing maintenance costs.

CN112905485BActive Publication Date: 2025-03-25CHINA CONSTRUCTION BANK
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202110322558.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-03-25
Publication Date
2025-03-25
Estimated Expiration
2041-03-25

AI Technical Summary

Technical Problem

When generating automated test scripts in the prior art, there are problems such as high product version requirements, changes in interface elements, resulting in script execution failure, poor accuracy and high maintenance costs.

Method used

By combining pattern recognition methods and code positioning methods, genetic algorithms are used to generate test scripts, which improves the controllability of fault tolerance and maintenance costs, and retains the proportion of the first test script to the greatest extent, reducing the algorithm search time.

Benefits of technology

The generated test scripts are achieved with high flexibility and accuracy, reducing maintenance costs, and improving the effectiveness and fault tolerance of test scripts.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112905485B_ABST
    Figure CN112905485B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and device for generating test scripts, and relates to the technical field of automatic program design. A specific implementation of the method includes: splitting the test cases of the current batch to obtain the business links corresponding to the test cases of the current batch; obtaining the first test script and the second test script corresponding to the business link, wherein the first test script is a test script generated based on code positioning, and the second test script is a test script generated based on pattern recognition; according to the first test script and the second test script corresponding to the business link, based on the genetic algorithm, determine the optimal test script corresponding to the business link; according to the optimal test script corresponding to the business link, generate the target test script corresponding to the test cases of the current batch. The target test script generated by this implementation has the characteristics of flexibility and accuracy, high fault tolerance, controllable maintenance cost, reduces the algorithm search time, and improves the effectiveness of the test script.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of automatic program design, and in particular to a method and device for generating a test script. Background Art

[0002] The requirements of bank front-end products change frequently, which leads to the need to adjust regression test cases with product versions. Among them, regression testing refers to retesting after modifying the old code to confirm that the modification has not introduced new errors or caused errors in other codes. Due to the large volume of products, regression testing tasks are arduous. Therefore, in order to improve product testing efficiency, automated test scripts need to meet the regression testing requirements in product version iterations to the greatest extent possible to ensure the effectiveness of the test.

[0003] At present, the design of automated test scripts for bank front-end products mainly includes: Method 1: Implementing the positioning, operation, information acquisition and other actions of interface elements based on the built-in methods of the operating system framework or application development framework to generate automated test scripts; Method 2: Generate automated test scripts based on pattern recognition, such as SikuliX, a novel graphical scripting language that can identify interface elements through pictures.

[0004] In the process of implementing the present invention, it was found that the prior art has the following problems: for method one, it has high requirements on the product version. Any changes in the interface elements may cause all related cases to fail to execute, and the script maintenance cost is high. For any product version, the test phase and demand changes may require the script to be re-edited; for method two, the accuracy of the generated test script is poor, and there are certain requirements for the test equipment. Summary of the invention

[0005] In view of this, an embodiment of the present invention provides a method and device for generating a test script, which can achieve the effect of generating a test script by using a pattern recognition method to assist a code positioning method, has a high fault tolerance rate, and controllable maintenance costs. In addition, the genetic algorithm can retain the proportion of the first test script in the target test script to the greatest extent, thereby reducing the algorithm search time and improving the effectiveness of the target test script.

[0006] To achieve the above objective, according to one aspect of an embodiment of the present invention, a method for generating a test script is provided.

[0007] The method for generating test scripts in an embodiment of the present invention includes: splitting the test cases of the current batch to obtain the business links corresponding to the test cases of the current batch; obtaining a first test script and a second test script corresponding to the business links, wherein the first test script is a test script generated based on code positioning, and the second test script is a test script generated based on pattern recognition; determining the optimal test script corresponding to the business link based on a genetic algorithm according to the first test script and the second test script corresponding to the business link; and generating a target test script corresponding to the test cases of the current batch according to the optimal test script corresponding to the business link.

[0008] Optionally, splitting the current batch of test cases to obtain business links corresponding to the current batch of test cases includes: splitting each test case in the current batch of test cases based on interface operations to obtain one or more business links corresponding to each test case, so as to obtain the business links corresponding to the current batch of test cases.

[0009] Optionally, obtaining the first test script and the second test script corresponding to the business link includes: for each business link in one or more business links corresponding to each test case, implementing each business link based on code positioning, and generating the first test script corresponding to each business link; implementing each business link based on pattern recognition, and generating the second test script corresponding to each business link.

[0010] Optionally, the determining the optimal test script corresponding to the business link based on the first test script and the second test script corresponding to the business link based on a genetic algorithm includes: generating a first-generation test script corresponding to each test case based on the first test script corresponding to each business link and the second test script corresponding to each business link to obtain the first-generation test script corresponding to the test case of the current batch; performing iterative training based on a genetic algorithm according to the first-generation test script corresponding to the test case of the current batch to determine the optimal test script corresponding to each business link; wherein the fitness function of the genetic algorithm is the overall test success rate corresponding to the test case.

[0011] Optionally, generating a first-generation test script corresponding to each test case based on the first test script corresponding to each business link and the second test script corresponding to each business link includes: verifying the first test script corresponding to each business link using test data; if the verification is successful, determining that the first test script corresponding to each business link is the first-generation test script corresponding to each business link; if the verification fails, generating the first-generation test script corresponding to each business link using a random sampling method with decreasing verification; generating the first-generation test script corresponding to each test case based on the first-generation test script corresponding to each business link.

[0012] Optionally, after splitting the test case into units of interface operations and obtaining one or more business links corresponding to each test case, the method further includes: determining the process sequence of each business link in each test case; and generating a first-generation test script corresponding to each test case based on the first-generation test script corresponding to each business link, including: combining the first-generation test scripts corresponding to each business link according to the process sequence of each business link in each test case to generate a first-generation test script corresponding to each test case.

[0013] Optionally, after generating a target test script corresponding to the current batch of test cases, the method further includes: executing the target test script using test data, obtaining an execution success rate, and determining whether the execution success rate is greater than a preset success rate threshold; if so, determining that the test has passed; if not, manually correcting the target test script.

[0014] Optionally, the manual correction of the target test script includes: obtaining an abnormal script contained in the target test script, wherein the abnormal script is a script corresponding to a business link that failed to execute; if the abnormal script is the first test script, manually correcting the abnormal script; and if the interface elements change, adjusting the image library used for pattern recognition.

[0015] Optionally, the method further includes: correcting an abnormal script included in the target test script according to demand.

[0016] To achieve the above objective, according to another aspect of an embodiment of the present invention, a device for generating a test script is provided.

[0017] The device for generating test scripts in an embodiment of the present invention includes: a splitting module, used to split the test cases of the current batch to obtain the business links corresponding to the test cases of the current batch; an acquisition module, used to obtain a first test script and a second test script corresponding to the business link, wherein the first test script is a test script generated based on code positioning, and the second test script is a test script generated based on pattern recognition; a determination module, used to determine the optimal test script corresponding to the business link based on a genetic algorithm according to the first test script and the second test script corresponding to the business link; a generation module, used to generate a target test script corresponding to the test cases of the current batch according to the optimal test script corresponding to the business link.

[0018] Optionally, the splitting module is also used to: split each test case in the current batch of test cases based on interface operations, obtain one or more business links corresponding to each test case, and obtain the business links corresponding to the test cases in the current batch.

[0019] Optionally, the acquisition module is also used to: for each business link in one or more business links corresponding to each test case, implement each business link based on code positioning, and generate a first test script corresponding to each business link; implement each business link based on pattern recognition, and generate a second test script corresponding to each business link.

[0020] Optionally, the determination module is also used to: generate an initial test script corresponding to each test case based on the first test script corresponding to each business link and the second test script corresponding to each business link, so as to obtain the initial test script corresponding to the test case of the current batch; perform iterative training based on a genetic algorithm according to the initial test script corresponding to the test case of the current batch, and determine the optimal test script corresponding to each business link; wherein the fitness function of the genetic algorithm is the overall test success rate corresponding to the test case.

[0021] Optionally, the determination module is also used to: use test data to verify the first test script corresponding to each business link; if the verification is successful, determine that the first test script corresponding to each business link is the first-generation test script corresponding to each business link; if the verification fails, use a random sampling method with decreasing test to generate the first-generation test script corresponding to each business link; based on the first-generation test script corresponding to each business link, generate the first-generation test script corresponding to each test case.

[0022] Optionally, the splitting module is also used to: determine the process order of each business link in each test case; and the determination module is also used to: combine the initial test scripts corresponding to each business link according to the process order of each business link in each test case to generate the initial test script corresponding to each test case.

[0023] Optionally, the generation module is also used to: execute the target test script using test data, obtain the execution success rate, and determine whether the execution success rate is greater than a preset success rate threshold; if so, determine that the test has passed; if not, manually correct the target test script.

[0024] Optionally, the generation module is also used to: obtain the abnormal script contained in the target test script, wherein the abnormal script is the script corresponding to the business link that failed to execute; if the abnormal script is the first test script, manually correct the abnormal script; and if the interface elements change, adjust the image library used for pattern recognition.

[0025] Optionally, the generating module is further used to: modify the abnormal script included in the target test script according to requirements.

[0026] To achieve the above objective, according to another aspect of an embodiment of the present invention, an electronic device is provided.

[0027] An electronic device according to an embodiment of the present invention includes: one or more processors; a storage device for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement the method for generating a test script according to an embodiment of the present invention.

[0028] To achieve the above objective, according to another aspect of an embodiment of the present invention, a computer readable medium is provided.

[0029] A computer-readable medium according to an embodiment of the present invention stores a computer program, and when the program is executed by a processor, the method for generating a test script according to an embodiment of the present invention is implemented.

[0030] An embodiment of the above invention has the following advantages or beneficial effects: a first test script corresponding to a business link can be generated based on code positioning and a second test script corresponding to the business link can be generated based on pattern recognition, and then a genetic algorithm can be used to select the test script to obtain the optimal test script corresponding to the business link, and then the target test script corresponding to the test case can be obtained. The code positioning method and the pattern recognition method are combined through a genetic algorithm, so that the generated target test script has the characteristics of flexibility and accuracy, and the effect of generating test scripts by using a pattern recognition method to assist a code positioning method has been achieved. The fault tolerance rate is high and the maintenance cost is controllable. In addition, the genetic algorithm can retain the proportion of the first test script in the target test script to the greatest extent, thereby reducing the algorithm search time and improving the effectiveness of the target test script.

[0031] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with specific implementation examples. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.

[0033] Figure 1 is a schematic diagram of main steps of a method for generating a test script according to an embodiment of the present invention;

[0034] Figure 2 is a schematic diagram of the main process of determining the optimal test script corresponding to the business link based on the genetic algorithm according to an embodiment of the present invention;

[0035] Figure 3 is a schematic diagram of the main process of a method for generating a test script according to an embodiment of the present invention;

[0036] Figure 4 is a schematic diagram of main modules of an apparatus for generating a test script according to an embodiment of the present invention;

[0037] Figure 5 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;

[0038] Figure 6 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION

[0039] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0040] Figure 1 FIG. 1 is a schematic diagram of the main steps of a method for generating a test script according to an embodiment of the present invention. Figure 1 As shown, the main steps of the method for generating a test script may include steps S101 to S104.

[0041] Step S101: split the test cases of the current batch to obtain the business links corresponding to the test cases of the current batch.

[0042] Among them, the test case can be understood as a description of the test task for a specific software product, reflecting the test plan, method, technology and strategy. The content of the test case includes the test objectives, test environment, input data, test steps, expected results, test scripts, etc., and is documented. The current batch of test cases can be understood as the currently used automated test scripts for testing the product, or as automated test scripts that need to be re-maintained and edited.

[0043] For bank front-end products, the business process is long, that is, there are many steps to operate the product interface, that is, the product contains many business links, so each business link needs to be tested. Therefore, in step S101, the test cases of the current batch can be split to obtain the business links corresponding to the test cases of the current batch.

[0044] In addition, the current batch of test cases may include one or more test cases, and each test case may include one or more business links, so the current batch of test cases includes one or more business links.

[0045] Step S102: Obtain a first test script and a second test script corresponding to the business link, wherein the first test script is a test script generated based on code location, and the second test script is a test script generated based on pattern recognition.

[0046] Specifically, the business link is implemented based on code positioning, and the first test script corresponding to the business link is generated. Code positioning refers to parsing the application interface based on the built-in method of the operating system framework or the application development framework, completing the automatic implementation of the operation actions included in the business link, and then generating the first test script corresponding to the business link. On the other hand, code positioning can be Selenium, a tool for testing Web applications, or QTP, which is the abbreviation of QuickTest Professional, an automatic testing tool.

[0047] Based on pattern recognition, the business link is implemented and a second test script corresponding to the business link is generated. Specifically, image recognition is performed on the interface corresponding to the business link to realize the positioning, operation, information acquisition and other actions of the interface elements, and then a second test script corresponding to the business link can be generated. In addition, pattern recognition can be SikuliX, a novel graphical scripting language that can identify interface elements through pictures. It should be noted that the pattern recognition method has a high dependence on resolution, so the load machines responsible for script execution are all installed with the Windows operating system, and the resolution is the same as the terminal used for script editing.

[0048] Step S103: Determine the optimal test script corresponding to the business link based on the genetic algorithm according to the first test script and the second test script corresponding to the business link.

[0049] Genetic algorithm is a kind of randomized search method evolved from the evolutionary law of the biological world (i.e., the survival of the fittest, the genetic mechanism of survival of the fittest). The main characteristics of genetic algorithm are that it operates directly on structural objects, without the limitation of derivative and function continuity; it has inherent implicit parallelism and better global optimization ability; it adopts probabilistic optimization method, can automatically obtain and guide the optimized search space, and adjust the search direction adaptively without the need for definite rules.

[0050] Through step S101 and step S102, the first test script and the second test script corresponding to each business link can be obtained, and then in step S103, a genetic algorithm is used to select and determine the optimal test script corresponding to each business link, thereby improving the test success rate.

[0051] Step S104: Generate a target test script corresponding to the test cases of the current batch according to the optimal test script corresponding to the business link.

[0052] In step S101, the test cases of the current batch are split to obtain the business links corresponding to the test cases of the current batch, and then the optimal test scripts corresponding to the business links are obtained through steps S102 and S103. Then, the optimal test scripts corresponding to the business links can be combined to generate the target test scripts corresponding to the test cases, so that the target test scripts can be used for testing.

[0053] According to the method for generating test scripts in an embodiment of the present invention, a first test script corresponding to a business link can be generated based on code positioning and a second test script corresponding to the business link can be generated based on pattern recognition, and then a genetic algorithm is used to select the test script to obtain the optimal test script corresponding to the business link, and then a target test script corresponding to the test case is obtained. The code positioning method and the pattern recognition method are combined through a genetic algorithm, so that the generated target test script has the characteristics of flexibility and accuracy, and the effect of generating test scripts by using a pattern recognition method to assist a code positioning method has been achieved, with high fault tolerance and controllable maintenance costs. In addition, the genetic algorithm can retain the proportion of the first test script in the target test script to the greatest extent, thereby reducing the algorithm search time and improving the effectiveness of the target test script.

[0054] As an embodiment of the present invention, step S101 of splitting the test cases of the current batch to obtain the business links corresponding to the test cases of the current batch may include: splitting each test case in the current batch of test cases based on interface operations to obtain one or more business links corresponding to each test case, so as to obtain the business links corresponding to the test cases of the current batch.

[0055] The test case includes many operations such as mouse click and drag, keyboard input, etc. For each test case, the test case is split into units of interface operations to obtain one or more business links corresponding to the test case, so as to obtain the business links corresponding to all test cases in the current batch.

[0056] Furthermore, after splitting the test case into units of interface operations and obtaining one or more business links corresponding to each test case, the process sequence of each business link in each test case can also be determined.

[0057] For ease of understanding, the following example is used for explanation. For example, if the current batch of test cases includes case 1, case 2, and case 3, then case 1, case 2, and case 3 need to be split based on interface operations to obtain business links k1 to k5 included in case 1, business links k5 to k8 included in case 2, and business links k1 to k8 included in case 3, and determine the process sequence of business links k1 to k5 in case 1, the process sequence of business links k5 to k8 in case 2, and the process sequence of business links k1 to k8 in case 3.

[0058] In addition, as an embodiment of the present invention, after obtaining one or more business links corresponding to each test case, the first test script and the second test script corresponding to each business link can be generated according to the following process: for each business link corresponding to each test case, the business link is implemented based on code positioning, and the first test script corresponding to the business link is generated; the business link is implemented based on pattern recognition, and the second test script corresponding to the business link is generated. And, the workload of generating the first test script and the second test script corresponding to each business link is large, but it is convenient for later maintenance and can effectively extend the maintenance cycle.

[0059] It should be noted that since the test case includes an assertion part, and the assertion part is an inseparable part. When writing code, some assumptions are always made, and assertions are used to capture these assumptions in the code. Assertions are expressed as some Boolean expressions. If the expression value is true at a certain point in the program, assertion verification can be enabled and disabled at any time, so assertions can be enabled during testing and disabled during deployment. Using assertions can create more stable, better quality and less error-prone code. In the method for generating a test script in an embodiment of the present invention, a test script language corresponding to the assertion part can be generated in a single manner, such as generating a test script language corresponding to the assertion part based on code positioning. In addition, considering that in the process of script selection based on a genetic algorithm, it is not necessary to select the test script language corresponding to the assertion part, so after the test script language corresponding to the assertion part is generated in a single manner, the test script language needs to be verified. If the verification fails, the test script language needs to be manually corrected.

[0060] As an embodiment of the present invention, determining the optimal test script corresponding to the business link based on the genetic algorithm in step S103 may include:

[0061] (1) Generate a first-generation test script corresponding to each test case according to a first test script corresponding to each business link and a second test script corresponding to each business link, so as to obtain a first-generation test script corresponding to the test case of the current batch.

[0062] Before selecting scripts based on genetic algorithms, if the initial test script corresponding to each test case can be determined, that is, the initial sample of the genetic algorithm is established, then the execution time of the genetic algorithm can be avoided to be too long and the convergence speed of the algorithm can be improved.

[0063] Furthermore, generating a first-generation test script corresponding to each test case based on the first test script corresponding to each business link and the second test script corresponding to each business link can include: verifying the first test script corresponding to each business link using test data; if the verification is successful, determining the first test script corresponding to each business link as the first-generation test script corresponding to each business link; if the verification fails, generating the first-generation test script corresponding to each business link using a random sampling method with a decreasing test; generating the first-generation test script corresponding to each test case based on the first-generation test script corresponding to each business link.

[0064] Specifically, test data can be pre-embedded, and these test data can be used to verify the first test script corresponding to each business link. This is because the first test script is generated based on code positioning, and its accuracy is relatively high, so the first test script corresponding to each business link can be verified. That is, the test data is used to verify whether the first test script corresponding to each business link can be executed normally. If it is executed normally, the script code corresponding to the business link is locked to 0, that is, the script code corresponding to the first test script is 0. In addition, for business links that cannot be executed normally, a decreasing test is used to perform random samples to generate the first-generation test script corresponding to the business link, avoiding the local optimal problem when selecting scripts based on genetic algorithms. That is, a random sampling method with a decreasing test is used to select the first-generation test script corresponding to the business link from the first test script and the second test script corresponding to the business link, that is, to determine whether the script code corresponding to the business link is 0 or 1, 0 represents the first test script, and 1 represents the second test script.

[0065] In addition, as an embodiment of the present invention, generating a first-generation test script corresponding to each test case based on the first-generation test script corresponding to each business link may include: combining the first-generation test scripts corresponding to each business link according to the process sequence of each business link in each test case to generate a first-generation test script corresponding to each test case.

[0066] As described above, after splitting by interface operation and obtaining one or more business links corresponding to each test case, the process sequence of each business link in each test case can also be determined. Therefore, the first-generation test scripts corresponding to each business link can be combined according to the process sequence of each business link in each test case to generate the first-generation test scripts corresponding to each test case. For example, case 1 contains business links k1 to k5, and the process sequence in case 1 is k1, k5, k4, k3, k2. The first-generation test scripts corresponding to k1, k2 and k5 are all the first test scripts, and the first-generation test scripts corresponding to k3 and k4 are all the second test scripts, that is, the script codes corresponding to k1, k2 and k5 are all 0, and the script codes corresponding to k3 and k4 are all 1, then the first-generation test script corresponding to case 1 is 00110.

[0067] In summary, in the method for generating test scripts of the embodiment of the present invention, before selecting scripts based on the genetic algorithm, the first-generation test script corresponding to each test case is determined, that is, the first-generation sample of the genetic algorithm is established, which avoids the genetic algorithm from executing too long and improves the algorithm convergence speed. Also, in the process of determining the first-generation test script corresponding to each business link, for business links that cannot be executed normally, a decreasing test is used to perform random samples to generate the first-generation test script corresponding to the business link, so that the script selection of the business link has strong directionality, avoiding the local optimal problem when selecting scripts based on the genetic algorithm.

[0068] (2) Based on the initial test scripts corresponding to the test cases in the current batch, iterative training is performed based on the genetic algorithm to determine the optimal test script corresponding to each business link.

[0069] Based on the genetic algorithm, determine the optimal test script selection for each business link. After the first-generation test scripts corresponding to all business links are edited, the first-generation test scripts corresponding to each test case are composed according to the process sequence of the business links in the test case, that is, the first-generation samples corresponding to the genetic algorithm are obtained. In addition, the fitness function of the genetic algorithm is: the overall test success rate corresponding to all test cases under the current script selection conditions. After iterative training of the genetic algorithm, the script type combination of the business link with the highest overall success rate is confirmed. The optimal test script selected by the genetic algorithm can effectively approximate the real optimal sample. Adjusting the script composition through the genetic algorithm can also alleviate the script failure caused by interface changes to a certain extent.

[0070] In addition, it should be noted that, for each test case, in the process of obtaining the first-generation test script corresponding to the test case, the repeated business links in the case can be removed.

[0071] Figure 21 is a schematic diagram of the main process of determining the optimal test script corresponding to the business link based on the genetic algorithm according to an embodiment of the present invention. Figure 2 As shown, the main process of determining the optimal test script corresponding to the business link based on the genetic algorithm may include:

[0072] Step S201: Verify the first test script corresponding to each business link using test data;

[0073] Step S202: if the verification is successful, determining that the first test script corresponding to each business link is the first generation test script corresponding to each business link;

[0074] Step S203: If the verification fails, a random sampling method of decreasing verification is used to generate a primary test script corresponding to each business link;

[0075] Step S204: combining the primary test scripts corresponding to each business link according to the process sequence of each business link in each test case to generate the primary test script corresponding to each test case;

[0076] Step S205: obtaining the initial test script corresponding to the test case of the current batch according to the initial test script corresponding to each test case;

[0077] Step S206: Perform iterative training based on a genetic algorithm according to the initial test scripts corresponding to the test cases of the current batch, and determine the optimal test script corresponding to each business link.

[0078] The above steps S201 to S203 refer to analyzing each business link in one or more business links to obtain the first-generation test script corresponding to each business link. Specifically, (1) randomly select a business link and use test data to verify the first test script corresponding to the selected business link; (2) if the verification is successful, determine that the first test script corresponding to the business link is the first-generation test script corresponding to the business link; (2) if the verification fails, use the random sampling method of decreasing test to generate the first-generation test script corresponding to the business link; (4) through the above (1) to (3), obtain the first-generation test script corresponding to each business link.

[0079] In an embodiment of the present invention, after generating a first test script corresponding to a business link based on code positioning and generating a second test script corresponding to a business link based on pattern recognition, a genetic algorithm can be used to select a test script from the first test script and the second test script to obtain the optimal test script corresponding to the business link, so as to subsequently obtain a target test script corresponding to the test case. On the one hand, the pattern recognition method can reduce the impact of interface changes on test cases. In some cases, the test script can still be successfully executed after the interface changes, reducing the burden of test script maintenance; on the other hand, the genetic algorithm can minimize the impact of the shortcomings of the pattern recognition method on the test results while pursuing the overall test success rate, and finally realize an automated regression test script that can be applied to agile versions.

[0080] As an embodiment of the present invention, after generating the target test script corresponding to the current batch of test cases, the target test script can also be executed using the test data to obtain the execution success rate and determine whether the execution success rate is greater than a preset success rate threshold; if so, the test is determined to have passed; if not, the target test script is manually corrected.

[0081] Furthermore, manually correcting the target test script may include: obtaining an abnormal script contained in the target test script, wherein the abnormal script is a script corresponding to a business link that failed to execute; if the abnormal script is the first test script, manually correcting the abnormal script; and, if the interface elements change, adjusting the image library used for pattern recognition.

[0082] The target test script generated by the iteration of the genetic algorithm represents the solution with the highest execution success rate that can be automatically adjusted at present. If the success rate cannot meet the standard, manual correction is required. The target test script corresponding to the case is composed of the optimal test scripts corresponding to each business link contained in the case. In the case where the success rate cannot meet the standard, it is necessary to determine the business link that failed to execute, and obtain the script corresponding to the business link that failed to execute in the target test script, that is, the exception script. If the exception script is the first test script, then the exception script can be manually corrected, that is, the exception script obtained by code positioning can be manually corrected. In addition, if the style of the interface element changes, the image library information stored by pattern recognition needs to be adjusted. In addition, it is necessary to set the preset success rate threshold according to the actual situation. Generally, it needs to be set so that the manual correction occurs in the middle of the development of the product version, so as to ensure that the user regression test task is accurately covered by the test script.

[0083] In addition, the method for generating a test script in an embodiment of the present invention may further include: modifying the abnormal script contained in the target test script according to the requirements. For bank front-end products, in addition to the normal maintenance process, the system can remind maintenance of error scripts in idle time periods; or in the product version design review stage, the front-end and back-end transformations can be communicated in advance, and maintenance resources can be allocated to relieve the pressure of automated testing.

[0084] Figure 3 FIG. 1 is a schematic diagram of the main process of the method for generating a test script according to an embodiment of the present invention. Figure 3 As shown, the main process of the method for generating a test script may include:

[0085] Step S301: Split each test case in the current batch of test cases into units of interface operations, obtain one or more business links corresponding to each test case, and determine the process sequence of each business link in each test case to obtain the business links corresponding to the test cases in the current batch;

[0086] Step S302: implementing each business link based on code positioning, generating a first test script corresponding to each business link, and implementing each business link based on pattern recognition, generating a second test script corresponding to each business link;

[0087] Step S303: Verify the first test script corresponding to each business link using the test data;

[0088] Step S304: if the verification is successful, determining that the first test script corresponding to each business link is the first generation test script corresponding to each business link;

[0089] Step S305: If the verification fails, a random sampling method of decreasing verification is used to generate a primary test script corresponding to each business link;

[0090] Step S306: according to the process sequence of each business link in each test case, the primary test scripts corresponding to each business link are combined to generate the primary test scripts corresponding to each test case;

[0091] Step S307: Obtaining the initial test scripts corresponding to the test cases of the current batch according to the initial test scripts corresponding to each test case;

[0092] Step S308: Perform iterative training based on a genetic algorithm according to the initial test scripts corresponding to the test cases of the current batch, and determine the optimal test script corresponding to each business link;

[0093] Step S309: Generate a target test script corresponding to the test case of the current batch according to the optimal test script corresponding to the business link;

[0094] Step S310: Execute the target test script using the test data, obtain the execution success rate of the target test script, and determine whether the execution success rate is greater than a preset success rate threshold. If so, execute step S311; if not, execute step S312;

[0095] Step S311: Determine if the test passes;

[0096] Step S312: Acquire the abnormal script included in the target test script, wherein the abnormal script is the script corresponding to the business link that failed to execute;

[0097] Step S313: if the abnormal script is the first test script, manually correct the abnormal script, and if the interface element changes, adjust the image library for pattern recognition to obtain a new target test script;

[0098] Step S314: Perform testing using the target test script.

[0099] Among them, step S303 to step S305 refer to analyzing each business link in one or more business links to obtain the initial test script corresponding to each business link, which has been specifically described by the above steps S201 to step S203 and will not be described in detail here. In addition, the method for generating a test script in an embodiment of the present invention may also include: according to the needs, correcting the abnormal script contained in the target test script.

[0100] From the technical solution for generating test scripts in the embodiment of the present invention, it is known that a first test script corresponding to a business link can be generated based on code positioning and a second test script corresponding to the business link can be generated based on pattern recognition, and then a genetic algorithm is used to select the test script to obtain the optimal test script corresponding to the business link, and then the target test script corresponding to the test case is obtained. The code positioning method and the pattern recognition method are combined through a genetic algorithm, so that the generated target test script has the characteristics of flexibility and accuracy, and the effect of generating test scripts by using a pattern recognition method to assist a code positioning method has been achieved, with high fault tolerance and controllable maintenance costs. In addition, the genetic algorithm can retain the proportion of the first test script in the target test script to the greatest extent, thereby reducing the algorithm search time and improving the effectiveness of the target test script.

[0101] Figure 4 Schematic diagram of the main modules of the apparatus for generating a test script according to an embodiment of the present invention. Figure 4 As shown, the main modules of the apparatus 400 for generating a test script may include: a splitting module 401 , an acquiring module 402 , a determining module 403 and a generating module 404 .

[0102] Among them, the splitting module 401 can be used to: split the test cases of the current batch to obtain the business links corresponding to the test cases of the current batch; the acquisition module 402 can be used to: obtain the first test script and the second test script corresponding to the business link, wherein the first test script is a test script generated based on code positioning, and the second test script is a test script generated based on pattern recognition; the determination module 403 can be used to: determine the optimal test script corresponding to the business link based on the first test script and the second test script corresponding to the business link based on a genetic algorithm; the generation module 404 can be used to: generate a target test script corresponding to the test cases of the current batch according to the optimal test script corresponding to the business link.

[0103] As an embodiment of the present invention, the splitting module 401 can also be used to split each test case in the current batch of test cases based on interface operations, obtain one or more business links corresponding to each test case, and obtain the business links corresponding to the test cases in the current batch.

[0104] As an embodiment of the present invention, the acquisition module 402 can also be used for: for each business link in one or more business links corresponding to each test case, implementing each business link based on code positioning, and generating a first test script corresponding to each business link; implementing each business link based on pattern recognition, and generating a second test script corresponding to each business link.

[0105] As an embodiment of the present invention, the determination module 403 can also be used to: generate an initial test script corresponding to each test case according to the first test script corresponding to each business link and the second test script corresponding to each business link, so as to obtain the initial test script corresponding to the test case of the current batch; perform iterative training based on a genetic algorithm according to the initial test script corresponding to the test case of the current batch, and determine the optimal test script corresponding to each business link; wherein the fitness function of the genetic algorithm is the overall test success rate corresponding to the test case.

[0106] As an embodiment of the present invention, the determination module 403 can also be used to: use test data to verify the first test script corresponding to each business link; if the verification is successful, determine that the first test script corresponding to each business link is the first-generation test script corresponding to each business link; if the verification fails, use a random sampling method with decreasing test to generate the first-generation test script corresponding to each business link; based on the first-generation test script corresponding to each business link, generate the first-generation test script corresponding to each test case.

[0107] As an embodiment of the present invention, the splitting module 401 can also be used to: determine the process order of each business link in each test case; and the determination module is also used to: combine the initial test scripts corresponding to each business link according to the process order of each business link in each test case to generate the initial test script corresponding to each test case.

[0108] As an embodiment of the present invention, the generation module 404 can also be used to: execute the target test script using the test data, obtain the execution success rate, and determine whether the execution success rate is greater than a preset success rate threshold; if so, determine that the test has passed; if not, manually correct the target test script.

[0109] As an embodiment of the present invention, the generation module 404 can also be used to: obtain the abnormal script contained in the target test script, wherein the abnormal script is the script corresponding to the business link that failed to execute; if the abnormal script is the first test script, manually correct the abnormal script; and if the interface elements change, adjust the image library used for pattern recognition.

[0110] As an embodiment of the present invention, the generating module 404 may also be used to: modify the abnormal script included in the target test script according to requirements.

[0111] According to the device for generating test scripts according to the embodiment of the present invention, a first test script corresponding to a business link can be generated based on code positioning and a second test script corresponding to the business link can be generated based on pattern recognition, and then a genetic algorithm is used to select the test script to obtain the optimal test script corresponding to the business link, and then a target test script corresponding to the test case is obtained. The code positioning method and the pattern recognition method are combined through a genetic algorithm, so that the generated target test script has the characteristics of flexibility and accuracy, and the effect of generating test scripts by using a pattern recognition method to assist a code positioning method has been achieved, with high fault tolerance and controllable maintenance costs. In addition, the genetic algorithm can retain the proportion of the first test script in the target test script to the greatest extent, thereby reducing the algorithm search time and improving the effectiveness of the target test script.

[0112] Figure 5 An exemplary system architecture 500 is shown to which the method for generating a test script or the apparatus for generating a test script according to the embodiment of the present invention can be applied.

[0113] like Figure 5 As shown, system architecture 500 may include terminal devices 501, 502, 503, a network 504 and a server 505. Network 504 is used to provide a medium for communication links between terminal devices 501, 502, 503 and server 505. Network 504 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.

[0114] Users can use terminal devices 501, 502, 503 to interact with server 505 through network 504 to receive or send messages, etc. Terminal devices 501, 502, 503 can be various electronic devices with display screens and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, etc.

[0115] Server 505 may be a server that provides various services, such as a background management server that provides support for users to generate scripts using terminal devices 501, 502, and 503 (only as an example); for another example, server 505 may complete the script generation of an embodiment of the present invention.

[0116] It should be noted that the method for generating a test script provided in the embodiment of the present invention is generally executed by the server 505 , and accordingly, the device for generating a test script is generally arranged in the server 505 .

[0117] It should be understood that Figure 5 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.

[0118] Reference below Figure 6 , which shows a schematic diagram of the structure of a computer system 600 of a terminal device suitable for implementing an embodiment of the present invention. Figure 6 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0119] like Figure 6 As shown, the computer system 600 includes a central processing unit (CPU) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage part 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the system 600 are also stored. The CPU 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.

[0120] The following components are connected to the I / O interface 605: an input section 606 including a keyboard, a mouse, etc.; an output section 607 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN card, a modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the I / O interface 605 as needed. A removable medium 611, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 610 as needed, so that a computer program read therefrom is installed into the storage section 608 as needed.

[0121] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 609, and / or installed from the removable medium 611. When the computer program is executed by the central processing unit (CPU) 601, the above-mentioned functions defined in the system of the present invention are executed.

[0122] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0123] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0124] The modules involved in the embodiments of the present invention may be implemented in software or hardware. The modules described may also be set in a processor. For example, they may be described as: a processor includes a splitting module, an acquisition module, a determination module, and a generation module. The names of these modules do not, in some cases, constitute limitations on the modules themselves. For example, the splitting module may also be described as "a module for splitting the test cases of the current batch according to the business process to obtain the business links corresponding to the test cases of the current batch".

[0125] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently and not be assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes: splitting the test cases of the current batch according to the business process to obtain the business links corresponding to the test cases of the current batch; obtaining the first test script and the second test script corresponding to the business link, wherein the first test script is a test script generated based on code positioning, and the second test script is a test script generated based on pattern recognition; according to the first test script and the second test script corresponding to the business link, based on the genetic algorithm, determine the optimal test script corresponding to the business link; according to the optimal test script corresponding to the business link, generate the target test script corresponding to the test cases of the current batch.

[0126] According to the technical solution of the embodiment of the present invention, a first test script corresponding to a business link can be generated based on code positioning and a second test script corresponding to the business link can be generated based on pattern recognition. Then, a genetic algorithm is used to select the test script to obtain the optimal test script corresponding to the business link, and then a target test script corresponding to the test case is obtained. The code positioning method and the pattern recognition method are combined through a genetic algorithm, so that the generated target test script has the characteristics of flexibility and accuracy, and the effect of generating a test script by assisting the code positioning method with the pattern recognition method is achieved. The fault tolerance rate is high and the maintenance cost is controllable. In addition, the genetic algorithm can retain the proportion of the first test script in the target test script to the greatest extent, thereby reducing the algorithm search time and improving the effectiveness of the target test script.

[0127] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for generating a test script, characterized in that: include: Splitting the test cases of the current batch to obtain the business links corresponding to the test cases of the current batch, including: splitting each test case in the current batch of test cases based on interface operations to obtain one or more business links corresponding to each test case, so as to obtain the business links corresponding to the test cases of the current batch; Obtaining the first test script and the second test script corresponding to the business link, including: for each business link in the one or more business links corresponding to each test case, implementing each business link based on code positioning, and generating the first test script corresponding to each business link; implementing each business link based on pattern recognition, and generating the second test script corresponding to each business link; wherein the first test script is a test script generated based on code positioning, and the second test script is a test script generated based on pattern recognition; Determine the optimal test script corresponding to the business link based on a genetic algorithm according to the first test script and the second test script corresponding to the business link; According to the optimal test script corresponding to the business link, a target test script corresponding to the test cases of the current batch is generated.

2. The method according to claim 1, characterized in that Determining the optimal test script corresponding to the business link based on the first test script and the second test script corresponding to the business link based on a genetic algorithm includes: Generate a first-generation test script corresponding to each test case according to the first test script corresponding to each business link and the second test script corresponding to each business link, so as to obtain a first-generation test script corresponding to the test case of the current batch; According to the first-generation test scripts corresponding to the test cases of the current batch, iterative training is performed based on a genetic algorithm to determine the optimal test script corresponding to each business link; wherein, The fitness function of the genetic algorithm is the overall test success rate corresponding to the test case.

3. The method according to claim 2, characterized in that The generating, according to the first test script corresponding to each business link and the second test script corresponding to each business link, a primary test script corresponding to each test case comprises: Verifying the first test script corresponding to each business link using the test data; If the verification is successful, the first test script corresponding to each business link is determined to be the first-generation test script corresponding to each business link; if the verification fails, the first-generation test script corresponding to each business link is generated by using a random sampling method of decreasing inspection; According to the first-generation test script corresponding to each business link, a first-generation test script corresponding to each test case is generated.

4. The method according to claim 3, characterized in that After splitting the test case into units of interface operations to obtain one or more business links corresponding to each test case, the method further includes: determining the process sequence of each business link in each test case; and, Generating the primary test script corresponding to each test case according to the primary test script corresponding to each business link includes: According to the process sequence of each business link in each test case, the primary test scripts corresponding to each business link are combined to generate the primary test script corresponding to each test case.

5. The method according to claim 1, characterized in that After generating the target test script corresponding to the test case of the current batch, the method further includes: Execute the target test script using the test data, obtain the execution success rate, and determine whether the execution success rate is greater than a preset success rate threshold; If yes, the test is confirmed to pass; If not, the target test script is manually corrected.

6. The method according to claim 5, characterized in that The manually correcting the target test script includes: Obtaining an abnormal script included in the target test script, wherein the abnormal script is a script corresponding to a business link that failed to execute; If the abnormal script is the first test script, manually correcting the abnormal script; and, If interface elements change, the image library used for pattern recognition is adjusted.

7. The method according to claim 1, characterized in that The method further includes: modifying the abnormal script included in the target test script according to demand.

8. A device for generating a test script, characterized in that: include: The splitting module is used to split the test cases of the current batch and obtain the business links corresponding to the test cases of the current batch, including: splitting each test case in the current batch of test cases based on the interface operation as a unit to obtain one or more business links corresponding to each test case, so as to obtain the business links corresponding to the test cases of the current batch; An acquisition module, used for acquiring the first test script and the second test script corresponding to the business link, including: for each business link in one or more business links corresponding to each test case, implementing each business link based on code positioning, and generating the first test script corresponding to each business link; implementing each business link based on pattern recognition, and generating the second test script corresponding to each business link; wherein, the first test script is a test script generated based on code positioning, and the second test script is a test script generated based on pattern recognition; A determination module, configured to determine the optimal test script corresponding to the business link based on a genetic algorithm according to the first test script and the second test script corresponding to the business link; A generation module is used to generate a target test script corresponding to the test cases of the current batch according to the optimal test script corresponding to the business link.

9. The device according to claim 8, characterized in that The determining module is also used for: Generate a first-generation test script corresponding to each test case according to the first test script corresponding to each business link and the second test script corresponding to each business link, so as to obtain a first-generation test script corresponding to the test case of the current batch; According to the first-generation test scripts corresponding to the test cases of the current batch, iterative training is performed based on a genetic algorithm to determine the optimal test script corresponding to each business link; wherein, The fitness function of the genetic algorithm is the overall test success rate corresponding to the test case.

10. The device according to claim 9, characterized in that The determining module is also used for: Verifying the first test script corresponding to each business link using the test data; If the verification is successful, the first test script corresponding to each business link is determined to be the first-generation test script corresponding to each business link; if the verification fails, the first-generation test script corresponding to each business link is generated by using a random sampling method of decreasing inspection; According to the first-generation test script corresponding to each business link, a first-generation test script corresponding to each test case is generated.

11. The device according to claim 8, characterized in that The generation module is also used for: Execute the target test script using the test data, obtain the execution success rate, and determine whether the execution success rate is greater than a preset success rate threshold; If yes, the test is confirmed to pass; If not, the target test script is manually corrected.

12. The device according to claim 11, characterized in that The generation module is also used for: Obtaining an abnormal script included in the target test script, wherein the abnormal script is a script corresponding to a business link that failed to execute; If the abnormal script is the first test script, manually correcting the abnormal script; and, If interface elements change, the image library used for pattern recognition is adjusted.

13. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 7.

14. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Method and device for generating test data and electronic equipment

    CN110147318A

  • Front-end page test method and device, medium and electronic equipment

    CN111966592A