Method and system for automatically generating UI (User Interface) automatic test script with target URI (Uniform Resource Identifier) function
By analyzing and identifying UI elements, UI automated test scripts are automatically generated, which solves the problems of low generation efficiency and insufficient coverage in the existing technology of test scripts, and achieves efficient and accurate test coverage, reducing maintenance costs.
Patent Information
- Application Number
- CN202411211708.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-30
- Publication Date
- 2024-12-13
AI Technical Summary
The prior art is difficult to efficiently and accurately generate UI automated test scripts, especially comprehensive functional tests for complex web applications, resulting in insufficient test coverage and high maintenance costs.
Through user input target URI, use web crawling technology and API parsing tools to parse page structure and functions, identify UI elements and their functions, generate test cases and convert them into executable test scripts, support multiple scripting languages, and perform syntax and logic check.
It improves the efficiency and accuracy of test script generation, reduces the complexity of manual writing, ensures comprehensive testing coverage of software systems, and reduces maintenance costs.
Smart Images

Figure CN119127695A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of software testing, and relates to a method and system for automatically generating a UI automation testing script for a target URI function. Background Art
[0002] With the rapid development of the Internet and mobile applications, the complexity and scale of software systems are increasing. In order to ensure the stability and reliability of software, UI automated testing has become an indispensable part of the quality assurance process. However, manually writing UI test scripts is not only time-consuming and laborious, but also prone to missing functions or causing poor maintainability of the scripts. Currently, there is a lack of a solution that can automatically generate UI test scripts efficiently and accurately, especially for comprehensive functional testing of complex web applications.
[0003] Necessity of UI automation testing: (1) Increased software complexity As application functions become richer, the complexity of UI continues to increase. Complex UI contains a large number of interactive elements, such as buttons, text boxes, drop-down menus, charts, etc. The interaction logic between these elements may be very complex. Manual testing takes a lot of time and is prone to missing details or human errors, and cannot guarantee the comprehensiveness and consistency of the test.
[0004] (2) Frequent version updates In modern software development, agile development methods and DevOps practices are widely adopted, and the iteration speed of software has been significantly accelerated. Every code change or function update may affect the performance of the UI, so regression testing is required frequently. Manual execution of these tests is not only inefficient, but also leads to testing bottlenecks, thus affecting the speed of software release.
[0005] (3) Coverage and quality assurance Manual testing usually only targets major functions and paths, and tends to ignore edge cases and extreme inputs, resulting in insufficient test coverage. Automated testing can systematically cover more scenarios based on predefined test cases, including normal operations, exception handling, and boundary conditions, thereby improving test coverage and software quality.
[0006] Limitations of existing UI automation testing tools: Currently, there are many UI automation testing tools on the market, such as Selenium, Appium, Cypress, etc. These tools provide testers with rich functions, which can simulate user operations and verify the behavior of UI. However, these tools still have the following limitations in actual use: (1) Script writing is complex UI automation testing tools usually require testers to have certain programming skills to manually write test scripts. This not only requires a lot of time and effort, but also increases maintenance costs. Especially for large and complex applications, writing and maintaining test scripts becomes particularly difficult.
[0007] (2) High maintenance cost As the application UI continues to evolve, the positioning, properties, and structure of UI elements may change, causing the original test scripts to become invalid. This means that test scripts need to be frequently updated and maintained, increasing the burden on development and testing teams.
[0008] (3) Complex test case design Designing effective test cases requires a deep understanding of the application's business logic and user behavior to ensure that the test cases cover all possible interaction paths. Manually designing these test cases is not only time-consuming, but may also miss key scenarios, resulting in insufficient test coverage. Summary of the invention
[0009] In order to make up for the deficiencies of the prior art, the present invention provides a method and system for automatically generating a UI automation test script for a target URI function, thereby improving the efficiency and accuracy of test script generation, reducing the complexity of manual writing, and ensuring comprehensive test coverage of the software system. The present invention is implemented through the following technical solution: The present invention provides a method for automatically generating a UI automation test script for a target URI function, comprising the following steps: (1) User inputs the target URI: The user enters the target URI to be tested through the system interface; (2) System parsing of target URI: The system uses web crawler technology and API parsing tools to access the target URI and analyze the function modules, parameters, and return value information it contains; (3) The system identifies all UI elements and their functions of the target URI and establishes a function mapping relationship; (4) Test case generation: The system automatically generates UI automation test cases based on the identified functional information; (5) Script output: The system converts the generated test cases into executable test scripts, supporting multiple scripting languages; (6) Script verification: The system performs syntax checking and logic verification on the generated test script to ensure its correctness and effectiveness.
[0010] A system for automatically generating UI automation test scripts for target URI functions, including the following modules: (1) User interface module, which is used to receive the target URI input by the user and provide operation feedback; (2) Parsing module, used to parse the target URI and extract the functional modules and related information of the page; (3) Function identification module, which identifies all UI elements and their functions in the target URI and establishes function mapping relationships; (4) Test case generation module, which automatically generates test cases based on the functional information provided by the function identification module; (5) Script generation module, which converts the generated test cases into executable test scripts and supports output in multiple script languages; (6) Verification module: performs syntax and logic verification on the generated test script to ensure that no errors occur during execution.
[0011] The beneficial effects of the present invention are: The system and method of the present invention improve the efficiency and accuracy of test script generation, reduce the complexity of manual writing, and ensure comprehensive test coverage of the software system. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] The present invention will be further described below in conjunction with the accompanying drawings; Figure 1 is a flow chart of the method of the present invention; Figure 2 is a system flow chart of the present invention; Figure 3 This is a flow chart of the analysis module of the present invention; Figure 4 This is a flow chart of the function identification module of the present invention; Figure 5 This is a flow chart of the test case module of the present invention. DETAILED DESCRIPTION
[0013] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the specific embodiments of the present invention are described in detail below in conjunction with the accompanying drawings. In the following description, many specific details are set forth to facilitate a full understanding of the present invention. However, the present invention can be implemented in many other ways different from those described herein, and those skilled in the art can make similar improvements without violating the connotation of the present invention, so the present invention is not limited by the specific embodiments disclosed below.
[0014] The accompanying drawings are specific embodiments of the method and system for automatically generating UI automated test scripts for target URI functions of the present invention.
[0015] The method for automatically generating a UI automation test script for a target URI function comprises the following steps: (1) User inputs the target URI: The user enters the target URI to be tested through the system interface.
[0016] (2) The system parses the target URI: The system uses web crawler technology and API parsing tools to access the target URI and analyze the functional modules, parameters, and return value information it contains. The purpose of this step is to extract information related to the page structure and functions, providing a basis for subsequent function identification.
[0017] (3) The system identifies all UI elements and their functions of the target URI and establishes a function mapping relationship; Based on the parsing results, the system identifies and extracts all UI elements and their corresponding functional information in the target URI, including but not limited to input boxes, buttons, drop-down menus, and links; the system establishes a mapping relationship between these elements and their functions to ensure that the generation of test cases can accurately reflect actual user interaction behaviors.
[0018] (4) Test case generation: The system automatically generates UI automation test cases based on the identified functional information. Each test case includes detailed operation steps, expected results, and test data, covering various scenarios of positive and negative tests.
[0019] (5) Script output: The system converts the generated test cases into executable test scripts and supports multiple scripting languages, such as Python, JavaScript, and Java. During the script generation process, the system uses standardized templates to ensure that the output scripts comply with industry best practices.
[0020] (6) Script verification: The system performs syntax checking and logic verification on the generated test scripts to ensure their correctness and effectiveness. The verification module can detect potential syntax errors and logical defects, and provide detailed error reports to help users quickly correct problems.
[0021] As attached Figure 1 As shown, the user inputs the target URI through the system, the system parses the target URI, the system identifies the function of the page or API, generates a test case, generates an automated test script, the system verifies the generated script, determines whether the script is valid, and if valid, saves or executes the script to complete the program; if the script is invalid, adjusts the generation process and returns to the system to parse the target URI step and start again.
[0022] A system for automatically generating UI automation test scripts for target URI functions, including the following modules: (1) User interface module, which is used to receive the target URI input by the user and provide operation feedback.
[0023] (2) Parsing module, used to parse the target URI and extract the functional modules and related information of the page, including parameters and return value information; this module obtains the page content through web crawler technology and combines it with API parsing tools to accurately analyze the structure and function of the page.
[0024] (3) Function identification module, which identifies all UI elements and their functions in the target URI and establishes function mapping relationships. The function identification module can process various UI elements and store them in categories to provide data support for subsequent test case generation.
[0025] (4) Test case generation module, which automatically generates test cases based on the functional information provided by the function identification module; this module ensures that the generated test cases have wide coverage and can simulate user operations in a real environment.
[0026] (5) Script generation module, which converts the generated test cases into executable test scripts and supports output in multiple script languages. This module ensures that the generated scripts are readable and maintainable by using standard templates.
[0027] (6) Verification module: Verify the syntax and logic of the generated test script to ensure that there are no errors when it is executed. The verification module provides an automated inspection process and can quickly feedback problems to help developers optimize script quality.
[0028] The parsing module is responsible for accessing and analyzing the target URI input by the user, and extracting information such as the function module, parameters, and return value of the page or API. The parsing module is the basis for subsequent function identification, ensuring that the system can understand the structure and function of the target URI.
[0029] The parsing module includes: (1) Web crawler technology: Use HTTP-based web crawler tools to make requests to the target URI and obtain the returned HTML content, JavaScript, CSS, and other resources; the crawler tool needs to handle possible redirects, page loading delays, and dynamic content rendering.
[0030] (2) HTML parsing: Use DOM parsing libraries (such as BeautifulSoup, lxml, etc.) to parse the obtained HTML document, build the DOM tree of the page, and identify the hierarchical relationships and attributes of each element in the page.
[0031] (3) API parsing tool: For API type URI, the parsing module obtains the API response by sending a simulated request (GET, POST, etc.) and extracts the request parameters, return value, and HTTP status code information; description files such as Swagger and OpenAPI may be used for auxiliary parsing.
[0032] (4) JavaScript dynamic content processing: The content of some pages relies on JavaScript dynamic loading. The parsing module needs to integrate a headless browser (such as Puppeteer, Selenium, etc.) to obtain the dynamically rendered page content.
[0033] (5) Data structuring: The extracted page structure, functional modules, parameters and return value information are stored in JSON and XML structured formats to provide a standardized data interface for subsequent modules.
[0034] As attached Figure 3 The flowchart of the parsing module shown includes: the parsing module receives URI input, sends an HTTP request to obtain page content, and determines whether it is dynamic content. If so, it first starts a headless browser to process JavaScript and then parses the HTML document. Otherwise, it directly parses the HTML document, builds a DOM tree, and determines whether it is an API. If it is an API, it sends a simulated request to obtain an API response, extracts API parameters and return values, and completes the process after storing the API information in a structured manner; if it is not an API, it extracts the UI elements in the page, extracts the functional modules in the page, and completes the process after storing the page information in a structured manner.
[0035] The task of the function identification module is to identify all UI elements and their corresponding functions from the information extracted by the parsing module. This module ensures that the system can understand the interactive behavior of each UI element and lays the foundation for test case generation.
[0036] The function identification module includes: (1) DOM element classification: Classify the parsed DOM tree and identify common UI elements (such as text boxes, buttons, check boxes, drop-down menus, etc.); use tag names, attributes (such as id, class) and other information to classify elements.
[0037] (2) Interaction attribute extraction: Further analyze the interaction attributes of each UI element, such as button click events, input box validation rules, drop-down menu options, etc. Identify event listeners (such as onClick, onChange, etc.) and associate them with the corresponding UI elements.
[0038] (3) Function mapping: Establish a mapping relationship between UI elements and their functions. For example, associate a submit button with a form submission function, and associate an input box with an input data function. This mapping information is stored in the form of key-value pairs or objects, providing a direct data source for test case generation.
[0039] (4) Polymorphic processing: handling polymorphic behaviors of the same UI element in different page states. For example, the operation performed by a button in the logged-in state is different from that in the non-logged-in state. The function identification module needs to distinguish these situations and record them separately.
[0040] As attached Figure 4 The flowchart of the function identification module shown includes: starting function identification, obtaining the DOM tree, classifying UI elements, identifying input boxes, buttons, links, etc., extracting interactive attributes, establishing a mapping between UI elements and functions, and determining whether there is polymorphic behavior. If there is polymorphic behavior, distinguish the polymorphic behavior and record it, and then generate function mapping data to complete; if there is no polymorphic behavior, directly record the function mapping data and then complete.
[0041] The test case generation module automatically generates test cases based on the function mapping relationship provided by the function identification module. The goal of this module is to create test scenarios that fully cover the target URI functions, including positive and negative tests.
[0042] The test case generation module includes, (1) Test case template: Design a variety of general test case templates, covering various common UI interaction modes (such as form submission, navigation jump, data verification, etc.). The template defines operation steps, input data, expected results and other information.
[0043] (2) Use case parameterization: Supports the parameterization of test cases, allowing the generation of test cases in multiple scenarios. For example, for an input box, the system can generate test cases with different input values to verify the processing logic of various inputs.
[0044] (3) Scenario coverage: By generating multiple test scenarios for each functional point, including normal input, abnormal input, boundary conditions, etc., the breadth and depth of the test are ensured. The generated use cases include both positive tests (verifying that the expected functions work properly) and negative tests (verifying that the system handles abnormal situations).
[0045] (4) Automated execution instructions: Generate automated execution instructions for each use case. These instructions will directly correspond to specific operations in the final test script. For example, the execution instruction corresponding to "click the login button" may be "driver.findElement(By.id('login')).click()".
[0046] As attached Figure 5 As shown, the flowchart of the test case module includes: obtaining function mapping data, loading test case templates, parameterizing test cases, generating positive test cases, generating negative test cases, determining whether the test cases cover all scenarios, if not, adjusting parameters to generate more test cases, if yes, generating automated execution instructions, and completing after outputting the test cases.
[0047] Example 1: Through the user interface module, the user enters the homepage URI of a web application. The parsing module uses a web crawler to obtain the page content and parses out all UI elements on the page (such as login form, registration button, etc.). The function identification module maps these elements to their functions and generates corresponding test cases. Finally, the script generation module converts these test cases into test scripts in Python language and performs syntax checking through the verification module. It has been verified that the script can run successfully in a standard test environment and cover all major functions.
[0048] Example 2: The user enters the URI of an API endpoint, and the system obtains the input parameters and return values of the endpoint through the API parsing tool. The system generates test cases for the API according to the above process and outputs an automated test script in Java language. After script verification, the test script can effectively verify the correctness and stability of the API.
Claims
1. Method for automatically generating UI automation test scripts for target URI functions, It is characterized in that The steps include: (1) User inputs the target URI: The user enters the target URI to be tested through the system interface; (2) System parsing of target URI: The system uses web crawler technology and API parsing tools to access the target URI and analyze the function modules, parameters, and return value information it contains; (3) The system identifies all UI elements and their functions of the target URI and establishes a function mapping relationship; (4) Test case generation: The system automatically generates UI automation test cases based on the identified functional information; (5) Script output: The system converts the generated test cases into executable test scripts, supporting multiple scripting languages; (6) Script verification: The system performs syntax checking and logic verification on the generated test script to ensure its correctness and effectiveness.
2. The method for automatically generating a UI automation test script for a target URI function according to claim 1, It is characterized in that The test case generation includes coverage of positive tests and negative tests.
3. A system that automatically generates UI automation test scripts for target URI functions, It is characterized in that Includes the following modules: (1) User interface module, which is used to receive the target URI input by the user and provide operation feedback; (2) Parsing module, used to parse the target URI and extract the functional modules and related information of the page; (3) Function identification module, which identifies all UI elements and their functions in the target URI and establishes function mapping relationships; (4) Test case generation module, which automatically generates test cases based on the functional information provided by the function identification module; (5) Script generation module, which converts the generated test cases into executable test scripts and supports output in multiple script languages; (6) Verification module: performs syntax and logic verification on the generated test script to ensure that no errors occur during execution.
4. The system for automatically generating a UI automated test script for a target URI function according to claim 3, It is characterized in that The parsing module includes: (1) Web crawler technology, using HTTP-based web crawler tools to make requests to the target URI and obtain the returned HTML content, JavaScript, CSS and other resources; (2) HTML parsing: Use the DOM parsing library to parse the obtained HTML document, build the DOM tree of the page, and identify the hierarchical relationship and attributes of each element in the page; (3) API parsing tool: For API type URI, the parsing module obtains the API response by sending a simulated request and extracts the request parameters, return value, and HTTP status code information; (4) JavaScript dynamic content processing: The content of some pages relies on JavaScript dynamic loading. The parsing module needs to integrate a headless browser to obtain the dynamically rendered page content. (5) Data structuring: The extracted page structure, functional modules, parameters and return value information are stored in JSON and XML structured formats to provide a standardized data interface for subsequent modules.
5. The system for automatically generating a UI automated test script for a target URI function according to claim 3, It is characterized in that The function identification module includes: (1) DOM element classification: classify the parsed DOM tree to identify common UI elements; classify elements using tag names and attribute information; (2) Interaction attribute extraction: further analyze the interaction attributes of each UI element, identify event listeners and associate them with the corresponding UI elements; (3) Functional mapping: Establishing the mapping relationship between UI elements and their functions; These mapping information are stored in the form of key-value pairs or objects, providing a direct data source for test case generation; (4) Polymorphic processing: handling polymorphic behaviors of the same UI element in different page states.
6. The system for automatically generating a UI automated test script for a target URI function according to claim 3, It is characterized in that The test case generation module includes, (1) Test case template: Design a variety of general test case templates, including various common UI interaction modes; The template defines the operation steps, input data, and expected result information; (2) Use case parameterization: Supports parameterization of test cases, allowing the generation of use cases for multiple scenarios; (3) Scenario coverage: Generate multiple test scenarios for each functional point to ensure the breadth and depth of the test; (4) Automated execution instructions: Generate automated execution instructions for each use case. These instructions directly correspond to specific operations in the final test script.
Citation Information
Cited By
Automatic test method and device for vehicle body controller
CN119987331A
Test script generation method and device
CN121144190A
Automatic testing method and device, electronic equipment and computer readable storage medium
CN121301197A
