Intelligent test identifier adding method and device, electronic equipment and storage medium

By automating the generation and addition of test identifiers, the problem of low efficiency and poor consistency of the traditional manual addition method is solved, realizing efficient and accurate front-end automated testing and reducing the burden on developers.

CN121051007APending Publication Date: 2025-12-02GUANGZHOU TOZED KANGWEI INTELLIGENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510966657.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-14
Publication Date
2025-12-02

AI Technical Summary

Technical Problem

The traditional method of manually adding test identifiers is inefficient, prone to inconsistencies and insufficient coverage, increases workload and maintenance complexity, and may miss some elements, affecting software quality.

Method used

By automatically scanning the system directory, using an AST parser to generate an abstract syntax tree, and utilizing a preset element processor to generate a test identifier for each node, which is automatically added to the node attributes, the uniqueness and consistency of the identifiers are ensured by combining formatting processing and automated testing processes.

Benefits of technology

It significantly improves the efficiency of front-end automated testing, reduces the burden on developers, enhances test accuracy and code maintainability, and ensures high efficiency in test coverage and development/testing cycles.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121051007A_ABST
    Figure CN121051007A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of artificial intelligence, and discloses an intelligent test identifier adding method and device, electronic equipment and a storage medium. The method comprises the steps that a target file is extracted by automatically scanning a specified directory, a first file set is formed, a preset AST parser is used for generating an abstract syntax tree (AST), and the first file set is used for generating a second file set; and inputting the node information to a preset element processor to generate an identifier meeting the project requirement. The method has the beneficial effects that the generated identifier is convenient for a tester to quickly position the webpage element, the front-end automatic testing efficiency is remarkably improved, meanwhile, the daily burden of a developer is relieved, and powerful support is provided for the development and testing period of a team.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of artificial intelligence technology, and in particular to a method, apparatus, electronic device, and storage medium for intelligently adding test identifiers. Background Technology

[0002] With the rapid development of front-end development, modern web applications are becoming increasingly complex, highlighting the growing importance of testing. Throughout the software development lifecycle, automated testing has been widely adopted as a crucial means to improve software quality and shorten update cycles. To ensure the accuracy and efficiency of testing, adding unique identifiers to web elements has become a common practice. These identifiers not only help automated testers easily locate web page elements but also make testing more stable, avoiding location failures caused by dynamic changes in elements.

[0003] However, the traditional manual method of adding identifiers has significant drawbacks. First, testers need to check each element one by one and add appropriate identifiers, increasing workload and time costs. Second, in team collaboration or environments with frequent code updates, manually maintaining these identifiers is not only prone to inconsistencies but may also make subsequent maintenance and expansion more complex. Finally, manually adding identifiers may miss some elements, leading to insufficient test coverage and affecting software quality. Summary of the Invention

[0004] Therefore, it is necessary to address the existing problem of intelligent addition of test identifiers by proposing a method, device, electronic device, and storage medium for intelligent addition of test identifiers.

[0005] A method for intelligently adding test identifiers, the method comprising:

[0006] Scan the specified directory in the system to extract files of a specified format and form the first file set;

[0007] The first set of files is parsed using a preset AST parser to generate an abstract syntax tree corresponding to each file; wherein the abstract syntax tree stores the original structure of the corresponding file.

[0008] The element information of the nodes on the abstract syntax tree is input into a preset element processor for processing to obtain the test identifiers for each node.

[0009] Add the test identifier to the attribute of the corresponding node to obtain the target node.

[0010] Further, the step of inputting the element information of the nodes on the abstract syntax tree into a preset element processor for processing to obtain the test identifiers corresponding to each node includes:

[0011] Extract the attribute information of each node on the abstract syntax tree;

[0012] Select an element processor for each node based on the attribute information;

[0013] Select the element processor as the preset element processor for processing the corresponding node;

[0014] The corresponding node is input into the preset element processor to obtain the test identifier for each node.

[0015] Furthermore, before the step of adding the test identifier to the attribute of the corresponding node to obtain the target node, the method further includes:

[0016] Check if each node has a test identifier and check if the preset forced mode is enabled;

[0017] If the test identifier does not exist or the preset forced mode is enabled, then the condition for performing the step of adding the test identifier to the attribute of the corresponding node to obtain the target node is met.

[0018] Furthermore, after the step of adding the test identifier to the attribute of the corresponding node to obtain the target node, the method further includes:

[0019] The code corresponding to the target node is formatted to obtain a formatted node, which in turn yields the target abstract syntax tree;

[0020] Each formatted node on the target abstract syntax tree is rendered back into the source code to form the target file;

[0021] Collect the modified target files according to the code format of each target file;

[0022] A set of modified files is formed based on each modified target file, which is then used to perform automated tests.

[0023] Further, after the step of collecting the modified target files according to the code format of each target file, the process includes:

[0024] Record other files that were not collected;

[0025] The other files are sent to the designated terminal to add test identifiers, thereby obtaining the test files corresponding to the other files;

[0026] Automated testing is performed based on the test file.

[0027] Furthermore, the element processors include: form binding element processors, selector element processors, and button element processors.

[0028] Further, the step of extracting files of a specified format from a specified directory in the scanning system to form a first file set includes:

[0029] Retrieves multiple specified suffixes corresponding to a specified format;

[0030] Based on a specified directory in multiple specified suffix scanning systems, files with specified suffixes are extracted to form a first file set.

[0031] A smart addition device for test identifiers, the device comprising:

[0032] The scanning module is used to scan a specified directory in the system to extract files of a specified format and form a first file set;

[0033] The parsing module is used to parse each file in the first file set using a preset AST parser to generate an abstract syntax tree corresponding to each file; wherein, the abstract syntax tree stores the original structure of the corresponding file;

[0034] The input module is used to input the element information of the nodes on the abstract syntax tree into a preset element processor for processing, so as to obtain the test identifiers of each node.

[0035] An add module is used to add the test identifier to the attribute of the corresponding node to obtain the target node.

[0036] An electronic device includes a memory and a processor, the memory storing a computer program that, when executed by the processor, causes the processor to perform the following steps:

[0037] Scan the specified directory in the system to extract files of a specified format and form the first file set;

[0038] The first set of files is parsed using a preset AST parser to generate an abstract syntax tree corresponding to each file; wherein the abstract syntax tree stores the original structure of the corresponding file.

[0039] The element information of the nodes on the abstract syntax tree is input into a preset element processor for processing to obtain the test identifiers for each node.

[0040] Add the test identifier to the attribute of the corresponding node to obtain the target node.

[0041] A computer-readable storage medium storing a computer program, which, when executed by a processor, causes the processor to perform the following steps:

[0042] Scan the specified directory in the system to extract files of a specified format and form the first file set;

[0043] The first set of files is parsed using a preset AST parser to generate an abstract syntax tree corresponding to each file; wherein the abstract syntax tree stores the original structure of the corresponding file.

[0044] The element information of the nodes on the abstract syntax tree is input into a preset element processor for processing to obtain the test identifiers for each node.

[0045] Add the test identifier to the attribute of the corresponding node to obtain the target node.

[0046] The beneficial effects of this invention are as follows: By automatically scanning a specified directory to extract target files and forming a first file set, an abstract syntax tree (AST) is generated using a preset AST parser. Node information is then input into a preset element processor to generate identifiers that meet project requirements. These generated identifiers facilitate testers in quickly locating webpage elements, significantly improving the efficiency of front-end automated testing while reducing the daily workload of developers, providing strong support for the team's development and testing cycles. Attached Figure Description

[0047] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0048] in:

[0049] Figure 1 This is a diagram illustrating the application environment of a test identifier intelligent addition method in one embodiment.

[0050] Figure 2 A flowchart of a method for intelligently adding identifiers in one embodiment;

[0051] Figure 3 This is a structural block diagram of a smart addition device for test identifiers in one embodiment;

[0052] Figure 4 This is a structural block diagram of an electronic device in one embodiment. Detailed Implementation

[0053] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0054] Figure 1 A diagram illustrating the intelligent addition of an application environment for testing identifiers in one embodiment. (Refer to...) Figure 1 This intelligent method for adding test identifiers is applied to an intelligent test identifier addition system. The system includes a terminal 110 and a server 120. The terminal 110 and server 120 are connected via a network. The terminal 110 can be a desktop terminal or a mobile terminal; a mobile terminal can be at least one of a mobile phone, tablet, or laptop. The server 120 can be a standalone server or a server cluster consisting of multiple servers. The terminal 110 is used to retrieve files, and the server 120 is used to add test identifiers.

[0055] like Figure 2 As shown, in one embodiment, a method for intelligently adding test identifiers is provided. This method can be applied to both terminals and servers; this embodiment uses server application as an example. The intelligent addition method for test identifiers specifically includes the following steps:

[0056] S1: Scan the specified directory in the system to extract files of the specified format and form the first file set;

[0057] S2: Use a preset AST parser to parse each file in the first file set to generate an abstract syntax tree corresponding to each file; wherein, the abstract syntax tree stores the original structure of the corresponding file;

[0058] S3: Input the element information of the nodes on the abstract syntax tree into the preset element processor for processing to obtain the test identifiers of each node.

[0059] S4: Add the test identifier to the attribute of the corresponding node to obtain the target node.

[0060] Before step S1, you need to install the various dependency libraries required by the project using Node.js's package manager, npm (Node Package Manager). This can be done by executing the `npm install` command in the project root directory, which quickly installs all the necessary dependencies. These dependencies are typically defined and managed in the project's `package.json` file. After running this command, npm reads the dependencies and their version information listed in `package.json`, downloads the corresponding library files from the npm registry, and stores them in the project's `node_modules` directory. Once this is complete, the development and build environment is ready, laying the foundation for subsequent automated testing processes. System dependencies include: `commander` (for handling command-line arguments), `prettier` (for code formatting), and other necessary AST parsing and processing libraries.

[0061] As described in step S1 above, the specified directories in the system are scanned to extract files of a specified format, forming a first file set. This process typically involves several key steps: First, the system determines the root directory to be scanned and sets the file types to be processed (e.g., .html, .vue, etc.). Next, the system recursively reads the directory and all its subdirectories. To improve scanning efficiency and avoid processing unnecessary content, the system skips certain special directories, such as node_modules and .git, which typically contain dependency or version control information unrelated to the generation of test identifiers. During the scan, files that meet the criteria are identified, and their paths are saved to the first file set. At this point, the file information is not limited to the filename but also includes metadata such as the file path and type. This significantly saves time and manpower while ensuring that all files that need to be processed are included, laying the foundation for the intelligent addition of test identifiers.

[0062] As described in step S2 above, a preset AST parser is used to parse each file in the first file set to generate an abstract syntax tree (AST) corresponding to each file; wherein, the AST stores the original structure of the corresponding file. The preset Abstract Syntax Tree (AST) parser is used to parse the files in the first file set to generate their respective ASTs. An AST is a way to represent the syntactic structure of program source code in a tree structure, which can effectively reflect the original logic and relationships of the code. The parser reads the file content and, through a series of syntactic and semantic analyses, converts the code structure in the file into an AST. During the parsing process, the AST retains the original structure of the code, including comments and formatting. It should be noted that the generated AST is not just a simple syntactic structure; it also contains information about each node, such as the node's type, name, and its position in the code. This detailed information helps with subsequent identifier generation and also allows testers to intuitively understand and manipulate the code. In this way, source code can be analyzed at different levels, improving the accuracy and reliability of automated testing.

[0063] As described in S3 above, the element information of the nodes on the abstract syntax tree is input into a preset element processor for processing to obtain the test identifiers for each node. The generated abstract syntax tree's node element information is input into the preset element processor for processing to obtain the test identifiers for the corresponding nodes. The preset element processor is a logical module responsible for analyzing the attributes of each node in the AST and generating unique test identifiers based on pre-set rules. For example, if a node is a button and its filename is user-form.vue, the element processor might generate a test identifier similar to user-form-button-001. During processing, the processor can maintain an internal counter to ensure that each generated identifier is unique. If an identifier already exists, it will automatically increment to ensure the uniqueness of the identifier.

[0064] As described in step S4 above, the test identifier is added to the attribute of the corresponding node to obtain the target node. This process mainly involves operations on each node. The system traverses the previously generated abstract syntax tree (AST) to find the node to which the identifier needs to be added. For each node that needs a data-id attribute, the system checks its existing attributes to determine if an identifier already exists or if "Force mode" is enabled. If the node does not have a data-id attribute, or if "Force mode" is enabled, the system adds the test identifier generated in the previous processing steps to the corresponding node's attribute. During this process, the system processes each node one by one through the AST tree structure, modifying its attribute values. This operation not only dynamically changes the node structure but also ensures visual consistency of the code. After all target nodes are updated, the system typically performs final code formatting to ensure all modified code conforms to a unified style. The final generated file will contain the new data-id attribute for easy use in subsequent automated testing. This efficient processing flow reduces the tedium of manual operations and improves the automation level of testing and the maintainability of the code.

[0065] In one embodiment, step S3, which involves inputting the element information of the nodes on the abstract syntax tree into a preset element processor for processing to obtain the test identifiers for each corresponding node, includes:

[0066] S301: Extract the attribute information of each node on the abstract syntax tree;

[0067] S302: Select an element processor for each node based on the attribute information;

[0068] S303: Select the element processor as the preset element processor for processing the corresponding node;

[0069] S304: Input the corresponding node into the preset element processor to obtain the test identifier for each node.

[0070] As described in steps S301-S304 above, the specific method for obtaining the test identifier has been implemented.

[0071] In step S301, attribute information for each node is extracted from the generated Abstract Syntax Tree (AST) to obtain key information related to each node for subsequent generation of test identifiers. Node attribute information typically includes node type, node name, node parent relationship, and other node characteristics, such as existing attributes and child nodes.

[0072] The extraction process typically traverses the entire Abstract Syntax Tree (AST), using recursive or iterative algorithms to access each node. For each node, the system reads its associated attributes and stores them in a data structure, such as a dictionary or key-value pairs, for later processing. For example, a... Nodes may have attributes such as class, id, and children. This extracted information not only forms the basis for generating test identifiers but also informs subsequent element handler selection. By comprehensively extracting this _info_, the system ensures that all necessary information is captured, thus supporting the generation of appropriate, unique data-id identifiers.

[0073] In step S302, based on the extracted node attribute information, a corresponding element processor is selected for each node. The selection of processors ensures that processors holding specific logic can generate specific identifiers based on the node's type and characteristics. For example, different types of nodes (such as...) <button>、 <input> 、 (e.g., nodes may require different processors for processing.) The choice of which specific element processor to use depends on node attributes (such as node type, class name, or other custom attributes). For complex systems, further analysis may be needed based on the node hierarchy or parent relationships. Selecting the appropriate element processor can improve the accuracy and consistency of generated identifiers while ensuring that specific business logic requirements are met.

[0074] In step S303, a specific preset element processor is determined based on the selected conditions to serve as the tool for processing the corresponding node, ensuring that each node can be properly processed and a unique test identifier is generated. Specifically, a preset element processor library is invoked, and the selected processor is instantiated according to the logic chosen in the previous steps. In many cases, the preset element processors are implemented using design patterns, such as the factory pattern or the strategy pattern, allowing the processor implementation to be extended or modified at any time without affecting the operation of the entire system. This flexibility enables the system to easily adapt to new node types or processing logic according to actual needs. Finally, it is determined which tasks the specific processor will perform to generate a test identifier suitable for that node.

[0075] In step S304, the corresponding node information is input into the previously determined preset element processor to generate test identifiers for each node. The processor performs specific logical operations and processing based on the input node information, and finally returns the generated test identifiers. The specific operation involves passing the node's attribute information as parameters to the element processor. Internally, the element processor uses predefined rules (such as decisions based on node type) to construct unique test identifiers, which may include concatenating filenames, element types, and unique identifiers. The processor typically ensures that the generated identifiers conform to certain naming rules and format requirements so that users can quickly identify and flexibly locate them. Finally, the generated test identifiers are stored in an appropriate data structure as a basis for subsequent steps (adding attributes), ensuring that the system can efficiently process a large number of nodes, thus facilitating enhanced testing accuracy and automation.

[0076] In one embodiment, before step S4 of adding the test identifier to the attribute of the corresponding node to obtain the target node, the method further includes:

[0077] S311: Detect whether each node has a test identifier and whether the preset forced mode is enabled;

[0078] S312: If the test identifier does not exist or the preset forced mode is enabled, then it is determined that the condition for performing the step of adding the test identifier to the attribute of the corresponding node to obtain the target node is met.

[0079] As described in steps S311-S312 above, the system checks whether each node already has a test identifier and whether the preset forced mode is enabled. Specific operations include: checking the attributes of each node to confirm whether it already contains a data-id or other form of test identifier. The system quickly determines the status of each node using the previously extracted node attribute information. If a node already has a test identifier, this status is recorded to avoid duplicate additions, ensuring that the generated identifier is unique and non-repeating. Simultaneously, the system checks whether forced mode is enabled in the user or configuration file. Forced mode is designed to provide flexibility for adding test identifiers when necessary, such as when some nodes need to regenerate identifiers for specific reasons. Through this check, the system can effectively determine whether an identifier addition operation is needed, preparing for subsequent condition determination steps. The system decides whether the conditions for adding a test identifier are met based on the detection results. Specifically, if a node does not have a test identifier or forced mode is enabled, then this node meets the conditions for adding a new test identifier. Furthermore, this judgment logic allows the system to handle different situations flexibly, adapting to changing development needs and code states. If one or more conditions are true (i.e., no test identifier exists or forced mode is enabled), the node is marked as "test identifier needs to be added," making it easier to process these specific nodes in subsequent steps. Conversely, if a node already has an identifier and forced mode is not enabled, the system skips these nodes to maintain their original state. This design not only improves the efficiency of code processing but also ensures the uniqueness and consistency of identifiers, thus laying a solid foundation for effective automated testing.

[0080] In one embodiment, after step S4 of adding the test identifier to the attribute of the corresponding node to obtain the target node, the method further includes:

[0081] S501: Format the code corresponding to the target node to obtain a formatted node, and then obtain the target abstract syntax tree;

[0082] S502: Render each formatted node on the target abstract syntax tree back to the source code to form the target file;

[0083] S503: Collect the modified target files according to the code format of each target file;

[0084] S504: Creates a set of modified files based on each modified target file for use in executing automated tests.

[0085] As described in steps S501-S504 above, format unification has been achieved.

[0086] In step S1, the code corresponding to the target nodes with added test identifiers is formatted to ensure consistent code style and improve readability and maintainability. Formatting typically uses code formatting tools such as Prettier or ESLint, which automatically adjust the code layout, indentation, spaces, and line breaks according to the set code standards, ensuring that all code snippets conform to the predefined format requirements. Specifically, the target nodes are traversed, and the entire code block containing these nodes is reconstructed. By applying formatting rules to these nodes, the system outputs a standardized code structure, generating a new Abstract Syntax Tree (AST). During formatting, comments and code logic remain unchanged, while all visual inconsistencies (such as unnecessary whitespace and different indentation styles) are corrected. Formatting not only improves the overall quality of the code but also facilitates subsequent code management and version control.

[0087] In step S2, the final target file is generated by rendering each formatted node on the target Abstract Syntax Tree (AST) back to the source code. The formatted AST structure is converted back into readable code, ensuring that all node and attribute information is correctly serialized into the original programming language format (such as JavaScript, HTML, Vue, etc.). Specifically, the formatted AST is traversed according to the programming language's syntax rules, rendering layer by layer starting from the root node to generate the corresponding code strings. During this process, the system ensures that the order and structure of each node are consistent with the source file to maintain semantic coherence as much as possible. If necessary insertions or deletions are made during processing, the system will also make appropriate adjustments to ensure that the final code accurately reflects the original logic.

[0088] In step S503, the system collects files that have changed during the modification process, based on the code format of each target file. This process is crucial to ensuring that automated tests accurately reflect all code updates. Collecting modified target files not only means selecting temporary update files but also ensuring that the system tracks the file paths that have been processed and updated. Specific operations typically involve comparing the original and target files to check which files have changed content. This can be achieved by comparing hash values, timestamps, or directly comparing text, storing all changed file paths in a list or set for use in subsequent steps.

[0089] In step S504, a set of modified files is formed based on each modified target file for use in automated testing. This process essentially organizes all the modified target files collected in the previous step into a set, allowing testing tools to easily reference and process them during the automated testing phase. The key to forming this set of modified files lies in the data structure design; the system can use arrays, lists, or other collection types to organize these files. The path of each file and related metadata (such as modification time and type) can be included to provide more detailed context. Next, when the automated testing framework executes tests, it prioritizes this set of modified files, helping developers quickly verify whether new changes have caused functional issues or regression errors. This improves testing efficiency and enhances the transparency and traceability of the testing process, ensuring developers can promptly identify and fix potential problems. This process effectively integrates code updates, verification, and automated testing, thereby achieving an efficient and reliable development and testing cycle.

[0090] In one embodiment, after step S503 of collecting the modified target files according to the code format of each target file, the method includes:

[0091] S5041: Record other files that were not collected;

[0092] S5042: Send the other files to the designated terminal to add test identifiers, thereby obtaining the test files corresponding to the other files;

[0093] S5043: Execute automated tests based on the test file.

[0094] As described in steps S5041-S5043 above, automated testing of other file formats is achieved.

[0095] In step S5041, it's necessary to record any other files that weren't collected. Specifically, the system iterates through all files in the project, combining this with the list of modified files collected in the previous step to identify those that weren't collected. Typically, the system uses data structures (such as lists or sets) to record the paths of these files, and may also include file metadata such as file type and last modified time. This recording process is crucial because, in some cases, files that weren't directly modified may still involve the addition of identifiers or adjustments to other logic, thus affecting the overall automated test results. Recording these files creates a clear list, ensuring that no file that could potentially cause test failures is missed. This provides a complete file view for subsequent steps, enabling testers to better understand the project status and ensure comprehensive test coverage.

[0096] In step S5042, any other files not collected are sent to a designated terminal for the addition of test identifiers. This process aims to ensure that all relevant files have undergone the necessary processing for the next step of automated testing, especially those files that may be logically related to the target file. At this stage, the system sends each identified additional file to the designated terminal via network, file transfer protocol, or other communication method. This terminal may be a local development environment, a CI / CD (Continuous Integration / Continuous Delivery) server, or a machine used for additional processing. During the transfer process, the system typically ensures the integrity and confidentiality of the files to prevent data loss or tampering during transmission.

[0097] At this point, the terminal's processing logic is similar to the previous process, potentially involving the use of the same abstract syntax tree parsing and identifier addition tools, or it could involve manual identifier addition. This ensures project integrity and improves the automation level of test identifier management.

[0098] In step S5043, automated testing is performed based on the generated test files. The purpose of this process is to ensure that all processed files, as well as previously uncollected files, have undergone sufficient automated testing according to the latest code state. The processed test files contain necessary test identifiers, which serve as key criteria for locating elements within the testing framework. Executing automated testing typically involves several key steps: First, the testing framework reads the test files based on predefined test cases, identifying all components and functions that need to be tested. Next, the system uses the test identifiers to locate the corresponding nodes and executes corresponding operations according to predefined test scripts, such as clicking buttons, inputting text, and verifying information. During automated testing, test results are recorded, including successful and failed test cases, which is crucial for subsequent test improvements and code adjustments. If certain test targets fail, developers can quickly locate the problem and fix it promptly, ultimately ensuring the stability and reliability of the software. Through this process, the system can achieve timely response and effective verification of changes in the project, ensuring test coverage, improving code quality, and enhancing project delivery efficiency. This automated testing mechanism not only reduces the workload of manual testing but also accelerates product iteration and improves the efficiency of the development team.

[0099] In one embodiment, the element processor includes a form binding element processor, a selector element processor, and a button element processor. The element processor is designed with multiple dedicated processors to generate appropriate test identifiers based on different types of front-end elements. Specifically, these processors include a form binding element processor, a selector element processor, and a button element processor. Each processor, targeting a specific element type and behavior, can effectively generate corresponding identifiers, thereby improving the efficiency and accuracy of automated testing. The form binding element processor is mainly used to handle elements related to forms, such as... <input> , <textarea> and< / textarea> <select> The selector element processor is primarily used to process selector-type elements, including dropdown menus.< / select> ), checkboxes <input type="checkbox"> ) and radio buttons ( <input type="radio"> The button element processor is used to process button elements, such as... < / button> <button>and <input type="button"> wait.

[0100] In one embodiment, step S1, which involves scanning a specified directory in the system to extract files of a specified format to form a first file set, includes:

[0101] S101: Retrieves multiple specified suffixes corresponding to a specified format;

[0102] S102: Based on a specified directory in multiple specified suffix scanning systems, extract files with specified suffixes to form a first file set.

[0103] As described in steps S101-S102 above, multiple specified suffixes corresponding to the specified format are obtained. The main purpose of this step is to generate a list of suffixes that can be used for subsequent scanning and file extraction. The specified format is usually determined by project requirements; for example, some front-end applications may need to handle HTML, JavaScript, and Vue files. Commonly used file formats in the project may be considered in this step. To achieve this, the system defines an array or collection containing these suffixes. For example, if HTML and Vue files need to be processed, the system may define the suffixes as .html and .vue. This process may also include the ability to dynamically read suffix information from configuration files or environment variables to adapt to different environments and requirements. In this way, the system can flexibly adapt to various development environments without manually modifying the code every time requirements change. Obtaining the specified suffixes is the foundation of the file scanning process, ensuring that the files scanned in subsequent steps are limited to relevant and valuable files. This strategy not only reduces redundancy in the processing but also improves the efficiency of subsequent operations. Based on the obtained multiple specified suffixes, the specified directories in the system are scanned to extract files matching these suffixes, forming the first file set. This step is crucial for the system's actual file search and collection, ensuring that all necessary files are included in subsequent processing. Specifically, the system recursively traverses the specified directory and all its subdirectories, checking if the extension of each file is in the generated list of file extensions. Typically, the system uses file system APIs (such as the `fs` module in Node.js) to access and manipulate the file system. For each file, the system checks its path and name; if the file's extension matches the obtained list of extensions, the file's path is added to the first file set.

[0104] Reference Figure 3 The present invention also provides a smart device for adding test identifiers, the device comprising:

[0105] The scanning module 902 is used to scan a specified directory in the system to extract files of a specified format and form a first file set;

[0106] The parsing module 904 is used to parse each file in the first file set using a preset AST parser to generate an abstract syntax tree corresponding to each file; wherein, the abstract syntax tree stores the original structure of the corresponding file;

[0107] The input module 906 is used to input the element information of the nodes on the abstract syntax tree into a preset element processor for processing, so as to obtain the test identifiers of each node.

[0108] Add module 908, which is used to add the test identifier to the attribute of the corresponding node to obtain the target node.

[0109] In one embodiment, the input module 906 includes:

[0110] The attribute information extraction submodule is used to extract the attribute information of each node on the abstract syntax tree;

[0111] The element processor selection submodule is used to select an element processor for each node based on the attribute information.

[0112] The preset element processor marker submodule is used to select an element processor as the preset element processor for processing the corresponding node.

[0113] The test identifier acquisition submodule is used to input the corresponding node into the preset element processor to obtain the test identifier for each node.

[0114] In one embodiment, the intelligent addition device for test identifiers further includes:

[0115] The test identifier detection module is used to detect whether a test identifier exists on each node, and to detect whether the preset forced mode is enabled.

[0116] The condition determination module is used to determine whether the conditions for performing the step of adding the test identifier to the attribute of the corresponding node to obtain the target node are met if the test identifier does not exist or the preset forced mode is enabled.

[0117] In one embodiment, the intelligent addition device for test identifiers further includes:

[0118] The formatting module is used to format the code corresponding to the target node to obtain the formatted node, and then obtain the target abstract syntax tree;

[0119] The rendering module is used to render each formatted node on the target abstract syntax tree back to the source code to form the target file;

[0120] The target file collection module is used to collect modified target files according to the code format of each target file.

[0121] The generation module is used to generate a set of modified files based on each modified target file, which can then be used to perform automated tests.

[0122] In one embodiment, the smart addition device for test identifiers includes:

[0123] The Other Files Recording Module is used to record other files that were not collected.

[0124] The other file sending module is used to send the other files to a designated terminal to add test identifiers, thereby obtaining the test files corresponding to the other files;

[0125] An automated testing module is used to perform automated tests based on the test file.

[0126] In one embodiment, the element processor includes: a form binding element processor, a selector element processor, and a button element processor.

[0127] In one embodiment, the scanning module 902 includes:

[0128] The specified suffix retrieval submodule is used to retrieve multiple specified suffixes corresponding to a specified format;

[0129] The file extraction submodule is used to extract files with specified suffixes from specified directories in multiple specified suffix scanning systems to form a first file set.

[0130] Figure 4 An internal structural diagram of an electronic device in one embodiment is shown. This electronic device can specifically be a terminal or a server. Figure 4 As shown, the electronic device includes a processor, a memory, and a network interface connected via a system bus. The memory includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system and may also store a computer program. When executed by the processor, this computer program enables the processor to implement a method for intelligently adding test identifiers. The internal memory may also store a computer program, which, when executed by the processor, enables the processor to implement the method for intelligently adding test identifiers. Those skilled in the art will understand that... Figure 4 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the electronic device to which the present application is applied. The specific electronic device may include more or fewer components than shown in the figure, or combine certain components, or have different component arrangements.

[0131] In one embodiment, an electronic device is provided, including a memory and a processor, the memory storing a computer program that, when executed by the processor, causes the processor to perform the following steps:

[0132] Scan the specified directory in the system to extract files of a specified format and form the first file set;

[0133] The first set of files is parsed using a preset AST parser to generate an abstract syntax tree corresponding to each file; wherein the abstract syntax tree stores the original structure of the corresponding file.

[0134] The element information of the nodes on the abstract syntax tree is input into a preset element processor for processing to obtain the test identifiers for each node.

[0135] Add the test identifier to the attribute of the corresponding node to obtain the target node.

[0136] By automatically scanning a specified directory to extract target files and forming a first file set, an Abstract Syntax Tree (AST) is generated using a preset AST parser. Node information is then input into a preset element processor to generate identifiers that meet project requirements. These generated identifiers facilitate quick location of web page elements by testers, significantly improving the efficiency of front-end automated testing while reducing the daily workload of developers, providing strong support for the team's development and testing cycles.

[0137] In one embodiment, a computer-readable storage medium is provided storing a computer program that, when executed by a processor, causes the processor to perform the following steps:

[0138] Scan the specified directory in the system to extract files of a specified format and form the first file set;

[0139] The first set of files is parsed using a preset AST parser to generate an abstract syntax tree corresponding to each file; wherein the abstract syntax tree stores the original structure of the corresponding file.

[0140] The element information of the nodes on the abstract syntax tree is input into a preset element processor for processing to obtain the test identifiers for each node.

[0141] Add the test identifier to the attribute of the corresponding node to obtain the target node.

[0142] By automatically scanning a specified directory to extract target files and forming a first file set, an Abstract Syntax Tree (AST) is generated using a preset AST parser. Node information is then input into a preset element processor to generate identifiers that meet project requirements. These generated identifiers facilitate quick location of web page elements by testers, significantly improving the efficiency of front-end automated testing while reducing the daily workload of developers, providing strong support for the team's development and testing cycles.

[0143] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and RAMbus dynamic RAM (RDRAM), etc.

[0144] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0145] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this patent application should be determined by the appended claims.< / button>

Claims

1. A method for intelligently adding test identifiers, characterized in that, The method includes: Scan the specified directory in the system to extract files of a specified format and form the first file set; The first set of files is parsed using a preset AST parser to generate an abstract syntax tree corresponding to each file; wherein the abstract syntax tree stores the original structure of the corresponding file. The element information of the nodes on the abstract syntax tree is input into a preset element processor for processing to obtain the test identifiers for each node. Add the test identifier to the attribute of the corresponding node to obtain the target node.

2. The intelligent addition method for test identifiers according to claim 1, characterized in that, The step of inputting the element information of the nodes on the abstract syntax tree into a preset element processor for processing to obtain the test identifiers for each corresponding node includes: Extract the attribute information of each node on the abstract syntax tree; Select an element processor for each node based on the attribute information; Select the element processor as the preset element processor for processing the corresponding node; The corresponding node is input into the preset element processor to obtain the test identifier for each node.

3. The intelligent addition method for test identifiers according to claim 1, characterized in that, Before the step of adding the test identifier to the attribute of the corresponding node to obtain the target node, the method further includes: Check if each node has a test identifier and check if the preset forced mode is enabled; If the test identifier does not exist or the preset forced mode is enabled, then the condition for performing the step of adding the test identifier to the attribute of the corresponding node to obtain the target node is met.

4. The intelligent addition method for test identifiers according to claim 1, characterized in that, After the step of adding the test identifier to the attribute of the corresponding node to obtain the target node, the method further includes: The code corresponding to the target node is formatted to obtain a formatted node, which in turn yields the target abstract syntax tree; Each formatted node on the target abstract syntax tree is rendered back into the source code to form the target file; Collect the modified target files according to the code format of each target file; A set of modified files is formed based on each modified target file, which is then used to perform automated tests.

5. The intelligent addition method for test identifiers according to claim 4, characterized in that, After the step of collecting the modified target files according to the code format of each target file, the following steps are included: Record other files that were not collected; The other files are sent to the designated terminal to add test identifiers, thereby obtaining the test files corresponding to the other files; Automated testing is performed based on the test file.

6. The intelligent addition method for test identifiers according to claim 1, characterized in that, The element processors include: form binding element processors, selector element processors, and button element processors.

7. The intelligent addition method for test identifiers according to claim 1, characterized in that, The step of extracting files of a specified format from a specified directory in the scanning system to form a first file set includes: Retrieves multiple specified suffixes corresponding to a specified format; Based on a specified directory in multiple specified suffix scanning systems, files with specified suffixes are extracted to form a first file set.

8. A smart device for adding test identifiers, characterized in that, The device includes: The scanning module is used to scan a specified directory in the system to extract files of a specified format and form a first file set; The parsing module is used to parse each file in the first file set using a preset AST parser to generate an abstract syntax tree corresponding to each file; wherein, the abstract syntax tree stores the original structure of the corresponding file; The input module is used to input the element information of the nodes on the abstract syntax tree into a preset element processor for processing, so as to obtain the test identifiers of each node. An add module is used to add the test identifier to the attribute of the corresponding node to obtain the target node.

9. A computer-readable storage medium, characterized in that, The system stores a computer program that, when executed by a processor, causes the processor to perform the steps of the intelligent addition method for the test identifier as described in any one of claims 1 to 7.

10. An electronic device, characterized in that, The device includes a memory and a processor, the memory storing a computer program that, when executed by the processor, causes the processor to perform the steps of the smart addition method for the test identifier as described in any one of claims 1 to 7.