Test script generation method and device, equipment and medium
By obtaining webpage control data tables and automatically generating test scripts, the problem of time-consuming, labor-intensive, and inaccurate manual script writing in webpage functional testing is solved, achieving efficient and accurate test script generation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-26
- Publication Date
- 2026-04-03
AI Technical Summary
In existing technologies, test scripts required for webpage functionality testing need to be written manually, which is time-consuming, labor-intensive, has low accuracy, and is prone to errors.
By obtaining the control data table of the webpage to be tested, the task chain and execution chain of the test task are determined, and the test script is automatically generated using code templates and control parameters.
It improves the efficiency and accuracy of test script generation, and reduces the time and error rate of manual script writing.
Smart Images

Figure CN121785929A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of software testing, and more particularly to a method, apparatus, device, and medium for generating test scripts. Background Technology
[0002] With the rapid development of internet technology, web pages have become the primary entry point for users to obtain information and services. Their functional complexity is increasing daily, evolving from simple information display to comprehensive applications incorporating elements of interaction, transactions, and multimedia. Against this backdrop, web page functional testing has emerged. Its core significance lies in ensuring, through systematic verification, that all functions of a web page strictly meet design requirements and user expectations. This is not only a crucial step in ensuring user experience and maintaining brand reputation, but also an indispensable quality assurance measure to prevent potential business losses and improve software quality.
[0003] However, the test scripts required for functional testing all need to be written manually, which is time-consuming and labor-intensive, and manually written scripts have low accuracy and are prone to errors. Summary of the Invention
[0004] This invention provides a method, apparatus, device, and medium for generating test scripts. Through the technical solution of this invention, test scripts for web pages can be automatically generated, improving the efficiency and accuracy of test script generation.
[0005] In a first aspect, embodiments of the present invention provide a method for generating test scripts, comprising:
[0006] Obtain the control data table of the webpage to be tested, wherein the webpage to be tested contains multi-level sub-webpages; the control data table includes the jump paths between the sub-webpages, page layout information, and the dependencies between controls in the webpage;
[0007] Determine the task chain of the test task corresponding to the webpage to be tested, wherein the link nodes of the task chain correspond to the sub-webpages of the webpage to be tested;
[0008] Based on the sub-web pages corresponding to the link nodes and the control data table, determine the execution link of the target control for executing the test task;
[0009] Based on the execution chain, code template, and control parameters of the target control, a test script for the test task is generated.
[0010] Secondly, embodiments of the present invention provide a test script generation apparatus, comprising:
[0011] The acquisition module is used to acquire the control data table of the webpage to be tested, wherein the webpage to be tested contains multi-level sub-webpages; the control data table includes the jump path between the sub-webpages, page layout information, and the dependency relationship between controls in the webpage;
[0012] The task link determination module is used to determine the task link of the test task corresponding to the webpage to be tested, wherein the link nodes of the task link correspond to the sub-webpages of the webpage to be tested.
[0013] The execution link determination module is used to determine the execution link of the target control that performs the test task based on the sub-web page corresponding to the link node and the control data table.
[0014] The generation module is used to generate the test script for the test task based on the execution chain, code template and control parameters of the target control.
[0015] Thirdly, embodiments of the present invention provide an electronic device, the electronic device comprising:
[0016] At least one processor; and,
[0017] A memory communicatively connected to the at least one processor; wherein,
[0018] The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to execute the test script generation method described in any one of the embodiments of the present invention.
[0019] Fourthly, embodiments of the present invention provide a computer-readable storage medium storing computer instructions, which are used to cause a processor to execute the test script generation method described in any one of the embodiments of the present invention.
[0020] This invention provides a method, apparatus, device, and medium for generating test scripts. The method includes: obtaining a control data table of a webpage to be tested, wherein the webpage to be tested contains multiple levels of sub-webpages; the control data table includes jump paths between the sub-webpages, page layout information, and dependencies between controls in the webpage; determining the task chain of a test task corresponding to the webpage to be tested, wherein the link nodes of the task chain correspond to the sub-webpages of the webpage to be tested; determining the execution chain of the target control executing the test task based on the sub-webpages corresponding to the link nodes and the control data table; and generating a test script for the test task based on the execution chain, code template, and control parameters of the target control. Specifically, by using the control data table and the task chain corresponding to the test task, the execution chain of the target control of the test task can be determined. Furthermore, based on the execution chain, code template, and control parameters of the target control, the test script for the test task can be automatically generated. This approach improves the accuracy and efficiency of script generation. Attached Figure Description
[0021] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying 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.
[0022] Figure 1 A flowchart illustrating a method for generating a test script according to Embodiment 1 of the present invention;
[0023] Figure 2 A flowchart illustrating a method for generating a test script according to Embodiment 2 of the present invention;
[0024] Figure 3 A schematic diagram of the test script generation method provided in an embodiment of the present invention;
[0025] Figure 4 A schematic diagram illustrating the verification of the test script provided in an embodiment of the present invention;
[0026] Figure 5 This is a schematic diagram of the structure of a test script generation device provided in Embodiment 3 of the present invention;
[0027] Figure 6 This is a schematic diagram of the structure of an electronic device provided in Embodiment 4 of the present invention. Detailed Implementation
[0028] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. 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 should fall within the scope of protection of the present invention.
[0029] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0030] It should be noted that the collection, storage, use, processing, transmission, provision, and disclosure of user personal information involved in the technical solution disclosed herein all comply with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0031] Example 1
[0032] Figure 1 This is a flowchart illustrating a test script generation method according to Embodiment 1 of the present invention. This method is specifically applicable to the field of software testing, but can also be applied to the field of financial technology, particularly for generating test scripts for web pages, such as test scripts for financial service web pages. This method can be implemented using a test script generation device, which can be composed of software and / or hardware and configured in a computer or server.
[0033] like Figure 1 As shown, it includes:
[0034] Step 110: Obtain the control data table of the webpage to be tested, wherein the webpage to be tested contains multiple levels of sub-webpages; the control data table includes the jump paths between the sub-webpages, page layout information, and the dependencies between controls in the webpage.
[0035] The webpage to be tested is the webpage that needs to be automated. It represents a complex structure containing multiple levels of sub-webpages. Sub-webpages are lower-level pages within the webpage to be tested. Navigation between webpages can be achieved by interacting with at least one control within the webpage. For example, if the webpage includes a "view button," clicking this button will navigate to the view page to view the data. Controls can include buttons, input boxes, and links, etc. Different controls have corresponding functions based on their type. For instance, an input box is limited to text input, certain buttons are used for page navigation, and others are used for content confirmation. The specific type and function of the controls are not limited here.
[0036] The control data table contains the navigation paths between subpages, page layout information, and dependencies between controls within the webpage. Specifically, the navigation path between subpages can be represented by the triggering order of controls. For example, in four subpages (A, B, C, and D), there are navigation controls a, b, and c, and a functional control d, respectively: triggering control a allows navigation from A to B; triggering control b allows navigation from B to C; triggering control c allows navigation from C to D; and finally, triggering functional control d on page D completes the target function. Therefore, the navigation path between subpages can be represented as a→b→c. It should be noted that the navigation path is implemented by default during the webpage design phase; therefore, when generating the corresponding control data table based on the webpage to be tested, the relevant data for the navigation path is known information. This can be determined through the properties of the navigation controls; for example, the function of navigation control a is directly set to navigate from A to B. Therefore, the navigation path can be obtained by recording the functions of each navigation control. Page layout information describes the position and arrangement of controls on a webpage, representing the visual structure, elements, and control distribution of the page. The dependency relationship between controls is the association between controls in terms of function or state, representing how the operation or state of one control affects other controls. For example, there is a dependency relationship between controls a, b, c, and d, specifically: controls b and c will only appear if control a is triggered first; and control d will only be displayed if control b is triggered again.
[0037] Optionally, the method for generating the control data table includes:
[0038] Obtain the document object model tree of the webpage to be tested and its sub-webpages at all levels, parse each document object model tree, and determine the webpage structure text of the webpage to be tested and its sub-webpages at all levels; wherein the webpage structure text of the webpage includes the page layout information of the webpage and the dependency relationship between controls in the webpage; generate the control data table according to the jump path between the webpage to be tested and its sub-webpages at all levels and the webpage structure text.
[0039] The Document Object Model (DOM) tree is a specific tree model representing the structure of a webpage. To complete the testing task of the test webpage and all its sub-webpages, it is necessary to obtain their corresponding DOM trees and generate control data tables by parsing these trees. Furthermore, by understanding the webpage structure of all levels of sub-webpages within the entire test webpage, an accurate and comprehensive control data table can be generated, thereby indirectly improving the accuracy of the generated test scripts.
[0040] Optionally, parsing each of the document object model trees to determine the webpage structure text of the webpage to be tested and its sub-webpages at each level includes:
[0041] The document object model trees are parsed to obtain the parsing results of the webpage to be tested and its sub-webpages at each level. If the parsing result includes a target node that failed to be parsed, the page information of the target node is determined based on the webpage screenshot corresponding to the document object model tree to which the target node belongs. Based on the parsing result and the page information of the target node, the webpage structure text is generated.
[0042] Specifically, during the development of test web pages or sub-web pages, due to oversight or differences in individual programming habits, the format of some page elements may be inconsistent. Consequently, when extracting the structure using established parsing rules, some target nodes cannot be parsed correctly, resulting in empty content or garbled characters in the web page structure text. To address this special case, a screenshot of the web page corresponding to the document object model tree (DOM) of the target node can be used to obtain page information, and combined with the successfully parsed results to generate complete web page structure text. Specifically, text recognition or image recognition can be performed on the web page screenshot to determine the type, function, and other key attributes of the control. Then, based on the recognized information, the page information of the target node is supplemented and integrated into the web page structure text. This method effectively addresses the parsing loss problem caused by inconsistent formats, improving the accuracy and overall efficiency of web page structure text generation. The web page structure text is the parsed text of the DOM tree, which can be in JSON format; the specific parsing process is not limited here.
[0043] Step 120: Determine the task link of the test task corresponding to the webpage to be tested, wherein the link node of the task link corresponds to the sub-webpage of the webpage to be tested.
[0044] Specifically, the task chain represents the execution sequence of the test task on the sub-page, indicating the page path covered by the test task. For example, a test task may involve navigation through multiple web pages. Therefore, the task chain represents the web pages to be tested in the test task, as well as the logical order of the test pages. For example, for testing a balance query task, it is necessary to reach the balance query page. Therefore, the corresponding task chain could be: login page → bank function menu page → balance query page. This requires triggering specific controls on each page in a specific order to navigate to the balance query page.
[0045] Step 130: Determine the execution link of the target control for executing the test task based on the sub-web page corresponding to the link node and the control data table.
[0046] In this context, the target control refers to the specific UI element required to complete the test task. It's important to note that page navigation and function implementation essentially rely on the invocation and triggering of specific controls. Therefore, achieving the ultimate goal of the test task can be reduced to the result of triggering multiple target controls in a specific order. Based on this, the task chain can be converted into an execution chain of target controls. By triggering each target control in the chain sequentially, the corresponding test function can be completed. Correspondingly, the generated test code is the program instruction that implements this sequential triggering process.
[0047] Step 140: Generate the test script for the test task based on the execution chain, code template, and control parameters of the target control.
[0048] The code template for the target control is a code snippet or structural model pre-written for a specific category of target control. The control parameters of the target control are a set of data items predefined by the code template. Essentially, it specifies the allowed range, format standards and specific content of the parameters, or the input values and configuration information required for the corresponding test task.
[0049] Specifically, the code templates of the corresponding controls can be assembled sequentially according to the execution chain of the target controls, and the corresponding control parameters can be configured for each target control to generate the final test script.
[0050] Optionally, based on the type of the target control in the execution chain, the code template and control parameters of the target control are determined; test code for the target control is generated based on the code template and control parameters of the target control; and test scripts for the test tasks are obtained based on the execution chain and the test code of each target control.
[0051] Specifically, code templates and control parameters are pre-stored in a specified database. During the actual generation process, the system can retrieve the corresponding code template and control parameters from the database based on the type of the target control. Furthermore, by filling the control parameters into the corresponding code template, the test code for the target control can be generated. Further, according to the triggering order of the target control in the execution chain, the various test code segments are sequentially combined to ultimately form a complete test task script. Moreover, by selecting templates and parameters based on the control type to generate code, the system can automatically assemble a complete executable script.
[0052] Optionally, the test script is run to determine the execution input and execution output of the test code for the target control; the test script is then validated based on the target input, target output, execution input, and execution output of the target control.
[0053] Specifically, test code can be run to obtain the execution input and output of the test code corresponding to each target control. Then, it can be compared with the target input and target output of the target control to determine whether the test code of the target control is accurate. By running and comparing the input and output, the correctness and reliability of the generated script can be ensured.
[0054] This invention provides a method for generating test scripts. The method includes: obtaining a control data table of a webpage to be tested, wherein the webpage to be tested contains multiple levels of sub-webpages; the control data table includes jump paths between the sub-webpages, page layout information, and dependencies between controls in the webpage; determining the task chain of a test task corresponding to the webpage to be tested, wherein the link nodes of the task chain correspond to the sub-webpages of the webpage to be tested; determining the execution chain of the target control executing the test task based on the sub-webpages corresponding to the link nodes and the control data table; and generating a test script for the test task based on the execution chain of the target control, a code template, and control parameters. Specifically, by using the control data table and the task chain corresponding to the test task, the execution chain of the target control of the test task can be determined. Furthermore, based on the execution chain of the target control, the code template, and control parameters, the test script for the test task can be automatically generated. This approach improves the accuracy and efficiency of script generation.
[0055] Example 2
[0056] Figure 2 This is a flowchart of a test script generation method provided in Embodiment 2 of the present invention. The method is based on the above embodiment, and further defines each step of the test script generation.
[0057] like Figure 2 As shown, it includes:
[0058] Step 210: Obtain the control data table of the webpage to be tested, wherein the webpage to be tested contains multiple levels of sub-webpages; the control data table includes the jump paths between the sub-webpages, page layout information, and the dependencies between controls in the webpage.
[0059] Step 220: In response to the drag-and-drop operation on the interactive page, display the link nodes of the test task on the interactive page, wherein the interactive page is a visual programming page.
[0060] The interactive page is a visual programming interface with pre-set icons for test web pages and subpages in its menu. Users can drag and drop the icons corresponding to the desired link nodes from the menu into the editing area of the interactive page.
[0061] Step 230: In response to the configuration operation on the interactive page, configure the attribute information of the controls in the sub-page corresponding to the link node.
[0062] Specifically, the code template, control type, parameter settings, and other attributes of each control in the subpage can be associated and bound with the corresponding control to complete the parameter configuration of the control.
[0063] Step 240: Determine historical test tasks whose similarity to the test task meets a preset threshold, and determine the test task based on the jump order of sub-pages at each level in the historical test tasks.
[0064] Step 250: Connect the link nodes according to the jump order of the sub-pages at each level to obtain the task link.
[0065] When historical test tasks and current test tasks are highly similar (e.g., both belong to the same or similar test tasks like "balance query"), it can be assumed that, as long as the webpage under test has not undergone structural reconstruction, the main subpages involved in historical and current test tasks are often the same or similar, meaning they have a consistent page navigation order. Therefore, based on the navigation order of subpages at each level in historical test tasks, the navigation order of the corresponding subpages in the current test task can be derived and determined. Then, the pre-set link nodes can be connected according to this order to form a complete task link. Furthermore, by combining visual interaction and historical task analysis, the efficiency and accuracy of link configuration can be improved, achieving automated task link generation.
[0066] Step 260: Match the identification information of the sub-page corresponding to the task link with the jump path in the control data table to obtain the target jump path.
[0067] Specifically, the task chain consists of multiple sub-pages as nodes. Based on the task chain, within each node's corresponding sub-page, the web page controls that can jump to the next level target sub-page can be located according to their type and function, thus obtaining the specific target jump path. For example, if the task chain is "Web Page A → Web Page B → Web Page C", then control 'a' for jumping to web page B can be located sequentially from web page A, and control 'b' for jumping to web page C can be located from web page B, thereby determining the target jump path as "a → b".
[0068] Step 270: Based on the dependency relationship between the first type of target control and the control in the target jump path, determine the second type of target control corresponding to the first type of target control.
[0069] The first type of target control directly triggers page navigation, and its core function is to enable navigation between different subpages. The second type of target control refers to auxiliary controls that have a logical dependency on the first type of controls in terms of display or usability. For example, the visibility or clickability of certain navigation controls (first type of target controls) may need to be activated by first manipulating one or more other controls (second type of target controls). For instance, to display navigation control A on the page, it may be necessary to trigger controls B and C sequentially, where B and C are second type of target controls associated with A.
[0070] Step 280: Determine the execution link based on the target jump path, the first type of target control, and the second type of target control.
[0071] For each sub-page, the operation order of all target controls within that page can be determined based on the dependency relationship between the second type of target controls and the first type of target controls. Then, by sequentially connecting the control operation sequences within each sub-page, the complete execution chain of the test task can be obtained. Specifically, by accurately identifying the target controls in each sub-page and generating the execution chain based on these target controls, the accuracy of the execution chain determination can be improved, ensuring the complete execution of the test task.
[0072] For example: Assume the target navigation path is "Webpage A → Webpage B → Webpage C". The dependencies and triggering order of the controls within each page are as follows:
[0073] In webpage A, the second type of control a2 must be triggered first before the first type of control a1, which is used to jump to webpage B, can be activated.
[0074] In webpage B, the second type of controls b2 and b3 must be triggered sequentially in order to activate the first type of control b1 used to jump to webpage C.
[0075] Webpage C is the final page and does not involve any redirection controls.
[0076] Based on the above dependencies, it can be determined that:
[0077] The control operation sequence within webpage A is: a2 → a1
[0078] The control operation sequence within webpage B is: b2 → b3 → b1
[0079] Furthermore, following the jump path "Webpage A → Webpage B → Webpage C", the operation sequences within the above pages are connected to obtain the complete execution chain: a2 → a1 → b2 → b3 → b1. It should be noted that after jumping to Webpage C, corresponding operations can be performed on the target controls in Webpage C according to the specific requirements of the test task, thereby completing the entire test task.
[0080] Step 290: Generate the test script for the test task based on the execution chain, code template, and control parameters of the target control.
[0081] For example, Figure 3 This is a schematic diagram of the test script generation method provided in this embodiment of the invention. Specifically, it requires obtaining the Document Object Model (DOM) tree of the webpage to be tested and its sub-webpages at all levels, parsing it, determining the parsing results of each DOM tree, and obtaining the webpage structure text in JSON structure. Simultaneously, based on the type of each control in the webpage structure text, corresponding attributes and rules are bound to the controls. Attributes can include the type and function of the control, and rules are the usage method and parameter limitations of the control. For example, "Amount Input Box → Numeric, Range 0-1,000,000". Further, for unrecognized tree nodes, text recognition and image recognition (such as the "Account Inquiry" icon) can be used to supplement the webpage structure text of the unrecognized tree nodes. Related controls of each level of sub-webpage in the webpage structure text are displayed in different control menus. For example, controls of the same webpage are located in the same menu. The connection relationship between menus at each level can be determined through the jump relationship and / or inclusion relationship of sub-webpages. It should be noted that the attributes and rules of the controls can be extracted from a preset control parameter pool based on the control type. Furthermore, for testing the functionality of controls in any subpage of the webpage under test, users can drag and drop the corresponding link nodes of the test task in the visualization, and automatically determine the order of each link node based on similar historical tasks, generating a task link. Further, based on the execution order of each control in the subpage corresponding to each link node, a basic test script for the subpage can be generated. Then, based on the jump order of each subpage after completing the test task, the basic test scripts of each subpage can be connected to obtain the final test script. After the script is generated, it needs to be verified; if the test is abnormal, the script needs to be automatically repaired. It should be noted that the test script needs to call data from the control parameter pool for data filling. For example, parsing the field types to be filled in the script (e.g., "login account" is a string, "deposit amount" is a numeric type), mapping them to the rules and data in the control parameter pool, and then calling the data and rules for filling. Simultaneously, data content for the test task can also be randomly generated in real time or directly specified by the user. Furthermore, assertion logic can be added to the test script, such as verifying that the "balance query" result = old balance + deposit amount.
[0082] For example, Figure 4This is a schematic diagram illustrating the verification of the test script provided in this embodiment of the invention. Specifically, the verification process of the test script begins with task startup. The system first performs intelligent scheduling and resource allocation for the script, and then drives three engines to execute verification in parallel: first, it handles basic operations of web page forms; second, it performs real-time assertions on key business results (such as transfer balances); and third, it verifies the compatibility of mobile terminal functions. All verification results are immediately compared with the expected standards. If they are completely consistent, a test report containing performance data is directly generated and the background rule base is updated synchronously. If an anomaly is found, the system automatically triggers a self-healing mechanism. First, it matches the anomaly type (such as response timeout, CAPTCHA error, or missing element), and then executes the corresponding strategy (including multiple retries, calling image recognition technology to re-identify content, or refreshing the page to reposition controls). Then, the test script is regenerated and re-enters the verification and comparison stage. Regardless of whether the self-repair is ultimately successful, the process will eventually generate a detailed test report and optimization analysis to ensure the accuracy of the generated test script.
[0083] In this embodiment of the invention, by establishing a task chain, and then generating an execution chain based on the connection relationships of sub-pages and controls in each sub-page, a test script for the entire task chain can be obtained by generating code snippets for each node of the execution chain and concatenating the code snippets according to the node order of the execution chain. This method can improve the efficiency and accuracy of test script generation and enable functional testing of the controls on the test webpage.
[0084] Example 3
[0085] Figure 3 This is a schematic diagram of the structure of a device provided in Embodiment 3 of the present invention. For example... Figure 3 As shown, the device includes: Figure 5 This is a schematic diagram of a test script generation device provided in Embodiment 3 of the present invention. Figure 5 As shown, the device includes:
[0086] The acquisition module 310 is used to acquire the control data table of the webpage to be tested, wherein the webpage to be tested contains multi-level sub-webpages; the control data table includes the jump path between the sub-webpages, page layout information, and the dependency relationship between controls in the webpage;
[0087] The task link determination module 320 is used to determine the task link of the test task corresponding to the webpage to be tested, wherein the link nodes of the task link correspond to the sub-webpages of the webpage to be tested.
[0088] The execution link determination module 330 is used to determine the execution link of the target control that performs the test task based on the sub-web page corresponding to the link node and the control data table.
[0089] The generation module 340 is used to generate a test script for the test task based on the execution chain, code template and control parameters of the target control.
[0090] This invention provides a test script generation device. The device proceeds by: acquiring a control data table of a webpage to be tested, wherein the webpage contains multiple levels of sub-webpages; the control data table includes jump paths between the sub-webpages, page layout information, and dependencies between controls within the webpage; determining the task chain of the test task corresponding to the webpage to be tested, wherein the link nodes of the task chain correspond to the sub-webpages of the webpage to be tested; determining the execution chain of the target control executing the test task based on the sub-webpages corresponding to the link nodes and the control data table; and generating a test script for the test task based on the execution chain, code template, and control parameters of the target control. Specifically, by using the control data table and the task chain corresponding to the test task, the execution chain of the target control of the test task can be determined. Furthermore, based on the execution chain, code template, and control parameters of the target control, the test script for the test task can be automatically generated. This approach improves the accuracy and efficiency of script generation.
[0091] Optionally, the device includes a control data table generation module, comprising:
[0092] The acquisition unit is used to acquire the document object model tree of the webpage to be tested and its sub-webpages at all levels, parse each document object model tree, and determine the webpage structure text of the webpage to be tested and its sub-webpages at all levels; wherein the webpage structure text of the webpage includes the page layout information of the webpage and the dependency relationships between controls in the webpage;
[0093] The generation unit is used to generate the control data table based on the jump paths between the webpage to be tested and its sub-webpages at all levels, as well as the structural text of each webpage.
[0094] Optionally, the generation unit includes:
[0095] The parsing subunit is used to parse each of the document object model trees to obtain the parsing results of the webpage to be tested and each level of subpages;
[0096] The judgment subunit is used to determine the page information of the target node based on the webpage screenshot corresponding to the document object model tree to which the target node belongs if the parsing result includes the target node that failed to be parsed.
[0097] A sub-unit is generated to generate the webpage structure text based on the parsing result and the page information of the target node.
[0098] The task link determination module 320 includes:
[0099] A drag-and-drop unit is used to respond to drag-and-drop operations on an interactive page, whereby the link nodes of the test task are displayed on the interactive page, which is a visual programming page.
[0100] The configuration unit is used to respond to configuration operations on the interactive page and configure the attribute information of controls in the sub-page corresponding to the link node;
[0101] The sequence determination unit is used to determine historical test tasks whose similarity to the test task meets a preset threshold, and to determine the jump order of the sub-pages corresponding to the test task based on the jump order of the sub-pages at each level in the historical test task.
[0102] The generation unit is used to connect the link nodes according to the jump order of the sub-pages at each level to obtain the task link.
[0103] The execution link determination module 330 includes:
[0104] The matching unit is used to match the identification information of the sub-page corresponding to the task link with the jump path in the control data table to obtain the target jump path;
[0105] The control determination unit is used to determine the second type of target control corresponding to the first type of target control based on the dependency relationship between the first type of target control in the target jump path and the control;
[0106] The path determination unit is used to determine the execution link based on the target jump path, the first type of target control, and the second type of target control.
[0107] Module 340 includes:
[0108] The determining unit is used to determine the code template and control parameters of the target control based on the type of the target control in the execution chain;
[0109] The fill cell is used to generate test code for the target control based on the target control's code template and control parameters;
[0110] The splicing unit is used to obtain the test script of the test task based on the execution link and the test code of each target control.
[0111] Optionally, the device further includes: a verification module, used to run the test script, determine the execution input and execution output of the test code of the target control; and perform script verification on the test script based on the target input, target output, execution input and execution output of the target control.
[0112] The test script generation apparatus provided in this embodiment of the invention can execute the test script generation method provided in any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0113] Example 4
[0114] Figure 6 A schematic diagram of an electronic device 10, which can be used to implement embodiments of the present invention, is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (e.g., helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.
[0115] like Figure 6 As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory 12 or a random access memory 13, communicatively connected to the at least one processor 11. The memory stores computer programs executable by the at least one processor. The processor 11 can perform various appropriate actions and processes based on the computer program stored in the read-only memory 12 or loaded from storage unit 18 into the random access memory 13. The random access memory 13 may also store various programs and data required for the operation of the electronic device 10. The processor 11, read-only memory 12, and random access memory 13 are interconnected via a bus 14. An input / output interface 15 is also connected to the bus 14.
[0116] Multiple components in electronic device 10 are connected to input / output interface 15, including: input unit 16, such as keyboard, mouse, etc.; output unit 17, such as various types of monitors, speakers, etc.; storage unit 18, such as disk, optical disk, etc.; and communication unit 19, such as network card, modem, wireless transceiver, etc. Communication unit 19 allows electronic device 10 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0117] Processor 11 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, central processing units, graphics processing units, various special-purpose artificial intelligence computing chips, various processors running machine learning model algorithms, digital signal processors, and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods and processes described above, such as the method of generating test scripts.
[0118] In some embodiments, the test script generation method may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on electronic device 10 via read-only memory 12 and / or communication unit 19. When the computer program is loaded into random access memory 13 and executed by processor 11, one or more steps of the test script generation method described above may be performed. Alternatively, in other embodiments, processor 11 may be configured to execute the test script generation method by any other suitable means (e.g., by means of firmware).
[0119] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays, application-specific integrated circuits (ASICs), application-specific standard products (ASICs), systems-on-a-chip (SoCs), complex programmable logic devices, computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0120] Computer programs used to implement the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0121] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory, read-only memory, erasable programmable read-only memory (EP memory or flash memory), optical fibers, portable compact disk read-only memory, optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0122] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a cathode ray tube or liquid crystal display, a monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0123] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or computing systems that include middleware components (e.g., application servers), or computing systems that include frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.
[0124] A computing system can include clients and servers. Clients and servers are generally geographically separated and typically interact via communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a host product within the cloud computing service system. This addresses the shortcomings of traditional physical hosts and cloud host services, such as high management difficulty and weak business scalability.
[0125] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.
[0126] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
[0127] This disclosure also provides a computer program product, including a computer program and / or instructions, which, when executed by a processor, implements the test script generation method provided in any embodiment of this application.
[0128] In implementing a computer program product, computer program code for performing the operations of the embodiments of this disclosure can be written in one or more programming languages or a combination thereof. Programming languages include object-oriented programming languages as well as conventional procedural programming languages, such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0129] Note that the above are merely preferred embodiments and the technical principles applied in this disclosure. Those skilled in the art will understand that this disclosure is not limited to the specific embodiments described herein, and various obvious changes, readjustments, and substitutions can be made without departing from the protection scope of this disclosure. Therefore, although the embodiments of this disclosure have been described in detail above, this disclosure is not limited to the above embodiments. More other equivalent embodiments may be included without departing from the concept of this disclosure, and the scope of this disclosure is determined by the scope of the appended claims.
Claims
1. A method for generating test scripts, characterized in that, include: Obtain the control data table of the webpage to be tested, wherein the webpage to be tested contains multi-level sub-webpages; the control data table includes the jump paths between the sub-webpages, page layout information, and the dependencies between controls in the webpage; Determine the task chain of the test task corresponding to the webpage to be tested, wherein the link nodes of the task chain correspond to the sub-webpages of the webpage to be tested; Based on the sub-web pages corresponding to the link nodes and the control data table, determine the execution link of the target control for executing the test task; Based on the execution chain, code template, and control parameters of the target control, a test script for the test task is generated.
2. The method according to claim 1, characterized in that, The method for generating the control data table includes: Obtain the document object model tree of the webpage to be tested and its sub-webpages at all levels, parse each document object model tree, and determine the webpage structure text of the webpage to be tested and its sub-webpages at all levels; wherein the webpage structure text of the webpage includes the page layout information of the webpage and the dependency relationships between controls in the webpage; The control data table is generated based on the jump paths between the webpage to be tested and its subpages, as well as the structural text of each webpage.
3. The method according to claim 2, characterized in that, The step of parsing each of the document object model trees to determine the webpage structure text of the webpage to be tested and its sub-webpages at all levels includes: The document object model trees are parsed to obtain the parsing results of the webpage to be tested and its sub-webpages at each level; If the parsing result includes a target node that failed to be parsed, the page information of the target node is determined based on the webpage screenshot corresponding to the document object model tree to which the target node belongs; Based on the parsing results and the page information of the target node, the webpage structure text is generated.
4. The method according to claim 1, characterized in that, The task chain for determining the test task corresponding to the webpage to be tested includes: In response to drag-and-drop operations on the interactive page, the link nodes of the test task are displayed on the interactive page, wherein the interactive page is a visual programming page; In response to configuration operations on the interactive page, configure the attribute information of controls in the sub-page corresponding to the link node; Identify historical test tasks whose similarity to the test task meets a preset threshold, and determine the jump order of the sub-pages corresponding to the test task based on the jump order of the sub-pages at each level in the historical test task; The task link is obtained by connecting the link nodes according to the jump order of the sub-pages at each level.
5. The method according to claim 1, characterized in that, The step of determining the execution link of the target control for executing the test task based on the sub-webpage corresponding to the link node and the control data table includes: The identification information of the sub-page corresponding to the task link is matched with the jump path in the control data table to obtain the target jump path; Based on the dependency relationship between the first type of target control and the control in the target jump path, determine the second type of target control corresponding to the first type of target control; The execution link is determined based on the target jump path, the first type of target control, and the second type of target control.
6. The method according to claim 1, characterized in that, The step of generating a test script for the test task based on the execution chain, code template, and control parameters of the target control includes: Based on the type of the target control in the execution chain, determine the code template and control parameters of the target control; Generate test code for the target control based on the target control's code template and control parameters; Based on the execution chain and the test code of each target control, the test script for the test task is obtained.
7. The method according to claim 6, characterized in that, Also includes: Run the test script to determine the execution input and output of the test code for the target control; The test script is validated based on the target input, target output, execution input, and execution output of the target control.
8. A test script generation apparatus, characterized in that, include: The acquisition module is used to acquire the control data table of the webpage to be tested, wherein the webpage to be tested contains multi-level sub-webpages; the control data table includes the jump path between the sub-webpages, page layout information, and the dependency relationship between controls in the webpage; The task link determination module is used to determine the task link of the test task corresponding to the webpage to be tested, wherein the link nodes of the task link correspond to the sub-webpages of the webpage to be tested. The execution link determination module is used to determine the execution link of the target control that performs the test task based on the sub-web page corresponding to the link node and the control data table. The generation module is used to generate the test script for the test task based on the execution chain, code template and control parameters of the target control.
9. An electronic device, characterized in that, The electronic device includes: At least one processor; and, A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the test script generation method according to any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that, when executed by a processor, implement the method for generating the test script according to any one of claims 1-7.