A parsing method and device for a test script structure and a storage medium

By dividing the test script into multiple script actions and using regular expressions to extract elements and parameters, the problem of reduced readability of structured test case scripts is solved, and an easy-to-maintain and scalable test script parsing method is provided.

CN114185596BActive Publication Date: 2026-01-13SHENZHEN YISHIHUOLALA TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202111546081.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-16
Publication Date
2026-01-13
Estimated Expiration
2041-12-16

AI Technical Summary

Technical Problem

As the number of parameters increases, the readability of structured test case scripts decreases, and they become more difficult to maintain.

Method used

The script is divided into multiple script actions by text matching, and elements and parameters in the actions are extracted using regular expressions. Each script action is then processed in sequence.

Benefits of technology

It improves the scalability and maintainability of test scripts, and enhances the ease of script parsing and readability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114185596B_ABST
    Figure CN114185596B_ABST
Patent Text Reader

Abstract

The application discloses a parsing method, device and storage medium of a test script structure. The method divides a script into multiple script actions through text matching; each script action is processed in sequence, elements in the action are extracted through the text matching, and actions or options and parameters are matched. The test script structure is extensible and easier to maintain, and the parsing method of the test script structure provided by the application divides a script into multiple script actions through text matching, so that the script can be parsed by using simple text matching operation when the test script is executed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of medical devices, and in particular to a method, apparatus and storage medium for parsing test script structures. Background Technology

[0002] Scripting languages, as a type of computer language, allow for modification of their structure after the program has started. Existing functions can be deleted, and new functions can be added; therefore, they are also known as dynamic languages. Scripting languages ​​were created to shorten the traditional edit-compile-link-run process. A script is typically interpreted rather than compiled. In recent years, with the maturity of internet technology and innovation in programming methods, scripting languages ​​have become increasingly widespread and popular.

[0003] In traditional testing frameworks, to shield the underlying complexity and provide a simpler way to write test scripts, such as... Figure 1 As shown, a test case script format is generally defined. Structured formats include CSV, YAML, or other custom formats, while unstructured formats such as natural language can also be used.

[0004] Structured test case scripts have no restrictions on parameter types and numbers, and the scripts are easy to parse. However, as the number of parameters increases, the readability of the test script will decrease, and it will be difficult to maintain. Test scripts written in unstructured ways, such as natural language, are easy to read and maintain, but they have restrictions on parameters and require high script parsing capabilities. Summary of the Invention

[0005] The main technical problem addressed by this application is that the readability of structured test case scripts decreases as the number of parameters increases.

[0006] To address the aforementioned technical problems, this application provides a method for parsing test script structures.

[0007] The script is divided into multiple script actions by text matching;

[0008] Process each script action sequentially, extract elements from the action through text matching, and match the action or option and parameters.

[0009] The text matching is regular expression matching, which divides the script into multiple script actions by matching the first regular expression.

[0010] The second regular expression is used to extract elements from the action, matching the action or option and parameters.

[0011] The step of dividing the script into multiple script actions through matching the first regular expression further includes:

[0012] Save the extracted script actions in sequence.

[0013] The step of dividing the script into multiple script actions through matching the first regular expression specifically includes:

[0014] Use the first regular expression to match the start and end characters, and extract the result of the first regular expression match as a script action.

[0015] The step of extracting elements from the action using the second regular expression and matching the action or option and parameters specifically includes:

[0016] Use a second regular expression to match the action or option and the parameter. Take the result of the first regular expression match as the action or option, and extract the result of the second regular expression match as the corresponding parameter.

[0017] Wherein, the first regular expression is ((#[^;]+;)), the start character is '#', the end character is ';', and the first regular expression matching result is Group1; the step of using the first regular expression to match the start and end characters and extracting the first regular expression matching result as a script action specifically includes:

[0018] Using the first regular expression ((#[^;]+;)), the line block that starts with '#' and ends with ';' is matched, and the result of the first regular expression match, Group1, is extracted as a script action.

[0019] The second regular expression is (([^(\\n]+)\\((.*)\\)), and the second matching result is Group2. The steps of using the second regular expression to match the action or option and the parameter, taking the first regular expression matching result as the action or option, and extracting the second regular expression matching result as the corresponding parameter specifically include:

[0020] The second regular expression (([^(\\n]+)\\((.*)\\)) is used to match the action or option and the parameter. Group1 of the first regular expression matching result is extracted as the action or option, and Group2 of the second regular expression matching result is extracted as the corresponding parameter.

[0021] Actions and options are distinguished by whether they have a special prefix.

[0022] To address the aforementioned issues, another technical solution adopted in this application is to provide a test script structure parsing device, comprising a processor and a memory coupled to the processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the aforementioned method.

[0023] To address the aforementioned issues, another technical solution adopted in this application is to provide a computer-readable storage medium, wherein program data is stored in the computer-readable storage medium, and the program data is used to implement the aforementioned method when executed by a processor.

[0024] The beneficial effects of this application are as follows: Unlike existing technologies, this application provides a method for parsing test script structures. This method divides the script into multiple script actions through text matching; it processes each script action sequentially, extracting elements from the actions through text matching to match actions or options and parameters. The test script structure of this application is scalable and easier to maintain. The provided test script structure parsing method, by dividing the script into multiple script actions through text matching, facilitates the parsing of the script using simple text matching operations when executing the test script. Attached Figure Description

[0025] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort. Wherein:

[0026] Figure 1 This is a structured test case script diagram provided in the background section of this application;

[0027] Figure 2 This is a script action structure diagram of an embodiment of a test script structure parsing method provided in this application;

[0028] Figure 3 This is a flowchart illustrating an embodiment of a test script structure parsing method provided in this application;

[0029] Figure 4 This is an example diagram illustrating the transfer of values ​​between actions according to another embodiment of the test script structure parsing method provided in this application;

[0030] Figure 5 This is a flowchart illustrating an embodiment of a test script structure parsing method provided in this application;

[0031] Figure 6 This is a script parsing example of an embodiment of the test script structure parsing device provided in this application;

[0032] Figure 7 This is a structural block diagram of an embodiment of a test script structure parsing device provided in this application;

[0033] Figure 8 This is a schematic diagram of an embodiment of the computer-readable storage medium provided in this application. Detailed Implementation

[0034] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. It is understood that the specific embodiments described herein are only for explaining this application and not for limiting it. Furthermore, it should be noted that, for ease of description, only the parts related to this application are shown in the accompanying drawings, not all methods and processes. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of this application.

[0035] The terms “comprising” and “having”, and any variations thereof, used in this application are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the steps or units listed, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to such process, method, product, or apparatus.

[0036] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.

[0037] See Figure 2 , Figure 2 This is a script structure diagram of an embodiment of a test script structure parsing method provided in this application. Figure 2 In this context, <> indicates a required item, and [] indicates an optional item.

[0038] A script consists of multiple script actions. The structure of a script action includes:

[0039] First line: Comment line, starting with the '#' marker (start character), used to describe the action and for script maintainers to read;

[0040] The next line: the action line, consisting of English characters, with the main parameters of the action to be filled in the parentheses;

[0041] The rest: Options lines, starting with a '.' marker, indicate extended options for the action, such as data extraction, timeout settings, etc.

[0042] Ending: Use a ';' marker (end character) to end the action.

[0043] The start and end symbols of the above script actions can be replaced with other easily readable symbols.

[0044] See Figure 2 , Figure 2 This is a flowchart illustrating an embodiment of a test script structure parsing method provided in this application. The test script structure parsing method of this embodiment specifically includes steps 10 to 20:

[0045] Step 10: Divide the script into multiple script actions by text matching.

[0046] Step 20: Process each script action in sequence, extract elements from the action through text matching, and match the action or option and parameters.

[0047] The test script structure of this application is scalable and easier to maintain. The provided test script structure parsing method divides the script into multiple script actions through text matching, making it convenient to parse the script using simple text matching operations when executing the test script.

[0048] Furthermore, the text matching is regular expression matching. The script is divided into multiple script actions by matching the first regular expression. Of course, in some embodiments, there are other text matching methods besides regular expression matching. Regular expression matching is just the optimal choice in this embodiment to divide the actions.

[0049] The extracted script actions are stored sequentially using an array data structure.

[0050] The second regular expression is used to extract elements from the action, matching the action or option and parameters.

[0051] In some embodiments, a first regular expression is used to match the start and end characters, and the result of the first regular expression match is extracted as a script action. The extracted script actions are saved in sequence, and elements in the actions are extracted using regular expression matching. A second regular expression is used to match the action or option and the parameters, and the result of the first regular expression match is used as the action or option, while the result of the second regular expression match is extracted as the corresponding parameter.

[0052] Optionally, the first regular expression is ((#[^;]+;)), the start character is '#', the end character is ';', and the first regular expression matching result is Group1; the step of using the first regular expression to match the start and end characters and extracting the first regular expression matching result as a script action specifically includes:

[0053] Using the first regular expression ((#[^;]+;)), the line block that starts with '#' and ends with ';' is matched, and the result of the first regular expression match, Group1, is extracted as a script action.

[0054] The second regular expression is (([^(\\n]+)\\((.*)\\)), and the second matching result is Group2; the steps of using the second regular expression to match the action or option and the parameter, taking the first regular expression matching result as the action or option, and extracting the second regular expression matching result as the corresponding parameter specifically include:

[0055] The second regular expression (([^(\\n]+)\\((.*)\\)) is used to match the action or option and the parameter. Group1 of the first regular expression matching result is extracted as the action or option, and Group2 of the second regular expression matching result is extracted as the corresponding parameter.

[0056] Furthermore, actions and options are distinguished based on whether they have a special prefix. That is, the extracted actions / options are distinguished based on whether they have a '.' prefix.

[0057] like Figure 4 The image shown is an example of value transfer between actions.

[0058] The above steps, which extract elements from the action using the second regular expression and match the action or option and parameters, are as follows: Figure 5 As shown, it includes:

[0059] Step 51: Extract elements of a single action using regular expression matching.

[0060] Step 52: Determine if there is a special prefix;

[0061] Step 53: If there is a special prefix, it indicates the action type;

[0062] Step 54: If there is no special prefix, it is an action option;

[0063] Step 55; Extract the parameters of a single action.

[0064] Figure 6 An example of script parsing from an embodiment of this application is provided. Figure 6This is a UI automation script. By parsing each step, the intermediate and final data obtained are as follows:

[0065] 1. Action list: [Wait, startPerformance, Click, swipeUp];

[0066] 2. Further extract the action elements, such as the Click action which includes two options: by and with;

[0067] The list of actions obtained by parsing the UI automation script is used as automation instructions and passed to the automation engine to execute automated tests.

[0068] This invention combines the advantages of structured test scripts—the ability to express multiple parameter types—with readability, maintainability, and low script parsing difficulty. It can be used within a testing framework, shielding it from underlying complexity and providing a simpler way to write test scripts.

[0069] Based on the above embodiments, this application proposes a test script structure parsing device. See details... Figure 7 , Figure 7 This is a schematic diagram of an embodiment of a test script structure parsing device provided in this application.

[0070] The test script structure parsing device 100 includes a processor 110 and a memory 120. The processor 110 and the memory 120 are coupled together. The memory 120 stores a computer program used to execute the test script structure parsing method described above.

[0071] For details, please refer to [link / reference]. Figure 8 , Figure 8 This is a schematic diagram of an embodiment of the computer-readable storage medium provided in this application.

[0072] The computer-readable storage medium 200 includes program data 210. When executed by a processor, the program data 210 can implement the parsing method of the test script structure described above.

[0073] Unlike existing technologies, this application provides a method for parsing test script structures. This method divides the script into multiple script actions through text matching; it processes each script action sequentially, extracting elements from the actions through text matching to match actions or options and parameters. The test script structure of this application is scalable and easier to maintain. The provided test script structure parsing method, by dividing the script into multiple script actions through text matching, facilitates script parsing using simple text matching operations when executing the test script.

[0074] The above description is merely an embodiment of this application and does not limit the patent scope of this application. Any equivalent structural or procedural transformations made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.

Claims

1. A method for parsing the structure of a test script, characterized in that, The script is divided into multiple script actions through text matching. The test script consists of multiple script actions. The structure of a script action includes: a comment line describing the action, an action line containing the main parameters of the action, and an option line representing the extended options of the action. The text matching is regular expression matching. A first regular expression is used to match the start and end characters, and the result of the first regular expression matching is extracted as a script action. A second regular expression is used to match the action or option and the parameters. The result of the first regular expression matching is taken as the action or option, and the result of the second regular expression matching is extracted as the corresponding parameter. Process each script action sequentially, extract elements from the action through text matching, and match the action or option and parameters.

2. The method according to claim 1, characterized in that, After the step of using the first regular expression to match the start and end characters and extracting the first regular expression matching result as a script action, the following is also included: Save the extracted script actions in sequence.

3. The method according to claim 2, characterized in that, The first regular expression is ((#[^;]+;)), with '#' as the start character and ';' as the end character, and the first regular expression matching result is Group1; the step of using the first regular expression to match the start and end characters and extracting the first regular expression matching result as a script action specifically includes: Using the first regular expression ((#[^;]+;)), the line block that starts with '#' and ends with ';' is matched, and the result of the first regular expression match, Group1, is extracted as a script action.

4. The method according to claim 3, characterized in that, The second regular expression is (([^(\\n]+)\\((.*)\\)), and the second matching result is Group2; the steps of using the second regular expression to match the action or option and the parameter, taking the first regular expression matching result as the action or option, and extracting the second regular expression matching result as the corresponding parameter specifically include: Use the second regular expression (([^(\\n]+)\\((.*)\\))) to match the action or option and the parameter. Extract Group1 of the first regular expression matching result as the action or option, and extract Group2 of the second regular expression matching result as the corresponding parameter.

5. The method according to any one of claims 1-4, characterized in that, The actions and options can be distinguished based on whether they have a special prefix.

6. A test script structure parsing device, characterized in that, The test script structure parsing device includes a processor and a memory coupled to the processor, the memory storing a computer program, and the processor executing the computer program to implement the method as described in any one of claims 1-5.

7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores program data, which, when executed by a processor, is used to implement the method as described in any one of claims 1-5.

Citation Information

Patent Citations

  • Script data extraction method and device, computer equipment and storage medium

    CN111626585A