UI automatic testing method and system
By identifying prototype interface elements and generating test scripts, the problem of inefficiency in traditional UI automation testing when interface layout changes is solved, and efficient testing without modifying scripts is achieved.
Patent Information
- Application Number
- CN202411510249.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-28
- Publication Date
- 2025-03-28
AI Technical Summary
When facing changes in front-end interface layout, traditional UI automation testing methods require frequent modification of test scripts, resulting in inefficiency and waste of resources.
By obtaining the HTML source code of the prototype interface, identifying interface elements, judging element types and click events, establishing a mapping relationship between element keywords and test logic, and using the AI large language model to generate UI automated test scripts.
Even if the interface layout changes, interface elements are positioned through element keywords, and the associated test logic is driven without modifying the test script, which improves the efficiency and timeliness of UI automation testing.
Smart Images

Figure CN119718908A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method and system for UI automated testing. Background Art
[0002] Currently, UI automated testing plays a key role in software quality. The traditional method mainly relies on Selenium tools to locate interface elements and simulate user operations. However, this method makes the test scripts extremely susceptible to changes in the front-end. Once the interface layout of the front-end interface changes, the test scripts need to be manually modified. Frequent maintenance work consumes a lot of time and energy, and the writing of automated test scripts and the assembly of use case business processes also require precious testing resources. That is, the efficiency of UI automated testing is low under traditional methods. Summary of the invention
[0003] The technical problem to be solved by the present invention is: the present invention provides a method and system for UI automated testing to improve the efficiency of UI automated testing.
[0004] In order to solve the above technical problems, the technical solution adopted by the present invention is:
[0005] In a first aspect, the present invention provides a method for UI automated testing, comprising:
[0006] Obtaining the HTML source code of the prototype interface, and performing element recognition on the prototype interface according to the HTML source code to obtain corresponding interface elements;
[0007] Obtaining the element type of the interface element, obtaining the element keyword of the interface element according to the element type, determining whether the interface element includes a click event, and if so, automatically recording and tracking the test logic of the click event, associating the element keyword with the test logic to establish a mapping relationship between the test logic and the interface element;
[0008] Construct a test requirement description of the prototype interface according to the element type and the mapping relationship, and input the test requirement description into the AI big language model to generate a UI automated test script;
[0009] Perform UI automation testing on the interface to be tested corresponding to the prototype interface according to the UI automation testing script to obtain a test result of the interface to be tested.
[0010] The beneficial effects of the present invention are: through the interface elements obtained from the HTML source code of the prototype interface, the element keywords and click events of the interface elements are identified, so that the element keywords are associated with the test logic of the click event to establish a mapping relationship between the test logic and the interface elements. Therefore, even if the interface layout of the interface to be tested changes, the corresponding interface elements can be located through the element keywords, and the associated test logic can be further driven without modifying and maintaining the UI automation test script, which completely changes the traditional mode of frequently adjusting the UI automation test script due to changes in the interface layout, improves the test efficiency of the UI automation test, and is implemented through the HTML source code of the prototype interface, so that the UI automation test script can be generated in the demand stage. After the function development is completed, the UI automation test can be performed through the generated UI automation test script, which improves the timeliness of the UI automation test, and the UI automation test script is generated through the AI large language model, without the need for manual writing, thereby improving the generation efficiency of the UI automation test script.
[0011] Optionally, the element type includes a single-line text input box, and obtaining the element type of the interface element includes:
[0012] When the element type is a single-line text input box, obtain the placeholder attribute of the single-line text input box, determine whether the placeholder attribute is empty, if not, obtain the attribute value of the placeholder attribute, obtain the data type of the single-line text input box according to the attribute value, if yes, obtain the element position of the interface element, obtain the text content of the first adjacent position according to the element position, and determine the data type of the single-line text input box according to the text content and the minimum distance principle;
[0013] The description of the test requirements for constructing the prototype interface according to the element type and the mapping relationship includes:
[0014] A description of the requirements to be tested of the prototype interface is constructed according to the element type, the data type and the mapping relationship.
[0015] Optionally, the first adjacent position is a right adjacent position.
[0016] According to the above description, when the element type is a single-line text input box, the data type of the single-line text input box, that is, the purpose of the single-line text input box, will be determined according to the placeholder attribute. When the placeholder attribute is not empty, the data type of the single-line text input box is obtained according to the attribute value of the placeholder attribute to ensure the rationality of the obtained data type. When the placeholder attribute is empty, the data type of the single-line text input box is determined according to the text content of the first adjacent position and the minimum distance principle, wherein the first adjacent position is the right adjacent position, thereby improving the accuracy of the obtained data type, and taking the data type into consideration when subsequently constructing the description of the requirements to be tested, thereby improving the comprehensiveness of the constructed description of the requirements to be tested.
[0017] Optionally, determining whether the interface element includes a click event includes:
[0018] The class name and style of the element type are obtained. When the class name meets the preset class name requirement and the style meets the preset style requirement, the interface element includes a click event. Otherwise, the interface element does not include a click event.
[0019] According to the above description, it can be known that whether an interface element includes a click event is judged according to the class name and style of the element type, thereby improving the accuracy and comprehensiveness of the judgment.
[0020] Optionally, constructing a test requirement description of the prototype interface according to the element type and the mapping relationship, and inputting the test requirement description into an AI large language model to generate a UI automated test script includes:
[0021] Determine whether there is a regular operation behavior in the test logic based on the behavior matching library, and if so, obtain a regular requirement description of the regular operation behavior;
[0022] Taking a real-time screenshot of the prototype interface to obtain a picture to be tested, judging whether the picture to be tested contains a special icon in the icon library by using OCR technology and preset prompt words, and if so, obtaining a behavior description of the special icon;
[0023] The description of the requirement to be tested is supplemented according to the conventional description of the requirement and the behavior description, the interface element and the element type are used as the input description of the description of the requirement to be tested, and the mapping relationship, the conventional description of the requirement and the behavior description are used as business rules to obtain a supplemented description of the requirement to be tested;
[0024] The supplemented description of the requirements to be tested is input into the AI big language model to generate a UI automation test script.
[0025] According to the above description, not only the conventional requirement description of the existing conventional operation behavior is supplemented to the requirement description to be tested, but also the behavior description of the existing special icons is supplemented to the requirement description to be tested, and the input description and business rules are divided, which not only improves the completeness of the supplemented requirement description to be tested but also improves the logic of the supplemented requirement description to be tested, thereby improving the accuracy of the generated UI automation test script.
[0026] Optionally, inputting the supplemented description of the requirement to be tested into the AI big language model to generate a UI automated test script includes:
[0027] Calculate the similarity between the supplemented requirement description to be tested and the historical requirement description in the historical requirement description library, select the historical requirement description with the highest similarity, and combine the historical requirement description with the supplemented requirement description to be tested to obtain a combined requirement description to be tested;
[0028] The combined description of the requirements to be tested is input into the AI big language model to generate a UI automation test script.
[0029] According to the above description, the historical requirement description with the highest similarity to the requirement description to be tested is screened out and combined with the supplemented requirement description to be tested to obtain the combined requirement description to be tested, which improves the completeness and accuracy of the requirement description to be tested, and further improves the accuracy of the UI automation test script generated according to the combined requirement description to be tested.
[0030] Optionally, inputting the combined description of the requirements to be tested into the AI big language model to generate a UI automated test script includes:
[0031] Constructing a corresponding behavior function according to the element type of the interface element, and using the element keyword of the interface element as a trigger condition of the behavior function, encapsulating the trigger condition and the behavior function to obtain a function package;
[0032] Inputting the combined description of the requirement to be tested and the function package into the first AI large language model to generate a use case of the requirement to be tested;
[0033] The requirement use case to be tested is input into the second AI large language model to generate a UI automation test script, wherein the UI automation test script includes test data and test scenarios.
[0034] According to the above description, a behavior function corresponding to the element type of the interface element is constructed, and the behavior function is triggered by the element keyword, which improves the flexibility and simplifies the configuration and execution process of the UI automated test. The test requirement use case is generated according to the function package and the combined test requirement description, and then the UI automated test script is generated, which improves the efficiency and maintainability of the automated test. The generated UI automated test script includes test data and test scenarios, which reduces the need for testers to manually combine test scenarios and prepare test data, thereby improving the test efficiency.
[0035] Optionally, performing UI automation testing on the interface to be tested corresponding to the prototype interface according to the UI automation testing script includes:
[0036] During the UI automation test, when the interface element is click tested, the element position of the interface element is obtained;
[0037] Determine whether the element type of the interface element is a single-line text input box. If it is a single-line text input box, determine whether there is a value in the single-line text input box. If so, click the interface element according to the element position. If not, translate the element position to the right by a first preset pixel to obtain the translated first element position, and click the interface element according to the translated first element position. If it is not a single-line text input box, determine whether it is a drop-down box. If it is a drop-down box, translate the element position to the right by a second preset pixel to obtain the translated second element position, and click the interface element according to the translated second element position. If it is not a drop-down box, determine whether it is a check box or a radio button. If it is a check box or a radio button, translate the element position to the right by a third preset pixel to obtain the translated third element position, and click the interface element according to the translated third element position.
[0038] According to the above description, when performing a click test on an interface element, the element position of the interface element will be translated by different preset pixels according to the element type of the interface element to ensure accurate clicking and improve the efficiency of the click test.
[0039] Optionally, the test result includes an execution status and an execution result, and obtaining the test result of the interface to be tested includes:
[0040] A code coverage analysis tool is used to perform code coverage analysis on the execution status and the execution result to obtain a code coverage report.
[0041] According to the above description, the generated test results include not only the execution results but also the execution status, so that testers can understand the test progress in a timely manner, and a code coverage report will be generated to ensure that testers can adjust the test strategy in time to ensure the efficiency and quality of the test.
[0042] In a second aspect, the present invention provides a system for UI automated testing, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements a method for UI automated testing as described in the first aspect when executing the computer program.
[0043] Among them, the technical effect corresponding to the UI automation testing system provided by the second aspect refers to the relevant description of the UI automation testing method provided by the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] Figure 1 A flowchart of a UI automation testing method provided in this embodiment;
[0045] Figure 2 A schematic diagram of the overall process of a UI automation testing method provided in this embodiment;
[0046] Figure 3 A schematic diagram of performing a click test on an interface element according to this embodiment;
[0047] Figure 4 A schematic diagram describing the requirements to be tested involved in this embodiment;
[0048] Figure 5 A schematic diagram of a test case involved in this embodiment;
[0049] Figure 6 A schematic diagram of a UI automation test script involved in this embodiment;
[0050] Figure 7 A schematic diagram of the test results involved in this embodiment;
[0051] Figure 8 This is a schematic diagram of the structure of a UI automation testing system provided in this embodiment.
[0052] [Description of Reference Numerals]
[0053] 1. A method system for UI automation testing;
[0054] 2. Processor;
[0055] 3. Memory. DETAILED DESCRIPTION
[0056] In order to better understand the above technical solution, exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided to enable a clearer and more thorough understanding of the present invention and to fully convey the scope of the present invention to those skilled in the art.
[0057] Embodiment 1
[0058] Please refer to Figures 1 to 7 The present invention provides a method for UI automated testing, comprising the steps of:
[0059] S1. Obtain the HTML source code of the prototype interface, and identify the elements of the prototype interface according to the HTML source code to obtain the corresponding interface elements;
[0060] In this embodiment, if Figure 2 As shown, the elements of the interface to be tested are identified according to the HTML source code of the acquired prototype interface, thereby obtaining the corresponding interface elements.
[0061] S2. Obtain the element type of the interface element, obtain the element keyword of the interface element according to the element type, determine whether the interface element includes a click event, and if so, automatically record and track the test logic of the click event, and associate the element keyword with the test logic to establish a mapping relationship between the test logic and the interface element;
[0062] In this embodiment, if Figure 2 As shown, the element type of the interface element can be obtained by identifying the "input type" in the HTML source code. The element types include but are not limited to: a single-line text input box, a radio button, a check box and a drop-down box. The element keyword of the interface element is obtained according to the element type, that is, the element keyword is used as the unique identifier of the corresponding interface element to determine whether the interface element contains a click event. If it does, the test logic of the click event is automatically recorded and tracked, that is, the operation process of the click event is automatically recorded and tracked, including pop-up windows, input item recognition, etc. The element keyword is associated with the test logic to establish a mapping relationship between the test logic and the interface element, that is, the element keyword is used as a bridge between the test logic and the interface element. As long as the element keyword remains unchanged, no matter how the interface layout of the interface to be tested changes, the corresponding test logic can be mobilized through the element keyword.
[0063] At this time, the element type in step S2 includes a single-line text input box, and the element type of the interface element obtained includes:
[0064] S21. When the element type is a single-line text input box, obtain the placeholder attribute of the single-line text input box, determine whether the placeholder attribute is empty, and if not, obtain the attribute value of the placeholder attribute, and obtain the data type of the single-line text input box according to the attribute value; if yes, obtain the element position of the interface element, obtain the text content of the first adjacent position according to the element position, and determine the data type of the single-line text input box according to the text content and the minimum distance principle;
[0065] In this embodiment, if Figure 2 As shown, when the element type is a single-line text input box, the data type of the single-line text input box is determined by obtaining the placeholder attribute of the single-line text input box. When the placeholder attribute is not empty, the data type of the single-line text input box is obtained according to the attribute value of the placeholder attribute. For example, if the attribute value of the placeholder attribute is: "Please enter a user name", the single-line text input box is automatically classified as a user name input area, that is, its data type is a user name. When the placeholder attribute is empty, the element position of the interface element is obtained, and the text content of the first adjacent position is obtained according to the element position, that is, the text content of the adjacent position on the right is obtained. The data type of the single-line text input box is determined according to the text content and the minimum distance principle, that is, the distance between the text content and the element position of the single-line text input box is calculated, and the purpose of the single-line text input box is determined according to the minimum distance principle, and the data type of the single-line text input box can be obtained.
[0066] The description of the test requirements for constructing the prototype interface according to the element type and the mapping relationship includes:
[0067] A description of the requirements to be tested of the prototype interface is constructed according to the element type, the data type and the mapping relationship.
[0068] In this embodiment, after the data type of the interface element is obtained, a description of the requirements to be tested of the prototype interface is constructed according to the data type, the element type and the mapping relationship.
[0069] At this time, in step S2, determining whether the interface element includes a click event includes:
[0070] S22. Obtain the class name and style of the element type. When the class name meets the preset class name requirement and the style meets the preset style requirement, the interface element includes a click event. Otherwise, the interface element does not include a click event.
[0071] In this embodiment, if Figure 2As shown, by obtaining the class name and style of the element type, it is determined whether the interface element includes a click event. When the class name meets the preset class name requirements and the style meets the preset style requirements, it means that the interface element includes a click event, where the preset class name requirement is "ax_default primary_button" and the preset style requirement is to include "cursor:pointer". Otherwise, the interface element does not include a click event.
[0072] S3, constructing a test requirement description of the prototype interface according to the element type and the mapping relationship, and inputting the test requirement description into the AI big language model to generate a UI automated test script;
[0073] At this time, step S3 includes:
[0074] S31, judging whether there is a regular operation behavior in the test logic based on the behavior matching library, and if so, obtaining a regular requirement description of the regular operation behavior;
[0075] In this embodiment, if Figure 2 As shown, a behavior matching library is pre-built, and the behavior matching library stores regular operation behaviors and regular requirement descriptions corresponding to the regular operation behaviors. Regular operation behaviors include but are not limited to: save operations, close operations, etc. Therefore, based on the behavior matching library, it is determined whether there is a regular operation behavior in the test logic. If so, the regular requirement description of the existing regular operation behavior is obtained.
[0076] S32, taking a real-time screenshot of the prototype interface to obtain a picture to be tested, determining whether the picture to be tested contains a special icon in the icon library by using OCR technology and preset prompt words, and if so, obtaining a behavior description of the special icon;
[0077] In this embodiment, if Figure 2 As shown, an icon library is pre-built, and special icons are stored in the icon library, such as page turning icons, query icons, form field icons, etc., and preset prompt words and behavior descriptions corresponding to the special icons are built, wherein the preset prompt words are as follows: the preset prompt word corresponding to the page turning icon is: page turning, and the preset prompt word corresponding to the query icon is: query. By taking a real-time screenshot of the interface to be tested, the image to be tested is obtained, and the OCR technology and preset prompt words are used to determine whether the image to be tested contains the special icon in the icon library. If it does, the behavior description of the special icon is obtained.
[0078] S33. Supplement the requirement description to be tested according to the general requirement description and the behavior description, use the interface elements and element types as input descriptions of the requirement description to be tested, use the mapping relationship, the general requirement description and the behavior description as business rules, and obtain a supplemented requirement description to be tested.
[0079] S34. Input the supplemented description of the requirements to be tested into the AI big language model to generate a UI automated test script.
[0080] In this embodiment, if Figure 2 As shown, the general requirement description and behavior description obtained through step S31 and step S32 are used to supplement the requirement description to be tested, and the interface elements and element types are used as input descriptions of the requirement description to be tested. If the data type of the interface element is obtained at this time, the data type is also used as the input description, and the mapping relationship, general requirement description and behavior description are used as business rules to obtain the supplemented requirement description to be tested. Here, the supplemented requirement description to be tested is divided into input description and business rules so that when the AI big language model is input to generate the UI automation test script, the AI big language model can better understand the input requirement description to be tested, thereby improving the accuracy of the generated UI automation test script.
[0081] At this time, step S34 includes:
[0082] S341, calculating the similarity between the supplemented requirement description to be tested and the historical requirement description in the historical requirement description library, screening out the historical requirement description with the highest similarity, combining the historical requirement description with the supplemented requirement description to be tested, and obtaining a combined requirement description to be tested;
[0083] S342. Input the combined description of the requirements to be tested into the AI big language model to generate a UI automated test script.
[0084] In this embodiment, if Figure 2 As shown, the similarity between the supplemented requirement description to be tested and the historical requirement descriptions in the historical requirement description library is calculated to find the historical requirement description that best matches the requirement description to be tested, that is, the historical requirement description with the highest similarity is screened out, and the screened historical requirement description is combined with the requirement description to be tested to obtain the combined requirement description to be tested.
[0085] At this time, step S342 includes:
[0086] S3421. Construct a corresponding behavior function according to the element type of the interface element, use the element keyword of the interface element as a trigger condition of the behavior function, and encapsulate the trigger condition and the behavior function to obtain a function package;
[0087] In this embodiment, if Figure 2 As shown, a corresponding behavior function is constructed according to the element type of the interface element, including but not limited to: click, input, drag and scroll, etc., and the element keyword of the interface element is used as the trigger condition of the behavior function, that is, the corresponding behavior function is triggered by the element keyword, and the trigger condition and the behavior function are encapsulated to obtain a function package.
[0088] S3422, inputting the combined description of the requirement to be tested and the function package into the first AI large language model to generate a use case of the requirement to be tested;
[0089] In this embodiment, if Figure 2 As shown, the combined description of the requirement to be tested and the function package are input into the first AI large language model to generate a test case of the requirement to be tested. Before generating the test case of the requirement to be tested, the first AI large language model will first generate a corresponding requirement description point according to the description of the requirement to be tested, such as Figure 4 As shown, the name of the requirement case is: requirement description point, and the requirement case description is: the requirement description to be tested. Then, the requirement case to be tested is generated according to the requirement description point, the requirement description to be tested and the function package, such as Figure 5 As shown, the requirement use case is: the requirement use case to be tested.
[0090] S3423. Input the test requirement use case into the second AI large language model to generate a UI automation test script, wherein the UI automation test script includes test data and test scenarios.
[0091] In this embodiment, if Figure 6 As shown, the test requirement case is input into the second AI large language model to generate a UI automation test script, wherein the second AI large language model can be the same large language model as the first AI large language model or a different large language model, and the generated UI automation test script includes test data and test scenarios.
[0092] S4. Perform UI automation testing on the interface to be tested corresponding to the prototype interface according to the UI automation testing script to obtain a test result of the interface to be tested.
[0093] At this time, the step S4 of performing UI automation testing on the interface to be tested corresponding to the prototype interface according to the UI automation testing script includes:
[0094] S41. During the UI automated test, when a click test is performed on the interface element, obtaining an element position of the interface element;
[0095] S42. Determine whether the element type of the interface element is a single-line text input box. If it is a single-line text input box, determine whether there is a value in the single-line text input box. If so, click the interface element according to the element position. If not, translate the element position to the right by a first preset pixel to obtain the translated first element position, and click the interface element according to the translated first element position. If it is not a single-line text input box, determine whether it is a drop-down box. If it is a drop-down box, translate the element position to the right by a second preset pixel to obtain the translated second element position, and click the interface element according to the translated second element position. If it is not a drop-down box, determine whether it is a check box or a radio button. If it is a check box or a radio button, translate the element position to the right by a third preset pixel to obtain the translated third element position, and click the interface element according to the translated third element position.
[0096] In this embodiment, if Figure 3 As shown, during the UI automation test, when the interface element is click-tested, the element position of the interface element is obtained, and the element position is translated by different preset pixels according to the element type of the interface element. When the element type of the interface element is a single-line text input box, if there is a value in the single-line text input box, the element position is directly clicked according to the element position. Otherwise, if there is no value in the single-line text input box, the element position is translated to the right by a first preset pixel, wherein the first preset pixel is 160, and the first element position after translation is obtained, and the interface element is clicked according to the first element position after translation. When the element type is a drop-down box, the element position is translated to the right by a second preset pixel, wherein the second preset pixel is 120, and the second element position after translation is obtained, and the interface element is clicked according to the second element position after translation. When the element type is a check box or a radio button, the element position is translated to the right by a third preset pixel, and the third element position after translation is obtained, and the interface element is clicked according to the third element position after translation, wherein the first preset pixel, the second preset pixel and the third preset pixel can be adjusted according to actual conditions.
[0097] At this time, the test result in step S4 includes an execution state and an execution result, and the test result of the interface to be tested includes:
[0098] S43. Perform code coverage analysis on the execution status and the execution result using a code coverage analysis tool to obtain a code coverage report.
[0099] In this embodiment, if Figure 7 As shown, the test results include execution status and execution results, where Figure 7 The debugging result of the case in is: execution result, Figure 7The "success" in the code indicates the execution status. Code coverage analysis tools such as jacoco are used to analyze the execution status and results to obtain a code coverage report.
[0100] Embodiment 2
[0101] Please refer to Figure 8 The present invention provides a method system 1 for UI automated testing, comprising a memory 3, a processor 2, and a computer program stored in the memory 3 and executable on the processor 2. When the processor 2 executes the computer program, the steps in the above-mentioned embodiment 1 are implemented.
[0102] Since the system / device described in the above embodiments of the present invention is a system / device used to implement the method of the above embodiments of the present invention, a person skilled in the art can understand the specific structure and deformation of the system / device based on the method described in the above embodiments of the present invention, and thus will not be described in detail here. All systems / devices used in the method of the above embodiments of the present invention belong to the scope of protection of the present invention.
[0103] It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as methods, systems or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0104] The present invention is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products according to the embodiments of the present invention. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions.
[0105] It should be noted that in the claims, any reference numerals placed between brackets shall not be construed as limiting the claims. The word "comprising" does not exclude the presence of components or steps not listed in the claims. The word "a" or "an" preceding a component does not exclude the presence of a plurality of such components. The invention may be implemented by means of hardware comprising several different components and by means of a suitably programmed computer. In the claims enumerating several means, several of these means may be embodied by the same hardware. The use of the words first, second, third, etc., is for convenience of expression only and does not indicate any order. These words may be understood as part of the component name.
[0106] In addition, it should be noted that, in the description of this specification, the description of the terms "one embodiment", "some embodiments", "embodiment", "example", "specific example" or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, unless they are contradictory.
[0107] Although the preferred embodiments of the present invention have been described, those skilled in the art may make other changes and modifications to these embodiments after knowing the basic creative concept. Therefore, the claims should be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present invention.
[0108] Obviously, those skilled in the art can make various modifications and variations to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention should also include these modifications and variations.
Claims
1. A method for UI automated testing, characterized in that: include: Obtaining the HTML source code of the prototype interface, and performing element recognition on the prototype interface according to the HTML source code to obtain corresponding interface elements; Obtaining the element type of the interface element, obtaining the element keyword of the interface element according to the element type, determining whether the interface element includes a click event, and if so, automatically recording and tracking the test logic of the click event, associating the element keyword with the test logic to establish a mapping relationship between the test logic and the interface element; Construct a test requirement description of the prototype interface according to the element type and the mapping relationship, and input the test requirement description into the AI big language model to generate a UI automated test script; Perform UI automation testing on the interface to be tested corresponding to the prototype interface according to the UI automation testing script to obtain a test result of the interface to be tested.
2. A UI automation testing method as claimed in claim 1, characterized in that: The element type includes a single-line text input box, and the element type for obtaining the interface element includes: When the element type is a single-line text input box, obtain the placeholder attribute of the single-line text input box, determine whether the placeholder attribute is empty, if not, obtain the attribute value of the placeholder attribute, obtain the data type of the single-line text input box according to the attribute value, if yes, obtain the element position of the interface element, obtain the text content of the first adjacent position according to the element position, and determine the data type of the single-line text input box according to the text content and the minimum distance principle; The description of the test requirements for constructing the prototype interface according to the element type and the mapping relationship includes: A description of the requirements to be tested of the prototype interface is constructed according to the element type, the data type and the mapping relationship.
3. A UI automated testing method as claimed in claim 2, characterized in that: The first adjacent position is a right adjacent position.
4. A UI automation testing method as claimed in claim 1, characterized in that: The determining whether the interface element includes a click event comprises: The class name and style of the element type are obtained. When the class name meets the preset class name requirement and the style meets the preset style requirement, the interface element includes a click event. Otherwise, the interface element does not include a click event.
5. A UI automation testing method as claimed in claim 1, characterized in that: The step of constructing a test requirement description of the prototype interface according to the element type and the mapping relationship, and inputting the test requirement description into the AI big language model to generate a UI automated test script comprises: Determine whether there is a regular operation behavior in the test logic based on the behavior matching library, and if so, obtain a regular requirement description of the regular operation behavior; Taking a real-time screenshot of the prototype interface to obtain a picture to be tested, judging whether the picture to be tested contains a special icon in the icon library by using OCR technology and preset prompt words, and if so, obtaining a behavior description of the special icon; The description of the requirement to be tested is supplemented according to the conventional description of the requirement and the behavior description, the interface element and the element type are used as the input description of the description of the requirement to be tested, and the mapping relationship, the conventional description of the requirement and the behavior description are used as business rules to obtain a supplemented description of the requirement to be tested; The supplemented description of the requirements to be tested is input into the AI big language model to generate a UI automation test script.
6. A UI automated testing method as claimed in claim 5, characterized in that: The step of inputting the supplemented description of the requirements to be tested into the AI big language model to generate a UI automated test script includes: Calculate the similarity between the supplemented requirement description to be tested and the historical requirement description in the historical requirement description library, select the historical requirement description with the highest similarity, and combine the historical requirement description with the supplemented requirement description to be tested to obtain a combined requirement description to be tested; The combined description of the requirements to be tested is input into the AI big language model to generate a UI automation test script.
7. A UI automated testing method as claimed in claim 6, characterized in that: The step of inputting the combined description of the requirements to be tested into the AI big language model to generate a UI automated test script includes: Constructing a corresponding behavior function according to the element type of the interface element, and using the element keyword of the interface element as a trigger condition of the behavior function, encapsulating the trigger condition and the behavior function to obtain a function package; Inputting the combined description of the requirement to be tested and the function package into the first AI large language model to generate a use case of the requirement to be tested; The requirement use case to be tested is input into the second AI large language model to generate a UI automation test script, wherein the UI automation test script includes test data and test scenarios.
8. A UI automated testing method as claimed in claim 1, characterized in that: The performing UI automation test on the interface to be tested corresponding to the prototype interface according to the UI automation test script comprises: During the UI automation test, when the interface element is click tested, the element position of the interface element is obtained; Determine whether the element type of the interface element is a single-line text input box. If it is a single-line text input box, determine whether there is a value in the single-line text input box. If so, click the interface element according to the element position. If not, translate the element position to the right by a first preset pixel to obtain the translated first element position, and click the interface element according to the translated first element position. If it is not a single-line text input box, determine whether it is a drop-down box. If it is a drop-down box, translate the element position to the right by a second preset pixel to obtain the translated second element position, and click the interface element according to the translated second element position. If it is not a drop-down box, determine whether it is a check box or a radio button. If it is a check box or a radio button, translate the element position to the right by a third preset pixel to obtain the translated third element position, and click the interface element according to the translated third element position.
9. A UI automated testing method as claimed in claim 1, characterized in that: The test result includes an execution status and an execution result, and obtaining the test result of the interface to be tested includes: A code coverage analysis tool is used to perform code coverage analysis on the execution status and the execution result to obtain a code coverage report.
10. A UI automated testing system, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 9 is implemented.
Citation Information
Cited By
Front-end automatic testing method of large language model based on LLM (Logistics Language Model)
CN120216385A
Script-free UI (User Interface) automatic test system and method based on swan monk system
CN120371699A
A scriptless UI automated testing system and method based on HarmonyOS
CN120371699B