CN115687079A - Test script public code generation method and device - Google Patents

Test script public code generation method and device Download PDF

Info

Publication number
CN115687079A
CN115687079A CN202211009249.XA CN202211009249A CN115687079A CN 115687079 A CN115687079 A CN 115687079A CN 202211009249 A CN202211009249 A CN 202211009249A CN 115687079 A CN115687079 A CN 115687079A
Authority
CN
China
Prior art keywords
target
test script
code
word frequency
generate
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211009249.XA
Other languages
Chinese (zh)
Inventor
侯文龙
杨洋
陈溪
刘孟昕
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Industrial and Commercial Bank of China Ltd ICBC
Original Assignee
Industrial and Commercial Bank of China Ltd ICBC
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Industrial and Commercial Bank of China Ltd ICBC filed Critical Industrial and Commercial Bank of China Ltd ICBC
Priority to CN202211009249.XA priority Critical patent/CN115687079A/en
Publication of CN115687079A publication Critical patent/CN115687079A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The disclosure provides a method for generating a test script public code, relates to the field of software testing, and can be applied to the technical field of finance. The method comprises the following steps: responding to a generation instruction of the test script public code, and preprocessing the test script code to generate target test script code information; performing word frequency analysis on the target test script code information by using a text keyword extraction algorithm to generate a word frequency analysis result; and packaging 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 disclosure also provides a device, equipment, storage medium and program product for generating the test script public code.

Description

Test script public code generation method and device
Technical Field
The present disclosure relates to the field of automated testing technologies, and in particular, to the field of page testing technologies, and in particular, to a method, an apparatus, a device, a storage medium, and a program product for generating a test script common code.
Background
In the financial field, in order to ensure the normal functions of a new online system, in the stage of user acceptance test, verification of a new version function is realized as far as possible from an actual service use scene through end-to-end service test scene design and verification, and a large amount of end-to-end UI (user interface) automated test technologies are introduced to improve the working efficiency.
In the process of performing end-to-end transaction flow test of UI interface, a complete business flow is usually composed of a plurality of different business functions or services. Because of the long transaction flow of financial transaction and the self-character of strong functional coupling, the code processing flow of the automatic test script is also long. Because each time the automatic test script design is oriented to a complete business process, and is not specific to a certain single function or service, meanwhile, in the large-scale acceptance test automation practical process, the compiling task of the automatic test script can be dispersed among different test developers, so that some public transaction parts are used as new contents to be recompiled and written in the business process automatic test script which is responsible for the public transaction parts in the process of compiling scripts by different test developers. In this mode, a large number of repeated code segments exist in the automated test scripts corresponding to the service scenarios with similar functions or the same transaction type, and the writing methods are not completely consistent with the development habits of different test developers.
It is to be noted that the information disclosed in the above background section is only for enhancement of understanding of the background of the present disclosure, and thus may include information that does not constitute prior art known to those of ordinary skill in the art.
Disclosure of Invention
In view of the foregoing, the present disclosure provides a method, apparatus, device, medium, and program product for generating test script common code that improves efficiency of automated test work.
According to a first aspect of the present disclosure, there is provided a method for generating test script common code, the method including:
responding to a generation instruction of the test script public code, and preprocessing the test script code to generate target test script code information;
performing word frequency analysis on the target test script code information by using a text keyword extraction algorithm to generate a word frequency analysis result; and
and packaging the target test script code information according to the word frequency analysis result and a preset packaging rule to generate a target public code block.
According to an embodiment of the present disclosure, the preprocessing the test script code to generate target test script code information includes:
scanning the test script codes to identify test page operation objects in the test script codes;
determining operation action information and processing method information of the test page operation object according to the test page operation object;
carrying out hash operation on the test page operation object to generate a hash value; and
and 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.
According to an embodiment of the present disclosure, the performing a word frequency analysis on the target test script code information using a text keyword extraction algorithm to generate a word frequency analysis result includes:
extracting the target test script codes according to a preset step length and a script execution sequence to generate a first target code;
calculating word frequency information of the first target code; and
and generating a word frequency analysis result according to the word frequency information.
According to the embodiment of the present disclosure, 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:
determining codes with word frequency larger than a preset threshold value in the target test script code information as public codes;
determining a target packaging rule according to the type of the operation object in the public code; and
and packaging the public codes according to the target packaging rule to generate a target public code block.
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:
if the type of the operation object is determined to be browser connection operation, determining the target encapsulation rule to be adding waiting and window maximization operation after the browser connection operation is obtained;
if the type of the operation object is determined to be click operation, determining that the target packaging rule is to increase waiting time after the click operation; and
and if the type of the operation object is determined to be the input operation, determining that the target packaging rule is the click operation of adding the same element before the input operation.
According to the embodiment of the present disclosure, after generating the target common code block, the method further includes:
verifying the validity of the target common code block;
and generating a common code block management list according to the validity verification result.
A second aspect of the present disclosure provides an apparatus for generating a test script common code, the apparatus including:
the code denoising module is used for preprocessing the test script codes to generate target test script code information;
the word frequency analysis module is used for performing word frequency analysis on the target test script code information by using a text keyword extraction algorithm to generate a word frequency analysis result;
and the target common code block packaging module is used for packaging the target test script code information according to the word frequency analysis result and a preset packaging rule so as to generate a target common code block.
According to an embodiment of the present disclosure, a code noise reduction module includes:
the scanning submodule is used for scanning the test script codes so as to identify the test page operation objects in the test script codes;
the first determining submodule is used for determining the operation action information and the processing method information of the test page operation object according to the test page operation object;
the Hash operation sub-module is used for carrying out Hash operation on the test page operation object to generate a Hash value;
and the first generation submodule is used 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.
According to an embodiment of the present disclosure, the word frequency analysis module includes:
the second generation submodule is used for extracting the target test script codes according to a preset step length and a script execution sequence so as to generate a first target code;
the word frequency calculation submodule is used for calculating the word frequency information of the first target code; and
and the third generation submodule is used for generating a word frequency analysis result according to the word frequency information.
According to an embodiment of the present disclosure, a target common code block encapsulation module includes:
the second determining submodule is used for determining that codes with the word frequency larger than a preset threshold value in the target test script code information are public codes;
the third determining submodule is used for determining a target packaging rule according to the type of the operation object in the public code; and
and the third generation submodule is used for packaging the public codes according to the target packaging rule so as to generate a target public code block.
According to an embodiment of the present disclosure, the third determination submodule includes:
the first determining unit is used for determining that the target packaging rule is to add waiting and window maximization operation after browser connection operation is acquired if the type of the operation object is determined to be browser connection operation acquisition;
the second determining unit is used for determining that the target packaging rule is to increase waiting time after clicking operation if the type of the operation object is determined to be clicking operation; and
and the third determining unit is used for determining that the target packaging rule is a click operation of adding the same element before the input operation if the operation object type is determined to be the input operation.
According to an embodiment of the present disclosure, the apparatus further comprises:
the verification module is used for verifying the validity of the target public code block;
and the generating module is used for generating a public code block management list according to the validity verification result.
According to an embodiment of the present disclosure, a verification module includes:
the replacing submodule is used for replacing the target common code block with a corresponding common code segment in the test script so as to generate a target test script;
the acquisition submodule is used for executing the target test script so as to acquire the execution success rate of the target test script;
a fourth determining submodule, 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; and
and the fifth determining submodule is used for determining that the target common code block is invalid when the execution success rate is smaller than a preset threshold value.
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 the one or more programs, when executed by the one or more processors, cause the one or more processors to perform the above-described test script common code generation method.
The fourth aspect of the present disclosure also provides a computer-readable storage medium having stored thereon executable instructions, which when executed by a processor, cause the processor to perform the above-mentioned test script common code generation method.
The fifth aspect of the present disclosure also provides a computer program product comprising a computer program which, when executed by a processor, implements the method for generating the test script common code described above.
According to the method for generating the test script common code, provided by the embodiment of the disclosure, the test script code is preprocessed in response to a generation instruction of the test script common code, and redundant information in the script code is removed to generate target test script code information; performing word frequency analysis on the target test script code information by using a text keyword extraction algorithm to generate a word frequency analysis result; and packaging 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. Compared with the prior art, the method provided by the embodiment of the disclosure intelligently adjusts the code blocks in the original automatic test script into the public module reference mode, simplifies the automatic test script structure, and intelligently forms the public code block assets for the follow-up test developers to write new processes for use, thereby improving the automatic test efficiency.
Drawings
The foregoing and other objects, features and advantages of the disclosure will be apparent from the following description of embodiments of the disclosure, taken in conjunction with the accompanying drawings of which:
FIG. 1 schematically illustrates an application scenario diagram of a method, apparatus, device, medium and program product for generating test script common code according to an embodiment of the present disclosure;
FIG. 2 is a flow chart schematically illustrating a method for generating test script common code according to an embodiment of the present disclosure;
FIG. 3 schematically illustrates a flow chart of a scripting code pre-processing method provided in accordance with an embodiment of the present disclosure;
FIG. 4 schematically illustrates a flow chart of a word frequency analysis of the target test script code information using a text keyword extraction algorithm provided in accordance with an embodiment of the present disclosure;
FIG. 5a is a flow chart schematically illustrating a target common code block generation method provided according to an embodiment of the present disclosure;
fig. 5b schematically shows a flowchart of a method for determining a preset encapsulation rule provided according to an embodiment of the present disclosure;
FIG. 6a is a flow chart schematically illustrating one of the target common code block validation methods provided in accordance with an embodiment of the present disclosure;
FIG. 6b schematically shows a second flowchart of a target common code block validation method provided in accordance with an embodiment of the present disclosure;
FIG. 7 is a block diagram schematically illustrating a device for generating common code of test scripts according to an embodiment of the present disclosure;
FIG. 8 schematically illustrates a block diagram of an electronic device suitable for implementing a method of generating test script common code according to an embodiment of the present disclosure.
Detailed Description
Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. It should be understood that the description is illustrative only and is not intended to limit the scope of the present disclosure. In the following detailed description, for purposes of explanation, numerous specific details are set forth in order to provide a thorough understanding of the embodiments of the disclosure. It may be evident, however, that one or more embodiments may be practiced without these specific details. Moreover, in the following description, descriptions of well-known structures and techniques are omitted so as to not unnecessarily obscure the concepts of the present disclosure.
The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure. The terms "comprises," "comprising," and the like, as used herein, specify the presence of stated features, steps, operations, and/or components, but do not preclude the presence or addition of one or more other features, steps, operations, or components.
All terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art unless otherwise defined. It is noted that the terms used herein should be interpreted as having a meaning that is consistent with the context of this specification and should not be interpreted in an idealized or overly formal sense.
Where a convention analogous to "A, B and at least one of C, etc." is used, in general such a construction is intended in the sense one having skill in the art would understand the convention (e.g., "a system having at least one of A, B and C" would include, but not be limited to, systems that have a alone, B alone, C alone, a and B together, a and C together, B and C together, and/or A, B, C together, etc.).
With the development of the IT technology, more and more enterprises begin to introduce an automated testing technology to perform version function verification on a developed software product, so that the version test verification efficiency is improved in response, and the problems of insufficient test execution coverage, incapability of strictly guaranteeing consistent test verification results due to repeated test clicking steps and the like caused by manual test execution of testers are solved.
In the financial field, the business transaction type is usually a long-flow transaction, and meanwhile, with the introduction of distributed and micro-service architectures, the architecture between application systems becomes more and more complex, the number of interfaces and services becomes more and more huge, and usually dozens or hundreds of services or interfaces need to be called in the process of one transaction, and the result of test verification performed from a single service or interface level cannot accurately reflect whether the function of a complete business transaction scene is normal or not.
In order to guarantee the normal function of a new online system to the maximum extent, and avoid BUG influencing normal business transaction, more and more financial enterprises introduce and expand the resource investment of a user acceptance test stage, and in the user acceptance test stage, the verification of a new version function is realized as far as possible from an actual business use scene through end-to-end business test scene design and verification, and the problem of abnormal scene omission caused by the fact that a single interface or a service test stage does not completely simulate the whole call chain is avoided as much as possible.
In the stage of user acceptance test, the test case is designed from an end-to-end complete business process, and the verification of related functions is carried out through the UI, because the execution process is long, the test time consumption is long, and the requirements of test time efficiency and test coverage efficiency cannot be ensured through the traditional manual test mode, more and more financial enterprises also introduce a large number of end-to-end UI automatic test technologies to improve the working efficiency in the stage of acceptance test, and the requirement of fast function update iteration requirement of the current enterprise version is met.
In the process of performing end-to-end transaction flow test of UI interface, a complete business flow is usually composed of a plurality of different business functions or services. Because of the long transaction flow of financial transaction and the self-character of strong functional coupling, the code processing flow of the automatic test script is also long. Because each time the automatic test script design is oriented to a complete business process, and is not specific to a certain single function or service, meanwhile, in the large-scale acceptance test automation practical process, the compiling task of the automatic test script can be dispersed among different test developers, so that some public transaction parts are used as new contents to be recompiled and written in the business process automatic test script which is responsible for the public transaction parts in the process of compiling scripts by different test developers.
In this mode, a large number of repeated code segments exist in the automated test scripts corresponding to the service scenarios with similar functions or the same transaction type, and the writing methods are not completely consistent with the development habits of different test developers.
The UI end-to-end automatic test performed in a business scenario is different from the automatic test performed in a functional level, and is limited by resource and time limitations, and all functions cannot be automatically tested and packaged in a test period, so that the above problems exist for a long time.
Based on the above technical problem, an embodiment of the present disclosure provides a method for generating a test script public code, where the method includes: responding to a generation instruction of the test script public code, and preprocessing the test script code to generate target test script code information; performing word frequency analysis on the target test script code information by using a text keyword extraction algorithm to generate a word frequency analysis result; and packaging 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.
Fig. 1 schematically illustrates an application scenario diagram of a test script common code generation method, apparatus, device, medium, and program product according to an embodiment of the present disclosure.
As shown in FIG. 1, an application scenario 100 according to this embodiment may include a page test script automation test scenario. The network 104 serves as a medium for providing communication links between the terminal devices 101, 102, 103 and the server 105. Network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
The user may use the terminal devices 101, 102, 103 to interact with the server 105 via the network 104 to receive or send messages or the like. The terminal devices 101, 102, 103 may have installed thereon various communication client applications, such as shopping-like applications, web browser applications, search-like applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only).
The terminal devices 101, 102, 103 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 105 may be a page test script management server, which preprocesses the stock quantity test script codes, extracts the common code part through word frequency analysis, and packages the common code part according to a preset packaging rule to generate a common code block, for a generation instruction of the test script common code initiated by a user through an application server, for example, in response to a generation instruction of the test script common code sent by the user by using the terminal devices 101, 102, 103.
It should be noted that the method for generating the test script common code provided by the embodiment of the present disclosure may be generally executed by the server 105. Accordingly, the generating device of the test script common code provided by the embodiment of the present disclosure may be generally disposed in the server 105. The method for generating the test script common code provided by the embodiment of the present disclosure may also be executed by a server or a server cluster which is different from the server 105 and can communicate with the terminal devices 101, 102, 103 and/or the server 105. Accordingly, the generating device of the test script common code provided by the embodiment of the present disclosure may 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.
It should be understood that the number of terminal devices, networks, and servers in fig. 1 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
It should be noted that the method and the apparatus for generating a common code of a test script determined in the embodiments of the present disclosure may be used in the field of an automated testing technology, may also be used in the field of a financial technology, and may also be used in any field other than the financial field.
The following describes in detail a method for generating test script common code according to an embodiment of the present disclosure with reference to fig. 2 to 6b based on the scenario described in fig. 1.
Fig. 2 schematically shows a flowchart of a method for generating test script common code according to an embodiment of the present disclosure. As shown in fig. 2, the method for generating common codes of test scripts according to this embodiment includes operations S210 to S230, which may be executed by an automatic test script code module intelligent packaging apparatus, and the method finds out similar code blocks through intelligent comparison and analysis by scanning an inventory automatic test script, and performs automatic packaging, and at the same time, submits and executes the packaged automatic test script, and analyzes an execution result, and when the execution fails, readjusts the code blocks, and submits and executes the code blocks after being packaged again, and finally, uses the code blocks after passing execution as common modules, synchronously adjusts all the automatic scripts corresponding to the similar code blocks, and intelligently adjusts the code blocks in the original automatic test script to be in a common module reference manner, thereby simplifying an automatic test script structure, and intelligently forming common code block assets for a subsequent test developer to write new processes.
In operation S210, the test script code is preprocessed in response to a generation instruction of the test script common code to generate target test script code information.
In an example, in the process of the UI end-to-end automation test, a large number of automation test script assets exist, and these script codes are written by different test developers, so that there are many redundant parts, in order to facilitate extracting a common code from a test script code, after receiving a generation instruction of the test script common code, noise reduction processing is performed on the test script code of the inventory, and redundant information in the script code is removed, where the redundant information may be, for example, annotation information in the script, a log print output statement, or a statement of other non-object operation related actions, and target test script code information is obtained, and a specific preprocessing process may refer to operation S211 to operation S214 shown in fig. 3, which is not described herein again.
In operation S220, word frequency analysis is performed on the target test script code information using a text keyword extraction algorithm to generate a word frequency analysis result.
In one example, a text keyword extraction algorithm is used to count the occurrence frequency of codes in a preset step length in target test script code information, that is, word frequency information, to generate a word frequency analysis result, codes with higher word frequency indicate that the possibility that the code can be packaged as a public code is higher, the process of word frequency analysis is also a process of determining the public code, and the specific process of generating the word frequency analysis result may refer to operations S221 to S223 shown in fig. 4.
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 common code block.
In one example, after the word frequency analysis result is obtained, the common codes in the target test script code information are encapsulated according to the analysis result to generate the target common code block, and in order to improve the execution success rate of the target common code block, before encapsulation, the common codes need to be processed according to a certain preset encapsulation rule, and a specific processing procedure may refer to operations S231 to S233 shown in fig. 5. After the target common code block is generated, the fragments corresponding to the common codes in the original automation script are deleted, the new packaged common codes are called instead, and meanwhile, the change history of the automation script is reserved, so that the script is convenient to rollback.
According to the method for generating the common codes of the test script, the common code blocks are generated according to the codes in the original test script, the code blocks in the original automatic test script are adjusted to be in a common module reference mode, the automatic test script structure is simplified, common code block assets are formed intelligently and used for a follow-up test developer to write a new process, and the automatic test efficiency is improved.
Fig. 3 schematically shows a flowchart of a script code preprocessing method provided according to an embodiment of the present disclosure, and as shown in fig. 3, operation S210 includes operations S211 to S214.
In operation S211, the test script code is scanned to identify a test page operation object in the test script code.
In operation S212, operation action information and processing method information of the test page operation object are determined according to the test page operation object.
In operation S213, a hash operation is performed on the test page operand to generate a hash value.
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.
In one example, a test page operation object in the test script code is scanned, the test page operation object includes a control element in a page, for example, 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, where the processing method information includes a judgment loop statement, for example, an ifelse if condition judgment statement. In order to facilitate the later term frequency analysis statistics, hash operation needs to be performed on the test page operation objects to obtain hash values, 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 values, as shown in table 1 below.
TABLE 1 target test script code information Table
Figure BDA0003808318730000121
Fig. 4 schematically shows a flowchart of performing a word frequency analysis on the target test script code information using a text keyword extraction algorithm according to an embodiment of the present disclosure, and as shown in fig. 4, operation S220 includes operations S221 to S223.
In operation S221, the target test script code is extracted according to a script execution sequence according to a preset step size to generate a first target code.
In operation S222, word frequency information of the first object code is calculated.
In operation S223, a word frequency analysis result is generated according to the word frequency information.
In one example, similarity analysis is performed on a preprocessed automatic test script, a text keyword extraction algorithm is used for extracting and packaging a common code block, the packaged code block is submitted to a common code definition module for storage processing, the state is to be verified, and the corresponding relation is recorded. The text keyword extraction algorithm is used for processing the noise-reduced codes and extracting script contents in a forward + word frequency + step length mode. The forward direction means that extraction must be performed according to the execution sequence of the script, the preset step size may be 6 lines, for example, 6 lines of codes are extracted according to the execution sequence of the script as a first object code, the frequency of the first object code appearing in the script is calculated to obtain word frequency information, the word frequency information is analyzed, and the codes with the word frequency reaching a certain condition can be packaged as public codes.
Fig. 5a schematically shows a flowchart of a target common code block generation method provided according to an embodiment of the present disclosure, and fig. 5b schematically shows a flowchart of a determination method of a preset encapsulation rule provided according to an embodiment of the present disclosure. As shown in fig. 5a, operation S230 includes operations S231 to S233.
In operation S231, a code having a word frequency greater than a preset threshold value in the target test script code information is determined to be a common code.
In operation S232, a target encapsulation rule is determined according to the operation object type in the common code.
In operation S233, the common code is encapsulated according to the target encapsulation rule to generate a target common code block.
As shown in fig. 5b, operation S232 includes operations S2321 to S2323.
In operation S2321, if it is determined that the operation object type is an operation of acquiring a browser connection, it is determined that the target encapsulation rule is an operation of adding a wait and maximizing a window after the browser connection operation is acquired.
In operation S2322, if it is determined that the operation object type is a click operation, it is determined that the target encapsulation rule is to increase the waiting time after the click operation.
In operation S2323, if it is determined that the operation object type is an input operation, it is determined that the target encapsulation rule is a click operation in which the same element is added before the input operation.
In an example, when the word frequency of a first target code corresponding to any one operation object reaches a preset threshold of the total number of the current scripts, for example, 5% of the total number of the scripts, the first target code is encapsulated, and in order to improve the success rate of executing the encapsulated public code and ensure the smooth execution of the test script, a preset encapsulation rule is used for encapsulation. The specific rules are as follows:
(1) The method includes adding a wait and window maximization operation (driver. Name ()) after acquiring a browser connection operation (driver. Get). Simulating page opening operation, increasing waiting time to wait for page loading, and increasing window maximization operation after page loading.
(2) The waiting time is increased after the click operation (click). In order to shield the influence of network difference on page test, the waiting time is increased after the click operation is carried out, and the server response is waited.
(3) Click operation of the same element is added before input operation (sendKeys). In order to ensure that information can be successfully input in the input box, click operation of the same element is added before input operation, and the current input box is ensured to be in an activated state.
(4) And adding screenshot operation after the if condition judgment is finished.
And determining corresponding packaging rules according to different operation object types to package and generate the target public block. And after the target common code block is generated, verifying the validity of the common code block.
Fig. 6a schematically shows one of the flowcharts of the target common code block verification method provided according to the embodiment of the present disclosure. Fig. 6b schematically illustrates a second flowchart of the target common code block verification method provided in accordance with an embodiment of the present disclosure, as shown in fig. 6a, including operation S310 and operation S320.
In operation S310, the validity of the target common code block is verified.
As shown in fig. 6b, operation S310 includes operations S311 to S314.
In operation S311, the target common code block is substituted for a corresponding common code segment in the test script to generate a target test script.
In operation S312, the target test script is executed to obtain an execution success rate of the target test script.
In operation S313, when it is determined that the execution success rate is greater than or equal to a preset threshold, it is determined that the target common code block is valid.
In operation S314, when it is determined that the execution success rate is less than a preset threshold, it is determined that the target common code block is invalid.
In one example, the common code block validity validation rules are as follows:
(1) If 80% of the automated test scripts pass the execution, the encapsulation is proved to be successful, the corresponding public code state in the public code block definition module is set to be verified to pass, and the version of the automated test script asset library after modularized encapsulation of the corresponding content of the executed automated test scripts passes is updated.
(2) If 80% of execution fails, readjusting the code public segment, putting the code public segment which fails into the code feature library, and when a corresponding code block appears in the subsequent comparison process, not performing secondary packaging treatment. While backing the script back to the last version.
In operation S320, a common code block management manifest is generated according to the validity verification result.
In an example, in order to avoid repeated extraction verification and improve the generation efficiency of the common code blocks, the verification result is used to generate a common code block management list, which is detailed in table 2. Recording the state of the common code block, storing the packaged common code block, the common code block and the corresponding list contrast relation of the automatic test script quoted to the common code block, wherein the common code block is defined with two sources: the device can automatically and intelligently package the public modules and manually package the public modules by testers. The common module manually packaged by the tester is mainly used for known parts which are not suitable for being packaged according to the model, and for the common codes which cannot be packaged, the corresponding information can be directly perfected into the common code block definition module, so that the resource waste caused by repeated screening is avoided.
Table 2 common code block management manifest
Figure BDA0003808318730000151
Figure BDA0003808318730000161
Based on the method for generating the test script public code, the disclosure also provides a device for generating the test script public code. The apparatus will be described in detail below with reference to fig. 7.
Fig. 7 schematically shows a block diagram of a device for generating common code of test scripts according to an embodiment of the present disclosure.
As shown in fig. 7, the apparatus 500 for generating test script common code of this embodiment includes a code noise reduction module 510, a word frequency analysis module 520, and a target common code block encapsulation module 530.
The code de-noising module 510 is used to pre-process the test script code to generate target test script code information. In an embodiment, the code denoising module 510 may be configured to perform the operation S210 described above, which is not described herein again.
The word frequency analysis module 520 is configured to perform word frequency analysis on the target test script code information by using a text keyword extraction algorithm to generate a word frequency analysis result. In an embodiment, the word frequency analysis module 520 may be configured to perform the operation S220 described above, which is not described herein again.
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 may be configured to perform the operation S230 described above, which is not described herein again.
According to an embodiment of the present disclosure, the code noise reduction module 510 includes a scanning sub-module, a first determining sub-module, a hash operation sub-module, and a first generating sub-module.
And the scanning submodule is used for scanning the test script codes so as to identify the test page operation objects in the test script codes. In an embodiment, the scan submodule may be configured to perform the operation S211 described above, which is not described herein again.
And the first determining submodule is used for determining the operation action information and the processing method information of the test page operation object according to the test page operation object. In an embodiment, the first determining submodule may be configured to perform operation S212 described above, and is not described herein again.
The hash operation submodule is used for carrying out hash operation on the test page operation object so as to generate a hash value. In an embodiment, the hash operation sub-module may be configured to perform the operation S213 described above, which is not described herein again.
And the first generation submodule is used 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. In an embodiment, the first generating submodule may be configured to perform the operation S214 described above, and is not described herein again.
According to an embodiment of the present disclosure, the word frequency analysis module 520 includes: the word frequency calculation sub-module comprises a second generation sub-module, a word frequency calculation sub-module and a third generation sub-module.
And the second generation submodule is used for extracting the target test script codes according to a preset step length and a script execution sequence so as to generate the first target code. In an embodiment, the second generation submodule may be configured to perform operation S221 described above, and is not described herein again.
And the word frequency calculation submodule is used for calculating the word frequency information of the first target code. In an embodiment, the word frequency calculating sub-module may be configured to perform the operation S222 described above, which is not described herein again.
And the third generation submodule is used for generating a word frequency analysis result according to the word frequency information. In an embodiment, the third generating submodule may be configured to perform operation S223 described above, and is not described herein again.
According to an embodiment of the present disclosure, the target common code block encapsulation module 530 includes a second determination submodule, a third determination submodule, and a third generation submodule.
And the second determining submodule is used for determining that the code with the word frequency larger than the preset threshold value in the target test script code information is a public code. In an embodiment, the second determining submodule may be configured to perform the operation S231 described above, and is not described herein again.
And the third determining submodule is used for determining a target packaging rule according to the type of the operation object in the public code. In an embodiment, the third determining submodule may be configured to perform operation S232 described above, and is not described herein again.
And the third generation submodule is used for packaging the public codes according to the target packaging rule so as to generate a target public code block. In an embodiment, the third generating unit may be configured to perform operation S233 described above, which is not described herein again.
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.
The first determining unit is used for determining that the target packaging rule is to add waiting and window maximization operation after browser connection operation is acquired if the operation object type is determined to be browser connection operation acquisition. In an embodiment, the first determining unit may be configured to perform operation S2321 described above, which is not described herein again.
The second determining unit is configured to determine that the target encapsulation rule is to increase waiting time after the click operation if the operation object type is determined to be the click operation. In an embodiment, the second determining unit may be configured to perform operation S2322 described above, which is not described herein again.
The third determining unit is configured to determine that the target encapsulation rule is a click operation that adds 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 may be configured to perform operation S2323 described above, which is not described herein again.
According to an embodiment of the present disclosure, the apparatus further comprises: the device comprises a verification module and a generation module.
And the verification module is used for verifying the validity of the target common code block. In an embodiment, the verification module may be configured to perform the operation S310 described above, which is not described herein again.
And the generating module is used for generating a public code block management list according to the validity verification result. In an embodiment, the generating module may be configured to perform operation S320 described above, which is not described herein again.
According to an embodiment of the present disclosure, a verification module includes: the device comprises a replacement sub-module, an acquisition sub-module, a fourth determination sub-module and a fifth determination sub-module.
And the replacing submodule is used for replacing the target common code block with the corresponding common code segment in the test script so as to generate the target test script. In an embodiment, the replacing sub-module may be configured to perform the operation S311 described above, and is not described herein again.
The obtaining submodule is used for executing the target test script so as to obtain the execution success rate of the target test script. In an embodiment, the obtaining submodule may be configured to perform operation S312 described above, and is not described herein again.
And the fourth determining submodule is used for determining that the target common code block is valid when the execution success rate is determined to be greater than or equal to a preset threshold value. In an embodiment, the fourth determining submodule may be configured to perform the operation S313 described above, and details are not described herein again.
And the fifth determining submodule is used for determining that the target common code block is invalid when the execution success rate is smaller than a preset threshold value. In an embodiment, the fifth determining submodule may be configured to perform operation S314 described above, and is not described herein again.
According to an embodiment of the present disclosure, any plurality of the code noise reduction module 510, the word frequency analysis module 520, and the target common code block encapsulation module 530 may be combined in one module to be implemented, or any one of them may be split into a plurality of modules. Alternatively, at least part of the functionality of one or more of these modules may be combined with at least part of the functionality of the other modules and implemented in one module. According to an embodiment of the present disclosure, at least one of the code noise reduction module 510, the word frequency analysis module 520, and the target common code block encapsulation module 530 may be implemented at least partially as a hardware circuit, such as a Field Programmable Gate Array (FPGA), a Programmable Logic Array (PLA), a system on a chip, a system on a substrate, a system on a package, an Application Specific Integrated Circuit (ASIC), or may be implemented in hardware or firmware in any other reasonable manner of integrating or encapsulating circuits, or in any one of three implementations of software, hardware, and firmware, or in any suitable combination of any of them. Alternatively, at least one of the code denoising module 510, the word frequency analysis module 520, and the target common code block encapsulating module 530 may be at least partially implemented as a computer program module that, when executed, may perform a corresponding function.
FIG. 8 schematically illustrates a block diagram of an electronic device suitable for implementing a method of generating test script common code according to an embodiment of the present disclosure.
As shown in fig. 8, an electronic apparatus 900 according to an embodiment of the present disclosure includes a processor 901 which can perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM) 902 or a program loaded from a storage portion 908 into a Random Access Memory (RAM) 903. Processor 901 may comprise, for example, a general purpose microprocessor (e.g., a CPU), an instruction set processor and/or associated chipset, and/or a special purpose microprocessor (e.g., an Application Specific Integrated Circuit (ASIC)), among others. The processor 901 may also include on-board memory for caching purposes. The processor 901 may comprise a single processing unit or a plurality of processing units for performing the different actions of the method flows according to embodiments of the present disclosure.
In the RAM 903, various programs and data necessary for the operation of the electronic apparatus 900 are stored. The processor 901, the ROM 902, and the RAM 903 are connected to each other through a bus 904. The processor 901 performs various operations of the method flows according to the embodiments of the present disclosure by executing programs in the ROM 902 and/or the RAM 903. Note that the programs may also be stored in one or more memories other than the ROM 902 and the RAM 903. The processor 901 may also perform various operations of the method flows according to the embodiments of the present disclosure by executing programs stored in the one or more memories.
Electronic device 900 may also include input/output (I/O) interface 905, input/output (I/O) interface 905 also connected to bus 904, according to an embodiment of the present disclosure. The electronic device 900 may also include one or more of the following components connected to the I/O interface 905: an input portion 906 including a keyboard, a mouse, and the like; an output portion 907 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 908 including a hard disk and the like; and a communication section 909 including a network interface card such as a LAN card, a modem, or the like. The communication section 909 performs communication processing via a network such as the internet. The 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, or the like is mounted on the drive 910 as necessary, so that a computer program read out therefrom is mounted into the storage section 908 as necessary.
The present disclosure also provides a computer-readable storage medium, which may be contained in the apparatus/device/system described in the above embodiments; or may exist separately and not be assembled into the device/apparatus/system. The computer-readable storage medium carries one or more programs which, when executed, implement a method for generating test script common code according to an embodiment of the present disclosure.
According to embodiments of the present disclosure, the computer-readable storage medium may be a non-volatile computer-readable storage medium, which may include, for example 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 suitable combination of the foregoing. In the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. For example, according to embodiments of the present disclosure, a computer-readable storage medium may include the ROM 902 and/or the RAM 903 described above and/or one or more memories other than the ROM 902 and the RAM 903.
Embodiments of the present disclosure also include a computer program product comprising a computer program containing program code for performing the method illustrated in the flow chart. When the computer program product runs in a computer system, the program code is used for causing the computer system to realize the method for generating the test script common code provided by the embodiment of the disclosure.
The computer program performs the above-described functions defined in the system/apparatus of the embodiments of the present disclosure when executed by the processor 901. The systems, apparatuses, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the present disclosure.
In one embodiment, the computer program may be hosted on a tangible storage medium such as an optical storage device, a magnetic storage device, or the like. In another embodiment, the computer program may also be transmitted, distributed in the form of a signal on a network medium, and downloaded and installed through the communication section 909 and/or installed from the removable medium 911. The computer program containing program code may be transmitted using any suitable network medium, including but not limited to: wireless, wired, etc., or any suitable combination of the foregoing.
In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 909, and/or installed from the removable medium 911. The computer program, when executed by the processor 901, performs the above-described functions defined in the system of the embodiment of the present disclosure. The systems, devices, apparatuses, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the present disclosure.
In accordance with embodiments of the present disclosure, program code for executing computer programs provided by embodiments of the present disclosure may be written in any combination of one or more programming languages, and in particular, these computer programs may be implemented using high level procedural and/or object oriented programming languages, and/or assembly/machine languages. The programming language includes, but is not limited to, programming languages such as Java, C + +, python, the "C" language, or the like. The program code may execute entirely on the user computing device, partly on the user device, partly on a remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computing device (e.g., through the internet using an internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
Those skilled in the art will appreciate that various combinations and/or combinations of features recited in the various embodiments and/or claims of the present disclosure can be made, even if such combinations or combinations are not expressly recited in the present disclosure. In particular, various combinations and/or combinations of the features recited in the various embodiments and/or claims of the present disclosure may be made without departing from the spirit or teaching of the present disclosure. All such combinations and/or associations are within the scope of the present disclosure.
The embodiments of the present disclosure have been described above. However, these examples are for illustrative purposes only and are not intended to limit the scope of the present disclosure. Although the embodiments are described separately above, this does not mean that the measures in the embodiments cannot be used in advantageous combination. The scope of the disclosure is defined by the appended claims and equivalents thereof. Various alternatives and modifications can be devised by those skilled in the art without departing from the scope of the present disclosure, and such alternatives and modifications are intended to be within the scope of the present disclosure.

Claims (11)

1. A method for generating test script public code, the method comprising:
responding to a generation instruction of the test script public code, and preprocessing the test script code to generate target test script code information;
performing word frequency analysis on the target test script code information by using a text keyword extraction algorithm to generate a word frequency analysis result; and
and packaging 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.
2. The method of claim 1, wherein preprocessing the test script code to generate target test script code information comprises:
scanning the test script codes to identify test page operation objects in the test script codes;
determining operation action information and processing method information of the test page operation object according to the test page operation object;
carrying out hash operation on the test page operation object to generate a hash value; and
and 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.
3. The method of claim 1, wherein said performing a word frequency analysis on said target test script code information using a text keyword extraction algorithm to generate a word frequency analysis result comprises:
extracting the target test script codes according to a preset step length and a script execution sequence to generate a first target code;
calculating word frequency information of the first target code; and
and generating a word frequency analysis result according to the word frequency information.
4. The method of claim 1, wherein 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 comprises:
determining codes with word frequency larger than a preset threshold value in the target test script code information as public codes;
determining a target packaging rule according to the type of the operation object in the public code; and
and packaging the public codes according to the target packaging rule to generate a target public code block.
5. The method of claim 4, wherein determining the target encapsulation rule based on the operand type in the common code comprises:
if the type of the operation object is determined to be browser connection operation, determining the target encapsulation rule to be adding waiting and window maximization operation after the browser connection operation is obtained;
if the type of the operation object is determined to be click operation, determining that the target packaging rule is to increase waiting time after the click operation; and
and if the operation object type is determined to be the input operation, determining that the target packaging rule is the click operation of adding the same element before the input operation.
6. The method of any of claims 1 to 5, further comprising, after generating a target common code block:
verifying the validity of the target common code block;
and generating a common code block management list according to the validity verification result.
7. The method of claim 6, wherein the verifying the validity of the target common code block comprises:
replacing the target common code block with a corresponding common code segment in the test script to generate a target test script;
executing 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 value, determining that the target common code block is valid; and
and when the execution success rate is smaller than a preset threshold value, determining that the target common code block is invalid.
8. An apparatus for generating test script common code, the apparatus comprising:
the code denoising module is used for preprocessing the test script codes to generate target test script code information;
the word frequency analysis module is used for performing word frequency analysis on the target test script code information by using a text keyword extraction algorithm to generate a word frequency analysis result;
and the target common code block packaging module is used for packaging the target test script code information according to the word frequency analysis result and a preset packaging rule so as to generate a target common code block.
9. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
wherein the one or more programs, when executed by the one or more processors, cause the one or more processors to perform the method of error correction of a page test script according to any of claims 1-7.
10. A computer readable storage medium having stored thereon executable instructions which, when executed by a processor, cause the processor to perform a method of error correction of a page test script according to any one of claims 1 to 7.
11. A computer program product comprising a computer program which, when executed by a processor, implements a method of error correction of a page test script according to any one of claims 1 to 7.
CN202211009249.XA 2022-08-22 2022-08-22 Test script public code generation method and device Pending CN115687079A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211009249.XA CN115687079A (en) 2022-08-22 2022-08-22 Test script public code generation method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211009249.XA CN115687079A (en) 2022-08-22 2022-08-22 Test script public code generation method and device

Publications (1)

Publication Number Publication Date
CN115687079A true CN115687079A (en) 2023-02-03

Family

ID=85060749

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211009249.XA Pending CN115687079A (en) 2022-08-22 2022-08-22 Test script public code generation method and device

Country Status (1)

Country Link
CN (1) CN115687079A (en)

Similar Documents

Publication Publication Date Title
US10642721B2 (en) Generation of automated testing scripts by converting manual test cases
CA3018196C (en) Visual regresssion testing tool
CN109815147B (en) Test case generation method, device, server and medium
US20150089296A1 (en) Derivation of generalized test cases
CN113535577B (en) Application testing method and device based on knowledge graph, electronic equipment and medium
US11615016B2 (en) System and method for executing a test case
CN111367799B (en) Method, device, medium and electronic equipment for locating source code breakdown position
CN116112746B (en) Online education live video compression method and system
CN115080433A (en) Testing method and device based on flow playback
CN116166547A (en) Code change range analysis method, device, equipment and storage medium
US20230297496A1 (en) System and method for serverless application testing
US11734299B2 (en) Message templatization for log analytics
CN115687079A (en) Test script public code generation method and device
CN114791885A (en) Interface test method, device, equipment and medium
CN114741294A (en) Page debugging method, device, equipment and storage medium
US20210312223A1 (en) Automated determination of textual overlap between classes for machine learning
US11030087B2 (en) Systems and methods for automated invocation of accessibility validations in accessibility scripts
CN111949510B (en) Test processing method, device, electronic equipment and readable storage medium
CN112596781A (en) Service execution and service configuration method and device
CN113157572A (en) Test case generation method and system, electronic equipment and storage medium
CN113032256A (en) Automatic test method, device, computer system and readable storage medium
CN113448578A (en) Page data processing method, processing system, electronic device and readable storage medium
CN113360365A (en) Flow testing method and flow testing system
CN117130903A (en) Packaging method and device for test script code
CN117170659A (en) Packaging method and device for test script code

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination