CN117130903A - Packaging method and device for test script code - Google Patents

Packaging method and device for test script code Download PDF

Info

Publication number
CN117130903A
CN117130903A CN202310388997.1A CN202310388997A CN117130903A CN 117130903 A CN117130903 A CN 117130903A CN 202310388997 A CN202310388997 A CN 202310388997A CN 117130903 A CN117130903 A CN 117130903A
Authority
CN
China
Prior art keywords
code
test script
target
invalid
test
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
CN202310388997.1A
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 CN202310388997.1A priority Critical patent/CN117130903A/en
Publication of CN117130903A publication Critical patent/CN117130903A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F18/00Pattern recognition
    • G06F18/20Analysing
    • G06F18/22Matching criteria, e.g. proximity measures
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/34Graphical or visual programming
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Data Mining & Analysis (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Bioinformatics & Cheminformatics (AREA)
  • Bioinformatics & Computational Biology (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Evolutionary Biology (AREA)
  • Evolutionary Computation (AREA)
  • Artificial Intelligence (AREA)
  • Stored Programmes (AREA)

Abstract

The disclosure provides a packaging method of test script codes, 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 the packaging instruction of the test script code, and carrying out first similarity analysis on the test script source code to determine an initial public code section; performing invalid code analysis on the test script based on the initial common code segment to determine an invalid code; performing second similarity analysis on the test script codes after the invalid code segments are removed to determine target public code segments; and encapsulating the target public code segment according to a preset encapsulation rule to generate a target public code block. The present disclosure also provides a packaging apparatus, device, storage medium and program product of test script code.

Description

Packaging method and device for test script code
Technical Field
The present disclosure relates to the field of automated testing technologies, and in particular, to the field of page testing technologies, and more particularly, to a method, apparatus, device, storage medium, and program product for packaging test script codes.
Background
In the process of automatic test script writing at the UI end, in order to improve working efficiency, testers usually adopt some automatic test tools with script recording functions to carry out automatic script writing, when the testers begin to write scripts, the automatic test tools record that the testers finish operation in a browser, the test tools automatically form corresponding automatic test scripts, and compared with a manual line-by-line writing mode, the automatic test script writing efficiency can be greatly improved by using the mode.
Because the user can not avoid clicking or repeating clicking actions in the testing process, the operations are ineffective operations for the whole service function, but because the automatic testing tool automatically forms the corresponding automatic testing script in a recording mode, corresponding script sentences in the automatic testing script can also appear, and each automatic execution needs to be executed, thereby wasting precious execution time and execution resources.
It should be noted that the information disclosed in the above background section is only for enhancing 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 packaging test script code that improves the efficiency of automated testing efforts.
According to a first aspect of the present disclosure, there is provided a method for generating test script common code, the method comprising:
responding to the packaging instruction of the test script code, and carrying out first similarity analysis on the test script source code to determine an initial public code section;
Performing invalid code analysis on the test script based on the initial common code segment to determine an invalid code;
performing second similarity analysis on the test script codes after the invalid code segments are removed to determine target public code segments; and
and encapsulating the target public code segment according to a preset encapsulation rule to generate a target public code block.
According to an embodiment of the present disclosure, the performing an invalid code analysis on the test script based on the initial common code segment to determine an invalid code includes:
performing similarity analysis on the test scripts according to the execution sequence of the initial public code segments to generate a test script group; and
and carrying out invalid code rule analysis on the test scripts in the test script group to determine invalid code segments.
According to an embodiment of the present disclosure, the performing similarity analysis on the test scripts according to the execution sequence of the initial common code segment to generate a test script group includes:
acquiring the number and execution sequence of initial public code segments in a test script; and
and classifying the test scripts with the same number of initial common code segments larger than a first preset threshold and the same execution sequence of the initial common code segments into the same test script group.
According to an embodiment of the present disclosure, the performing an invalid code rule analysis on the test scripts in the test script set to determine an invalid code segment includes:
acquiring code segments between adjacent public code segments in a test script group; and
and determining an invalid code segment corresponding to an invalid operation in the code segments, wherein the invalid operation comprises repeated clicking operation, repeated input operation and invalid dragging operation.
According to an embodiment of the present disclosure, the encapsulating the target common code segment according to a preset encapsulation rule to generate a target common code block includes:
determining a target encapsulation rule according to the type of the operation object in the target public code section; and
and encapsulating the target public code segment according to the target encapsulation rule to generate a target public code block.
According to an embodiment of the disclosure, the determining a target encapsulation rule according to an operation object type in the common code includes:
if the operation object type is determined to be the browser connection operation, determining the target encapsulation rule to be the operation of adding waiting and window maximization after the browser connection operation is acquired;
if the operation object type is determined to be the click operation, determining the target encapsulation rule to be to increase the waiting time after the click operation; and
And if the operation object type is determined to be the input operation, determining the target encapsulation rule to be a click operation added with the same element before the input operation.
According to an embodiment of the present disclosure, after generating the target common code block, further includes:
verifying the validity of the target public code block; and
and generating a public code block management list according to the validity verification result.
According to an embodiment of the disclosure, the verifying the validity of the target common code block includes:
replacing the corresponding public code segments in the test script with the target public code blocks 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 greater than or equal to a preset threshold, determining that the target public code block is valid; and
and when the execution success rate is determined to be smaller than a preset threshold value, determining that the target public code block is invalid.
According to an embodiment of the present disclosure, the performing a first similarity analysis on the test script source code to determine an initial common code segment includes:
preprocessing the test script source 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 determining codes with word frequency larger than a preset threshold value in the target test script code information as initial public code segments.
According to an embodiment of the present disclosure, the preprocessing the test script source code to generate target test script code information includes:
scanning a test script source code to identify a test page operation object in the test script source code;
determining operation action information and processing method information of the test page operation object according to the test page operation object;
performing 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 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 script execution sequence according to a preset step length to generate first target codes;
Calculating word frequency information of the first target code; and
and generating a word frequency analysis result according to the word frequency information.
A second aspect of the present disclosure provides a packaging apparatus for testing script code, the apparatus comprising:
the initial public code segment determining module is used for responding to the packaging instruction of the test script code and carrying out first similarity analysis on the test script source code so as to determine an initial public code segment;
an invalid code determining module for performing an invalid code analysis on the test script based on the initial common code segment to determine an invalid code;
the target public code segment determining module is used for carrying out second similarity analysis on the test script codes after the invalid code segments are removed so as to determine target public code segments; and
and the target public code block generation module is used for encapsulating the target public code segments according to preset encapsulation rules to generate target public code blocks.
According to an embodiment of the present disclosure, the invalid code determining module includes: the test script group generation sub-module and the invalid code analysis sub-module.
The test script group generation sub-module is used for carrying out similarity analysis on the test scripts according to the execution sequence of the initial public code segment so as to generate a test script group; and
And the invalid code analysis sub-module is used for carrying out invalid code rule analysis on the test scripts in the test script group so as to determine invalid code segments.
According to an embodiment of the present disclosure, a test script group generation submodule includes: a first acquisition unit and a classification unit.
The first acquisition unit is used for acquiring the number and execution sequence of initial public code segments in the test script; and
and the classification unit is used for classifying the test scripts with the same number of the initial common code segments larger than a first preset threshold value and the same execution sequence of the initial common code segments into the same test script group.
According to an embodiment of the present disclosure, the invalid code analysis sub-module includes: a second acquisition unit and a determination unit.
The second acquisition unit is used for acquiring code segments between adjacent public code segments in the test script group; and
and the determining unit is used for determining an invalid code segment corresponding to the invalid operation in the code segments, wherein the invalid operation comprises repeated clicking operation, repeated input operation and invalid dragging operation.
According to an embodiment of the present disclosure, an object common code block generation module includes: the first determination sub-module and the target common code block generation sub-module.
A first determining submodule, configured to determine a target encapsulation rule according to an operation object type in the target common code segment; and
and the target public code block generation sub-module is used for packaging the target public code segments according to the target packaging rule so as to generate target public code blocks.
According to an embodiment of the present disclosure, the first 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 encapsulation rule is to increase waiting and window maximizing operations after the browser connection operation is acquired if the operation object type is determined to be the browser connection operation;
the second determining unit is used for determining that the target encapsulation rule is to increase the waiting time after the clicking operation if the operation object type is determined to be the clicking operation; and
and the third determining unit is used for determining the target encapsulation rule as a click operation added with 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, further comprising: the system comprises a verification module and a public code block management list generation module.
The verification module is used for verifying the validity of the target public code block; and
And the public code block management list generation 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, the common code block management manifest generation module includes: the target test script generation sub-module, the acquisition sub-module, the second determination sub-module and the third determination sub-module.
The target test script generation sub-module is used for replacing the corresponding public code segments in the test script with the target public code blocks so as to generate a target test script;
the acquisition sub-module is used for executing the target test script to acquire the execution success rate of the target test script;
the second determining submodule is used for determining that the target public code block is valid when the execution success rate is greater than or equal to a preset threshold value; and
and the third determining submodule is used for determining that the target public code block is invalid when the execution success rate is smaller than a preset threshold value.
According to an embodiment of the present disclosure, the initial common code segment determination module includes: the system comprises a preprocessing sub-module, a word frequency analysis sub-module and a fourth determination sub-module.
The preprocessing sub-module is used for preprocessing the test script source code to generate target test script code information;
The word frequency analysis sub-module is used for performing word frequency analysis on the target test script code information by using a text keyword extraction algorithm so as to generate a word frequency analysis result; and
and the fourth determination submodule is used for determining that codes with word frequency larger than a preset threshold value in the target test script code information are initial public code segments.
According to an embodiment of the present disclosure, the preprocessing submodule includes: scanning unit, fourth determining unit, hash value calculating unit, and target test script code information generating unit
The scanning unit is used for scanning the test script source code to identify a test page operation object in the test script source code;
a fourth determining unit, configured to determine operation action information and processing method information of the test page operation object according to the test page operation object;
the hash value calculation unit is used for carrying out hash operation on the test page operation object so as to generate a hash value; and
and the target test script code information generating unit 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, a word frequency analysis submodule includes: the system comprises a first target code generation sub-module, a calculation sub-module and a word frequency analysis result generation sub-module.
The first target code generation sub-module is used for extracting the target test script codes according to a script execution sequence according to a preset step length so as to generate first target codes;
a computing sub-module for computing word frequency information of the first object code; and
and the word frequency analysis result generation sub-module is used for generating a word frequency analysis result according to the word frequency information.
A third aspect of the present disclosure provides an electronic device, comprising: one or more processors; and 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 method of packaging test script code described above.
A fourth aspect of the present disclosure also provides a computer-readable storage medium having stored thereon executable instructions that, when executed by a processor, cause the processor to perform the method of packaging test script code described above.
A 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 of encapsulating test script code described above.
According to the method for packaging the test script codes, provided by the embodiment of the disclosure, the first similarity analysis is conducted on the test script source codes in response to the packaging instructions of the test script codes so as to determine initial public code segments; in order to reduce invalid redundant codes, carrying out invalid code analysis on an initial public code segment before generating a target public code block, and automatically eliminating the invalid codes, namely carrying out invalid code analysis on the test script based on the initial public code segment so as to determine the invalid codes; performing second similarity analysis on the test script codes after the invalid code segments are removed to determine target public code segments; and encapsulating the target public code segment according to a preset encapsulation rule to generate a target public code block. Compared with the related art, the method provided by the embodiment of the disclosure deletes the original invalid operation script statement in the packaged code segment, simplifies the automatic test script structure, reduces the invalid redundant code quantity, maximizes the common code block, avoids the fragmentation of the common code, saves the test execution resource, and improves the packaging quality and the execution efficiency of the common module of the automatic script.
Drawings
The foregoing and other objects, features and advantages of the disclosure will be more apparent from the following description of embodiments of the disclosure with reference to the accompanying drawings, in which:
FIG. 1 schematically illustrates application scenario diagrams of test script code packaging methods, apparatus, devices, media and program products according to embodiments of the present disclosure;
FIG. 2 schematically illustrates a flow chart of a method of packaging test script code provided in accordance with an embodiment of the present disclosure;
FIG. 3a schematically illustrates one of the flowcharts of one method of determining an initial common code segment provided in accordance with embodiments of the present disclosure;
FIG. 3b schematically illustrates a second flowchart of a method of determining an initial common code segment provided in accordance with an embodiment of the present disclosure;
FIG. 3c schematically illustrates a third flowchart of a method of determining an initial common code segment provided in accordance with an embodiment of the present disclosure;
FIG. 4a schematically illustrates one of the flowcharts of one method of determining invalid code provided in accordance with embodiments of the present disclosure;
FIG. 4b schematically illustrates a second flowchart of a method of determining invalid code provided in accordance with an embodiment of the present disclosure;
FIG. 4c schematically illustrates a third flowchart of a method of determining invalid code provided in accordance with an embodiment of the present disclosure;
FIG. 5a schematically illustrates one of the flowcharts of a method of encapsulating a target common code block provided in accordance with an embodiment of the present disclosure;
FIG. 5b schematically illustrates a second flowchart of a method of encapsulating a target common code block provided in accordance with an embodiment of the present disclosure;
FIG. 6a schematically illustrates one of the flowcharts of the target common code block verification method provided in accordance with an embodiment of the present disclosure;
FIG. 6b schematically illustrates a second flowchart of a target common code block verification method provided in accordance with an embodiment of the present disclosure;
FIG. 7 schematically illustrates a block diagram of a package of test script code, according to an embodiment of the disclosure; and
fig. 8 schematically illustrates a block diagram of an electronic device adapted to implement a method of encapsulation of test script code, in accordance with 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 only exemplary 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 present disclosure. It may be evident, however, that one or more embodiments may be practiced without these specific details. In addition, in the following description, descriptions of well-known structures and techniques are omitted so as not to 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/or 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 should be noted that the terms used herein should be construed to have meanings consistent with the context of the present specification and should not be construed in an idealized or overly formal manner.
Where expressions like at least one of "A, B and C, etc. are used, the expressions should generally be interpreted in accordance with the meaning as commonly understood by those skilled in the art (e.g.," a system having at least one of A, B and C "shall include, but not be limited to, a system having 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.).
In the process of automatic test script writing at the UI end, in order to improve working efficiency, a tester usually adopts some automatic test tools with script recording functions to carry out automatic script writing, when the tester starts to write scripts, the tester records that the tester completes operation in a browser through the automatic test tools, the test tools automatically form corresponding automatic test scripts, compared with a manual line-by-line writing mode, the writing efficiency of the automatic test scripts can be greatly improved by using the mode, but because a user cannot avoid false clicking or repeated clicking actions in the process of testing, the operations are ineffective operations for the whole service function, but because the automatic test tools automatically form corresponding automatic test scripts in the recording mode, corresponding script sentences can also appear in the automatic test scripts, and precious execution time and execution resources are wasted.
In the process of intelligent packaging of an automatic test script, under the scheme mode of analyzing and packaging common repeated code similarity from the perspective of whether code operation objects are completely consistent, when script sentences with misoperation or repeated clicking and other operations exist in the automatic test script, the traditional similarity comparison method cannot distinguish, and only the fact that the code segments with the completely consistent operation objects are packaged can be realized. If the same business operation flow has more misoperation or repeated clicking operation in a plurality of scripts, the package of one business operation flow is fragmented, so that the packaged code fragments are more and scattered, and the subsequent maintenance and fresh keeping are not facilitated.
Based on the technical problems described above, an embodiment of the present disclosure provides a method for packaging test script codes, the method including: responding to the packaging instruction of the test script code, and carrying out first similarity analysis on the test script source code to determine an initial public code section; performing invalid code analysis on the test script based on the initial common code segment to determine an invalid code; performing second similarity analysis on the test script codes after the invalid code segments are removed to determine target public code segments; and encapsulating the target public code segment according to a preset encapsulation rule to generate a target public code block.
Fig. 1 schematically illustrates an application scenario diagram of a method, apparatus, device, medium, and program product for packaging test script code 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 is used as a medium to provide communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.
The user may interact with the server 105 via the network 104 using the terminal devices 101, 102, 103 to receive or send messages or the like. Various communication client applications, such as shopping class applications, web browser applications, search class applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only) may be installed on the terminal devices 101, 102, 103.
The terminal devices 101, 102, 103 may be a variety of electronic devices having a display screen and supporting web browsing, including but not limited to smartphones, tablets, laptop and desktop computers, and the like.
The server 105 may be a page test script management server, which pre-processes the stock test script codes, extracts a common code portion by word frequency analysis, analyzes an invalid code for the common code, and encapsulates the common code after the invalid code is removed and according to a preset encapsulation rule to generate a common code block, for an encapsulation instruction of the test script codes initiated by the user through the application server, for example, in response to an encapsulation instruction of the test script codes sent by the user through the terminal devices 101, 102 and 103.
It should be noted that, the method for packaging test script codes provided in the embodiments of the present disclosure may be generally executed by the server 105. Accordingly, the encapsulation means of the test script code provided by the embodiments of the present disclosure may be generally provided in the server 105. The encapsulation method of the test script code provided by the embodiments of the present disclosure may also be performed by a server or a server cluster that is different from the server 105 and is capable of communicating with the terminal devices 101, 102, 103 and/or the server 105. Accordingly, the encapsulation means of the test script code provided by the embodiments of the present disclosure may also be provided 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 device for packaging the test script code determined by the embodiments of the present disclosure may be used in the field of automated testing technology, may also be used in the field of financial technology, and may also be used in any field other than the financial field.
The following will describe in detail a method of packaging test script codes of the embodiment of the present disclosure by fig. 2 to 6 based on the scenario described in fig. 1.
Fig. 2 schematically illustrates a flowchart of a method of packaging test script code provided in accordance with an embodiment of the present disclosure. As shown in fig. 2, the method for packaging test script code of this embodiment includes operations S210 to S240, which can be performed by an automated test script code module smart packaging apparatus.
In operation S210, a first similarity analysis is performed on the test script source code in response to the package instruction of the test script code to determine an initial common code segment.
In one example, there are a large number of duplicate code segments in an automation test script corresponding to a business scenario of similar function or transaction type; in addition, due to development habits of different test developers, codes of the same function are not completely consistent, and when corresponding functions in the repeated code segments are changed, all relevant automatic test scripts need to be adjusted, so that a large amount of repeated redundant workload is generated. In order to reduce a large number of redundant codes existing in test script source codes, similarity analysis is carried out on the source codes, similar code fragments are used as common code fragments for encapsulation, when a certain system function is changed, and corresponding automatic test script codes are subjected to fresh-keeping maintenance, the fresh-keeping maintenance cost of test developers on the stored automatic test scripts is greatly reduced, the working cost of modularized encapsulation is carried out on high-frequency use common modules, the efficiency of automatic test work is improved, and the resource investment is reduced. The specific similarity analysis process can refer to the operation steps shown in fig. 3a to 3c, and will not be described herein.
In operation S220, an invalid code analysis is performed on the test script based on the initial common code segment to determine an invalid code.
In one example, to further reduce redundant codes, invalid code analysis is performed on code segments between initial common code segments in the test script, to determine whether invalid operations such as false clicks, repeated clicks, and the like exist, and to determine corresponding invalid codes. The invalid code analysis process can refer to the operation steps shown in fig. 4a to 4c, and will not be described herein.
In operation S230, a second similarity analysis is performed on the test script code from which the invalid code segment is removed to determine a target common code segment.
In operation S240, the target common code segment is encapsulated according to a preset encapsulation rule to generate a target common code block.
In one example, after the invalid code is removed, a second similarity analysis is performed on the test script code to determine the target common code segment, where the second similarity analysis scheme and the technical principle are the same as the similarity analysis process in operation S210, and are not described herein.
In one example, in order to improve the execution success rate of the modularization of the public code, after determining the target public code segment, the code information existing in the target public code segment finally obtained in operation S230 is packaged according to a preset packaging rule by an intelligent method, and the modularization packaging of the inventory automation test script is completed by a mode of calling the public code, and specific packaging rules and packaging processes can refer to the operation steps shown in fig. 5a to 5b, which are not repeated here.
According to the method for packaging the test script codes, provided by the embodiment of the disclosure, the first similarity analysis is conducted on the test script source codes in response to the packaging instructions of the test script codes so as to determine initial public code segments; in order to reduce invalid redundant codes, carrying out invalid code analysis on an initial public code segment before generating a target public code block, and automatically eliminating the invalid codes, namely carrying out invalid code analysis on the test script based on the initial public code segment so as to determine the invalid codes; performing second similarity analysis on the test script codes after the invalid code segments are removed to determine target public code segments; and encapsulating the target public code segment according to a preset encapsulation rule to generate a target public code block. Compared with the related art, the method provided by the embodiment of the disclosure deletes the original invalid operation script statement in the packaged code segment, simplifies the automatic test script structure, reduces the invalid redundant code quantity, maximizes the common code block, avoids the fragmentation of the common code, saves the test execution resource, and improves the packaging quality and the execution efficiency of the common module of the automatic script.
Fig. 3a schematically illustrates one of flowcharts of a method for determining an initial common code segment provided according to an embodiment of the present disclosure, fig. 3b schematically illustrates the second of the flowcharts of the method for determining an initial common code segment provided according to an embodiment of the present disclosure, and fig. 3c schematically illustrates the third of the flowcharts of the method for determining an initial common code segment provided according to an embodiment of the present disclosure.
As shown in fig. 3a, operation S210 includes operations S211 to S213.
In operation S211, the test script source code is preprocessed to generate target test script code information.
As shown in fig. 3b, operation S211 includes operations S2111 to S2114.
In operation S2111, the test script source code is scanned to identify a test page operation object in the test script source code.
In operation S2112, operation action information and processing method information of the test page operation object are determined according to the test page operation object.
In operation S2113, a hash operation is performed on the test page operation object to generate a hash value.
In operation S2114, target test script code information is generated from 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, the control element may be an input box, a click button, or 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 ifelsif condition judgment statement. In order to facilitate the analysis and statistics of the word frequency in the later stage, hash operation is needed 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
In operation S212, 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 operation S213, it is determined that the code with the word frequency greater than the preset threshold value in the target test script code information is the initial common code segment.
As shown in fig. 3c, operation S212 includes operations S2121 to S2123.
In operation S2121, 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 S2122, word frequency information of the first object code is calculated.
In operation S2123, a word frequency analysis result is generated from the word frequency information.
In one example, the pre-processed automated test scripts are subjected to similarity analysis, the common code blocks are extracted and packaged by using a text keyword extraction algorithm, the packaged code blocks are submitted to a common code definition module for storage processing, the state is set to be verified, and the corresponding relationship is recorded. The text keyword extraction algorithm is used for processing the noise-reduced codes and extracting script contents in a mode of positive +word frequency +step length. The forward direction means that extraction is required according to the execution sequence of the script, the preset step length can be, for example, 6 lines of codes are extracted according to the execution sequence of the script to be used as a first target code, the frequency of the first target code in the script is calculated, word frequency information is obtained, the word frequency information is analyzed, and codes with the word frequency reaching a certain condition can be used as public codes to be packaged.
Fig. 4a schematically illustrates one of the flowcharts of one method of determining an invalid code provided according to an embodiment of the present disclosure, fig. 4b schematically illustrates the second of the flowcharts of one method of determining an invalid code provided according to an embodiment of the present disclosure, and fig. 4c schematically illustrates the third of the flowcharts of one method of determining an invalid code provided according to an embodiment of the present disclosure.
As shown in fig. 4a, operation S220 includes operation S221 and operation S222.
In operation S221, a similarity analysis is performed on the test scripts according to an execution order of the initial common code segment to generate a test script group.
As shown in fig. 4b, operation S221 includes operation S2211 and operation S2212.
In operation S2211, the number and execution order of initial common code segments in the test script are acquired.
In operation S2212, test scripts having the same number of initial common code segments greater than a first preset threshold and the same execution order of the initial common code segments are classified into the same test script group.
In one example, the obtained initial public code segments and the scripts calling the initial public code segments are analyzed, if more than two identical initial public code segments exist in each script and the appearance sequence is identical, namely the execution sequence is identical, the number of the current line number of each initial public code segment and the number of the identical initial public code segments in each script are recorded and marked as a new group, if more than two initial public code segments exist in the two scripts and the appearance sequence of the initial public code segments is identical, the scripts are classified as an automatic script group, and it is understood that one automatic script can be classified as a plurality of script groups.
In operation S222, an invalid code rule analysis is performed on test scripts in the test script set to determine an invalid code segment.
As shown in fig. 4c, operation S222 includes operation S2221 and operation S2222.
In operation S2221, code segments between adjacent common code segments in the test script group are acquired.
In operation S2222, an invalid code segment corresponding to the invalid operation in the code segments is determined.
According to an embodiment of the present disclosure, the invalidation operation includes a repeated click operation, a repeated input operation, and an invalidation drag operation.
In one example, a script group is taken, wherein the number of calling public code segments reaches a preset threshold value and the current number of calling public code segments is the largest, for example, the number of the public code segments reaches 5% of the total number of scripts, in the script group, based on the principle of analysis of two adjacent public code blocks, the automatic script segments between the two adjacent public code blocks are subjected to invalid code rule analysis one by one, until the script group calling the public script does not have more than two public code segments or does not reach 5% of the total number of scripts, and then the invalid code analysis is ended. Specific rules for invalid code analysis include: (1) If the codes between two adjacent public code blocks exist and the clicking operation of the public script on the same control is carried out, and no other effective operation exists in the middle, only one clicking operation is reserved; (2) If the codes between two adjacent public code blocks exist and the public script inputs the operation to the same control, and no other effective operation exists in the middle, the last input operation is reserved; (3) The deleting invalidation operation comprises a single coordinate clicking operation and an invalidation dragging operation (for example, the original object and the target object are the same), and the processing mode is that the corresponding sentence is directly deleted.
Fig. 5a schematically illustrates one of the flowcharts of a method of encapsulating a target common code block provided according to an embodiment of the present disclosure. Fig. 5b schematically illustrates a second flowchart of a method of encapsulating a target common code block provided in accordance with an embodiment of the present disclosure. As shown in fig. 5a, operation S240 includes operations S241 to S242.
In operation S241, a target encapsulation rule is determined according to the type of the operation object in the target common code segment.
In operation S242, the target common code segment is encapsulated according to the target encapsulation rule to generate a target common code block.
As shown in fig. 5b, operation S241 includes operations S2411 to S2413.
In operation S2411, if it is determined that the operation object type is the get browser connection operation, the target encapsulation rule is determined to add a wait and window maximization operation after the get browser connection operation.
In operation S2412, if it is determined that the operation object type is a click operation, the target encapsulation rule is determined to increase a waiting time after the click operation.
In operation S2413, 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 to add the same element before the input operation.
In one example, when the word frequency of the first object code corresponding to any operation object reaches a preset threshold value of the total number of the current scripts, for example, 5% of the total number of the scripts, the first object code is packaged, so that in order to improve the success rate of executing the packaged public code, smooth execution of the test scripts is ensured, and the package is required to be performed by using a preset package rule. The specific rules are as follows:
(1) After the browser connection operation (driver. Get) is acquired, a waiting and window maximizing operation (driver. Message (). Window (). Maximum ()) is added. Simulating page opening operation, increasing waiting time to wait for page loading, and increasing window maximizing operation after page loading.
(2) The wait time is increased after the click operation (click). In order to shield the influence of the network difference on the page test, waiting time is increased after clicking operation is performed, and the server response is waited.
(3) The click operation of the same element is added before the input operation (sendKeys). In order to ensure that information can be successfully input in the input box, clicking operation of the same element is added before the input operation, and the current input box is ensured to be in an activated state.
(4) And adding a screen capturing operation after the if condition judgment is finished.
And determining corresponding encapsulation rules according to different operation object types, and encapsulating to generate a target public block. After the target common code block is generated, validity of the common code block needs to be verified.
Fig. 6a schematically illustrates one of the flowcharts of the target common code block verification method provided according to an embodiment of the present disclosure. Fig. 6b schematically illustrates a second flowchart of a target common code block verification method provided according to an embodiment of the present disclosure, as shown in fig. 6a, including operations S310 and S320.
In operation S310, 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 the 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 verification rule is as follows:
(1) If 80% of the automated test scripts pass the execution, the packaging is proved to be successful, the corresponding public code state in the public code block definition module is set to pass the verification, and the version of the corresponding content of the executed automated test scripts after the modular packaging is updated to the asset library of the automated test scripts.
(2) If 80% of the code blocks are not passed, readjusting the code public segments, and putting the code segments which are not passed into a code feature library which is not passed, and when corresponding code blocks appear in the subsequent comparison process, not carrying out secondary packaging processing. While rollback the script to the last version.
In operation S320, a common code block management manifest is generated according to the validity verification result.
In one example, to avoid repeated extraction of the verification and improve the generation efficiency of the common code blocks, the verification result is generated into a common code block management list, which is shown in table 2 in detail. Recording the state of a public code block used for storing the packaged public code block, and comparing the public code block with a corresponding list of an automatic test script which is referenced to the code block, wherein the public code block is defined with two sources: the device automatically and intelligently packages the public module and manually packages the public module by testers. The public module manually packaged by the tester is mainly used for the known parts which are not suitable for being packaged according to the models, and for the public codes which cannot be packaged, the corresponding information can be directly perfected into the public code block definition module, so that the resource waste caused by repeated screening is avoided.
Table 2 common code block management checklist
According to the method for packaging the test script codes, provided by the embodiment of the disclosure, the code blocks in the original automatic test script are intelligently adjusted to be in a common module reference mode, so that the structure of the automatic test script is simplified, and the common code block asset is intelligently formed; meanwhile, intelligent analysis can be carried out on invalid operations such as misoperation clicking or repeated clicking and the like in the script, invalid misoperation is automatically removed, and original invalid operation script sentences are deleted from the packaged code fragments. And then, the packaging is automatically carried out, so that the structure of an automatic test script is greatly simplified, the invalid redundant code quantity is reduced, and the packaging quality and the execution efficiency of the public module of the automatic script are provided.
Based on the above test script code packaging method, the present disclosure also provides a test script code packaging device. The device will be described in detail below in connection with fig. 7.
Fig. 7 schematically illustrates a block diagram of a package apparatus for testing script code according to an embodiment of the present disclosure.
As shown in fig. 7, the encapsulation apparatus 700 of the test script code of this embodiment includes an initial common code section determination module 710, an invalid code determination module 720, a target common code section determination module 730, and a target common code block generation module 740.
The initial common code segment determination module 710 is configured to perform a first similarity analysis on the test script source code in response to the package instructions of the test script code to determine an initial common code segment. In an embodiment, the initial common code segment determining module 710 may be configured to perform the operation S210 described above, which is not described herein.
The invalid code determining module 720 is configured to perform an invalid code analysis on the test script based on the initial common code segment to determine an invalid code. In an embodiment, the invalid code determining module 720 may be used to perform the operation S220 described above, which is not described herein.
The target common code section determining module 730 is configured to perform a second similarity analysis on the test script code after the invalid code section is removed, so as to determine a target common code section. In an embodiment, the target common code segment determining module 730 may be configured to perform the operation S230 described above, which is not described herein.
The target common code block generating module 740 is configured to encapsulate the target common code segment according to a preset encapsulation rule, so as to generate a target common code block. In an embodiment, the target common code block generating module 740 may be configured to perform the operation S230 described above, which is not described herein.
According to an embodiment of the present disclosure, the invalid code determining module includes: the test script group generation sub-module and the invalid code analysis sub-module.
And the test script group generation sub-module is used for carrying out similarity analysis on the test scripts according to the execution sequence of the initial public code segment so as to generate a test script group. In an embodiment, the test script set generating sub-module may be used to perform the operation S221 described above, which is not described herein.
And the invalid code analysis sub-module is used for carrying out invalid code rule analysis on the test scripts in the test script group so as to determine invalid code segments. In an embodiment, the invalid code analysis sub-module may be used to perform the operation S222 described above, which is not described herein.
According to an embodiment of the present disclosure, a test script group generation submodule includes: a first acquisition unit and a classification unit.
The first acquisition unit is used for acquiring the number and the execution sequence of the initial common code segments in the test script. In an embodiment, the first obtaining unit may be configured to perform the operation S2211 described above, which is not described herein.
And the classification unit is used for classifying the test scripts with the same number of the initial common code segments larger than a first preset threshold value and the same execution sequence of the initial common code segments into the same test script group. In an embodiment, the classification unit may be used to perform the operation S2212 described above, which is not described herein.
According to an embodiment of the present disclosure, the invalid code analysis sub-module includes: a second acquisition unit and a determination unit.
And the second acquisition unit is used for acquiring the code segments between the adjacent common code segments in the test script group. In an embodiment, the second obtaining unit may be configured to perform the operation S2221 described above, which is not described herein.
And the determining unit is used for determining an invalid code segment corresponding to the invalid operation in the code segments, wherein the invalid operation comprises repeated clicking operation, repeated input operation and invalid dragging operation. In an embodiment, the determining unit may be configured to perform the operation S2222 described above, which is not described herein.
According to an embodiment of the present disclosure, an object common code block generation module includes: the first determination sub-module and the target common code block generation sub-module.
And the first determining submodule is used for determining a target encapsulation rule according to the type of the operation object in the target public code segment. In an embodiment, the first determining sub-module may be used to perform the operation S241 described above, which is not described herein.
And the target public code block generation sub-module is used for packaging the target public code segments according to the target packaging rule so as to generate target public code blocks. In an embodiment, the target common code block generating sub-module may be used to perform the operation S242 described above, which is not described herein.
According to an embodiment of the present disclosure, the first determination submodule includes a first determination unit, a second determination unit, and a third determination unit.
And the first determining unit is used for determining that the target encapsulation rule is to add waiting and window maximizing operations after the browser connection operation is acquired if the operation object type is determined to be the browser connection operation. In an embodiment, the first determining unit may be configured to perform the operation S2411 described above, which is not described herein.
And the second determining unit is used for determining that the target encapsulation rule is to increase the waiting time after the clicking operation if the operation object type is determined to be the clicking operation. In an embodiment, the second determining unit may be configured to perform the operation S2412 described above, which is not described herein.
And the third determining unit is used for determining the target encapsulation rule as a click operation added with the same element before the input operation if the operation object type is determined to be the input operation. In an embodiment, the third determining unit may be configured to perform the operation S2413 described above, which is not described herein.
According to an embodiment of the present disclosure, further comprising: the system comprises a verification module and a public code block management list generation module.
And the verification module is used for verifying the validity of the target public code block. In an embodiment, the verification module may be configured to perform the operation S310 described above, which is not described herein.
And the public code block management list generation module is used for generating a public code block management list according to the validity verification result. In an embodiment, the common code block management manifest generating module may be configured to perform the operation S320 described above, which is not described herein.
According to an embodiment of the present disclosure, the common code block management manifest generation module includes: the target test script generation sub-module, the acquisition sub-module, the second determination sub-module and the third determination sub-module.
And the target test script generation sub-module is used for replacing the corresponding public code segments in the test script with the target public code blocks so as to generate the target test script. In an embodiment, the common code block management manifest generating module may be configured to perform the operation S320 described above, which is not described herein.
And the acquisition sub-module is used for executing the target test script to acquire the execution success rate of the target test script. In an embodiment, the obtaining sub-module may be used to perform the operation S321 described above, which is not described herein.
And the second determining submodule is used for determining that the target public code block is valid when the execution success rate is greater than or equal to a preset threshold value. In an embodiment, the second determining sub-module may be used to perform the operation S322 described above, which is not described herein.
And the third determining submodule is used for determining that the target public code block is invalid when the execution success rate is smaller than a preset threshold value. In an embodiment, the third determining sub-module may be used to perform the operation S323 described above, which is not described herein.
According to an embodiment of the present disclosure, the initial common code segment determination module includes: the system comprises a preprocessing sub-module, a word frequency analysis sub-module and a fourth determination sub-module.
And the preprocessing sub-module is used for preprocessing the test script source code to generate target test script code information. In an embodiment, the preprocessing sub-module may be used to perform the operation S211 described above, which is not described herein.
And the word frequency analysis sub-module is used for carrying out word frequency analysis on the target test script code information by using a text keyword extraction algorithm so as to generate a word frequency analysis result. In an embodiment, the word frequency analysis sub-module may be used to perform the operation S212 described above, which is not described herein.
And the fourth determination submodule is used for determining that codes with word frequency larger than a preset threshold value in the target test script code information are initial public code segments. In an embodiment, the fourth determining sub-module may be used to perform the operation S213 described above, which is not described herein.
According to an embodiment of the present disclosure, the preprocessing submodule includes: scanning unit, fourth determining unit, hash value calculating unit, and target test script code information generating unit
And the scanning unit is used for scanning the test script source code to identify a test page operation object in the test script source code. In an embodiment, the scanning unit may be configured to perform the operation S2111 described above, which is not described herein.
And a fourth determining unit, 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 fourth determining unit may be configured to perform the operation S2112 described above, which is not described herein.
And the hash value calculation unit 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 value calculation unit may be used to perform the operation S2113 described above, which is not described herein.
And the target test script code information generating unit 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 target test script code information generating unit may be configured to perform the operation S2114 described above, which is not described herein.
According to an embodiment of the present disclosure, a word frequency analysis submodule includes: the system comprises a first target code generation sub-module, a calculation sub-module and a word frequency analysis result generation sub-module.
And the first target code generation sub-module is used for extracting the target test script codes according to a script execution sequence according to a preset step length so as to generate the first target codes. In an embodiment, the first object code generating sub-module may be configured to perform the operation S2121 described above, which is not described herein.
And the computing sub-module is used for computing word frequency information of the first target code. In an embodiment, the calculation sub-module may be used to perform the operation S2122 described above, which is not described herein.
And the word frequency analysis result generation sub-module is used for generating a word frequency analysis result according to the word frequency information. In an embodiment, the word frequency analysis result generation sub-module may be used to perform the operation S2123 described above, which is not described herein.
Any of the initial common code section determining module 710, the invalid code determining module 720, the target common code section determining module 730, and the target common code block generating module 740 may be combined in one module to be implemented, or any of them may be split into a plurality of modules according to an embodiment of the present disclosure. Alternatively, at least some of the functionality of one or more of the modules may be combined with at least some of the functionality of other modules and implemented in one module. According to embodiments of the present disclosure, at least one of the initial common code section determination module 710, the invalid code determination module 720, the target common code section determination module 730, and the target common code block generation module 740 may be implemented at least in part as hardware circuitry, 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 as hardware or firmware in any other reasonable manner of integrating or packaging the circuitry, or as any one of or a suitable combination of three of software, hardware, and firmware. Alternatively, at least one of the initial common code section determining module 710, the invalid code determining module 720, the target common code section determining module 730, and the target common code block generating module 740 may be at least partially implemented as a computer program module, which when executed, may perform the corresponding functions.
Fig. 8 schematically illustrates a block diagram of an electronic device adapted to implement a method of encapsulation of test script code, in accordance with an embodiment of the present disclosure.
As shown in fig. 8, an electronic device 900 according to an embodiment of the present disclosure includes a processor 901 that can perform various appropriate actions and processes according to 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. The processor 901 may include, for example, a general purpose microprocessor (e.g., a CPU), an instruction set processor and/or an associated chipset and/or a special purpose microprocessor (e.g., an Application Specific Integrated Circuit (ASIC)), or the like. Processor 901 may also include on-board memory for caching purposes. Processor 901 may include a single processing unit or multiple 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 device 900 are stored. The processor 901, the ROM 902, and the RAM 903 are connected to each other by a bus 904. The processor 901 performs various operations of the method flow according to the embodiments of the present disclosure by executing programs in the ROM 902 and/or the RAM 903. Note that the program may 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 flow according to embodiments of the present disclosure by executing programs stored in the one or more memories.
According to an embodiment of the disclosure, the electronic device 900 may also include an input/output (I/O) interface 905, the input/output (I/O) interface 905 also being connected to the bus 904. The electronic device 900 may also include one or more of the following components connected to the I/O interface 905: an input section 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 a speaker; a storage portion 908 including a hard disk or 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 needed. A removable medium 911 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is installed as needed on the drive 910 so that a computer program read out therefrom is installed into the storage section 908 as needed.
The present disclosure also provides a computer-readable storage medium that may be embodied in the apparatus/device/system described in the above embodiments; or may exist alone without being assembled into the apparatus/device/system. The computer-readable storage medium carries one or more programs that, when executed, implement the method of packaging test script code according to embodiments 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 context of this 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, the computer-readable storage medium may include ROM 902 and/or RAM 903 and/or one or more memories other than ROM 902 and RAM 903 described above.
Embodiments of the present disclosure also include a computer program product comprising a computer program containing program code for performing the methods shown in the flowcharts. When the computer program product runs in a computer system, the program code is used for enabling the computer system to realize the encapsulation method of the test script code provided by the embodiment of the disclosure.
The above-described functions defined in the system/apparatus of the embodiments of the present disclosure are performed when the computer program is executed by the processor 901. The systems, apparatus, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the disclosure.
In one embodiment, the computer program may be based 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, and downloaded and installed in the form of a signal on a network medium, via communication portion 909, and/or installed from removable medium 911. The computer program may include program code that may be transmitted using any appropriate 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 the network via the communication portion 909 and/or installed from the removable medium 911. The above-described functions defined in the system of the embodiments of the present disclosure are performed when the computer program is executed by the processor 901. The systems, devices, apparatus, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the disclosure.
According to embodiments of the present disclosure, program code for performing computer programs provided by embodiments of the present disclosure may be written in any combination of one or more programming languages, and in particular, such computer programs may be implemented in high-level procedural and/or object-oriented programming languages, and/or assembly/machine languages. Programming languages include, but are not limited to, such as Java, c++, python, "C" or similar programming languages. The program code may execute entirely on the user's computing device, partly on the user's device, partly on a remote computing device, or entirely on the remote computing device or server. In the case of remote computing devices, 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., connected via the Internet using an Internet service provider).
The flowcharts 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 the features recited in the various embodiments of the disclosure and/or in the claims may be provided in a variety of combinations and/or combinations, even if such combinations or combinations are not explicitly recited in the disclosure. In particular, the features recited in the various embodiments of the present disclosure and/or the claims may be variously combined and/or combined without departing from the spirit and teachings of the present disclosure. All such combinations and/or combinations fall within the scope of the present disclosure.
The embodiments of the present disclosure are 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 above separately, this does not mean that the measures in the embodiments cannot be used advantageously in combination. The scope of the disclosure is defined by the appended claims and equivalents thereof. Various alternatives and modifications can be made by those skilled in the art without departing from the scope of the disclosure, and such alternatives and modifications are intended to fall within the scope of the disclosure.

Claims (15)

1. A method of packaging test script code, the method comprising:
responding to the packaging instruction of the test script code, and carrying out first similarity analysis on the test script source code to determine an initial public code section;
Performing invalid code analysis on the test script based on the initial common code segment to determine an invalid code;
performing second similarity analysis on the test script codes after the invalid code segments are removed to determine target public code segments; and
and encapsulating the target public code segment according to a preset encapsulation rule to generate a target public code block.
2. The method of claim 1, wherein said performing an invalid code analysis on the test script based on the initial common code segment to determine an invalid code comprises:
performing similarity analysis on the test scripts according to the execution sequence of the initial public code segments to generate a test script group; and
and carrying out invalid code rule analysis on the test scripts in the test script group to determine invalid code segments.
3. The method of claim 2, wherein performing similarity analysis on the test scripts according to an execution order of the initial common code segments to generate the test script groups comprises:
acquiring the number and execution sequence of initial public code segments in a test script; and
and classifying the test scripts with the same number of initial common code segments larger than a first preset threshold and the same execution sequence of the initial common code segments into the same test script group.
4. The method of claim 2, wherein said performing an invalid code rule analysis on test scripts in the set of test scripts to determine invalid code segments comprises:
acquiring code segments between adjacent public code segments in a test script group; and
and determining an invalid code segment corresponding to an invalid operation in the code segments, wherein the invalid operation comprises repeated clicking operation, repeated input operation and invalid dragging operation.
5. The method of claim 1, wherein encapsulating the target common code segment according to a preset encapsulation rule to generate the target common code block comprises:
determining a target encapsulation rule according to the type of the operation object in the target public code section; and
and encapsulating the target public code segment according to the target encapsulation rule to generate a target public code block.
6. The method of claim 5, wherein said determining a target encapsulation rule based on the type of operand in the common code comprises:
if the operation object type is determined to be the browser connection operation, determining the target encapsulation rule to be the operation of adding waiting and window maximization after the browser connection operation is acquired;
If the operation object type is determined to be the click operation, determining the target encapsulation rule to be to increase the waiting time after the click operation; and
and if the operation object type is determined to be the input operation, determining the target encapsulation rule to be a click operation added with the same element before the input operation.
7. The method of claim 1, further comprising, after generating the target common code block:
verifying the validity of the target public code block; and
and generating a public code block management list according to the validity verification result.
8. The method of claim 7, wherein verifying the validity of the target common code block comprises:
replacing the corresponding public code segments in the test script with the target public code blocks 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 greater than or equal to a preset threshold, determining that the target public code block is valid; and
and when the execution success rate is determined to be smaller than a preset threshold value, determining that the target public code block is invalid.
9. The method of any of claims 1 to 8, wherein performing a first similarity analysis on test script source code to determine an initial common code segment comprises:
preprocessing the test script source 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 determining codes with word frequency larger than a preset threshold value in the target test script code information as initial public code segments.
10. The method of claim 9, wherein preprocessing the test script source code to generate target test script code information comprises:
scanning a test script source code to identify a test page operation object in the test script source code;
determining operation action information and processing method information of the test page operation object according to the test page operation object;
performing 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.
11. The method of claim 9, wherein performing word frequency analysis on the 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 script execution sequence according to a preset step length to generate first target codes;
calculating word frequency information of the first target code; and
and generating a word frequency analysis result according to the word frequency information.
12. A packaging apparatus for testing script code, the apparatus comprising:
the initial public code segment determining module is used for responding to the packaging instruction of the test script code and carrying out first similarity analysis on the test script source code so as to determine an initial public code segment;
an invalid code determining module for performing an invalid code analysis on the test script based on the initial common code segment to determine an invalid code;
the target public code segment determining module is used for carrying out second similarity analysis on the test script codes after the invalid code segments are removed so as to determine target public code segments; and
and the target public code block generation module is used for encapsulating the target public code segments according to preset encapsulation rules to generate target public code blocks.
13. An electronic device, comprising:
one or more processors;
storage means 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 packaging test script code according to any of claims 1-11.
14. A computer readable storage medium having stored thereon executable instructions which when executed by a processor cause the processor to perform the method of packaging test script code according to any of claims 1 to 11.
15. A computer program product comprising a computer program which, when executed by a processor, implements a method of encapsulating test script code according to any of claims 1-11.
CN202310388997.1A 2023-04-12 2023-04-12 Packaging method and device for test script code Pending CN117130903A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310388997.1A CN117130903A (en) 2023-04-12 2023-04-12 Packaging method and device for test script code

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310388997.1A CN117130903A (en) 2023-04-12 2023-04-12 Packaging method and device for test script code

Publications (1)

Publication Number Publication Date
CN117130903A true CN117130903A (en) 2023-11-28

Family

ID=88858931

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310388997.1A Pending CN117130903A (en) 2023-04-12 2023-04-12 Packaging method and device for test script code

Country Status (1)

Country Link
CN (1) CN117130903A (en)

Similar Documents

Publication Publication Date Title
CN109062780B (en) Development method of automatic test case and terminal equipment
CN110489120B (en) Page development method based on components and server
CN109815147B (en) Test case generation method, device, server and medium
US10289262B2 (en) Method and system for determining user interface usage
CN111666201A (en) Regression testing method, device, medium and electronic equipment
CN114398673A (en) Application compliance detection method and device, storage medium and electronic equipment
US8572553B2 (en) Systems and methods for providing feedback for software components
US11615016B2 (en) System and method for executing a test case
CN112527655B (en) Software version quality abnormality detection method and device, electronic equipment and storage medium
CN116720489B (en) Page filling method and device, electronic equipment and computer readable storage medium
CN113032256A (en) Automatic test method, device, computer system and readable storage medium
CN115795058B (en) Threat modeling method, threat modeling system, electronic equipment and storage medium
CN117130903A (en) Packaging method and device for test script code
US11734299B2 (en) Message templatization for log analytics
CN117170659A (en) Packaging method and device for test script code
CN114579405A (en) Data processing method, data processing apparatus, electronic device, and storage medium
CN113609018A (en) Test method, training method, device, apparatus, medium, and program product
CN115687079A (en) Test script public code generation method and device
CN113238796B (en) Code reconstruction method, device, equipment and storage medium
CN111400623A (en) Method and apparatus for searching information
CN113849785B (en) Mobile terminal information asset use behavior identification method for application program
CN116627792A (en) Test code optimization method, apparatus, device, medium and program product
CN118733310A (en) Abnormal data management method, device and equipment of application program and storage medium
CN117111933A (en) Front-end code generation method, device and computer readable storage medium
CN116502054A (en) Flow data analysis method, system, medium and electronic equipment

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