Test script generation method and device, equipment, medium and product

By simplifying the page document structure and determining the contextual dependencies of target test elements, automated test scripts are generated, solving the problem of frequent script failures caused by page structure changes in existing technologies, and improving the efficiency and adaptability of test script generation.

CN120994558APending Publication Date: 2025-11-21INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511125329.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-08-12
Publication Date
2025-11-21

AI Technical Summary

Technical Problem

Existing automated test script solutions based on recording and playback are extremely sensitive to changes in page structure, causing scripts to frequently fail, requiring extensive maintenance, and reducing the efficiency of test script generation.

Method used

By acquiring the operation sequence and response page, the document structure is simplified, the location information and contextual dependencies of the target test elements are determined, a script logic description of the temporal relationship is established, and test scripts are generated.

Benefits of technology

It improves the efficiency of test script generation, reduces location failures caused by page changes, and enhances the adaptability and accuracy of the script.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120994558A_ABST
    Figure CN120994558A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a test script generation method and device, equipment, a medium and a product, and relates to the field of financial science and technology or other related fields. The method comprises the steps of obtaining an operation sequence triggered on an interface of a to-be-tested application and a response page corresponding to operation; according to a test requirement, simplifying and storing a document structure of the response page, and determining positioning information of a target test element in the response page; and determining a context dependency relationship corresponding to the target test element based on the simplified document structure of the response page, so as to generate a test script of the to-be-tested application after the script logic description of the time sequence relationship is established. According to the method provided by the invention, the complexity of the document structure is reduced by selectively storing the document structure of the corresponding page according to requirements, and the situation of positioning failure caused by page change is reduced by positioning the element based on the element selector and the multi-dimensional information of the element attribute, so that the test script generation efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of financial technology or other related fields, and in particular to a method, apparatus, device, medium and product for generating test scripts. Background Technology

[0002] In financial applications such as banking, key business processes such as user login, account management, fund transfers, loan applications, and transaction inquiries require application testing to ensure functional correctness, data security, and user experience. To improve testing efficiency, automated test scripts are typically used to simulate user behavior, verify business processes, and enable large-scale regression testing.

[0003] One related automated testing solution based on recorded playback script generation works by recording user actions on the interface, such as clicks, inputs, and selections, and automatically generating corresponding test scripts. However, this solution is extremely sensitive to changes in page structure. Even minor adjustments to the front-end page, such as changes to element names or page hierarchy, can cause the script to malfunction, requiring multiple maintenance steps and reducing the efficiency of test script generation. Summary of the Invention

[0004] This application provides a test script generation method, apparatus, device, medium, and product to improve the efficiency of test script generation.

[0005] Firstly, this application provides a test script generation method, comprising: acquiring the operation sequence triggered on the interface of the application under test and the corresponding response page; simplifying and storing the document structure of the response page according to test requirements, determining the location information of the target test element in the response page, the location information including element selector and element attributes; determining the context dependency relationship corresponding to the target test element based on the simplified document structure of the response page; establishing a script logic description of the timing relationship based on the location information of the target test element and the context dependency relationship corresponding to the target test element; and generating the test script of the application under test based on the script logic description.

[0006] Secondly, this application provides a test script generation apparatus, comprising: an acquisition module, configured to acquire the operation sequence triggered on the interface of the application under test and the corresponding response page; a determination module, configured to simplify and store the document structure of the response page according to test requirements, determine the location information of the target test element in the response page, the location information including element selector and element attributes; and determine the context dependency relationship corresponding to the target test element based on the simplified document structure of the response page; a generation module, configured to establish a script logic description of the timing relationship based on the location information of the target test element and the context dependency relationship corresponding to the target test element; and generate a test script for the application under test based on the script logic description.

[0007] Thirdly, this application provides an electronic device, including: a processor, and a memory communicatively connected to the processor;

[0008] The memory stores instructions that the computer executes;

[0009] The processor executes computer-executable instructions stored in memory to achieve the above method.

[0010] Fourthly, this application provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the above-described method.

[0011] Fifthly, this application provides a computer program product, including a computer program that, when executed by a processor, implements the method described above.

[0012] This application provides a test script generation method, apparatus, device, medium, and product. The method includes: acquiring the operation sequence triggered on the interface of the application under test and the corresponding response page; simplifying and storing the document structure of the response page according to test requirements, and determining the location information of the target test element in the response page; and determining the context dependency relationship corresponding to the target test element based on the simplified document structure of the response page, so as to generate the test script of the application under test after establishing the script logic description of the timing relationship. The method of this application selectively stores the document structure of the corresponding page according to requirements, reducing the complexity of the document structure. It also reduces the possibility of location failure due to page modifications by locating elements based on multi-dimensional information of element selectors and element attributes, thereby improving the efficiency of test script generation. Attached Figure Description

[0013] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

[0014] Figure 1 A flowchart illustrating the test script generation method provided in this application embodiment;

[0015] Figure 2 A flowchart illustrating the test script generation method provided in this application embodiment;

[0016] Figure 3 A flowchart illustrating the test script generation method provided in this application embodiment;

[0017] Figure 4 A flowchart illustrating the test script generation method provided in this application embodiment;

[0018] Figure 5A flowchart illustrating the test script generation method provided in this application embodiment;

[0019] Figure 6 This is a schematic diagram of the test script generation device provided in the embodiments of this application;

[0020] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.

[0021] The accompanying drawings have illustrated specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to specific embodiments. Detailed Implementation

[0022] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.

[0023] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, storage, use, processing, transmission, provision, disclosure, and application of the relevant data all comply with the relevant laws, regulations, and standards of the relevant countries and regions, have taken necessary confidentiality measures, do not violate public order and good morals, and provide corresponding operation access points for users to choose to authorize or refuse.

[0024] Furthermore, the technical solution involved in this application, which involves big data analysis of user information (including but not limited to personal biometrics, identity data, consumption data, asset data, electronic terminal operation data, etc.) and the use of artificial intelligence technology for automated decision-making, and makes decisions that have a significant impact on personal rights based on the results of automated decision-making, provides users with corresponding operation entry points for users to choose to agree to or reject the results of automated decision-making; if the user chooses to reject, the process will proceed to the expert decision-making process.

[0025] It should be noted that the test script generation method, apparatus, equipment, medium and product provided in this application can be used in the field of fintech, or in any field other than fintech. The application field of the test script generation method, apparatus, equipment, medium and product in this application is not limited.

[0026] In the financial sector, rigorous testing of websites and applications related to critical banking operations is crucial. This includes, but is not limited to, core functional modules such as user login authentication, account balance inquiry, fund transfers (intra-bank / inter-bank), bill payment, investment and wealth management transactions, credit card application and management, loan application processes, and personal information modification. These aspects directly relate to user fund security, privacy protection, and business continuity; any functional defects or process interruptions can have serious consequences. To ensure that these high-frequency operations and high-risk processes operate stably, accurately, and efficiently in various scenarios and meet stringent compliance requirements, manual testing alone is insufficient in terms of coverage and execution efficiency. Therefore, introducing automated test scripts to simulate user operations, verify business processes, check data consistency, and perform regression testing has become the mainstream choice for improving testing quality and efficiency.

[0027] A common method for automated script generation is based on recording and playback to automatically generate corresponding test scripts. In this approach, testers manually perform the actions to be tested on the browser or application interface, such as clicking buttons, entering text, and selecting dropdown menus. A dedicated recording tool captures these actions and the positioning information of the corresponding UI elements, such as buttons and input boxes. After recording, the tool generates an executable script that, during playback, attempts to locate the elements using the same positioning method and repeat the actions, following the recorded steps. However, this approach is extremely sensitive to changes in page structure. Any minor adjustments made by the front-end user, such as changes to element names, element levels, hierarchical adjustments, or the addition / deletion of elements, can cause the locators used by the script to become invalid, resulting in playback failure. This leads to significant investment in script maintenance, requiring testers to continuously update the locators manually based on interface changes.

[0028] The technical content provided in this application aims to solve the above-mentioned technical problems of the prior art. The test script generation method, apparatus, device, medium, and product provided in this application include: acquiring the operation sequence triggered on the interface of the application under test and the corresponding response page; simplifying and storing the document structure of the response page according to test requirements, and determining the location information of the target test element in the response page; and determining the context dependency relationship corresponding to the target test element based on the simplified document structure of the response page, so as to generate the test script of the application under test after establishing the script logic description of the timing relationship. The method of this application selectively stores the document structure of the corresponding page according to requirements, reducing the complexity of the document structure; and locates elements based on multi-dimensional information of element selectors and element attributes, reducing the possibility of location failure due to page modifications, thereby improving the efficiency of test script generation.

[0029] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will now be described with reference to the accompanying drawings.

[0030] Figure 1 This is a flowchart illustrating the test script generation method provided in an embodiment of this application, as shown below. Figure 1 As shown, the method includes:

[0031] S101. Obtain the sequence of operations triggered on the interface of the application under test and the corresponding response page;

[0032] S102. Based on the test requirements, simplify and store the document structure of the response page, determine the location information of the target test element in the response page, including the element selector and element attributes; and determine the context dependency relationship corresponding to the target test element based on the simplified document structure of the response page.

[0033] S103. Based on the location information of the target test element and the context dependency relationship corresponding to the target test element, establish a script logic description of the timing relationship; based on the script logic description, generate the test script of the application to be tested.

[0034] In practical applications, the execution entity of this method can be a test script generation device, which can be implemented in various ways. For example, it can be implemented through a computer program, such as application software; or it can be implemented as a medium storing the relevant computer program, such as a cloud disk; or it can be implemented through a physical device that integrates or installs the relevant computer program, such as a chip.

[0035] In some embodiments, the application under test can be a web application, a mobile application, or a desktop application. It should be noted that the application under test should be able to obtain the page structure through a programming interface or debugging protocol.

[0036] For example, user actions such as clicks, inputs, and swipes on the application interface under test can be captured using automated testing tools or behavior logging tools, generating corresponding action sequences. These tools record action types, such as button IDs, input box content, and page jumps or dynamic content changes triggered by the actions, in chronological order. Further, after each action, the tool extracts the current page's document structure, such as the HTML (HyperText Markup Language) DOM tree (Document Object Model) or mobile view hierarchy, and saves it as structured data in formats such as JSON or XML (JavaScript ObjectNotation or eXtensible Markup Language). Optionally, for dynamic content that requires asynchronous loading, capture should wait until the page state stabilizes before capturing.

[0037] In some embodiments, after obtaining the document structure of the corresponding page, it is also necessary to simplify the document structure of the response page corresponding to the operation. For example, the document structure can be denoised, such as removing nodes irrelevant to the test, such as advertisements and decorative elements, while retaining core interactive components such as forms and lists; the document structure can be aggregated, such as abstracting repetitive sub-modules, such as product list items, into templates, retaining only the different attributes, such as product IDs; the document structure can also be standardized, such as replacing dynamically generated IDs or class names with semantic tags.

[0038] For example, an element selector can be a unique identifier for an element, or an XPath (XML Path Language) or CSS (Cascading Style Sheets) selector for the element. For example, element attributes can be attributes needed for testing, such as the value of an input field, the operable state of a button or text field, value constraints on visual elements such as text content, and icon type, reducing attributes irrelevant to the test.

[0039] In some embodiments, the determined contextual dependencies can include various factors, such as analyzing whether the target test element depends on its parent container (e.g., a dropdown menu requires triggering a parent button first); whether the target test element only appears under specific conditions (e.g., a menu displayed only after login); or whether the content of the target test element depends on a preceding operation (e.g., an order number generated after form submission). In practical applications, by analyzing the changes in page structure before and after the operation sequence, the appearance conditions, disappearance conditions, and associated operations of the target test element are marked.

[0040] Furthermore, based on the location information of the target test element and its corresponding contextual dependencies, a script logic description establishing a temporal relationship can be understood as a mapping process of operation sequences, that is, converting user operations into script steps. For example, a user operation sequence such as "login → input → submit" can be broken down into atomic operations, each bound to a specific target test element. The location information of the target test element is directly referenced in the script logic description, enabling the operation to accurately trigger the target test element. The final obtained script logic description could be: first, click the login button; second, input the username; third, submit the form. It should be noted that because the generated script logic description considers the contextual dependencies of the target test element, the accuracy of locating the target test element can be further improved.

[0041] In some optional embodiments, the script logic description can also be adjusted according to the response page, such as selecting "Confirm" or "Cancel" after the detection pop-up, or inserting waiting conditions such as performing visibility checks on the target test element or waiting for the network request to complete in the script logic description, so as to improve the correctness of the timing.

[0042] In some embodiments, a test framework template can be applied based on the script logic description. Specifically, the script logic description needs to be mapped to statements supported by the test framework, such as "click element X" corresponding to the click() method. In some optional embodiments, dynamic data such as username and password in the script logic description can also be extracted as variables to support reuse of multiple test cases.

[0043] The test script generation method provided in this application includes: obtaining the operation sequence triggered on the interface of the application under test and the corresponding response page; simplifying and storing the document structure of the response page according to the test requirements, and determining the location information of the target test element in the response page; and determining the context dependency relationship corresponding to the target test element based on the simplified document structure of the response page, so as to generate the test script of the application under test after establishing the script logic description of the timing relationship. The method of this application selectively stores the document structure of the corresponding page according to the requirements, reducing the complexity of the document structure; and locates elements based on multi-dimensional information of element selectors and element attributes, reducing the possibility of location failure due to page changes, thereby improving the efficiency of test script generation.

[0044] Figure 2 This is a flowchart illustrating the test script generation method provided in an embodiment of this application, as shown below. Figure 2 As shown, the method also includes:

[0045] S201. Construct a weight matrix, which includes multiple weight values ​​that correspond one-to-one with the target test elements; wherein, the weight values ​​are proportional to the test frequency of the corresponding target test elements.

[0046] S202. Based on the context dependency relationship corresponding to the target test element, increase the weight value of the target test element when the target test element meets any of the following conditions: the target test element triggers page jump, or the correlation between the target test element and other target test elements is higher than a preset threshold.

[0047] S103 describes the script logic for establishing timing relationships based on the location information of the target test element and the context dependencies corresponding to the target test element, including:

[0048] S203. Based on the location information of the target test element and the context dependency relationship corresponding to the target test element, establish a script logic description of the temporal relationship based on the test weight matrix.

[0049] For example, the weight matrix can be stored in the form of a table, which may include a unique identifier for the target test element and its corresponding weight value. It can be understood that the weight value corresponding to the target test element can be divided into initial weight values ​​and dynamic weight values. Specifically, the initial weight value can be manually imported by the tester or be an initial value based on the historical testing frequency of the target test element; for example, if a button is operated 80 times in 100 tests, its weight is 0.8. The dynamic weight value is determined based on the contextual dependencies of the target test element. In practical applications, a lower weight limit can also be set for target test elements with low operation frequency to avoid completely ignoring them.

[0050] In some embodiments, for web applications, changes in the page URL can be monitored, while for mobile applications, changes in the interface route identifier can be used to determine if a page redirect has been triggered. For example, a fixed value can be added to the weight of the target test element that triggered the redirect. If the redirection of the target test element results in changes to multiple levels of pages, such as from the homepage → details page → payment page, the weight value corresponding to the target test element is increased progressively at each level.

[0051] Furthermore, the association between target test elements and other target test elements can be: structural association: proximity in the DOM tree or view hierarchy, such as input boxes within the same form; behavioral association: the probability of consecutive occurrences in an action sequence, such as clicking login immediately after entering a password; data association: sharing the same data source. In practical applications, the median of all target test elements in the test case can be obtained to determine the baseline value of the degree of association, and a preset threshold can be determined based on the baseline value.

[0052] It's important to note that without a weighting mechanism, the script logic description treats all target test elements uniformly. For example, when testing an e-commerce application, the operation sequence might be: select a product, view the shopping cart, click checkout, and fill out the order. All steps are executed with equal frequency and validation intensity; the script checks for the existence of basic elements on each page but doesn't focus on deep coverage of core functions. With the introduction of a weighting matrix, for instance, the "checkout button," which triggers page navigation, will have its weight increased. This will result in priority execution and additional validation layers, such as checking the order page loading after clicking checkout, and mandatory verification of payment method options, order price consistency, and real-time inventory updates. Furthermore, the "inventory notification," highly correlated with the "checkout button," has its weight increased, and the script logic description inserts inventory check logic before checkout. If insufficient inventory is detected, a preset branch is immediately triggered, such as prompting the user or switching products, rather than simply skipping it. Finally, the "shopping cart icon," with its reduced weight, has its operation frequency decreased; the script logic description is changed to execute this path once every three tests, freeing up resources for higher-weighted steps.

[0053] The solution presented in this example optimizes the timing relationship of the script logic description by constructing a weight matrix that is proportional to the testing frequency of the target test element and dynamically adjusting the weight values ​​when specific conditions are met. This improves the rationality of test resource allocation and test efficiency.

[0054] Figure 3 This is a flowchart illustrating the test script generation method provided in an embodiment of this application, as shown below. Figure 3 As shown, the method also includes:

[0055] S301. Obtain the business domain script library and the historical execution script library; different business domain scripts in the business domain script library have different script processes; the historical execution script library includes: historical execution scripts and corresponding execution logs; the execution logs include: the implementation paths of multiple implementation scripts under the same historical execution script, the waiting time of operation steps, and the retry strategy;

[0056] S302. Train the script generation model based on the business domain script library and the historical execution script library;

[0057] S103 generates test scripts for the application under test based on script logic descriptions, including:

[0058] S303. Input the script logic description into the script generation model, and generate the test script for the application under test based on the output of the script generation model.

[0059] For example, the script processes for different application platforms, such as e-commerce platforms and banking platforms, can be different or partially the same. For instance, both may have script processes for user registration and transaction payment. Specifically, the same application platform can be divided into multiple business areas. For example, an e-commerce platform includes business areas such as user registration, product search, and order payment, and the script processes for each business area will differ. For instance, the user registration script process might include steps such as entering a username, setting a password, and verifying an email address, while the order payment script process might include steps such as selecting products, confirming the order, and entering payment information. As another example, the transfer process on a banking platform includes large-amount transfers and small-amount transfers. The script process for large-amount transfers will have additional manual review steps, such as pop-up confirmation and secondary verification via SMS verification codes, while the script process for small-amount transfers will directly use the quick payment channel without manual intervention.

[0060] In some embodiments, the historical execution script library includes multiple historical execution scripts and execution logs corresponding to each historical execution script. In practical applications, the same test objective can be achieved through different paths, and all feasible solutions need to be recorded. For example, a typical process path A includes: searching for products on the homepage, adding to cart, checkout, and payment; a promotional activity process path B includes: claiming coupons on the activity page, directly jumping to the product details page, one-click purchase, and payment; and a low-stock scenario path C includes: detecting insufficient stock in the shopping cart, automatically recommending similar products, and checking out after replacement.

[0061] It's important to note that in an automated test script, a certain operation step might require waiting for background processing to complete, such as waiting for a response from a payment gateway. In this case, the waiting time can be set to 30 seconds. If no response is received within 30 seconds, a retry strategy can be triggered, for example, retrying twice with a 10-second interval between each attempt. The script generation model can use the execution logs of historically executed scripts to determine a reasonable waiting time and retry strategy for operation steps when generating subsequent test scripts.

[0062] In some embodiments, the script generation model is capable of understanding and processing script logic descriptions and generating corresponding test scripts. For example, the script generation model can be a natural language processing model, where a model using natural language processing techniques can parse and understand script logic descriptions in natural or semi-structured language form. For example, the script generation model can also be a sequence-to-sequence model, used to handle tasks where both input and output are sequences; that is, in script generation, the input sequence can be a script logic description, and the output sequence is the generated test script. Optionally, the script generation model can also be a hybrid model combining multiple technologies to perform tasks suitable for complexity.

[0063] The solution presented in this example utilizes a business domain script library and a historical execution script library to train a script generation model, enabling it to understand script logic descriptions and automatically generate test scripts that conform to business domain process specifications and have reasonable waiting times and retry strategies, thereby improving the automation level and execution efficiency of the testing process.

[0064] Figure 4 This is a flowchart illustrating the test script generation method provided in an embodiment of this application, as shown below. Figure 4 As shown, the method also includes:

[0065] S401. Obtain the test results of the test script of the application under test;

[0066] S402. Use the test script of the application under test as the historical execution script and the test results as the execution log to train the script generation model.

[0067] For example, after executing a test script, its test results can be recorded, such as the execution status (success or failure), response time, error type (e.g., element not found, timeout, data mismatch), and number of retries. Furthermore, the test script and its execution logs (including operation paths, waiting strategies, and retry records) are stored in a historical execution script library as model training data.

[0068] In some embodiments, the script generation strategy is adjusted based on the test results. For example, if a target test element times out frequently, its location method is optimized or the default waiting time is extended; if a business path has a high failure rate, alternative paths are generated first or the exception handling logic is enhanced.

[0069] The approach in this example continuously optimizes and improves the script generation model by feeding the newly generated test scripts and their test results back into the training process, thereby enhancing the accuracy and adaptability of the generated test scripts.

[0070] Figure 5 This is a flowchart illustrating the test script generation method provided in an embodiment of this application, as shown below. Figure 5 As shown, in S303, the test script for the application under test is generated based on the output of the script-generated model, including:

[0071] S501. Based on a preset script template, the output of the script generation model is converted into an initial test script; different script templates correspond to different programming languages.

[0072] S502. Provide the user with a first interface so that the user can return to the script modification information;

[0073] S503. Update the initial test script according to the script modification information, and use the updated test script as the test script for the application under test.

[0074] For example, conversion based on preset script templates can include many aspects, such as preset script template libraries for different programming languages ​​(such as Python, Java, JavaScript) and automatically matching them according to user needs or project technology stack; such as converting the logical description of the model output, such as "click the login button", into valid code in the target language, such as Python's click(login_button); such as inserting necessary framework code according to script template rules, such as test class declarations, assertion library imports, etc.

[0075] This example also provides a user-friendly initial interface that allows users to view the generated initial test script and provide modification suggestions. The interface should support user input of script modification information, such as adjusting time intervals, adding or modifying logical judgments (such as if and for statements), etc.

[0076] Furthermore, the initial test script is dynamically updated based on the modifications provided by the user. Specifically, the update process should include parsing the user input, applying it to the script, and ensuring that the generated script is syntactically and logically correct. Optionally, the user-adjusted if statements can also be parsed into business rules and stored in the business domain knowledge base.

[0077] This example solution achieves flexibility and customizability in generating test scripts by pre-setting script templates for different programming languages ​​and testing frameworks and adjusting them in real time using a user interface. This allows users to dynamically modify test scripts according to specific needs, improving the applicability and efficiency of script generation.

[0078] As yet another example, based on any previous example, S102 simplifies and stores the document structure of the response page according to test requirements, including:

[0079] For each node in the document structure of the response page, if the node is the node corresponding to the target test element, then store all child nodes of the node; if the node is not the node corresponding to the target test element, then store the parent node of the node.

[0080] In some embodiments, the page structure of a bank transfer confirmation page in a bank transfer scenario includes: an amount input field, an error message, a security prompt, and a confirmation button. Specifically, when the target test element includes an error message indicating that the amount has exceeded the limit, all content of its corresponding partition, such as the input field and the error message, is stored. For non-target test elements such as security prompts and confirmation buttons, only the name of the large block to which the full prompt and confirmation button belong is recorded.

[0081] In other embodiments, when the target test element of an e-commerce website's shopping cart page is the total price of the goods, and this total price is located within a node in the document structure, this node contains the total price information. On one hand, all child nodes of this node are stored to ensure that all information related to the total price, such as taxes and discounts, is captured. On the other hand, for nodes that do not contain total price information, only their parent nodes are stored to reduce unnecessary details. For example, the parent node of the product list is stored instead of the detailed information for each product.

[0082] This example simplifies the document structure of the response page by storing only the child nodes of the nodes related to the target test element and the parent nodes of the non-target nodes, reducing data redundancy and improving the efficiency and relevance of test data processing.

[0083] In some examples, the generated scripts can be tested using script-based automated testing tools. Specifically, first, an automated test task is created, and a version control system is configured to access the code repository storing the automated scripts and designated branches, ensuring the task obtains the latest test scripts. Next, a trigger mechanism is set up to automatically start the test task at a specific time or event via network hooks or scheduled tasks. Once the task starts, the latest code is pulled from the code repository into the execution environment, and the necessary dependencies, such as the programming language runtime and related tools, are installed and configured to ensure the test scripts run in the appropriate environment. Subsequently, the preset automated test scripts are executed. After the test is completed, the test results are parsed and a standard-format test report is generated, providing detailed test results and analysis. Finally, the test report can be sent to relevant personnel via email or other notification methods, allowing team members to promptly understand the test results and system status, enabling them to quickly take necessary measures for adjustment and optimization. Through this process, the testing process achieves a high degree of automation and real-time performance, improving testing efficiency and response speed.

[0084] The test script generation method provided in this application includes: obtaining the operation sequence triggered on the interface of the application under test and the corresponding response page; simplifying and storing the document structure of the response page according to the test requirements, and determining the location information of the target test element in the response page; and determining the context dependency relationship corresponding to the target test element based on the simplified document structure of the response page, so as to generate the test script of the application under test after establishing the script logic description of the timing relationship. The method of this application selectively stores the document structure of the corresponding page according to the requirements, reducing the complexity of the document structure; and locates elements based on multi-dimensional information of element selectors and element attributes, reducing the possibility of location failure due to page changes, thereby improving the efficiency of test script generation.

[0085] Figure 6This is a schematic diagram of the test script generation device provided in the embodiments of this application, as shown below. Figure 6 As shown, the device includes:

[0086] The acquisition module 61 is used to acquire the sequence of operations triggered on the interface of the application under test and the corresponding response page of the operation;

[0087] The determination module 62 is used to simplify and store the document structure of the response page according to the test requirements, determine the location information of the target test element in the response page, including the element selector and element attributes; and determine the context dependency relationship corresponding to the target test element based on the simplified document structure of the response page.

[0088] The generation module 63 is used to establish a script logic description of the timing relationship based on the location information of the target test element and the context dependency relationship corresponding to the target test element; and to generate the test script of the application under test based on the script logic description.

[0089] In practical applications, there are various ways to implement a test script generation device. For example, it can be implemented through a computer program, such as application software; or it can be implemented as a medium storing the relevant computer program, such as a cloud drive; or it can be implemented through a physical device that integrates or installs the relevant computer program, such as a chip.

[0090] In some embodiments, the application under test can be a web application, a mobile application, or a desktop application. It should be noted that the application under test should be able to obtain the page structure through a programming interface or debugging protocol.

[0091] For example, user actions such as clicks, inputs, and swipes on the application interface under test can be captured using automated testing tools or behavior logging tools, generating corresponding action sequences. These tools record action types, such as button IDs, input box content, and page jumps or dynamic content changes triggered by the actions, in chronological order. Further, after each action, the tool extracts the current page's document structure, such as the HTML (HyperText Markup Language) DOM tree (Document Object Model) or mobile view hierarchy, and saves it as structured data in formats such as JSON or XML (JavaScript ObjectNotation or eXtensible Markup Language). Optionally, for dynamic content that requires asynchronous loading, capture should wait until the page state stabilizes before capturing.

[0092] In some embodiments, after obtaining the document structure of the corresponding page, it is also necessary to simplify the document structure of the response page corresponding to the operation. For example, the document structure can be denoised, such as removing nodes irrelevant to the test, such as advertisements and decorative elements, while retaining core interactive components such as forms and lists; the document structure can be aggregated, such as abstracting repetitive sub-modules, such as product list items, into templates, retaining only the different attributes, such as product IDs; the document structure can also be standardized, such as replacing dynamically generated IDs or class names with semantic tags.

[0093] For example, an element selector can be a unique identifier for an element, or an XPath (XML Path Language) or CSS (Cascading Style Sheets) selector for the element. For example, element attributes can be attributes needed for testing, such as the value of an input field, the operable state of a button or text field, value constraints on visual elements such as text content, and icon type, reducing attributes irrelevant to the test.

[0094] In some embodiments, the determined contextual dependencies can include various factors, such as analyzing whether the target test element depends on its parent container (e.g., a dropdown menu requires triggering a parent button first); whether the target test element only appears under specific conditions (e.g., a menu displayed only after login); or whether the content of the target test element depends on a preceding operation (e.g., an order number generated after form submission). In practical applications, by analyzing the changes in page structure before and after the operation sequence, the appearance conditions, disappearance conditions, and associated operations of the target test element are marked.

[0095] Furthermore, based on the location information of the target test element and its corresponding contextual dependencies, a script logic description establishing a temporal relationship can be understood as a mapping process of operation sequences, that is, converting user operations into script steps. For example, a user operation sequence such as "login → input → submit" can be broken down into atomic operations, each bound to a specific target test element. The location information of the target test element is directly referenced in the script logic description, enabling the operation to accurately trigger the target test element. The final obtained script logic description could be: first, click the login button; second, input the username; third, submit the form. It should be noted that because the generated script logic description considers the contextual dependencies of the target test element, the accuracy of locating the target test element can be further improved.

[0096] In some optional embodiments, the script logic description can also be adjusted according to the response page, such as selecting "Confirm" or "Cancel" after the detection pop-up, or inserting waiting conditions such as performing visibility checks on the target test element or waiting for the network request to complete in the script logic description, so as to improve the correctness of the timing.

[0097] In some embodiments, a test framework template can be applied based on the script logic description. Specifically, the script logic description needs to be mapped to statements supported by the test framework, such as "click element X" corresponding to the click() method. In some optional embodiments, dynamic data such as username and password in the script logic description can also be extracted as variables to support reuse of multiple test cases.

[0098] In one example, module 63 is also used for:

[0099] Construct a weight matrix, which includes multiple weight values ​​that correspond one-to-one with the target test elements; wherein, the weight values ​​are proportional to the test frequency of the corresponding target test elements;

[0100] Based on the context dependency of the target test element, the weight value of the target test element is increased when the target test element meets any of the following conditions: the target test element triggers a page jump, or the correlation between the target test element and other target test elements is higher than a preset threshold.

[0101] Module 63 is generated, specifically for:

[0102] Based on the location information of the target test element and the context dependency relationship corresponding to the target test element, a script logic description of the temporal relationship is established based on the test weight matrix.

[0103] In one example, module 63 is also used for:

[0104] The system retrieves the business domain script library and the historical execution script library. Different business domain scripts in the business domain script library have different script flows. The historical execution script library includes historical execution scripts and corresponding execution logs. The execution logs include the implementation paths of multiple implementation scripts under the same historical execution script, the waiting time of operation steps, and retry strategies.

[0105] The script generation model is trained based on the business domain script library and the historical execution script library;

[0106] Module 63 is generated, specifically for:

[0107] The script logic description is input into the script generation model, and the test script of the application under test is generated based on the output of the script generation model.

[0108] In one example, module 63 is also used for:

[0109] Obtain the test results of the test scripts for the application under test;

[0110] The test scripts of the application under test are used as historical execution scripts, and the test results are used as execution logs to train the script generation model.

[0111] In one example, module 63 is generated, specifically for:

[0112] Based on preset script templates, the output of the script generation model is converted into an initial test script; different script templates correspond to different programming languages.

[0113] Provide the user with a primary interface so that the user can return to the script modification information;

[0114] Update the initial test script based on the script modification information, and use the updated test script as the test script for the application under test.

[0115] In one example, module 62 is identified as being used specifically for:

[0116] For each node in the document structure of the response page, if the node is the node corresponding to the target test element, then store all child nodes of the node; if the node is not the node corresponding to the target test element, then store the parent node of the node.

[0117] The test script generation device provided in this embodiment can execute the method provided in the above method embodiment. Its implementation principle and technical effect are similar, and will not be described in detail here.

[0118] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 7 As shown, the electronic device provided in this embodiment includes a processor 291 and a memory 292; it may also include a communication interface 293 and a bus 294. The processor 291, memory 292, and communication interface 293 can communicate with each other via the bus 294. The communication interface 293 can be used for information transmission. The processor 291 can call logical instructions in the memory 292 to execute the method described above.

[0119] Furthermore, the logic instructions in the aforementioned memory 292 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium.

[0120] The memory 292, as a computer-readable storage medium, can be used to store software programs and computer-executable programs, such as program instructions / modules corresponding to the methods in the embodiments of this application. The processor 291 executes functional applications and data processing by running the software programs, instructions, and modules stored in the memory 292, that is, it implements the methods in the above method examples.

[0121] The memory 292 may include a program storage area and a data storage area. The program storage area may store the operating system and application programs required for at least one function; the data storage area may store data created based on the use of the terminal device. Furthermore, the memory 292 may include high-speed random access memory and may also include non-volatile memory.

[0122] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the methods described in the above embodiments.

[0123] This application also provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the method described in the above embodiments.

[0124] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily essential to this application.

[0125] It should be further noted that although the steps in the flowchart are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowchart may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the sub-steps or stages of other steps.

[0126] It should be understood that the above-described device embodiments are merely illustrative, and the device of this application can also be implemented in other ways. For example, the division of units / modules in the above embodiments is only a logical functional division, and there may be other division methods in actual implementation. For example, multiple units, modules, or components may be combined, or integrated into another system, or some features may be ignored or not executed.

[0127] Furthermore, unless otherwise specified, the functional units / modules in the various embodiments of this application can be integrated into one unit / module, or each unit / module can exist physically separately, or two or more units / modules can be integrated together. The integrated units / modules described above can be implemented in hardware or as software program modules.

[0128] If the integrated unit / module is implemented as a software program module and sold or used as an independent product, it can be stored in a computer-readable storage device (CMD). Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a memory and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned memory includes various media capable of storing program code, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard drive, magnetic disk, or optical disk.

[0129] In the above embodiments, the descriptions of each embodiment have their own emphasis. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments. The technical features of the above embodiments can be combined arbitrarily. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as the combination of these technical features does not contradict each other, it should be considered within the scope of this specification.

[0130] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this application are indicated by the following claims.

[0131] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this application is limited only by the appended claims.

Claims

1. A test script generation method characterized by comprising: The method comprises: obtaining an operation sequence triggered by an interface of a to-be-tested application and a corresponding response page of the operation; simplifying and storing a document structure of the response page according to a test requirement, determining positioning information of a target test element in the response page, the positioning information comprising an element selector and element attributes, and determining a context dependency relationship corresponding to the target test element based on the simplified document structure of the response page; establishing a script logic description of a time sequence relationship according to the positioning information of the target test element and the context dependency relationship corresponding to the target test element; and generating a test script of the to-be-tested application based on the script logic description.

2. The method of claim 1, wherein, The method further comprises: constructing a weight matrix comprising a plurality of weight values corresponding to the target test elements one by one; wherein the weight values are directly proportional to the test frequencies of the corresponding target test elements; based on the context dependency relationship corresponding to the target test element, increasing the weight value corresponding to the target test element when the target test element satisfies any one of the following conditions: the target test element triggers a page jump, and the degree of association between the target test element and other target test elements is higher than a preset threshold; the establishing of the script logic description of the time sequence relationship according to the positioning information of the target test element and the context dependency relationship corresponding to the target test element comprises: establishing the script logic description of the time sequence relationship based on the test weight matrix according to the positioning information of the target test element and the context dependency relationship corresponding to the target test element.

3. The method of claim 1, wherein, The method further comprises: obtaining a business domain script library and a historical execution script library; the different business domain scripts in the business domain script library correspond to different script processes; the historical execution script library comprises historical execution scripts and corresponding execution logs; wherein the execution logs comprise a plurality of implementation script implementation paths, operation step waiting time lengths, and retry strategies under the same historical execution script; training a script generation model based on the business domain script library and the historical execution script library; the generating of the test script of the to-be-tested application based on the script logic description comprises: inputting the script logic description into the script generation model, and generating the test script of the to-be-tested application according to an output result of the script generation model.

4. The method of claim 3, wherein, The method further comprises: obtaining a test result of the test script of the to-be-tested application; training the script generation model by taking the test script of the to-be-tested application as the historical execution script and taking the test result as the execution log.

5. The method of claim 3, wherein, The generating of the test script of the to-be-tested application according to the output result of the script generation model comprises: based on a preset script template, converting the output result of the script generation model into an initial test script; wherein different script templates correspond to different programming languages; providing a first interface to a user to enable the user to return script modification information; updating the initial test script according to the script modification information, and taking the updated test script as the test script of the to-be-tested application.

6. The method of claim 1, wherein, Simplifying and storing the document structure of the response page according to the test requirement comprises: For each node in the document structure of the response page, if the node is the node corresponding to the target test element, all child nodes of the node are stored; if the node is not the node corresponding to the target test element, the parent node of the node is stored.

7. A test script generation apparatus characterized by comprising: Comprise: The acquisition module is used to acquire an operation sequence and an operation corresponding response page triggered by an interface of the application under test; The determination module is used to simplify and store the document structure of the response page according to the test requirement, determine the positioning information of the target test element in the response page, and the positioning information comprises an element selector and element attributes; And, determine the context dependency relationship corresponding to the target test element based on the simplified document structure of the response page; The generation module is used to establish a script logic description of a timing relationship according to the positioning information of the target test element and the context dependency relationship corresponding to the target test element; Based on the script logic description, a test script of the application under test is generated.

8. An electronic device, comprising: Comprise: A processor, and a memory connected with the processor in communication; The memory stores computer execution instructions; The processor executes the computer execution instructions stored in the memory to realize the method in any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that, The computer readable storage medium stores computer execution instructions, and the computer execution instructions are executed by the processor to realize the method in any one of claims 1 to 6.

10. A computer program product, characterised in that, A computer program is executed by the processor to realize the method in any one of claims 1 to 6.