Method and apparatus for generating test script common code

By preprocessing and word frequency analysis of the test script code, target common code blocks are generated and verified, solving the redundancy problem of automated test scripts in the end-to-end transaction process of the UI interface in the financial field. This achieves intelligent management of code blocks, simplifies the automated testing process, and improves testing efficiency.

CN115687079BActive Publication Date: 2026-02-13INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211009249.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-08-22
Publication Date
2026-02-13
Estimated Expiration
2042-08-22

AI Technical Summary

Technical Problem

In end-to-end transaction process testing of UI interfaces in the financial field, the code processing flow of automated test scripts is long and redundant. Different test developers have different writing habits, resulting in a lot of duplicate code snippets. When the function changes, all related scripts need to be adjusted, resulting in a lot of repetitive and redundant work.

Method used

By preprocessing the test script code, using a text keyword extraction algorithm for word frequency analysis, generating target public code blocks based on word frequency and preset encapsulation rules, and verifying their effectiveness, a public code block asset is formed.

Benefits of technology

Simplify the structure of automated test scripts, improve testing efficiency, reduce repetitive work, enable intelligent management and referencing of code blocks, and improve the work efficiency of developers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115687079B_ABST
    Figure CN115687079B_ABST
Patent Text Reader

Abstract

The present disclosure provides a test script common code generation method, relates to the software testing field, and can be applied to the financial technology field. The method comprises the following steps: in response to a test script common code generation instruction, pre-processing test script code to generate target test script code information; using a text keyword extraction algorithm to perform word frequency analysis on the target test script code information to generate a word frequency analysis result; and encapsulating the target test script code information according to the word frequency analysis result and a preset encapsulation rule to generate a target common code block. The present disclosure also provides a test script common code generation device, equipment, a storage medium and a program product.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present disclosure relates to the field of automation testing, in particular to the field of page testing, and more particularly to a method, device, equipment, storage medium and program product for generating test script public code. BACKGROUND

[0002] In the financial field, in order to ensure that the functions of the newly online system are normal, in the user acceptance test stage, through the design and verification of end-to-end business test scenarios, the verification of new version functions is as much as possible implemented from the actual business use scenarios, and a large number of end-to-end UI interface automation testing technologies are introduced to improve work efficiency.

[0003] In the process of performing UI interface end-to-end transaction process testing, a complete business process is usually composed of multiple different business functions or services. Because of the long transaction process and strong function coupling of the financial transaction, the code processing process of the automation test script is also long. Because each automation test script design is for a complete business process, it is not for a single function or service, and at the same time, in the process of large-scale acceptance test automation practice, the compilation task of the automation test script is scattered among different test developers, resulting in that some public transaction parts are recompiled as new content in the automation test script of the business process responsible by the test developer each time. In this mode, there are a large number of repeated code segments in the automation test scripts corresponding to similar functions or business scenarios of the same transaction type, and the writing methods of different test developers are not completely consistent, so when the corresponding function in the repeated code segment changes, all related automation test scripts need to be adjusted, resulting in a large amount of repetitive redundant work.

[0004] It should be noted that the information disclosed in the above background section is only used to strengthen the understanding of the background of the present disclosure, and therefore can include information that does not constitute prior art known to those of ordinary skill in the art. SUMMARY

[0005] In view of the above problems, the present disclosure provides a method, device, equipment, medium and program product for generating test script public code to improve the efficiency of automation testing.

[0006] According to a first aspect of the present disclosure, a method for generating test script public code is provided, the method comprising:

[0007] In response to a generation instruction of test script public code, pre-processing test script code to generate target test script code information;

[0008] perform word frequency analysis on the target test script code information using a text keyword extraction algorithm to generate a word frequency analysis result; and

[0009] encapsulate the target test script code information according to the word frequency analysis result and a preset encapsulation rule to generate a target common code block.

[0010] According to an embodiment of the present disclosure, the preprocessing of the test script code to generate target test script code information includes:

[0011] scanning the test script code to identify a test page operation object in the test script code;

[0012] determining operation action information and processing method information of the test page operation object according to the test page operation object;

[0013] performing a hash operation on the test page operation object to generate a hash value; and

[0014] generating target test script code information according to the test page operation object information, the operation action information, the processing method information, and the hash value.

[0015] According to an embodiment of the present disclosure, the performing word frequency analysis on the target test script code information using a text keyword extraction algorithm to generate a word frequency analysis result includes:

[0016] extracting the target test script code according to a preset step size and in a script execution order to generate a first target code;

[0017] calculating word frequency information of the first target code; and

[0018] generating a word frequency analysis result according to the word frequency information.

[0019] According to an embodiment of the present disclosure, the encapsulating the target test script code information according to the word frequency analysis result and a preset encapsulation rule to generate a target common code block includes:

[0020] determining code with a word frequency greater than a preset threshold in the target test script code information as common code;

[0021] determining a target encapsulation rule according to an operation object type in the common code; and

[0022] encapsulating the common code according to the target encapsulation rule to generate a target common code block.

[0023] According to an embodiment of the present disclosure, the determining a target encapsulation rule according to an operation object type in the common code includes:

[0024] If it is determined that the operation object type is a get browser connection operation, it is determined that the target encapsulation rule is to add a waiting and window maximization operation after the get browser connection operation;

[0025] If it is determined that the operation object type is a click operation, it is determined that the target encapsulation rule is to add a waiting time after the click operation; and

[0026] If it is determined that the operation object type is an input operation, it is determined that the target encapsulation rule is to add a click operation of the same element before the input operation.

[0027] According to an embodiment of the present disclosure, after the target common code block is generated, further comprising:

[0028] verifying the validity of the target common code block;

[0029] generating a common code block management list according to the validity verification result.

[0030] A second aspect of the present disclosure provides a test script common code generation device, the device comprising:

[0031] a code noise reduction module for preprocessing test script code to generate target test script code information;

[0032] a word frequency analysis module for performing word frequency analysis on the target test script code information using a text keyword extraction algorithm to generate a word frequency analysis result;

[0033] a target common code block encapsulation module for encapsulating the target test script code information according to the word frequency analysis result and a preset encapsulation rule to generate a target common code block.

[0034] According to an embodiment of the present disclosure, the code noise reduction module comprises:

[0035] a scanning sub-module for scanning test script code to identify test page operation objects in the test script code;

[0036] a first determination sub-module for determining operation action information and processing method information of the test page operation objects according to the test page operation objects;

[0037] a hash operation sub-module for performing hash operation on the test page operation objects to generate a hash value;

[0038] a first generation sub-module for generating target test script code information according to the test page operation object information, the operation action information, the processing method information and the hash value.

[0039] According to an embodiment of the present disclosure, the word frequency analysis module comprises:

[0040] The second generation submodule is configured to extract the target test script code according to a preset step length and a script execution sequence to generate a first target code.

[0041] The word frequency calculation submodule is configured to calculate word frequency information of the first target code.

[0042] The third generation submodule is configured to generate a word frequency analysis result according to the word frequency information.

[0043] According to an embodiment of the present disclosure, the target common code block encapsulation module comprises:

[0044] The second determination submodule is configured to determine that a code with a word frequency greater than a preset threshold in the target test script code information is a common code.

[0045] The third determination submodule is configured to determine a target encapsulation rule according to an operation object type in the common code.

[0046] The third generation submodule is configured to encapsulate the common code according to the target encapsulation rule to generate a target common code block.

[0047] According to an embodiment of the present disclosure, the third determination submodule comprises:

[0048] The first determination unit is configured to determine that the target encapsulation rule is to add a waiting and window maximization operation after a browser connection operation is acquired if it is determined that the operation object type is the browser connection operation.

[0049] The second determination unit is configured to determine that the target encapsulation rule is to add a waiting time after a click operation if it is determined that the operation object type is the click operation.

[0050] The third determination unit is configured to determine that the target encapsulation rule is to add a click operation of the same element before an input operation if it is determined that the operation object type is the input operation.

[0051] According to an embodiment of the present disclosure, the device further comprises:

[0052] The verification module is configured to verify validity of the target common code block.

[0053] The generation module is configured to generate a common code block management list according to a validity verification result.

[0054] According to an embodiment of the present disclosure, the verification module comprises:

[0055] The replacement submodule is configured to replace the target common code block in the test script to generate a target test script.

[0056] The acquisition submodule is configured to execute the target test script to acquire an execution success rate of the target test script.

[0057] The fourth determination submodule is configured to determine that the target common code block is valid when it is determined that the execution success rate is greater than or equal to a preset threshold.

[0058] The fifth determination submodule is configured to determine that the target common code block is invalid when it is determined that the execution success rate is less than the preset threshold.

[0059] A third aspect of the present disclosure provides an electronic device, comprising: one or more processors; a memory for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors execute the test script common code generation method described above.

[0060] A fourth aspect of the present disclosure further provides a computer-readable storage medium having stored executable instructions, which, when executed by a processor, cause the processor to execute the test script common code generation method described above.

[0061] A fifth aspect of the present disclosure further provides a computer program product comprising a computer program, which, when executed by a processor, implements the test script common code generation method described above.

[0062] The test script common code generation method provided by the embodiments of the present disclosure responds to a test script common code generation instruction, pre-processes test script code, removes redundant information in the script code to generate target test script code information, uses a text keyword extraction algorithm to perform word frequency analysis on the target test script code information to generate a word frequency analysis result, and encapsulates the target test script code information according to the word frequency analysis result and a preset encapsulation rule to generate a target common code block. Compared with related technologies, the method provided by the embodiments of the present disclosure intelligently adjusts the code blocks in the original automated test script to a common module reference manner, simplifies the structure of the automated test script, and intelligently forms a common code block asset for subsequent test developers to write new processes, thereby improving the efficiency of automated testing. BRIEF DESCRIPTION OF DRAWINGS

[0063] The above and other objects, features and advantages of the present disclosure will become more apparent from the following description of embodiments of the present disclosure, taken in conjunction with the accompanying drawings, in which:

[0064] Figure 1An application scenario diagram of a method, device, equipment, medium and program product for generating test script common code according to an embodiment of the present disclosure is schematically shown.

[0065] Figure 2 A flowchart of a method for generating test script common code according to an embodiment of the present disclosure is schematically shown.

[0066] Figure 3 A flowchart of a script code preprocessing method according to an embodiment of the present disclosure is schematically shown.

[0067] Figure 4 A flowchart of word frequency analysis of target test script code information using a text keyword extraction algorithm according to an embodiment of the present disclosure is schematically shown.

[0068] Figure 5a A flowchart of a target common code block generation method according to an embodiment of the present disclosure is schematically shown.

[0069] Figure 5b A flowchart of a method for determining a preset packaging rule according to an embodiment of the present disclosure is schematically shown.

[0070] Figure 6a One of flowcharts of a target common code block verification method according to an embodiment of the present disclosure is schematically shown.

[0071] Figure 6b The other of flowcharts of a target common code block verification method according to an embodiment of the present disclosure is schematically shown.

[0072] Figure 7 A structural block diagram of a device for generating test script common code according to an embodiment of the present disclosure is schematically shown.

[0073] Figure 8 A block diagram of an electronic device suitable for implementing a method for generating test script common code according to an embodiment of the present disclosure is schematically shown. DETAILED DESCRIPTION

[0074] Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. However, it should be understood that these descriptions are merely exemplary and are not intended to limit the scope of the present disclosure. In the following detailed description, numerous specific details are set forth in order to provide a thorough understanding of the embodiments of the present disclosure. However, it will be apparent to those skilled in the art that one or more embodiments can be practiced without these specific details. In addition, in the following description, descriptions of well-known structures and techniques have been omitted to avoid unnecessarily obscuring the concept of the present disclosure.

[0075] The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure. As used herein, the terms "comprises", "comprising", "includes", "including" and the like are specifically intended to be open-ended terms meaning that other elements can be added.

[0076] All terms used herein including technical and scientific terms have the meanings commonly understood by one of ordinary skill in the art unless otherwise specified. It should be noted that the use of terms herein, such as should be construed to have meanings consistent with the context of the specification and relevant work in the field.

[0077] In the case of using expressions similar to "at least one of A, B, and C, etc.", it should generally be interpreted to include any of them, to include, for example, only A, only B, only C, A and B, A and C, B and C, and / or A and B and C, etc.

[0078] With the development of IT technology, more and more enterprises begin to introduce automated testing technology to verify the version functions of the developed software products, which not only improves the efficiency of version testing verification, but also reduces the problems of incomplete test execution coverage, inconsistent test verification results, and lack of objectivity of test verification results caused by manual test execution.

[0079] In the financial field, the business transaction type is usually a long process transaction. At the same time, with the introduction of distributed and micro-service architecture, the architecture between application systems becomes more and more complex, and the number of interfaces and services is also growing. Usually, dozens or hundreds of services or interfaces need to be called in the process of a transaction. The test verification from the single service or interface level cannot accurately reflect whether the function of a complete business transaction scenario is normal.

[0080] In order to maximize the guarantee of the normal function of the newly online system and the absence of BUGs affecting normal business transactions, more and more financial enterprises introduce and expand the resource investment in the user acceptance test phase. In the user acceptance test phase, through the design and verification of end-to-end business test scenarios, the verification of new version functions is realized as much as possible from the actual business use scenarios, and the problems caused by the absence of complete simulation of the entire call chain in the single interface or service test phase are avoided as much as possible.

[0081] In the user acceptance test stage, test cases are designed from end-to-end complete business processes, and the relevant functions are verified through the UI interface. Because the execution process is long and the test time-consuming, the test time efficiency and test coverage efficiency requirements cannot be guaranteed through traditional manual testing methods. Therefore, more and more financial enterprises also introduce a large number of end-to-end UI interface automation testing technologies in the acceptance test stage to improve work efficiency and meet the requirements of fast version function iteration of enterprises.

[0082] In the process of testing the UI interface end-to-end transaction process, a complete business process is usually composed of multiple different business functions or services. Because the financial transaction transaction process is long and the functions are strongly coupled, the code processing process of the automated test script will also be long. Because each automated test script design is for a complete business process, it is not for a single function or service, and in the process of large-scale acceptance test automation practice, the compilation task of the automated test script is scattered among different test developers, resulting in some common transaction parts being recompiled as new content in the business process automated test script of each test developer.

[0083] In this mode, there are a large number of repeated code fragments in the automated test scripts corresponding to similar functions or business scenarios of the same transaction type, and the writing methods of different test developers are not completely consistent. When the corresponding function in the repeated code fragment changes, all related automated test scripts need to be adjusted, resulting in a large amount of redundant work.

[0084] UI end-to-end automated testing from a business scenario is different from automated testing from a functional level. Due to resource and time constraints, it is not possible to automate all functions in the test cycle, resulting in the long-term existence of the above problems. For the testing department and test personnel, there is a lot of repetitive and redundant work.

[0085] Based on the above technical problems, the embodiments of the present disclosure provide a test script public code generation method, which comprises: in response to a test script public code generation instruction, preprocessing test script code to generate target test script code information; using a text keyword extraction algorithm to perform word frequency analysis on the target test script code information to generate a word frequency analysis result; and encapsulating the target test script code information according to the word frequency analysis result and a preset encapsulation rule to generate a target public code block.

[0086] Figure 1An application scenario diagram of a method and apparatus for generating test script common code according to an embodiment of the present disclosure is shown schematically.

[0087] As shown in Figure 1 The application scenario 100 according to this embodiment can include a page test script automated testing scenario. The network 104 is a medium for providing communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 can include various connection types, such as wired, wireless communication links, or fiber optic cables, and the like.

[0088] The users can use the terminal devices 101, 102, 103 to interact with the server 105 through the network 104 to receive or send messages, and the like. Various communication client applications can be installed on the terminal devices 101, 102, 103, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, and the like (only as examples).

[0089] The terminal devices 101, 102, 103 can be various electronic devices with display screens and supporting web browsing, including but not limited to smartphones, tablet computers, laptop computers, desktop computers, and the like.

[0090] The server 105 can be a page test script management server. In response to a user issuing a test script common code generation instruction using a terminal device 101, 102, 103, the page test script management server preprocesses the inventory test script code, extracts the common code portion through term frequency analysis, and encapsulates the common code portion according to a preset encapsulation rule to generate a common code block.

[0091] It should be noted that the method for generating test script common code provided by the embodiments of the present disclosure can generally be executed by the server 105. Accordingly, the test script common code generation apparatus provided by the embodiments of the present disclosure can generally be disposed in the server 105. The method for generating test script common code provided by the embodiments of the present disclosure can also be executed by a server or a server cluster different from the server 105 and capable of communicating with the terminal devices 101, 102, 103 and / or the server 105. Accordingly, the test script common code generation apparatus provided by the embodiments of the present disclosure can also be disposed in a server or a server cluster different from the server 105 and capable of communicating with the terminal devices 101, 102, 103 and / or the server 105.

[0092] It should be understood that Figure 1The number of terminal devices, networks and servers in the foregoing is merely illustrative. Any number of terminal devices, networks and servers can be provided according to implementation requirements.

[0093] It should be noted that the method and device for generating test script public code determined by the embodiments of the present disclosure can be used in the field of automated testing technology, and can also be used in the field of financial technology, and can also be used in any field other than the field of finance. The application field of the method and device for generating test script public code determined by the embodiments of the present disclosure is not limited.

[0094] The following will be based on Figure 1 The scenario described above is described by Figure 2-6b The method for generating test script public code of the embodiments of the present disclosure is described in detail.

[0095] Figure 2 A flowchart of a method for generating test script public code according to an embodiment of the present disclosure is schematically shown. As Figure 2 shown, the method for generating test script public code of this embodiment includes operation S210 to operation S230. The method can be executed by an automated test script code module intelligent encapsulation device. By scanning the inventory of automated test scripts, similar code blocks are found through intelligent comparison and analysis, and encapsulation is automatically performed. At the same time, the encapsulated automated test scripts are submitted for execution, and the execution results are analyzed. When the execution does not pass, the code blocks are re-adjusted, and then encapsulated and submitted for execution again. Finally, the encapsulated code blocks that pass the execution are used as public modules, and all corresponding automated scripts with similar code blocks are synchronized and adjusted. The original automated test script code blocks are intelligently adjusted to a public module reference mode, the structure of the automated test script is simplified, and intelligent public code block assets are formed for subsequent test developers to write new processes.

[0096] In operation S210, in response to a test script public code generation instruction, the test script code is preprocessed to generate target test script code information.

[0097] In one example, in the process of UI end-to-end automated testing, there are a large number of automated test script assets, and these script codes are written by different test developers, so there are many redundant parts. In order to facilitate the extraction of public code in the test script code, after receiving the test script public code generation instruction, the inventory of test script codes is denoised to remove redundant information in the script code. The redundant information may be, for example, comment information in the script, log printing output statements, or other statements of non-object operation related actions. The target test script code information is obtained. The specific preprocessing process can be referred to operation S211 to operation S214 shown in Figure 3 not described again here.

[0098] In operation S220, a text keyword extraction algorithm is used to perform word frequency analysis on the target test script code information to generate a word frequency analysis result.

[0099] In one example, a text keyword extraction algorithm is used to count the frequency of code appearing in a preset step in the target test script code information, i.e., word frequency information, to generate a word frequency analysis result. The higher the word frequency, the greater the possibility that the code can be encapsulated as public code. The word frequency analysis process is also the process of determining public code. For details of the specific process of generating a word frequency analysis result, please refer to operations S221-S223 shown in FIG. 2B. Figure 4

[0100] In operation S230, the target test script code information is encapsulated according to the word frequency analysis result and a preset encapsulation rule to generate a target public code block.

[0101] In one example, after obtaining the word frequency analysis result, the public code in the target test script code information is encapsulated to generate a target public code block according to the analysis result. To improve the execution success rate of the target public code block, the public code needs to be processed according to a certain preset encapsulation rule before encapsulation. For details of the specific processing process, please refer to operations S231-S233 shown in FIG. 5. After generating the target public code block, the corresponding public code segment in the original automation script is deleted and replaced with a call to the new encapsulated public code. At the same time, the change history of the automation script is retained to facilitate script rollback.

[0102] The test script public code generation method provided by the embodiments of the present disclosure generates a public code block from the code in the original test script, adjusts the code block in the original automation test script to a public module reference manner, simplifies the structure of the automation test script, and intelligently forms a public code block asset for subsequent test developers to write new processes, thereby improving the efficiency of automation testing.

[0103] Figure 3 A flowchart of a script code preprocessing method provided by an embodiment of the present disclosure is schematically shown in FIG. 2A. Figure 3 As shown in FIG. 2A, operation S210 includes operations S211-S214.

[0104] In operation S211, the test script code is scanned to identify the test page operation object in the test script code.

[0105] In operation S212, the operation action information and processing method information of the test page operation object are determined according to the test page operation object.

[0106] ​In operation S213, the test page operation object is hashed to generate a hash value.

[0107] In operation S214, target test script code information is generated according to the test page operation object information, the operation action information, the processing method information, and the hash value.

[0108] In one example, test page operation objects in a test script code are scanned, the test page operation objects including control elements in a page, such as an input box, a click button, and the like, and operation action information and processing method information corresponding to each test page operation object are determined according to the type of the test page operation object and the test script code, wherein the processing method information includes a judgment loop statement, such as an ifelse if conditional judgment statement. In order to facilitate later word frequency analysis and statistics, the test page operation object is hashed to obtain a hash value, that is, the hash values of the same test page operation object are the same, and target test script code information is generated according to the test page operation object information, the operation action information, the processing method information, and the hash value. As shown in Table 1 below, the target test script code information can be obtained.

[0109] Table 1: Target test script code information table

[0110]

[0111] Figure 4 An example of a flowchart of word frequency analysis of the target test script code information using a text keyword extraction algorithm is shown in FIG. 2, which is provided according to an embodiment of the present disclosure. Figure 4 As shown in FIG. 2, operation S220 includes operation S221 to operation S223.

[0112] In operation S221, the target test script code is extracted according to a preset step size in a script execution order to generate first target code.

[0113] In operation S222, word frequency information of the first target code is calculated.

[0114] In operation S223, a word frequency analysis result is generated according to the word frequency information.

[0115] In one example, similarity analysis is performed on the preprocessed automated test script, a text keyword extraction algorithm is used to extract common code blocks, encapsulate the common code blocks, submit the encapsulated code blocks to the common code definition module for storage processing, set the status to be verified, and record the corresponding relationship. The text keyword extraction algorithm processes the denoised code, extracts the script content in the order of forward + word frequency + step length. The forward refers to extracting the code in the order of script execution, with a preset step length, for example, 6 lines. Extract 6 lines of code as the first target code according to the script execution order, calculate the frequency of the first target code in the script, obtain the word frequency information, and analyze the word frequency information. The code that meets the certain condition of word frequency can be encapsulated as common code.

[0116] Figure 5a A flowchart of a target common code block generation method is schematically shown, Figure 5b A flowchart of a method for determining a preset encapsulation rule is schematically shown. As Figure 5a shown, operation S230 includes operation S231 to operation S233.

[0117] In operation S231, the code with a word frequency greater than a preset threshold in the target test script code information is determined as common code.

[0118] In operation S232, a target encapsulation rule is determined according to the operation object type in the common code.

[0119] In operation S233, the common code is encapsulated according to the target encapsulation rule to generate a target common code block.

[0120] As Figure 5b shown, operation S232 includes operation S2321 to operation S2323.

[0121] In operation S2321, if it is determined that the operation object type is a get browser connection operation, the target encapsulation rule is determined to be a wait and window maximization operation after the get browser connection operation.

[0122] In operation S2322, if it is determined that the operation object type is a click operation, the target encapsulation rule is determined to be a waiting time after the click operation.

[0123] In operation S2323, if it is determined that the operation object type is an input operation, the target encapsulation rule is determined to be a click operation of the same element before the input operation.

[0124] In one example, when the word frequency of the first target code corresponding to any operation object reaches a preset threshold of the total number of scripts, for example, 5% of the total number of scripts, the first target code is encapsulated. In order to improve the success rate of the execution of the encapsulated public code and ensure the smooth execution of the test script, the preset encapsulation rule needs to be used for encapsulation. The specific rules are as follows:

[0125] (1) After the browser connection operation (driver.get), the waiting and window maximization operations (driver.manage().window().maximize()) are added. The page opening operation is simulated, the waiting time is increased to wait for page loading, and the window maximization operation is added after the page is loaded.

[0126] (2) The waiting time is added after the click operation. In order to shield the influence of network difference on page test, the waiting time is added after the click operation to wait for server response.

[0127] (3) The click operation of the same element is added before the input operation (sendKeys). In order to ensure that the information can be successfully input in the input box, the click operation of the same element is added before the input operation to ensure that the current input box is in the active state.

[0128] (4) The screenshot operation is added after the if condition judgment is ended.

[0129] According to different operation object types, the corresponding encapsulation rule is determined to encapsulate and generate a target public block. After generating the target public code block, the validity of the public code block needs to be verified.

[0130] Figure 6a One of the flowcharts of the target public code block verification method provided by the embodiments of the present disclosure is schematically shown. Figure 6b Another flowchart of the target public code block verification method provided by the embodiments of the present disclosure is schematically shown, as shown in Figure 6a , which includes operation S310 and operation S320.

[0131] In operation S310, the validity of the target public code block is verified.

[0132] As shown in Figure 6b , operation S310 includes operation S311 to operation S314.

[0133] In operation S311, the target public code block is replaced with the corresponding public code segment in the test script to generate a target test script.

[0134] In operation S312, the target test script is executed to obtain the execution success rate of the target test script.

[0135] In operation S313, when it is determined that the execution success rate is greater than or equal to the preset threshold, it is determined that the target common code block is valid.

[0136] In operation S314, when it is determined that the execution success rate is less than the preset threshold, it is determined that the target common code block is invalid.

[0137] In one example, the common code block validity verification rule is as follows:

[0138] (1) If 80% of the automated test scripts pass the execution, it proves that the encapsulation is successful, the corresponding common code state in the common code block definition module is set to pass the verification, and the version of the modularized encapsulation of the content corresponding to the automated test script that has passed the execution is updated to the automated test script asset library.

[0139] (2) If 80% of the execution does not pass, the code common segment is re-adjusted, and the code segment that does not pass is put into the failed code feature library. In the subsequent comparison process, when the corresponding code block appears, no secondary encapsulation processing is performed. At the same time, the script is rolled back to the previous version.

[0140] In operation S320, a common code block management list is generated according to the validity verification result.

[0141] In one example, in order to avoid repeated extraction verification and improve the generation efficiency of the common code block, the above verification result is used to generate the common code block management list, which is shown in Table 2. The state of the common code block is recorded, which is used to store the encapsulated common code block, and the corresponding list of the common code block and the automated test script referring to the code block. The common code block definition has two sources: the common module encapsulated by the device automatically and the common module encapsulated by the test personnel manually. The common module encapsulated by the test personnel is mainly used for known parts that are not suitable for encapsulation according to the above model. For these common codes that cannot be encapsulated, the corresponding information can be directly improved in the common code block definition module, so as to avoid repeated screening and waste of resources.

[0142] Table 2 Common Code Block Management List

[0143]

[0144]

[0145] Based on the above test script common code generation method, the disclosure also provides a test script common code generation device. The device will be described in detail below. Figure 7

[0146] Figure 7 ​A structural block diagram of a test script common code generation apparatus according to an embodiment of the present disclosure is shown schematically.

[0147] As shown in Figure 7 The test script common code generation apparatus 500 of this embodiment includes a code denoising module 510, a word frequency analysis module 520, and a target common code block encapsulation module 530.

[0148] The code denoising module 510 is configured to preprocess test script code to generate target test script code information. In an embodiment, the code denoising module 510 can be configured to perform operation S210 described above, and thus repeated details are not provided herein.

[0149] The word frequency analysis module 520 is configured to perform word frequency analysis on the target test script code information using a text keyword extraction algorithm to generate a word frequency analysis result. In an embodiment, the word frequency analysis module 520 can be configured to perform operation S220 described above, and thus repeated details are not provided herein.

[0150] The target common code block encapsulation module 530 is configured to encapsulate the target test script code information according to the word frequency analysis result and a preset encapsulation rule to generate a target common code block. In an embodiment, the target common code block encapsulation module 530 can be configured to perform operation S230 described above, and thus repeated details are not provided herein.

[0151] According to an embodiment of the present disclosure, the code denoising module 510 includes a scanning sub-module, a first determining sub-module, a hash operation sub-module, and a first generating sub-module.

[0152] The scanning sub-module is configured to scan test script code to identify a test page operation object in the test script code. In an embodiment, the scanning sub-module can be configured to perform operation S211 described above, and thus repeated details are not provided herein.

[0153] The first determining sub-module is configured to determine operation action information and processing method information of the test page operation object according to the test page operation object. In an embodiment, the first determining sub-module can be configured to perform operation S212 described above, and thus repeated details are not provided herein.

[0154] The hash operation sub-module is configured to perform hash operation on the test page operation object to generate a hash value. In an embodiment, the hash operation sub-module can be configured to perform operation S213 described above, and thus repeated details are not provided herein.

[0155] The first generation submodule is configured to generate target test script code information according to the test page operation object information, the operation action information, the processing method information, and the hash value. In an embodiment, the first generation submodule can be configured to perform operation S214 described above, and details are not repeated here.

[0156] According to an embodiment of the present disclosure, the word frequency analysis module 520 includes a second generation submodule, a word frequency calculation submodule, and a third generation submodule.

[0157] The second generation submodule is configured to extract the target test script code according to a preset step size in a script execution order to generate first target code. In an embodiment, the second generation submodule can be configured to perform operation S221 described above, and details are not repeated here.

[0158] The word frequency calculation submodule is configured to calculate word frequency information of the first target code. In an embodiment, the word frequency calculation submodule can be configured to perform operation S222 described above, and details are not repeated here.

[0159] The third generation submodule is configured to generate a word frequency analysis result according to the word frequency information. In an embodiment, the third generation submodule can be configured to perform operation S223 described above, and details are not repeated here.

[0160] According to an embodiment of the present disclosure, the target common code block packaging module 530 includes a second determination submodule, a third determination submodule, and a third generation submodule.

[0161] The second determination submodule is configured to determine that code with a word frequency greater than a preset threshold in the target test script code information as common code. In an embodiment, the second determination submodule can be configured to perform operation S231 described above, and details are not repeated here.

[0162] The third determination submodule is configured to determine a target packaging rule according to an operation object type in the common code. In an embodiment, the third determination submodule can be configured to perform operation S232 described above, and details are not repeated here.

[0163] The third generation submodule is configured to package the common code according to the target packaging rule to generate a target common code block. In an embodiment, the third generation submodule can be configured to perform operation S233 described above, and details are not repeated here.

[0164] According to an embodiment of the present disclosure, the third determination submodule includes a first determination unit, a second determination unit, and a third determination unit.

[0165] The first determining unit is configured to determine that the target encapsulation rule is to add a waiting time and a window maximization operation after the browser connection obtaining operation if it is determined that the operation object type is the browser connection obtaining operation. In an embodiment, the first determining unit can be configured to perform operation S2321 described above, and details are not repeated here.

[0166] The second determining unit is configured to determine that the target encapsulation rule is to add a waiting time after the click operation if it is determined that the operation object type is the click operation. In an embodiment, the second determining unit can be configured to perform operation S2322 described above, and details are not repeated here.

[0167] The third determining unit is configured to determine that the target encapsulation rule is to add a click operation on the same element before the input operation if it is determined that the operation object type is the input operation. In an embodiment, the third determining unit can be configured to perform operation S2323 described above, and details are not repeated here.

[0168] According to an embodiment of the present disclosure, the apparatus further includes a verifying module and a generating module.

[0169] The verifying module is configured to verify the validity of the target common code block. In an embodiment, the verifying module can be configured to perform operation S310 described above, and details are not repeated here.

[0170] The generating module is configured to generate a common code block management manifest according to the validity verification result. In an embodiment, the generating module can be configured to perform operation S320 described above, and details are not repeated here.

[0171] According to an embodiment of the present disclosure, the verifying module includes a replacing submodule, an obtaining submodule, a fourth determining submodule, and a fifth determining submodule.

[0172] The replacing submodule is configured to replace the target common code block with a corresponding common code segment in the test script to generate a target test script. In an embodiment, the replacing submodule can be configured to perform operation S311 described above, and details are not repeated here.

[0173] The obtaining submodule is configured to execute the target test script to obtain an execution success rate of the target test script. In an embodiment, the obtaining submodule can be configured to perform operation S312 described above, and details are not repeated here.

[0174] The fourth determining submodule is configured to determine that the target common code block is valid if it is determined that the execution success rate is greater than or equal to a preset threshold. In an embodiment, the fourth determining submodule can be configured to perform operation S313 described above, and details are not repeated here.

[0175] The fifth determining sub-module is configured to determine that the target common code block is invalid when it is determined that the execution success rate is less than the preset threshold. In an embodiment, the fifth determining sub-module can be configured to perform the operation S314 described above, and details are not repeated here.

[0176] According to embodiments of the present disclosure, any of the code denoising module 510, the word frequency analysis module 520 and the target common code block packaging module 530 can be combined in one module, or any of them can be split into multiple modules. Alternatively, at least part of the function of one or more of these modules can be combined with at least part of the function of other modules, and implemented in one module. According to embodiments of the present disclosure, at least one of the code denoising module 510, the word frequency analysis module 520 and the target common code block packaging module 530 can be at least partially implemented as a hardware circuit, such as a field programmable gate array (FPGA), a programmable logic array (PLA), a system on chip, a system on board, a system on package, an application specific integrated circuit (ASIC), or any other reasonable way of integrating or packaging circuits, etc. hardware or firmware, or any one of software, hardware and firmware or any appropriate combination of several of them. Alternatively, at least one of the code denoising module 510, the word frequency analysis module 520 and the target common code block packaging module 530 can be at least partially implemented as a computer program module which can perform corresponding functions when it is run.

[0177] Figure 8 A block diagram of an electronic device suitable for implementing the method for generating test script common code according to embodiments of the present disclosure is schematically shown.

[0178] As Figure 8 shown, the electronic device 900 according to embodiments of the present disclosure includes a processor 901 which can perform various appropriate actions and processes according to programs stored in a read-only memory (ROM) 902 or loaded from a storage portion 908 into a random access memory (RAM) 903. The processor 901 can include, for example, a general-purpose microprocessor (such as a CPU), an instruction set processor and / or a related chipset, and / or a special-purpose microprocessor (such as an application specific integrated circuit (ASIC)), etc. The processor 901 can also include an on-board memory for cache use. The processor 901 can include a single processing unit or multiple processing units for performing different actions of the method processes according to embodiments of the present disclosure.

[0179] In the RAM 903, various programs and data required for the operation of the electronic device 900 are stored. The processor 901, the ROM 902, and the RAM 903 are connected to each other via the bus 904. The processor 901 performs various operations of the method flow according to the embodiments of the present disclosure by executing the programs in the ROM 902 and / or the RAM 903. It should be noted that the programs can also be stored in one or more memories other than the ROM 902 and the RAM 903. The processor 901 can also perform various operations of the method flow according to the embodiments of the present disclosure by executing the programs stored in the one or more memories.

[0180] According to an embodiment of the present disclosure, the electronic device 900 can further include an input / output (I / O) interface 905, which is also connected to the bus 904. The electronic device 900 can further include one or more of the following components connected to the I / O interface 905: an input part 906 including a keyboard, a mouse, etc.; an output part 907 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage part 908 including a hard disk, etc.; and a communication part 909 including a network interface card such as a LAN card, a modem, etc. The communication part 909 performs communication processing via a network such as the Internet. A drive 910 is also connected to the I / O interface 905 as necessary. A removable medium 911 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc. is mounted on the drive 910 as necessary, so that a computer program read therefrom is installed in the storage part 908 as necessary.

[0181] The present disclosure also provides a computer readable storage medium, which can be included in the device / apparatus / system described in the above embodiments; or can exist separately without being assembled into the device / apparatus / system. The above computer readable storage medium carries one or more programs, when the one or more programs are executed, realizing the generation method of the test script common code according to the embodiments of the present disclosure.

[0182] According to an embodiment of the present disclosure, the computer readable storage medium can be a nonvolatile computer readable storage medium, for example, can include, but is not limited to, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a Read Only Memory (ROM), an Erasable Programmable Read Only Memory (EPROM or Flash memory), a portable compact disc read only memory (CD-ROM), an optical storage device, a magnetic storage device, or any appropriate combination thereof. In the present disclosure, the computer readable storage medium can be any tangible medium that contains or stores a program that can be used by or in connection with an instruction execution system, apparatus, or device. For example, according to an embodiment of the present disclosure, the computer readable storage medium can include one or more memories such as the ROM 902 and / or the RAM 903 described above and / or one or more memory other than the ROM 902 and the RAM 903.

[0183] Embodiments of the present disclosure also include a computer program product, which includes a computer program containing program codes for executing the methods shown in the flowcharts. When the computer program product is run in a computer system, the program codes are used to make the computer system implement the method for generating the test script common code provided by the embodiments of the present disclosure.

[0184] The above-described functions defined in the system / apparatus / module / unit of the embodiments of the present disclosure are performed when the computer program is executed by the processor 901. According to an embodiment of the present disclosure, the above-described system, apparatus, module, unit, etc. can be implemented by the computer program modules.

[0185] In one embodiment, the computer program can rely on a tangible storage medium such as an optical storage device, a magnetic storage device, etc. In another embodiment, the computer program can also be transmitted, distributed, and downloaded in the form of a signal via a network medium, and be downloaded and installed through the communication part 909 and / or installed from the detachable medium 911. The program codes contained in the computer program can be transmitted by any appropriate network medium, including but not limited to wireless, wired, etc., or any appropriate combination thereof.

[0186] In such an embodiment, the computer program can be downloaded and installed from the network via the communication part 909 and / or installed from the detachable medium 911. When the computer program is executed by the processor 901, the above-described functions defined in the system of the embodiments of the present disclosure are performed. According to an embodiment of the present disclosure, the above-described system, apparatus, device, module, unit, etc. can be implemented by the computer program modules.

[0187] According to embodiments of the present disclosure, program code of the computer program for performing the methods provided by the embodiments of the present disclosure can be written in any combination of one or more programming languages, and can be implemented in a computer program product. Specifically, the computer program can be implemented in a high-level procedural and / or object-oriented programming language, and / or in assembly / machine language. The programming language includes, but is not limited to, Java, C++, python, “C” language, or similar programming languages. The program code can execute entirely on the user's computing device, partly on the user's device, and partly on a remote computing device, or entirely on the remote computing device or server. In the latter scenario, the remote computing device can be connected to the user's computing device through any kind of network, including a local area network (LAN) or a wide area network (WAN), or the connection can be made to an external computing device, such as through the Internet using an Internet Service Provider (ISP).

[0188] The computer program product of the present disclosure can be a computer program product, which is a machine-readable medium (or computer readable medium) having stored therein a sequence of instructions executable by a machine such as a personal digital assistant (PDA), a laptop, a desktop computer, or a server. Alternatively, the computer program product can be a propagated signal per se generated by using the program code, and the program code can be stored on a machine-readable medium that can be read by a machine such as a personal digital assistant (PDA), a laptop, a desktop computer, or a server. The program code of the computer program product defines a function, preferably a corresponding action, and / or implements the elements / object / means for performing this function or a part thereof as disclosed in the embodiments of the present disclosure. The program code can be executed by using one or more processors.

[0189] Those skilled in the art will appreciate that features of the various embodiments and / or claims of the present disclosure can be combined or / and integrated with one another, even though such combinations or integrations are not expressly disclosed in the present disclosure. In particular, the features of the various embodiments and / or claims of the present disclosure can be combined and / or integrated with one another in any manner, without departing from the spirit and scope of the present disclosure. All such combinations and / or integrations are within the scope of the present disclosure.

[0190] The above describes embodiments of the present disclosure. However, these embodiments are merely for illustrative purposes, and are not intended to limit the scope of the present disclosure. Although each embodiment is described above separately, this does not mean that the measures in each embodiment cannot be used advantageously in combination. The scope of the present disclosure is defined by the appended claims and their equivalents. Those skilled in the art can make various substitutions and modifications without departing from the scope of the present disclosure, and these substitutions and modifications should all fall within the scope of the present disclosure.

Claims

1. A method for generating a test script common code, characterized by, The method includes: In response to the command to generate common test script code, the test script code is preprocessed to generate target test script code information; A text keyword extraction algorithm is used to perform word frequency analysis on the target test script code information to generate word frequency analysis results; and The target test script code information is encapsulated based on the word frequency analysis results and preset encapsulation rules to generate target common code blocks; The preprocessing of the test script code to generate target test script code information includes: The test script code is scanned to identify the test page operation objects in the test script code; Determine the operation action information and processing method information of the test page operation object based on the test page operation object; Perform a hash operation on the object operated on the test page to generate a hash value; and Target test script code information is generated based on the test page operation object information, the operation action information, the processing method information, and the hash value; The process of encapsulating the target test script code information based on the word frequency analysis results and preset encapsulation rules to generate a target common code block includes: Codes in the target test script code information with a word frequency greater than a preset threshold are identified as common code; The target encapsulation rule is determined based on the type of the operation object in the public code; and The common code is encapsulated according to the target encapsulation rules to generate a target common code block.

2. The method of claim 1, wherein, The step of using a text keyword extraction algorithm to perform word frequency analysis on the target test script code information to generate word frequency analysis results includes: The target test script code is extracted according to the preset step size and the script execution order to generate the first target code; Calculate the word frequency information of the first target code; and The word frequency analysis results are generated based on the word frequency information.

3. The method of claim 1, wherein, The step of determining the target encapsulation rule based on the type of the operation object in the public code includes: If the type of the operation object is determined to be a browser connection acquisition operation, then the target encapsulation rule is determined to be to add a wait and window maximization operation after the browser connection acquisition operation. If the operation object type is determined to be a click operation, then the target encapsulation rule is determined to be to add a waiting time after the click operation; and If the type of the operation object is determined to be an input operation, then the target encapsulation rule is determined to be to add a click operation of the same element before the input operation.

4. The method according to any one of claims 1 to 3, characterized in that, After generating the target public code block, the following is also included: The validity of the target public code block is verified; A public code block management list is generated based on the validity verification results.

5. The method of claim 4, wherein, The verification of the validity of the target public code block includes: Replace the corresponding public code segment in the test script with the target public code block to generate the target test script; Execute the target test script to obtain the execution success rate of the target test script; When the execution success rate is determined to be greater than or equal to a preset threshold, the target common code block is determined to be valid; and If the execution success rate is determined to be less than a preset threshold, then the target public code block is determined to be invalid.

6. An apparatus for generating a test script common code, characterized by comprising: The device includes: The code denoising module is configured to preprocess test script code to generate target test script code information. The word frequency analysis module is configured to perform word frequency analysis on the target test script code information using a text keyword extraction algorithm to generate a word frequency analysis result. The target common code block packaging module is configured to package the target test script code information according to the word frequency analysis result and a preset packaging rule to generate a target common code block. The code denoising module is further configured to scan test script code to identify test page operation objects in the test script code, determine operation action information and processing method information of the test page operation objects according to the test page operation objects, perform a hash operation on the test page operation objects to generate a hash value, and generate target test script code information according to the test page operation object information, the operation action information, the processing method information, and the hash value. The target common code block packaging module is further configured to determine that code with a word frequency greater than a preset threshold in the target test script code information is common code, determine a target packaging rule according to an operation object type in the common code, and package the common code according to the target packaging rule to generate a target common code block.

7. An electronic device, comprising: one or more processors; a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors perform the test script common code generation method according to any one of claims 1-5.

8. A computer-readable storage medium having stored thereon executable instructions that, when executed by a processor, cause the processor to perform the test script common code generation method according to any one of claims 1-5.

9. A computer program product comprising a computer program that, when executed by a processor, implements the test script common code generation method according to any one of claims 1-5.

Citation Information

Patent Citations

  • Method and device for extracting public codes in html pages

    CN108491209A

  • Text similarity determination method and device, storage medium and electronic equipment

    CN112528630A