Automatic script generation method
By constructing an initial UI model and a dynamic update mechanism, combined with spatial partitioning graphs and a data-driven framework, the adaptability problem of automated test scripts in dynamic user interfaces is solved, achieving real-time capture and stable execution of dynamic changes.
Patent Information
- Application Number
- CN202511745570.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-26
- Publication Date
- 2025-12-26
- Estimated Expiration
- 2045-11-26
AI Technical Summary
Existing automated test script generation methods are not adaptable enough to the face of updates to user interface layout or interaction logic, and cannot fully identify dynamic changes, resulting in difficulties in test script execution or incomplete coverage.
An initial UI model is constructed by extracting initial user interface elements and attributes, interactive behavior tracking points are set to obtain state change data, the UI model is dynamically updated, supplementary test script fragments are generated, functional areas are identified based on the spatial segmentation graph structure, conditional test script branches are generated, and integrated into the data-driven testing framework.
It improves the adaptability and execution stability of automated test scripts, can capture dynamic element changes in real time, reduces the failure rate of operations, and improves test execution efficiency and reusability.
Smart Images

Figure CN121209855A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of data processing, in particular to an automatic script generation method. BACKGROUND
[0002] In existing automatic test script generation techniques, static analysis of user interface (UI) elements is usually relied on to generate test scripts. A common method is to pre-record user operations and generate scripts based on relatively fixed UI attributes. However, with the enrichment of application functions and dynamic adjustment of user interfaces, such static methods may face some adaptability challenges.
[0003] Specifically, existing technologies may have limited adaptability when facing updates in UI layout or interaction logic. For example, in the order placement process of an e-commerce application, if a coupon selection area is added or the properties of a payment button are adjusted in the interface, a script generation method based on static analysis may not be able to fully identify these changes, which may cause difficulties in the execution of test scripts or may not fully cover new interaction paths. In addition, existing methods may have some deficiencies in the intelligent division of interface function areas and the analysis of context-dependent behaviors, which may affect the adaptability and stability of generated test scripts in complex scenarios. SUMMARY
[0004] The technical problem to be solved by the present application is to provide an automatic script generation method to improve the generation efficiency of automatic test scripts and enhance the adaptability of scripts to user interfaces.
[0005] To solve the above technical problems, the technical solution of the present application is as follows: In a first aspect, an automatic script generation method comprises: Step 1: Extract initial user interface elements and corresponding element attributes, construct an initial UI model, and generate a basic test script segment based on the initial UI model, wherein the initial UI model includes layout information and interaction attributes of the initial user interface elements. Step 2: Execute the basic test script segment and set multiple interaction behavior tracking points in the user interface to obtain user interface state change data; update the initial UI model based on the user interface state change data to form an updated UI model. Step 3, generating a supplementary test script fragment based on the updated UI model, and constructing a spatial segmentation graph structure by analyzing the spatial distribution characteristics of the user interface elements; establishing the spatial influence area of the user interface elements based on the spatial segmentation graph structure, and identifying the high-density aggregation area boundary according to the spatial influence area; determining the function area division scheme based on the high-density aggregation area boundary, and classifying the user interface elements into multiple function areas according to the function characteristics based on the function area division scheme; Step 4, based on the user interface state change data, analyzing the layout characteristics and interaction attributes of the user interface elements in each function area, generating test adaptation parameters, and generating conditional test script branches based on the test adaptation parameters and the context-dependent behavior of the user interface elements; Step 5, integrating the basic test script fragment, the supplementary test script fragment and the conditional test script branch into the data-driven test framework to form a complete automated test script.
[0006] The second aspect is a computing device, comprising: One or more processors; Storage device for storing one or more programs, when the one or more programs are executed by the one or more processors, so that the one or more processors implement the method.
[0007] The third aspect is a computer readable storage medium, the computer readable storage medium stores a program, the program is executed by a processor to implement the method.
[0008] The above-mentioned scheme of the present application at least includes the following beneficial effects: Through the interaction behavior tracking point and the UI model dynamic updating mechanism, the newly added dynamic elements in the execution process can be captured in real time, such as the coupon area and element state change of the e-commerce APP, such as the payment button from not clickable to clickable, and the UI model is iteratively updated, avoiding the problem of invalid or incomplete coverage of static scripts, and improving the adaptability of the script in the application with frequent function iteration; based on the spatial distribution characteristics of the UI elements, the spatial segmentation graph is constructed, the spatial influence area is established, and then the high-density aggregation area boundary is identified to divide the core function areas such as navigation area, content display area and user operation area, and the elements are classified according to the function characteristics, so that the test script can be adaptively adapted to the interaction characteristics of different areas, and the logical clarity and execution stability of the script under complex interface are improved; relying on the UI state change data, the layout characteristics and interaction attributes of the elements in each function area are extracted, the regional test adaptation parameters are generated, and the conditional test script branches are constructed, so that the script has dynamic judgment logic, and the execution path can be adjusted according to the pre-operation result, effectively reducing the operation failure rate.
[0009] The data-driven test framework integration module integrates the modular script fragments and the parameterized data set, realizes decoupling of the script and the test data and the adaptive parameters, only needs to update the UI model, supplement the script fragments or adjust the adaptive parameters when the UI layout or the interaction logic changes, does not need to restructure the entire script, supports batch expansion of test cases, such as adding different coupon type test scenarios, improves the reusability and expansion efficiency of the script, with the aid of the static basic interaction coverage constructed by the initial UI model, in combination with the dynamic element interaction path supplemented by the dynamic state capture, in cooperation with the branch scene coverage depending on the context, forms a full-dimensional test coverage system, compared with single static script coverage, is more comprehensive, and the regional adaptive parameter optimization reduces invalid waiting and failure retry in the script execution process, and improves the test execution efficiency. BRIEF DESCRIPTION OF DRAWINGS
[0010] Figure 1 is a flowchart of an automatic script generation method provided by an embodiment of the present application.
[0011] Figure 2 is a flowchart of step 3 provided by an embodiment of the present application. DETAILED DESCRIPTION
[0012] Exemplary embodiments of the present disclosure will be described in greater detail below with reference to the accompanying drawings. Although exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. Rather, these embodiments are provided so that the present disclosure can be more thoroughly understood and the scope of the present disclosure can be accurately conveyed to those skilled in the art.
[0013] As Figure 1 shown, an embodiment of the present application proposes an automatic script generation method, which comprises the following steps: Step 1, extracting initial user interface elements and corresponding element attributes, constructing an initial UI model, the initial UI model comprising layout information and interaction attributes of the initial user interface elements; generating a basic test script fragment based on the initial UI model; Step 2, executing the basic test script fragment, and setting a plurality of interaction behavior tracking points in the user interface to obtain user interface state change data; updating the initial UI model based on the user interface state change data to form an updated UI model; Step 3, based on the updated UI model, a supplementary test script fragment is generated, and a spatial segmentation graph structure is constructed by analyzing the spatial distribution characteristics of the user interface elements; based on the spatial segmentation graph structure, the spatial influence area of the user interface elements is established, and the high-density aggregation area boundary is identified according to the spatial influence area; based on the high-density aggregation area boundary, a functional area division scheme is determined, and the user interface elements are classified into multiple functional areas according to the functional characteristics based on the functional area division scheme; Step 4, based on the user interface state change data, the layout characteristics and interaction attributes of the user interface elements in each functional area are analyzed, test adaptation parameters are generated, and conditional test script branches are generated based on the test adaptation parameters and the context-dependent behavior of the user interface elements; Step 5, the basic test script fragment, the supplementary test script fragment and the conditional test script branch are integrated into the data-driven test framework to form a complete automated test script.
[0014] In the embodiments of the present application, through the interaction behavior tracking point and the UI model dynamic updating mechanism, the newly added dynamic elements in the execution process can be captured in real time, such as the coupon area and element state change of the e-commerce APP, such as the payment button from not clickable to clickable, and the UI model is iteratively updated to avoid the problem of invalid or incomplete coverage of static scripts, and the adaptability of the script in the application of frequent function iteration is improved; based on the spatial distribution characteristics of the UI elements, a spatial segmentation graph is constructed, a spatial influence area is established, and then a high-density aggregation area boundary is identified to divide core functional areas such as navigation area, content display area and user operation area, and the design of classifying elements according to functional characteristics enables the test script to adapt to the interaction characteristics of different areas, improving the logical clarity and execution stability of the script under complex interface; relying on UI state change data, the layout characteristics and interaction attributes of elements in each functional area are extracted, regional test adaptation parameters are generated, and conditional test script branches are constructed, so that the script has dynamic judgment logic and can adjust the execution path according to the pre-operation result, effectively reducing the operation failure rate.
[0015] Through the data-driven test framework integration module, the modular script fragments and parameterized data sets are integrated, the decoupling of the script and the test data and the adaptation parameters is realized, when the UI layout or interaction logic changes, only the UI model, the supplementary script fragment or the adaptation parameter needs to be updated, without the need to reconstruct the entire script, while supporting batch expansion of test cases, such as adding test scenarios of different coupon types, improving the reusability and expansion efficiency of the script; with the help of static basic interaction coverage constructed by the initial UI model, combined with the dynamic element interaction path supplemented by dynamic state capture, and in combination with the branch scene coverage of context-dependent, a full-dimensional test coverage system is formed, which is more comprehensive than single static script coverage, and the optimization of regional adaptation parameters reduces the invalid waiting and failure retry in the script execution process, improving the test execution efficiency.
[0016] In a preferred embodiment of the present application, the step 1 comprises: Step 100, parsing the interface definition file and source code of the target application, identifying and extracting all initial user interface elements, specifically including: parsing the interface definition file and source code of the target application, identifying and extracting all initial user interface elements, first determining the running platform of the target application (Android mobile terminal, Apple mobile terminal or web terminal), selecting a dedicated syntax analyzer accordingly, matching an Android layout file dedicated parser for Android mobile terminals, matching an Apple interface description file dedicated parser for Apple mobile terminals, and matching a web document structure dedicated parser for web terminals; then starting the structured parsing process, synchronously parsing two types of core files of the target application, the first type being the interface definition file, which is a core file directly describing the interface structure, containing the hierarchical relationship of layout tags, such as which component contains which sub-component, the unique identifier of each component, the exclusive mark for distinguishing different components, style parameters, such as the appearance configuration of the component's width, height, color, margin, font size, etc., binding events, such as the events triggered by user interactions, such as clicking, inputting, sliding, and long pressing, etc. key configuration information; the second type is the front-end page rendering related source code, which is responsible for controlling the loading and display of interface components, covering component import statements (used to import system-provided components or external components), class definitions of custom components (including component attribute descriptions and function implementation methods), and instance creation code (code that generates component instances using keywords), component mounting rules of rendering functions, such as how web rendering functions load components to pages, how mobile page loading methods load layouts, and conditional rendering trigger logic (logic that controls whether a component is displayed through judgment statements, exclusive rendering instructions, and component display and hide attributes).
[0017] During the parsing process, the syntax analyzer strictly follows the syntax specifications of the corresponding files, the Android parser parses the layout hierarchy and component attributes according to the syntax rules of the Android layout file; the Apple parser parses the component association and parameters according to the format of the Apple interface description file; the web parser parses the tag structure and rendering logic according to the web document specifications and development framework syntax, and finally converts the tag nesting relationship, component configuration parameters in the interface definition file, and the component calling process, rendering trigger conditions in the source code into a standardized abstract syntax tree. Each node of this syntax tree contains complete information, i.e. component type (explicitly marked as button, text box, drop-down box, list view, etc.), attribute configuration (including unique identifier, style parameter, event binding list, etc.), parent node reference (records the direct superior component identifier of the component), instantiation path (records the complete code path of the component from being imported to creating an instance), ensuring that the information of each component is traceable.
[0018] Then the depth-first traversal algorithm is used to identify elements, starting from the root node of the abstract syntax tree (the web root tag for the web side, the root layout component for Android, and the application window root component for Apple), in the recursive order of root node, child node, and grandchild node, all child nodes are traversed layer by layer, and type judgment and element identification are performed on each node, focusing on identifying declarative-defined user interface elements, which are directly defined in the file, including layout container tags, input box tags, button tags, and drop-down selection tags for the web side; button components, input text components, text display components, and list display components for mobile side; through component import statements, external component libraries are identified, and component instances created through keywords are imported from the library; custom components are generated through class definitions and constructors. After identifying an element, record its component type, attribute configuration, parent node reference, instantiation path, and other core information, and store it in the initial element set; at the same time, start the component instantiation call link tracking mechanism, and use static code analysis tools to check the implicitly declared elements in the source code, which are not directly defined in the initial code and need to meet certain conditions to appear, focusing on tracking component instantiation triggered by dynamic function calls, such as web-side dynamic component creation functions, mobile-side layout loading methods, and condition rendering logic, such as user operation, data state change, and the like, such as list item components loaded after clicking the expand more button, popup components displayed after user input meets the requirements, and chart components created after data loading is completed. Mark and supplement each implicit element to the initial element set to ensure that all initial user interface elements are identified without omission.
[0019] Suppose we want to extract the initial user interface elements of a shopping APP's commodity list page on an Android mobile terminal, the specific process is as follows: First, check the installation package of the Android mobile shopping APP, which is a special installation package for Android system, and the development document also clearly marks it as an Android mobile application, so the special layout file parser for Android is selected accordingly; When parsing the core file, on the one hand, parse the Android layout configuration file of the commodity list page, find that it contains linear layout components (used to nest and wrap commodity card components), text display components (used to display commodity name and commodity price respectively), button components (annotated with shopping cart function), picture components (used to load and display commodity pictures), each component is configured with a unique identifier, among which the button component is bound with a click interaction event, and the text component is configured with font size and font color style parameters; On the other hand, parse the Android development code, identify the component import statements such as importing system button components, importing external picture loading component library picture components, etc. from the code, thereby determining that the application uses an external picture loading component library, and the code also contains class definitions of custom components such as commodity card (covering attribute declarations such as commodity name, commodity price, and button click event handling methods), commodity card instance code created by keywords, and conditional rendering logic (explicitly set to automatically hide the shopping cart button when the commodity inventory is 0).
[0020] After completing the core file parsing, the parser will strictly follow the Android layout file syntax rules to convert the tag nesting relationship, component configuration parameters in the above interface definition file, and component call flow, rendering trigger conditions in the source code into a standardized abstract syntax tree. For example, the node information of the shopping cart button is particularly specific, including component type (button), attribute configuration (unique identifier, width 80px, height 30px, red background), parent node reference (unique identifier of the commodity card component), instantiation path (import system button component, then create instance by keyword, and mount to commodity card component), ensuring that each node information is complete and traceable.
[0021] After the abstract syntax tree is generated, a depth-first traversal algorithm is used to start from the root layout component node, recursively traverse all child nodes layer by layer, identify the declarative defined user interface elements one by one, and finally identify the linear layout component, product name text component, product price text component, add to cart button component, picture component of the external picture loading component library, custom product card instance and other elements, and store the component type, attribute configuration, parent node reference, instantiation path and other core information of these elements into the initial element set one by one; while identifying the declarative elements, the component instantiation call link tracking mechanism is started synchronously, the elements implicitly declared in the source code are checked reversely through the static code analysis tool, it is found in the process that there is a logic in the code that after clicking the load more button, a new product card component is created by calling the dynamic loading layout method, this new product card component needs to be instantiated after clicking operation, which belongs to the implicitly declared element; at the same time, combined with the condition rendering logic of hiding the add to cart button when the product inventory is 0 parsed before, the corresponding inventory 0 prompt text component (which will only be displayed when the inventory is 0) is identified as an implicitly declared element, and then these two types of implicitly declared elements are marked and supplemented to the initial element set one by one.
[0022] After the above series of processes, the initial element set formed finally covers all related elements such as linear layout component, product name text component, product price text component, add to cart button component, product picture component, custom product card instance, new product card component generated after loading more, inventory 0 prompt text component, and completely covers all initial user interface elements of the product list page, ensuring that there is no omission.
[0023] In step 101, the element attributes of each initial user interface element are collected, including position coordinates, size, element type and interactive state, specifically including: after completing the full identification of the initial user interface elements in step 100, a special interface for reading attributes of the rendering engine of the corresponding platform is called to accurately collect the core attributes of each element. The position coordinates are recorded in a two-dimensional coordinate system of the element relative to the direct parent container. First, the direct parent container of the element is located, such as the linear layout container of Android or the layout container of a webpage. Then, the horizontal coordinate (x1) and the vertical coordinate (y1) of the top left corner of the element are directly read by using the methods of getting the left distance from the left boundary of the parent container and getting the top distance from the top boundary of the parent container of the mobile terminal view class, or the left offset relative to the parent container and the top offset relative to the parent container attributes of the webpage document element. The horizontal coordinate (x2) and the vertical coordinate (y2) of the bottom right corner of the element are read by using the methods of getting the right distance from the left boundary of the parent container and getting the bottom distance from the top boundary of the parent container of the mobile terminal view class, or the right offset relative to the parent container and the bottom offset relative to the parent container attributes of the webpage document element. The size is calculated based on the two collected vertex coordinates by the formula, width = x2-x1, height = y2-y1. The element type is determined by analyzing the declaration identifier of the component, for example, the component corresponding to the button class tag in the Android layout file is determined as the button type, the component with the input class tag and the text input function attribute in the webpage is determined as the input box type, the selection class component instance imported by the component library is determined as the drop-down menu type, and the specific types such as button, input box, list item, drop-down menu and check box are clearly classified. The interactive state is determined by jointly reading multiple core attribute fields of the element. The priority is set. First, the enabled state is checked. If it is not available, all interactions are excluded. Then, the special interactive attribute is checked. If the enabled state is available and the clickable state is allowed, it is determined that the click operation is supported. If the enabled state is available and the input state is allowed, it is determined that the input operation is supported. If the enabled state is available and the selection state is allowed, it is determined that the selection operation is supported. Finally, all the interactive types supported by each element are clearly determined.
[0024] At step 102, an initial UI model is constructed based on the initial user interface elements and element attributes, a hierarchical relationship between the initial user interface elements is established, and a basic test script fragment containing a complete operation sequence is generated according to the layout information and interaction attributes of the initial user interface elements in the initial UI model, specifically including: based on the complete element attributes collected in step 101 and the initial user interface element set identified in step 100, taking each element as an independent node, constructing the initial UI model, first establishing a four-level hierarchical association according to the tag nesting relationship in the interface definition file, such as the relative layout parent tag containing the text display sub-tag in the Android layout file, the form parent tag containing the button sub-tag in the webpage, and the calling logic of the parent-child components in the source code, such as the direct calling of the child component in the rendering function of the parent component, the association achieved through the reference passing of the child component, the root node is the page core container, such as the mobile page container of Android, the Apple page controller of Apple, and the page main container of the webpage, the second level is the page layout container, such as the linear layout container of Android and the webpage layout block of the webpage, the third level is the business function module, such as the login module and the commodity list module, and the fourth level is the specific user interface element, wherein the execution logic of the rendering function is quantitatively described by a formula, the formula is rendering function execution result = basic component mounting order + conditional trigger identifier x dynamic component instantiation quantity, wherein the basic component mounting order is the fixed component loading priority preset by the application interface, which is quantified as an ordered numerical sequence of 1, 2, 3, …, and the smaller the numerical value, the higher the component mounting priority; the conditional trigger identifier is a binary variable, taking value 0 means that the condition rendering is not triggered, i.e. no additional dynamic component needs to be loaded, and taking value 1 means that the condition rendering is triggered (dynamic components need to be loaded according to the rules); the dynamic component instantiation quantity is the actual number of newly added components after triggering the condition rendering, which is quantified as a non-negative integer (0 and above) (0 when not triggered, and the actual number of newly added components when triggered), through the calculation logic of the formula, the final rendering order (sorted according to the numerical value of the rendering function execution result) and the instantiation quantity (the sum of the number of basic components and the number of dynamically added components) of the component can be directly determined, realizing the standardized definition of the component rendering rule; the initial UI model synchronously stores the complete information of each element, such as the hierarchical relationship, position coordinates, size, element type, and interactive state, and finally forms a structured and traceable initial UI model.
[0025] When the basic test script fragment is generated based on the initial UI model, the interactive elements are sorted according to the rule that the core priority of the business process is higher than the visual order, the core business process related elements are sorted preferentially, for example, the login page needs to input the account first, then input the password, then check the agreement, and finally click the login, and the business logic is strictly sorted; the elements without business dependency are supplemented by sorting according to the visual order from top to bottom and from left to right of the interface, then a unique positioning method is generated for each interactive element, the unique identification of the element is preferentially extracted as the positioning basis, if the element has no unique identification, a composite positioning expression is generated by combining the hierarchical path description (the complete hierarchical link from the root node to the element) + the position coordinate range (the interval composed of the upper left corner coordinates x1, y1 and the lower right corner coordinates x2, y2) + the element type, so as to ensure that the positioning result has no ambiguity; finally, the corresponding interactive action type of each element is matched, such as clicking, inputting fixed test data, selecting a drop-down option, etc., all positioning expressions and interactive actions are sequentially concatenated according to the sorting result, and the basic test script fragment containing the complete operation sequence is formed.
[0026] In this embodiment, the initial user interface elements are comprehensively identified and the attributes are accurately collected by parsing the interface definition file and the source code by the system, the element omission problem caused by the dependence of static analysis on manual recording is avoided, the hierarchical relationship and the interaction attribute between the elements are clarified by the constructed initial UI model, the structured generation basis is provided for the basic test script fragment, the basic test script fragment containing the complete operation sequence is generated, the core interaction path of the initial interface is covered, the defect that the initial path of the static script is not fully covered is solved, and the initial integrity and the execution accuracy of the test script are improved.
[0027] In a preferred embodiment of the present application, the step 2 comprises: In step 200, the operation sequence in the basic test script fragment is executed, and interaction behavior tracking points are set in the key interaction areas of the user interface, including setting a first interaction behavior tracking point in the interface top navigation area, a second interaction behavior tracking point in the main content display area, and a third interaction behavior tracking point in the bottom operation area. Specifically, first, the basic test script fragment generated in step 102 is loaded into the automatic test execution engine corresponding to the target application platform. Mobile end applications are adapted to mobile end automatic test execution engines, and web applications are adapted to web end automatic test execution engines. The execution engine simulates the operation logic of a real user, executes the operation sequence contained in the script in order, and at the same time, through the element listening interface of the test execution engine, interaction behavior tracking points are deployed in the three key interaction areas of the user interface. The first interaction behavior tracking point is deployed in the interface top navigation area. The actual height value of the top navigation bar component is obtained through the execution engine, and the lower limit of the coverage range is calculated according to the formula: lower limit of coverage range = vertical coordinate value of the top edge of the interface + height value of the top navigation bar. The vertical coordinate value of the top edge of the interface is fixed at 0, and the final coverage range is defined as the top edge (vertical coordinate value 0) to the lower edge corresponding to the lower limit of the coverage range. The second interaction behavior tracking point is deployed in the main content display area, and its coverage range is from the lower edge of the top navigation bar to the upper edge of the bottom operation area, which is calculated by the formula: upper edge of bottom operation area = vertical coordinate value of the bottom edge of the interface - height value of the bottom operation area component. The vertical coordinate value of the bottom edge of the interface and the height value of the bottom operation area component are obtained by the execution engine. The third interaction behavior tracking point is deployed in the bottom operation area, and its coverage range is directly defined as the upper edge of the bottom operation area to the bottom edge of the interface. Each interaction behavior tracking point is bound to four types of core events, namely element loading events such as web page loading completion events, mobile end interface layout completion events, rendering completion events, attribute change listening mechanisms, core interaction events such as clicks and inputs, and through multi-event binding, the state changes of elements in the corresponding area are comprehensively and real-time monitored.
[0028] In step 201, the user interface state change data is recorded in real time through the interactive behavior tracking points, and based on the user interface state change data, the dynamically loaded user interface elements and the user interface element state changes are identified, specifically including: three interactive behavior tracking points capture various state change data of the user interface in real time through the binding of the listening event callback function, the execution logic of the callback function is described by a quantitative formula, the formula is O = I x W + C + T, in the formula, O represents the output result of the listening event callback function, that is, the state change data coding after standardization; I represents the unique identification coding of each user interface element, which is a unique positive integer generated by mapping the element unique identification, ensuring that the coding of different elements is not repeated; W represents the event type weight, which is a fixed value preset according to the state change type (element addition W = 1, element deletion W = 2, position coordinate offset W = 3, size parameter adjustment W = 4, element type association change W = 5, interactive state switching W = 6, display or hidden state change W = 7); C represents the change content quantitative value, which is the numerical value converted from the specific change information, such as the coordinate difference value of the position offset, 0 / 1 is used to represent the state switching, 0 corresponds to the initial state and 1 corresponds to the changed state; T represents the timestamp serialization value, which is the numerical value converted from the original timestamp to 10-bit integer format, ensuring that the time dimension is traceable.
[0029] All the data captured and standardized through the callback function are stored in the fixed structure of element unique identification, change type, change content and change timestamp, and the data coverage range includes element addition, element deletion, position coordinate offset, size parameter adjustment, element type association change, interactive state switching, display or hidden state change and various interface state changes; after the data capture is completed, all the state change data are aligned and compared with the element information in the initial UI model one by one, that is, the element unique identification is taken as the core index, the elements without matching records in the initial UI model are first screened out, then the visibility verification mechanism of the tracking point is used to verify whether the elements meet the condition of "display state being display and visibility state being visible", the elements meeting the condition are directly determined as the dynamically loaded user interface elements, and for the elements already existing in the initial UI model, the specific numerical values before and after the change of each attribute field are recorded one by one, finally the complete information of the dynamically loaded elements and the state change information of the original elements are integrated to form the structured user interface element state change data set.
[0030] Step 202, using the dynamically loaded user interface element and user interface element state change update initial UI model, form updated UI model, specifically including: based on the user interface element state change data set generated in step 201, carry out the updating operation of the initial UI model, first, for the dynamically loaded user interface element identified in the data set, through the parent container associated attribute of the element, locate the direct parent container of the element in the current interface, and then query the specific hierarchical position of the direct parent container in the initial UI model, according to the four-level hierarchical structure rule of the initial UI model, insert the dynamically loaded element as a child node into the corresponding level, and at the same time, completely supplement the position coordinates, size, element type, interactive state and all other core attribute information of the dynamic element, to ensure the structural integrity and attribute integrity of the dynamic element in the model; then, according to the element unique identifier, the corresponding element in the initial UI model is traversed in sequence, and the position coordinate parameter of the element is corrected, the size value is adjusted, the interactive state identifier is updated, and other attribute fields that have changed are modified, to ensure that the attribute information of the original element in the model is consistent with the actual state of the interface; when all the addition operations of the dynamic elements and the attribute update operations of the original elements are completed, the actual information of all elements in the current interface is collected in real time through the automatic test execution engine, and the collected actual information is fully consistent with the updated UI model. The verification range covers the hierarchical relationship of the elements, all attribute fields, and the verification rule is explicitly set as the error value of a single attribute field ≤ the preset error threshold, wherein the preset error threshold of the coordinate type (position coordinates) and the size type (size) attribute is ±1 pixel, and the preset error threshold of the state type (interactive state, display state), type type (element type) and structure type (hierarchical relationship) attribute is 0, that is, completely consistent. Through the rule, it is ensured that the error of each data in the model is within a reasonable range, and finally the updated UI model is completely matched with the actual state of the interface, forming a standardized and high-precision updated UI model.
[0031] In this embodiment, by setting specific interactive behavior tracking points in the key interactive area, the user interface state change data is fully captured, the state change of the dynamically loaded user interface element and the original element is effectively identified, and the deficiency that static analysis cannot perceive the dynamic change of the interface is made up; through the dynamic updating mechanism, the initial UI model is iteratively optimized, so that the UI model can match the actual state of the application interface in real time, and the problem of poor adaptability of the script when facing UI layout adjustment or dynamic element loading is solved; the updated UI model improves the adaptation ability of the automatic test script to the application function iteration and interface dynamic change.
[0032] As shown in Figure 2 In another preferred embodiment of the application, step 3 includes: At step 300, based on the updated UI model, the dynamically loaded user interface elements and corresponding element attributes are identified, and based on the dynamically loaded user interface elements and element attributes, a supplementary test script fragment is generated, specifically including: based on the updated UI model, first, the user interface element set in the initial UI model and the updated UI model is extracted respectively, and an element unique identification index library is established for the two sets respectively, and by performing set difference operation on the two index libraries, the element unique identification existing only in the updated UI model index library is screened out, and the corresponding user interface element is the newly added element, and it is determined that the newly added element is a dynamically loaded user interface element; then, all dynamically loaded user interface elements are traversed, and the system extracts the complete element attributes of each element, that is, the layout attributes cover the position coordinates of the element in the unified coordinate system (left upper corner X-axis coordinate, left upper corner Y-axis coordinate, right lower corner X-axis coordinate, right lower corner Y-axis coordinate), width and height size (width = right lower corner X-axis coordinate - left upper corner X-axis coordinate, height = right lower corner Y-axis coordinate - left upper corner Y-axis coordinate), hierarchical relationship (priority number of the element in the interface rendering level); the interaction attributes cover the binding event type (click, input, sliding, etc.), the event trigger condition (the user operation action or data state required for triggering); the state attributes cover the display and hidden state (display / hidden identification), the interactive state (operable / inoperable identification); based on the extracted dynamically loaded user interface elements and corresponding complete attributes, the syntax specification of the basic test script fragment is followed, including element positioning format, interaction instruction structure, and state verification logic, a supplementary test script fragment containing element positioning statements (positioning based on unique identification and position coordinates), interaction trigger statements (matching element binding event type), and state verification statements (verifying display state and interactive state) is generated, to ensure that the supplementary test script fragment and the basic test script fragment are completely compatible in syntax format and execution logic, and seamless connection is achieved.
[0033] Step 301: Based on the updated UI model, analyze the spatial distribution characteristics of user interface elements, construct a spatial segmentation graph structure, and establish the spatial influence area of user interface elements based on the spatial segmentation graph structure. Specifically, based on the updated UI model, firstly, establish a unified coordinate system for the user interface, with the top-left corner of the user interface as the origin, the horizontal direction to the right as the positive X-axis, and the vertical direction downward as the positive Y-axis. The coordinate unit is unified as pixels. Under this coordinate system, the actual display range of each user interface element is converted into a rectangular bounding box. Its core parameters are directly extracted from the element layout attributes. The top-left corner coordinates (X1, Y1) correspond to the top-left X-axis and Y-axis coordinates of the element layout attributes, and the bottom-right corner coordinates (X2, Y2) correspond to the bottom-right X-axis and Y-axis coordinates of the element layout attributes. This provides a basis for subsequent spatial analysis. Further, based on the extracted bounding box parameters, calculate the core spatial parameters of each element. That is, the center X-coordinate is calculated by the average of the top-left and bottom-right X-axis coordinates. The formula is: Center X Coordinate The center Y-coordinate is calculated by averaging the Y-axis coordinates of the top left and bottom right corners. The formula is: Center Y-coordinate The diagonal length of a rectangular bounding box is derived using the formula for the distance between two points. The formula is: Diagonal length The square operation is based on the coordinate difference in pixels, and the square root operation is used to obtain the actual pixel length of the diagonal.
[0034] After calculating the core spatial parameters of the elements, a spatial segmentation map structure is constructed based on the overall size parameters of the user interface (interface width W, interface height H, both in pixels). Considering the average width and height of mainstream user interface elements such as buttons, text boxes, and icons, and balancing segmentation accuracy and computational efficiency, the grid cell size is set to a×a (a is a preset fixed pixel value, taken as 60 pixels). Combining the interface size and the grid cell size, the number of grid cells in the spatial segmentation map is calculated, i.e., the number of horizontal grids is the ratio of the interface width to the grid cell side length rounded up. The formula is: [Formula for horizontal grid count]. , This represents the floor operation, i.e., when... When the result is not divisible by 60, take the integer part of the quotient and add 1); the vertical grid number is the ratio of the interface height to the grid cell side length, rounded up, and the formula is: Vertical Grid Number ; according to the calculated transverse and longitudinal grid numbers, a two-dimensional space segmentation graph structure is built, each grid unit is taken as an independent node, and (i, j) is taken as the node coordinate identification (i is the longitudinal serial number, and the value range is 1 to the longitudinal grid number; j is the transverse serial number, and the value range is 1 to the transverse grid number), each node not only records its own coordinate range (X range is (j-1) * 60 to j * 60, and Y range is (i-1) * 60 to i * 60), but also synchronously records the unique identification of all user interface elements falling within the coordinate range, forming the association mapping relationship between the grid unit and the element.
[0035] On the basis of the space segmentation graph structure, the spatial influence area of each user interface element is established, the center coordinate (center X coordinate, center Y coordinate) of the element is taken as the center of the circle, and half of the diagonal length of the element is taken as the influence radius (the influence radius calculation formula is, influence radius ), a circular spatial influence area is constructed, and the boundary of the area is described by the standard equation of the circle as The center coordinate is the center coordinate, and the influence radius (where x and y are coordinates of any point in the area). To clarify the spatial association between elements, the spatial influence areas of any two elements are determined: first, the distance between the two centers is calculated by the distance formula between two points, and the formula is center distance , where x and y are coordinates of any point in the area; to clarify the spatial association between elements, the spatial influence areas of any two elements are determined, first, the distance between the two centers is calculated by the distance formula between two points, and the formula is center distance , if the calculated center distance is less than the sum of the influence radii of the two elements, it is determined that the two areas overlap; for the overlapping areas, the intersection X and Y coordinates are obtained by solving the quadratic equation after eliminating the two circle standard equations, the coordinate range of the overlapping area is determined with the intersection coordinates as the vertex, and all element unique identifications and mutual association relationships participating in the overlap are recorded, and finally the spatial influence area of all user interface elements is established.
[0036] Step 302, based on the spatial influence area, the boundary of the high-density aggregation area of the user interface element is identified, and based on the boundary of the high-density aggregation area, the function area division scheme is determined, wherein the function area division scheme divides the user interface into a navigation function area, a content display area and a user operation area, and specifically includes: based on the spatial influence area of all user interface elements and the space segmentation graph structure, first, the high-density aggregation area identification is carried out: each grid unit in the space segmentation graph is traversed, and the total number of user interface elements recorded in each grid unit through the association mapping (i.e. the number of elements actually falling within the grid coordinate range) is counted. The element density of each grid unit is calculated in combination with the grid unit size: the grid unit area is the square of the side length, and the calculation formula is grid unit area ); element density is the ratio of the number of elements in the grid cell to the area of the grid cell, and the calculation formula is , and the density unit is unified as the number of elements To accurately screen high-density grid cells, statistical parameters of the element density of all grid cells need to be calculated, wherein the average value μ is the arithmetic mean of the density of all grid cells, and the calculation formula is μ , wherein is the total number of grid cells of the spatial segmentation map, is the element density of the kth grid cell; the standard deviation σ is used to reflect the dispersion degree of the density data, and the calculation formula is σ , that is, the square sum of the difference between the density of each grid cell and the average value divided by the total number of grid cells, and the square root is taken, and the density threshold T is set as the sum of the average value and the standard deviation, and the formula is T = μ + σ. The grid cell with an element density >T is marked as a high-density grid cell.
[0037] The connected region analysis algorithm is used to merge the high-density grid cells, and all high-density grid cells are traversed in the order from left to right and from top to bottom. For the currently traversed high-density grid cell (i, j), it is judged whether there is another high-density grid cell in the X-axis direction (left and right adjacent grids (i, j-1), (i, j+1) in the same row) and the Y-axis direction (up and down adjacent grids (i-1, j), (i+1, j) in the same column). If there is an adjacent high-density grid cell sharing an edge, the two are merged into the same connected region. The traversal and merging process is repeated until all high-density grid cells are merged into a unique connected region, and each connected region is a high-density aggregation area.
[0038] When calculating the boundary parameters of each high-density aggregation area, the X range of all grid cells in the aggregation area is traversed, the minimum X value is extracted as the minimum X coordinate of the aggregation area, and the maximum X value is extracted as the maximum X coordinate of the aggregation area. Similarly, the Y range of all grid cells in the aggregation area is traversed, the minimum Y value is extracted as the minimum Y coordinate of the aggregation area, and the maximum Y value is extracted as the maximum Y coordinate of the aggregation area. The four parameters form the rectangular boundary of the high-density aggregation area (X range: minimum X coordinate of the aggregation area to maximum X coordinate of the aggregation area, Y range: minimum Y coordinate of the aggregation area to maximum Y coordinate of the aggregation area).
[0039] In combination with the location feature, size feature and element function attribute of the high-density aggregation area, the function area division scheme is determined according to the following rules. For the determination of the navigation function area, if the Y coordinate range of the high-density aggregation area falls in the top (Y range is 0 to H / 5) or bottom (Y range is 4H / 5 to H) of the user interface, and the vertical size (calculated by subtracting the minimum Y coordinate from the maximum Y coordinate of the aggregation area) is less than H / 5, and the elements contained in the aggregation area are mainly jump type and menu type elements (determined based on the element interaction attribute), the high-density aggregation area is divided into the navigation function area. For the determination of the content display area, if the Y coordinate range of the high-density aggregation area falls in the middle area (Y range is H / 5 to 4H / 5) of the user interface, and the horizontal size (calculated by subtracting the minimum X coordinate from the maximum X coordinate of the aggregation area) is greater than 3W / 4, and the elements contained in the aggregation area are mainly text display type and picture display type elements (determined based on the element state attribute and layout attribute), the high-density aggregation area is divided into the content display area. For the determination of the user operation area, if the elements contained in the high-density aggregation area are mainly interactive type elements such as button type, input box type and selection box type (determined based on the element interaction attribute), and the Y coordinate range falls in the middle (Y range is H / 5 to 3H / 5) or bottom (Y range is 3H / 5 to H) of the user interface, the high-density aggregation area is divided into the user operation area.
[0040] In step 303, based on the function area division scheme, the user interface elements in the updated UI model are classified into the navigation function area, the content display area or the user operation area according to the function characteristics, specifically including: based on the function area division scheme determined in step 302, the rectangular boundary parameters (minimum X coordinate, maximum X coordinate, minimum Y coordinate and maximum Y coordinate) of the navigation function area, the content display area and the user operation area are first extracted to provide a basis for element classification; all user interface elements in the updated UI model are traversed, the center coordinates (Xc, Yc) of each element calculated in step 301 are extracted, and the function area classification is performed through coordinate range matching. If the element center coordinate Xc is between the minimum X coordinate and the maximum X coordinate of the navigation function area, and Yc is between the minimum Y coordinate and the maximum Y coordinate of the navigation function area, the element is classified into the navigation function area. If the element center coordinate Xc is between the minimum X coordinate and the maximum X coordinate of the content display area, and Yc is between the minimum Y coordinate and the maximum Y coordinate of the content display area, the element is classified into the content display area. If the element center coordinate Xc is between the minimum X coordinate and the maximum X coordinate of the user operation area, and Yc is between the minimum Y coordinate and the maximum Y coordinate of the user operation area, the element is classified into the user operation area.
[0041] For the scattered elements that do not fall within the boundary of any high-density aggregation area rectangle, supplementary classification is performed based on the functional attributes of the elements, that is, by analyzing the interactive attributes and state attributes of the elements, if the elements have navigation functions such as jumping and menu switching, the elements are classified into the navigation function area; if the elements only have information display functions and have no interactive event binding, the elements are classified into the content display area; if the elements have user-operable interactive functions such as click and input event binding, the elements are classified into the user operation area, so that all user interface elements in the updated UI model are accurately classified into the corresponding functional areas without omission or mismatch.
[0042] In this embodiment, the adaptability of the test script to the dynamic interface scene is ensured by identifying the dynamically loaded user interface elements and generating a supplementary test script segment; the division of the functional areas is realized by constructing a space segmentation graph and a space influence area with the aid of spatial distribution feature analysis, and identifying the boundary of the high-density aggregation area by density calculation and connected region analysis; the functional attribution and spatial correlation of the elements are clarified by classifying the user interface elements according to the functional characteristics, and the logical rationality of the test script and the comprehensiveness of the scene coverage are improved.
[0043] In a preferred embodiment of the present application, the step 4 comprises: Step 400: Based on the user interface state change data, layout feature data of user interface elements in each functional area is extracted, specifically including: based on the user interface element state change data generated in step 201, in combination with the functional area classification result determined in step 303, layout feature data of user interface elements in each area is extracted in three categories of navigation function area, content display area and user operation area, the extraction dimension covers element arrangement, element spacing, alignment, hierarchical distribution, element density and element size consistency, and the specific process is as follows: first, determine the element arrangement, analyze the X1, Y1 coordinates of the top left corner of all user interface elements in the area, and preset the spacing threshold value as 10 pixels, which is suitable for the standard spacing range of most UI designs, can effectively distinguish the element arrangement direction, and avoid the determination deviation caused by too close or too far spacing; if the Y1 coordinate difference between elements is ≤10 pixels, it is determined as horizontal arrangement; if the X1 coordinate difference between elements is ≤10 pixels, it is determined as vertical arrangement; if the coordinate distribution characteristics of horizontal and vertical arrangement are both met, it is determined as grid arrangement.
[0044] Secondly, the element spacing is calculated. For adjacent elements in the same arrangement direction, the difference between X1 of the latter element and X2 of the former element is taken when arranged horizontally, and the difference between Y1 of the latter element and Y2 of the former element is taken when arranged vertically. The spacing values of all adjacent elements in the region are counted, and the average and standard deviation of the spacing are calculated as the element spacing characteristics of the region. Then, the alignment mode is determined. The X1 coordinates (to determine left alignment), X2 coordinates (to determine right alignment), Y1 coordinates (to determine top alignment), or Y2 coordinates (to determine bottom alignment) of all elements in the region are compared, and the proportion of elements with the same coordinate value is counted. The alignment mode with the highest proportion is the main alignment mode of the region. Then, the hierarchical attribute value of each element in the region is extracted, and the number and proportion of elements corresponding to each level are counted. The proportion = the number of elements of the level ÷ the total number of elements in the region, forming the hierarchical distribution characteristic data. Then, the element density is calculated. The grid cell density data calculated in step 302 is reused, and the density values of all grid cells in the corresponding functional region are summarized. The average value is taken as the element density of the functional region, and the density unit is the number of elements. .
[0045] Finally, the size consistency feature is extracted. First, the average width of all elements in the region (average width = the sum of the widths of all elements in the region ÷ the total number of elements in the region) and the average height (average height = the sum of the heights of all elements in the region ÷ the total number of elements in the region) are calculated. Then, all elements in the region are traversed one by one, and the difference between the width of each element and the average width of the region is calculated. The width difference proportion = |single element width - average width| ÷ average width x 100%, and the difference between the height of each element and the average height of the region is calculated. The height difference proportion = |single element height - average height| ÷ average height x 100%. The preset proportion threshold is 10%. It is determined whether each element satisfies the width difference proportion ≤ 10% and the height difference proportion ≤ 10% at the same time. The elements that satisfy both conditions are marked as size consistent elements, and the number of all size consistent elements is counted, which is the number of elements that meet the conditions. Finally, the proportion of size consistency feature = the number of elements that meet the conditions ÷ the total number of elements in the region, and the calculated proportion is taken as the size consistency feature of the region.
[0046] Step 401, based on the layout feature data, determine the interaction attribute data of the user interface elements in each functional area, specifically including: based on the layout feature data extracted in step 400, combined with the interaction event records in the user interface state change data, further determine the interaction attribute data of the user interface elements in each functional area, including user interface element response time data, interaction success rate data, error handling mechanism data, the specific determination process is as follows: for response time data, for each interactive element, extract the trigger timestamp and feedback timestamp (feedback timestamp is the time point when the element interaction produces explicit state change) of each interaction event from the state change data, calculate the single response time by the formula single response time = feedback timestamp - trigger timestamp, and calculate the average value and maximum value of all single response time of the element as the response time data of the element; aggregate the average value of the response time of all interactive elements in the same functional area to form the response time data set of the region; for interaction success rate data, count the total interaction times and successful interaction times of all interactive elements in the same functional area, wherein the successful interaction criterion is that the preset feedback event is triggered after interaction, such as button click jump, input content verification pass and no corresponding error record in the state change data; calculate the interaction success rate of each element by the formula interaction success rate = successful interaction times ÷ total interaction times × 100%, and aggregate the interaction success rates of all elements to form the interaction success rate data set of the region; for error handling mechanism data, extract the error type, error trigger frequency and error handling completion time (error handling completion time is the time length from error trigger to interface recovery to normal interactive state) in the element interaction process in the region from the state change data; calculate the average processing completion time of each type of error by the formula average processing completion time of each type of error = sum of all error processing times of this type ÷ error trigger times of this type, and calculate the average processing completion time of each type of error, combined with the error type and trigger frequency, to form the error handling mechanism data set of the region.
[0047] Step 402, based on the interaction attribute data, generate test adaptation parameters corresponding to each functional area, wherein step 402a, based on the user interface element response time data in the interaction attribute data, generate the operation delay time parameter corresponding to the functional area, specifically including: based on the response time data set determined in step 401, generate the corresponding operation delay time parameter according to the functional area, and the specific calculation process is unfolded in logical order, when calculating the average mean value of the area response time, the average value of the response time of all interactive elements in the functional area is summed up, and then divided by the number of elements, the formula is area response time average mean value=(sum of all element response time average value)÷element quantity, which reflects the conventional response level of most normal interactions in the area; when calculating the maximum mean value of the area response time, the maximum value of the response time of all interactive elements in the functional area is summed up, and then divided by the number of elements, the formula is area response time maximum mean value=(sum of all element response time maximum value)÷element quantity, which covers the special interaction scenarios with longer time consumption in the area; When calculating the operation delay time parameter, the result is obtained through the formula operation delay time parameter=area response time average mean value×1.2+area response time maximum mean value×0.3, wherein 1.2 and 0.3 are weight coefficients set based on the adaptability of interaction scenarios: 1.2 is used to amplify the influence of the conventional response level (because the average value can reflect the characteristics of most interactions), and 0.3 is used to consider the special time-consuming scenarios, the combination of the two ensures that the parameter not only fits the conventional demand, but also is compatible with extreme cases, so as to cover the response demand of most interaction scenarios.
[0048] Step 402b, based on the user interface element interaction success rate data in the interaction attribute data, generate the operation retry times parameter corresponding to the functional area, specifically including: based on the interaction success rate data set determined in step 401, generate the corresponding operation retry times parameter according to the functional area, and the specific calculation process is as follows, when calculating the area average interaction success rate, the interaction success rate of all interactive elements in the functional area is summed up, and then divided by the number of elements, the formula is area average interaction success rate=(sum of all element interaction success rate)÷element quantity, which reflects the overall reliability of the interaction operation in the area; when calculating the operation retry times parameter, the result is obtained through the formula operation retry times parameter= The adjustment coefficient 5 is a reasonable value based on a large number of test scenarios, which can make the retry times and the success rate form a linear correlation (the lower the success rate, the more the retry times); the upward rounding operation ensures that the retry times are non-negative integers, which conforms to the actual test execution logic; the special case processing is that if the above calculation result is 0, it means that the area average interaction success rate is very high, but in order to ensure the interaction fault tolerance of a single failure caused by sudden network fluctuations in extreme cases, the operation retry times parameter is set to 1.
[0049] Step 402c, based on the user interface element error handling mechanism data in the interaction attribute data, generate the operation timeout threshold parameter of the corresponding function area, specifically including: based on the user interface element error handling mechanism data in the interaction attribute data determined in step 401, combined with the maximum average response time of the region obtained in step 402a, generate the corresponding operation timeout threshold parameter of the function area, the specific calculation process is as follows, first calculate the sum of the average processing time of all error types in the function area, then divide by the number of error types, get the average error handling time of the region, this value reflects the general time-consuming of error handling in the region, then through the formula operation timeout threshold parameter = region average error handling time × 1.5 + region response time maximum average value calculation result, wherein the 1.5 times coefficient is used to cover the potential time fluctuation in the error handling process, and the maximum average value of the region response time is added to consider the timeout requirements of normal interaction and error handling, so as to ensure that the parameter can comprehensively cover the timeout judgment of various interaction scenarios.
[0050] Step 403, based on the test adaptation parameters and the context-dependent behavior characteristics of the user interface elements, generate conditional test script branches containing conditional judgment logic, specifically including: based on the test adaptation parameters generated in steps 402a, 402b, 402c, that is, the operation delay time parameter, the operation retry number parameter, and the operation timeout threshold parameter, combined with the context-dependent behavior characteristics of the user interface elements, covering the pre-conditional of element interaction, the post-associated elements, and the state switching logic, generate conditional test script branches containing conditional judgment logic, the specific implementation process is as follows, first extract the context-dependent behavior characteristics of the user interface elements in each function area, and determine the pre-conditions of element interaction, such as whether the pre-elements are loaded, whether the pre-interactions are successfully executed, and whether the specific data meets the requirements and the post-associated logic, such as the associated element interaction to be triggered after the current element interaction is successful, and the target state to be switched to the interface state; secondly, based on the test adaptation parameters, design the corresponding conditional judgment logic, if the interaction response time exceeds the operation delay time parameter, trigger the waiting mechanism (waiting time = operation delay time parameter - time consumed, to avoid false judgment due to normal time consumption); if the number of interaction failures reaches the operation retry number parameter, trigger error recording and branch jump (record error type and context, jump to the backup interaction path or test termination process); if the interaction duration exceeds the operation timeout threshold parameter, trigger the timeout termination and retry process (terminate the current invalid interaction, execute the retry according to the retry number parameter, and record the timeout error if the retry fails); Finally, the conditional judgment logic is combined with the context-dependent behavior characteristics to generate a conditional test script branch for the corresponding functional area according to the fixed process of precondition judgment, interactive execution, parameter verification, and post-association trigger. Each branch contains explicit conditional trigger rules, execution logic, and jump paths. Then, the branch is integrated with the basic test script segment generated in step 102 and the supplementary test script segment generated in step 300 to ensure that the script can adapt to the interactive characteristics and dependency relationships of different functional areas.
[0051] In this embodiment, the layout feature data of each functional area is extracted to realize the association mapping of layout features and interactive behaviors, avoiding parameter deviation caused by indiscriminate analysis. The interactive attribute data is determined based on the layout feature data to establish the association logic between layout and interactive effect, making the interactive attribute data more consistent with the regional functional characteristics and providing a reliable basis for the generation of test adaptation parameters. The operation delay time, operation retry number, and operation timeout threshold are generated through standardized calculation to make the parameters have scene adaptability and fault tolerance, effectively improving the stability and accuracy in the test execution process. The conditional test script branch is generated by combining the test adaptation parameters and the context-dependent behavior characteristics to realize the coverage of dynamic interactive scenarios and dependency relationships by the test script, improving the flexibility and pertinence of the test script and avoiding the problem that fixed scripts cannot adapt to complex interactive logic. The overall process realizes layer-by-layer data analysis and parameter generation to make the test script adapt to the characteristics and interactive requirements of different functional areas, improving the comprehensiveness, accuracy, and execution efficiency of the test, and providing strong support for the stable test of the user interface.
[0052] In a preferred embodiment of the present application, step 5 comprises: Step 500, constructing a data-driven test framework based on the test adaptation parameters, the data-driven test framework comprising a parameterized test data set and a test logic controller, specifically comprising: based on the test adaptation parameters (operation delay time parameter, operation retry number parameter, operation timeout threshold parameter) generated in steps 402a, 402b and 402c, constructing a data-driven test framework, which is composed of two parts of parameterized test data set and test logic controller, the specific process is as follows: when constructing the parameterized test data set, first define the unique identification system with the functional area as the core dimension, the functional area ID adopts the standardized format of area type and serial number, such as user operation area 01, content display area 02, navigation function area 03, to ensure that the identification is unique and strictly consistent with the functional area classification result determined in step 303; the element set identification is associated with the unique ID list of all elements in the area, the element unique ID adopts the format of functional area ID, element type, serial number, such as user operation area 01, submit button 03, content display area 02, list component 05, to realize the strong binding of elements and functional areas; on this basis, structured data set is constructed in JSON format, each data record uniquely corresponds to a functional area, containing the following core fields: functional area ID as the unique identification field, consistent with the functional area classification result; operation delay time parameter is the parameter value corresponding to the area calculated in step 402a; operation retry number parameter is the non-negative integer parameter calculated in step 402b; operation timeout threshold parameter is the parameter value corresponding to the area calculated in step 402c; the associated element ID list stores the unique IDs of all interactive elements in the area in array form, such as [user operation area 01, submit button 03, user operation area 01, input box 06]; the parameter effective priority is numerically set as user operation area (3) > content display area (2) > navigation function area (1), the larger the value, the higher the framework call priority; after data entry is completed, double verification is performed through data verification tool, i.e. field integrity requires no missing parameters and no invalid IDs, such as non-existent functional area ID or element ID; the logic consistency requires that all parameter values are non-negative numbers, and the priority value strictly matches the area type, such as the priority of user operation area must be 3, and the parameterized test data set can be finally called after verification.
[0053] After the construction of the parameterized test data set is completed, the test logic controller is developed using a modular development mode. The core includes three functional modules, and each module implements the following logic: the parameter analysis module has a built-in JSON parsing engine, and the logic of matching by function area ID, field extraction, parameter format conversion, and sequence binding is executed in the above order. First, the corresponding record in the parameterized data set is matched according to the function area identifier in the test sequence header, and after all test adaptation parameters are extracted, they are converted into a format that can be recognized by the framework, such as converting string type parameter values into integers. Then, the parameter name is bound to the parameter placeholder in the test sequence one by one. The sequence scheduling module has preset basic scheduling rules, including initial sequence priority, dynamic sequence completion, and conditional sequence on-demand triggering. It also has embedded parameter effective priority judgment logic. When multiple function area test sequences need to be loaded simultaneously, they are executed in descending order of parameter effective priority value, and the execution status of each sequence (not executed, executing, completed) is recorded in real time to avoid repeated loading or execution omissions. For example, the sequence of the user operation area (priority 3) is executed before the sequence of the content display area (priority 2), ensuring that the interaction process of the high-priority area is given priority. The conditional judgment module has a built-in data comparison engine that collects actual response data, such as actual response time, interaction failure times, and operation duration, in real time during each interaction operation execution process. The collected actual data is compared with the test adaptation parameters of the corresponding function area in the parameterized data set to determine if any of the following conditions are met: actual response time > operation delay time parameter, failure times ≥ operation retry times parameter, and duration > operation timeout threshold parameter. If any of the conditions are met, the associated conditional test script branch is triggered, and detailed trigger logs containing the trigger timestamp, parameter comparison results, trigger branch ID, and current operation context are recorded.
[0054] Step 501, loading the basic test script fragment into the data-driven test framework as an initial test sequence, loading the supplementary test script fragment into the data-driven test framework as a dynamic test sequence, loading the conditional test script branch into the data-driven test framework as a conditional test sequence, specifically including: after completing the core construction of the data-driven test framework, according to the functional positioning classification of the test sequence, following the unified process of identification binding, association verification, framework input, and state marking, different script fragments are sequentially loaded into the framework, the specific process is as follows: first, the initial test sequence is loaded, the basic test script fragment generated in step 1 is first split according to the functional area ID, the splitting rule is that the core operation of the script fragment belongs to the functional area, and the area corresponding to the functional area ID is consistent, for example, the page jump operation belongs to the navigation function area, and is split to the fragment corresponding to the navigation function area, and the form submission operation belongs to the user operation area, and is split to the fragment corresponding to the user operation area; then a fixed format functional area ID identification field is added to the head of each split fragment, so that the framework can accurately identify and match; then the fragments are loaded into the framework in ascending order of functional area ID, and after loading, they are automatically marked as initial test sequences and set to the highest execution priority (executed first in scheduling), this sequence contains the basic interaction process of each functional area, such as menu expansion / contraction of the navigation function area, content scrolling / switching of the content display area, and basic button clicking of the user operation area.
[0055] After completing the initial test sequence loading, the dynamic test sequence loading is carried out, the supplementary test script fragment generated in step 300 is first extracted, each fragment is labeled with a core adaptation scenario, such as form repeated submission, drop-down menu quick switching, and abnormal data input, then the association between the fragment and the parameterized data set is established through the bidirectional mapping of the functional area ID, the adaptation functional area ID field is added to each fragment, such as a fragment adapted to the user operation area, which is marked as user operation area 01, and the supplementary script fragment ID field is added to the corresponding functional area record in the parameterized data set, which clearly indicates that each fragment only adapts to the parameter range of the corresponding functional area, finally the fragment is loaded into the framework and marked as a dynamic test sequence, and the execution priority is set to be lower than that of the initial test sequence, the core function of which is to complete the special interaction scenarios not covered by the initial sequence, such as interaction under extreme parameters, edge scenario operation process, and abnormal feedback processing process.
[0056] Finally, the loading of the condition test sequence is completed, the condition test script branches generated in step 403 are divided into three categories according to the condition trigger type (the delay trigger category corresponds to the operation delay time parameter, the retry trigger category corresponds to the operation retry number parameter, and the timeout trigger category corresponds to the operation timeout threshold parameter), and then the trigger parameter type and the associated parameter name field are added to each category branch, such as the delay trigger category branch, which marks the trigger parameter type, including the operation delay time parameter; the associated parameter name is operationDelayTime, and then through the one-to-one mapping relationship between the parameter name and the branch ID, the branch is bound to the corresponding parameter in the parameterized data set, such as the operation delay time parameter bound to all delay trigger category branch IDs, and the operation retry number parameter bound to all retry trigger category branch IDs. Finally, the branch is loaded into the framework and marked as a condition test sequence, set to an on-demand trigger state, and only executed when the threshold comparison logic of the condition judgment module is met.
[0057] In step 502, the test logic controller of the data-driven test framework integrates the initial test sequence, the dynamic test sequence and the condition test sequence to generate a complete automated test script, which specifically includes: after all test sequences are loaded into the framework, the test logic controller of the data-driven test framework gradually integrates the initial test sequence, the dynamic test sequence and the condition test sequence according to the progressive process of initialization, fusion, embedding, verification and output, and finally generates a complete automated test script, the specific implementation process is as follows: first, sequence initialization is performed, the test logic controller first calls the parameterized test data set, traverses all records in ascending order of function area ID, and matches the corresponding initial test sequence one by one; after loading the sequence, three initialization works are completed, one is to determine the execution order of each operation in the sequence, to sort the basic operations before the complex operations, such as executing element loading detection before clicking / inputting operation, two is to assign default values to parameter placeholders in the sequence (the values are taken from the test adaptation parameters of the corresponding function area in the parameterized data set), and three is to sort the dependency relationship between operations, such as the username input box operation needs to be executed after the input box element loading is completed and the navigation function area menu jump is completed, and finally the initialized basic execution flow is generated.
[0058] After the sequence initialization is completed, the dynamic sequence fusion stage is entered, the controller based on the parameterization data set The parameter takes effect priority value (3>2>1), the dynamic test sequence of the high priority function area is preferentially processed; The initial test sequence is preset with adaptive nodes, and each core interactive operation, such as button click, form submission, content switching, is reserved for expansion nodes and marked with dynamic sequence insertion points; The controller judges the insertion position according to the adaptive scene of the dynamic sequence, such as inserting the form repeated submission segment into the adaptive node after the form submission operation, and inserting the drop-down menu quick switching segment into the adaptive node after the menu expansion operation; Before insertion, the logical coherence of the dynamic sequence and the initial sequence needs to be verified, the operation sequence is checked for no conflict, the dependence relationship is consistent with the initial sequence, there is no repeated operation step, the verification is passed, the insertion is completed, and it is ensured that the sequence flow after fusion has no redundancy and no breakpoint.
[0059] After the dynamic sequence fusion is completed, the conditional branch embedding work is carried out: the controller configures a corresponding conditional branch ID list for each interactive operation in the initial sequence and the dynamic sequence, the branch ID in the list corresponds to the branch of the conditional test sequence one by one, and an explicit condition trigger rule execution process is set. When the interactive operation is executed, the actual response data is collected in real time by the condition judgment module first, then the controller calls the parameterization data set to extract the corresponding test adaptation parameters of the function area to which the operation belongs, and then the data comparison engine compares the actual data with the parameters Threshold judgment, if the judgment condition is met, the corresponding branch is matched from the conditional branch ID list and embedded in the current execution process; After embedding, the binding relationship between the branch and the operation is recorded, supporting the same operation triggering multiple different types of conditional branches, when multiple conditions are met at the same time, according to the priority of delay trigger> retry trigger> timeout trigger, for example, if an operation meets the actual response time> delay parameter and the number of failures≥ retry parameter at the same time, the delay trigger type branch is executed first, and then the retry trigger type branch is executed.
[0060] After the conditional branch embedding is completed, the controller performs integration verification from three dimensions, one is logical coherence, traversing the integrated sequence, checking that the operation order is reasonable, the dependency relationship is conflict-free, and there is no logical breakpoint, such as no operation execution condition without loading element; two is parameter mapping accuracy, checking that all parameter placeholders are bound to the valid parameters of the parameterized data set, and the parameter value type is matched, such as the delay time is an integer millisecond, the retry number is a non-negative integer, and there is no unmatched or wrong binding; three is branch trigger uniqueness, ensuring that only a unique corresponding conditional branch is triggered under the same condition, and there is no repeated triggering, such as the same failure scenario of the same operation will not trigger two retry type branches at the same time; after the verification is passed, the framework outputs the complete automatic test script in the executable code format, such as Python script format, the script contains function area identification, test adaptation parameter configuration, sequence execution logic, condition triggering rule and detailed annotation, such as parameter explanation of each function area, operation dependency relationship annotation, condition branch trigger condition explanation, to ensure that the script can be directly run.
[0061] In this embodiment, the data-driven test framework constructed separates the test adaptation parameters from the test logic, realizes centralized management and flexible adjustment of the parameters, avoids large-scale modification of the test script caused by parameter change, and improves the maintainability of the test framework; different test sequences are loaded according to types, the function positioning and applicable scenarios of each sequence are clear, and hierarchical coverage of basic scenarios, special scenarios and conditional scenarios is realized, to ensure the comprehensiveness of test coverage; the test logic controller automatically integrates multiple types of test sequences, establishes the association and triggering mechanism between sequences based on the parameterized data set, reduces redundant operations and logical errors of manual integration, and improves the generation efficiency of the automatic test script.
[0062] Embodiments of the present application also provide a computing device, comprising a processor and a memory storing a computer program, when the computer program is run by the processor, the method described above is executed. All implementation manners in the above method embodiments are applicable to this embodiment, and the same technical effects can also be achieved.
[0063] Embodiments of the present application also provide a computer readable storage medium, storing instructions, when the instructions are run on a computer, the computer executes the method described above. All implementation manners in the above method embodiments are applicable to this embodiment, and the same technical effects can also be achieved.
[0064] The above is the preferred embodiment of the present application, it should be noted that for ordinary skilled in the art, without departing from the principles of the present application, a number of improvements and refinements can be made, these improvements and refinements should also be considered as the protection scope of the present application.
Claims
1. An automated script generation method, characterized by, The method comprises: Step 1, extracting initial user interface elements and corresponding element attributes, constructing an initial UI model, the initial UI model comprising layout information and interaction attributes of the initial user interface elements; generating a basic test script fragment based on the initial UI model; Step 2, executing the basic test script fragment, and setting multiple interaction behavior tracking points in the user interface to obtain user interface state change data; updating the initial UI model based on the user interface state change data to form an updated UI model; Step 3, generating a supplementary test script fragment based on the updated UI model, and constructing a spatial segmentation graph structure by analyzing the spatial distribution characteristics of the user interface elements; establishing a spatial influence area of the user interface elements based on the spatial segmentation graph structure, and identifying the boundary of a high-density aggregation area according to the spatial influence area; determining a functional area division scheme based on the boundary of the high-density aggregation area, and classifying the user interface elements into multiple functional areas according to the functional characteristics based on the functional area division scheme; Step 4, based on the user interface state change data, analyzing the layout characteristics and interaction attributes of the user interface elements in each functional area, generating test adaptation parameters, and generating conditional test script branches based on the test adaptation parameters and the context-dependent behaviors of the user interface elements; Step 5, integrating the basic test script fragment, the supplementary test script fragment and the conditional test script branches into a data-driven test framework to form a complete automated test script.
2. The automated script generation method of claim 1, wherein, The step 1 comprises: Parsing the interface definition file and the source code of the target application, identifying and extracting all initial user interface elements; Collecting element attributes of each initial user interface element, including position coordinates, size, element type and interactive state; Based on the initial user interface elements and the element attributes, constructing an initial UI model, establishing a hierarchical relationship between the initial user interface elements, and generating a basic test script fragment containing complete operation sequences according to the layout information and interaction attributes of the initial user interface elements in the initial UI model.
3. The automated script generation method of claim 2, wherein, The step 2 comprises: Executing the operation sequences in the basic test script fragment, and setting interaction behavior tracking points in the key interaction areas of the user interface, including setting a first interaction behavior tracking point in the interface top navigation area, a second interaction behavior tracking point in the main content display area, and a third interaction behavior tracking point in the bottom operation area; Real-time recording of user interface state change data through the interaction behavior tracking points, and identifying dynamically loaded user interface elements and user interface element state changes based on the user interface state change data; Updating the initial UI model using the dynamically loaded user interface elements and the user interface element state changes to form an updated UI model.
4. The automated script generation method of claim 3, wherein, The step 3 comprises: Based on the updated UI model, identifying dynamically loaded user interface elements and corresponding element attributes, and generating a supplementary test script fragment based on the dynamically loaded user interface elements and the element attributes; Based on the updated UI model, analyzing the spatial distribution characteristics of the user interface elements, constructing a spatial segmentation graph structure, and establishing a spatial influence area of the user interface elements based on the spatial segmentation graph structure; Based on the spatial influence area, a high-density cluster area boundary of the user interface elements is identified, and based on the high-density cluster area boundary, a functional area division scheme is determined, wherein the functional area division scheme divides the user interface into a navigation function area, a content display area, and a user operation area; Based on the functional area division scheme, the user interface elements in the updated UI model are classified into the navigation function area, the content display area, or the user operation area according to the functional characteristics.
5. The automated script generation method of claim 4, wherein, The step 4 comprises: Based on the user interface state change data, layout feature data of the user interface elements in each functional area is extracted; Based on the layout feature data, interaction attribute data of the user interface elements in each functional area is determined; Based on the interaction attribute data, test adaptation parameters corresponding to each functional area are generated; Based on the test adaptation parameters and the context-dependent behavior characteristics of the user interface elements, a conditional test script branch containing conditional judgment logic is generated.
6. The automated script generation method of claim 5, wherein, Based on the interaction attribute data, test adaptation parameters corresponding to each functional area are generated, comprising: Based on the user interface element response time data in the interaction attribute data, operation delay time parameters corresponding to the functional area are generated; Based on the user interface element interaction success rate data in the interaction attribute data, operation retry number parameters corresponding to the functional area are generated; Based on the user interface element error handling mechanism data in the interaction attribute data, operation timeout threshold parameters corresponding to the functional area are generated.
7. The automated script generation method of claim 6, wherein, The step 5 comprises: Based on the test adaptation parameters, a data-driven test framework is constructed, which includes parameterized test data sets and test logic controllers; The basic test script fragments are loaded into the data-driven test framework as initial test sequences, the supplementary test script fragments are loaded into the data-driven test framework as dynamic test sequences, and the conditional test script branches are loaded into the data-driven test framework as conditional test sequences; Through the test logic controllers of the data-driven test framework, the initial test sequences, the dynamic test sequences, and the conditional test sequences are integrated to generate a complete automated test script.
8. A computing device, comprising: Comprise: One or more processors; A storage device for storing one or more programs, when the one or more programs are executed by the one or more processors, so that the one or more processors implement the method as claimed in any one of claims 1 to 7.
9. A computer-readable storage medium, characterized in that, The computer readable storage medium stores a program which, when executed by a processor, implements the method as claimed in any one of claims 1 to 7.
Citation Information
Patent Citations
Method for automatically maintaining testing script based on model changing
CN107766253A
Software automatic testing method and system based on visual attention mechanism
CN119292953A
Automatic test script dynamic generation method and system based on multi-modal AI identification
CN120011247A
Code automatic testing method and device based on low-code platform and medium
CN120469923A
AI-based computer software automatic test system and method
CN120821662A