A UI automation testing method and system for intelligently updating page positioning elements
Patent Information
- Application Number
- CN202311655641.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-05
- Publication Date
- 2026-10-20
- Estimated Expiration
- 2043-12-05
AI Technical Summary
[0009]本申请提供一种智能更新页面定位元素的UI自动化测试方法及系统,旨在解决现有技术测试用例的覆盖率和稳定性不佳、维护效率较低等问题
[0036]本申请通过基于当前页面所有非隐藏元素,递归点击可点击定位元素、递归嗅探可输入元素来获取定位元素变动信息和隐藏元素信息,获得所有的全量数据,再通过对比旧版本数据确定变更数据,智能判断并更新基线版本定位元素数据,从而可不断更新UI自动化测试系统中定位元素的全量信息,并实现智能化管理,运行UI自动化用例;这样,就可以保证原有用例正常执行,同时提高测试效率和质量,让测试人员能够更早地参与到UI自动化测试用例编写中。具体来说:
Smart Images

Figure CN117472778B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of automated testing technology, and in particular to a web page UI testing method. Background Technology
[0002] In software development, UI automation testing is an important method for verifying the functionality of an application and the proper functioning of its user interface. By writing automated scripts to perform various operations on the user interface (such as clicking, filling out forms, selecting menus, etc.) and checking whether the results meet expectations, testing efficiency and accuracy can be significantly improved, saving time and resources.
[0003] However, in real-world projects, script execution often fails or encounters errors due to factors such as element relocation, element name modification, element deletion or addition, and page layout changes. In such cases, testers need to invest significant time manually updating the script to adapt to the changes, sometimes even requiring rewriting or abandoning some test cases. This leads to a large amount of repetitive work and wasted human resources.
[0004] To address this issue, testers can participate in maintaining basic information such as location elements to solve UI automation test cases. However, in real-world engineering applications, the number of UI automation test cases is enormous, with each iteration accumulating tens of thousands of cases. Some hidden tags require manual triggering of specific environments to display and obtain the latest location elements, which undoubtedly increases the complexity of maintenance for testers. Furthermore, as the functionality of engineering applications continues to expand, the operation of UI automation testing systems faces severe challenges. Currently, the main shortcomings of UI automation testing systems include:
[0005] 1. Deleting or adding elements causes script execution to fail or result in errors;
[0006] 2. Moving elements requires manually updating the script to adapt to the new position;
[0007] 3. Issues such as page layout changes causing existing scripts to be unable to manipulate elements on the page;
[0008] 4. Hidden positioned elements also require specific environmental triggering conditions to be triggered and modified. Summary of the Invention
[0009] This application provides a UI automation testing method and system for intelligently updating page positioning elements, aiming to solve the problems of poor coverage and stability of existing test cases and low maintenance efficiency.
[0010] Firstly, a UI automation testing method for intelligently updating page positioning elements includes:
[0011] Step 1: Obtain the positioning data of all non-hidden elements on the current page, and generate a corresponding custom code name for each non-hidden element according to the set naming logic; the non-hidden elements are divided into clickable positioning elements and input-enabled positioning elements;
[0012] Step 2: Recursively click all clickable elements on the current page, obtain the location data of newly added elements caused by the clicks, and generate corresponding custom code names for the newly added elements according to the naming logic set above.
[0013] Step 3: Recursively retrieve the input-accessible elements on the current page, configure the sniffing strategy, obtain the location data of all hidden elements, and generate corresponding custom code names for the hidden elements according to the naming logic set above.
[0014] Step 4: Store the full data obtained in Steps 1 to 3 into the first database. The first database also stores the full data of several previous versions. The full data includes the code-defined name and location data of each element. Compare the full data of the current version with the full data of the previous version to determine the data that has changed, and record it as the changed data.
[0015] Step 5: For the changed data, the positioning data of the corresponding element in the baseline positioning element database is intelligently updated by reverse lookup of the full data of the baseline positioning element database and an identifier is added, but the custom code name of the element remains unchanged, so that the test cases in the UI automation test cases can be executed normally.
[0016] Step 6: Based on the baseline location element database, run UI automation test cases and output a test report.
[0017] Optionally, the clickable positioning elements include buttons, links, dropdown lists, checkboxes, and labels.
[0018] Optionally, the naming logic is as follows: the custom code name includes the page title and the name or meaning of the element displayed on the page, separated by a period.
[0019] Optionally, in step two, all clickable elements on the current page are clicked recursively to generate new elements, including: for hidden pop-ups that require other operations during the clicking process, a pre-written corresponding algorithm is used to assist the clicking, so as to ensure that all hidden data related to all clickable elements is obtained.
[0020] Optionally, step four specifically includes:
[0021] The full data of the current version is compared with the full data of the previous version. AI technology is used to calculate the similarity. If the similarity is lower than the set threshold, it is judged as changed data and stored in the second database, which is used to record changed data. Otherwise, it is judged as unchanged data.
[0022] Optionally, in step five, the location data of the corresponding element in the location element database of the intelligently updated baseline includes: determining whether the element found in the reverse lookup is an element that needs to be updated; if so, updating the location data; otherwise, determining it as a new element and appending it to the location dataset of the location element database of the baseline.
[0023] Optionally, step five, determining whether the element found in the reverse lookup is an element that needs to be updated, specifically includes:
[0024] Using the custom name in the changed data, reverse the lookup to find the full data of the baseline's location element database. If the corresponding location data exists, further determine whether the current element is a changed element (an element whose name has changed). If neither location data exists nor is it a changed element, it indicates that it is a newly added element; otherwise, it is an element that needs to be updated.
[0025] Optionally, the method for determining whether the current element is a changed element is as follows: Suppose that the xpath_id of the current element's positioning data in the baseline positioning element database changes by M positions due to the addition of the new element, then the current element is determined to be an element that needs to be updated or a changed element by querying the identifiers of the M elements above the current element in the baseline positioning element database and counting the number of various markers.
[0026] Secondly, a UI automation testing system for intelligently updating page positioning elements includes:
[0027] The page positioning element information update module is used to implement steps one to five in the UI automation testing method for intelligently updating page positioning elements described above.
[0028] A test case database is used to store test cases;
[0029] The element database is located and is specifically divided into three databases:
[0030] a) The first database, used to store the full data of each version;
[0031] b. Second database, used to store changed data;
[0032] c. The baseline location element database serves as the source of test case data;
[0033] The test execution module is used to automatically run the test cases stored in the test case database based on the baseline location element database and output a test report (i.e., step six in the above-mentioned UI automation test method for intelligently updating page location elements).
[0034] Thirdly, a computer device for UI automation testing includes a memory and a processor, wherein the memory stores a computer program, and the processor, when executing the computer program, implements the steps of the above-described UI automation testing method for intelligently updating page positioning elements.
[0035] Compared with the prior art, this application has at least the following beneficial effects:
[0036] This application obtains information on changes in located elements and hidden elements by recursively clicking on clickable elements and recursively sniffing input elements based on all non-hidden elements on the current page. It acquires all the complete data, then determines the changed data by comparing it with the old version data, intelligently judges and updates the baseline version's located element data. This allows for continuous updating of the complete information on located elements in the UI automation testing system, achieving intelligent management and running UI automation test cases. This ensures the normal execution of existing test cases while improving testing efficiency and quality, allowing testers to participate in writing UI automation test cases earlier. Specifically:
[0037] 1. This application can accurately and clearly locate and modify the location information, automatically obtain and update the underlying location data, and keep the test cases unchanged, saving the maintenance time of automated test cases and the maintenance time of the underlying location elements. Automatic maintenance ensures that the location elements are all up-to-date; it facilitates the sustainable maintenance of UI automated test cases by testers, reduces manual input, and improves testing efficiency.
[0038] 2. This application eliminates the hassle of manually searching for hidden elements, and can directly obtain each hidden element. It solves the problem that traditional element location methods cannot obtain hidden UI positioning elements, improves the coverage of test cases, ensures the continuous and stable availability of existing UI automation test cases, and can adapt to different types of web pages, with wide applicability and flexibility. Attached Figure Description
[0039] Figure 1 A flowchart illustrating a UI automation testing method for intelligently updating page positioning elements, provided as an embodiment of this application;
[0040] Figure 2 This is a schematic diagram illustrating the principle of fully acquiring all positioning elements in one embodiment of this application;
[0041] Figure 3This is a schematic diagram illustrating the principle of intelligent updating of positioning elements in one embodiment of this application;
[0042] Figure 4 This is an example of the page before the elements were changed;
[0043] Figure 5 for Figure 4 The page shown corresponds to database a;
[0044] Figure 6 for Figure 4 The database c corresponding to the page shown;
[0045] Figure 7 Here is an example of a page after the elements have changed;
[0046] Figure 8 for Figure 7 The page shown corresponds to database a;
[0047] Figure 9 for Figure 7 The database b corresponding to the page shown;
[0048] Figure 10 for Figure 7 The database c corresponding to the page shown;
[0049] Figure 11 To Figure 7 The diagram illustrates the process of adding markers (marks) sequentially to "Demo.D", "Demo.B", "Demo.C", "Demo.Search", and "Demo.Reset" in database c corresponding to the page shown. Detailed Implementation
[0050] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0051] In the description of this application, unless otherwise stated, expressions such as "comprising," "including," and "having" also mean "not limited to" (certain units, steps, etc.).
[0052] This embodiment addresses the problems of traditional UI automation testing, such as the inability of written automated test cases to function properly due to web page changes and excessively high maintenance costs, as well as the inability of traditional element location methods to capture hidden UI elements. It proposes a UI automation testing method that intelligently updates page positioning elements. For example... Figure 1 As shown, the method includes:
[0053] 1) Get the location data of all elements on the current page
[0054] This section primarily retrieves the location data of all non-hidden elements on the current page, performs data cleaning and constructs element names (custom names in the code), and stores them in the database (or they can be stored uniformly in step 4) for user convenience.
[0055] The positioning data for non-hidden elements is the full set of positioning element tags in the HTML of the web page.
[0056] Custom code names are configured when retrieving each positioned element, providing a custom name for later user use and maintenance. The naming logic for custom code names can be: including the page title and the name or meaning of the element displayed on the page, separated by periods; for example, if the current page is "demo" and a button is named "search", the custom code name would be: demo.search; if the page is "domain homepage", the custom code name would be: domain homepage.search.
[0057] 2) Recursively click on clickable elements, obtain element changes (all newly added elements due to clicks) and their corresponding location data, and store them in the database (or store them uniformly in step 4).
[0058] Here, clickable elements include buttons, links, dropdown lists, checkboxes, and labels. Taking buttons on the page as an example, by exploring all hidden pop-ups on the current page, and for those hidden pop-ups that require other operations during the click process, corresponding methods are written to assist the click, ensuring that all hidden data related to all button elements is obtained.
[0059] 3) Recursively retrieve all input-enabled elements from all elements, configure the corresponding sniffing strategy, and obtain the location data of all hidden elements (e.g., input tag hints) to ensure that each hidden element is captured for subsequent location verification; store it in the database (or in step 4 for unified storage).
[0060] 4) Compare the full data with the old version to obtain the changed data.
[0061] After obtaining all the full data through the previous steps (steps 1), 2), and 3), the data can be stored uniformly at this point. This database can be referred to as the first database, primarily used to store different versions of data, providing executable conditions for subsequent comparisons. The full data includes the code name and location data of each element. Then, it is compared with the full data of the previous version to obtain the changed data. Changed data refers to data information different from the previous version, and this changed data can be stored separately in another database (this database can be referred to as the second database).
[0062] The system compares the latest full data with the old version of the full data. Specifically, it uses AI technology to calculate the similarity. If the similarity is low, the data is judged as changed and stored in the corresponding database. If the similarity is high or the data is identical, the data is judged as unchanged.
[0063] For example, if the code name of an element in the previous version was "domain homepage.search", and the xpath_id of the element remains the same in the current version, but the code name is "domain homepage.searching", then using AI technology to calculate similarity may identify it as unchanged data.
[0064] 5) By changing the data, intelligently determine and update the positioning element information of the old version.
[0065] Based on the changed data determined in the previous step, reverse the search for the full data of the baseline's positioning element database, and intelligently update the basic information of the positioning elements in the baseline's positioning element database.
[0066] This mainly involves reverse lookup based on the element name (custom name in the code). Therefore, it is necessary to determine whether the element found in the reverse lookup is the element that needs to be updated. Thus, an algorithm is used to determine whether the old data is the element that needs to be updated. If it is, it is updated; otherwise, it is considered new data and is appended to the old version of the location dataset. (The test cases are written manually, and some of the newly added elements are generally new functions that do not usually conflict with the business logic in the old test cases.)
[0067] This involves identifying and marking changed data after code analysis and judgment, and then using statistical calculations to intelligently locate the data that needs to be updated in the previous version, ensuring that test cases in automated test cases can be executed normally.
[0068] 6) Use the code-defined name of the locating element as the step object in the test case, write the test case, run the test case, and output the test case execution result report and email information.
[0069] Specifically, the process involves executing pre-written UI automation test cases, ensuring that the data in the test case steps corresponds to the names of the UI automation location elements, automatically retrieving the underlying location data corresponding to each element's name through encapsulated methods, performing the corresponding operations, completing the test case execution, and sending the final test result report to the testers. The email notification is sent to relevant personnel after successful execution.
[0070] When writing test cases, in addition to using custom names from the code, testers sometimes want to better express or represent the test cases. They can also add manually defined names (which correspond one-to-one with the custom names from the code) to the baseline's location element database. This way, test cases can be written using manually defined names.
[0071] This embodiment, through intelligent and comprehensive methods, can automatically update the location element information of a web page, achieving fast and accurate element location. When the web page changes, the system can automatically identify and update the relevant location element information, ensuring the availability of automated test cases; thereby significantly reducing the maintenance cost of UI automated testing and improving the efficiency and stability of automated testing. Furthermore, the system's intelligent and comprehensive characteristics can adapt to different types of web pages, exhibiting broad applicability and flexibility. In summary, this method provides a more efficient and stable solution for automated testing, improving test results and quality.
[0072] In one embodiment, such as Figure 2 The diagram illustrates the processing logic for fully capturing all located elements. This mainly includes recursively clicking all clickable elements in the original page and recursively searching for inputtable elements in all pages. Specifically:
[0073] Recursively clicking on all clickable elements in the original page requires working on the elements within the original page. It recursively retrieves all clickable data from each element, compares it to the original page, and obtains information about the changed elements. This clickable data includes not only the original page but also the clickable data from elements that have changed after being clicked. Based on this method, all data changes caused by clicks on the current page can be fully retrieved.
[0074] Recursively sniffing all input elements on the page mainly involves recursively obtaining each input tag, configuring relevant strategies (e.g., maximum value, minimum value, empty, special value, etc.) to lure and retrieve hidden elements with relevant input tags, so that users can extract data without manually performing the extraction.
[0075] The above-mentioned full-quantization element location result refers to the full data that combines the original page element data, click change data, and input hidden data.
[0076] In one embodiment, such as Figure 3 The diagram illustrates the processing logic for intelligently updating location elements. First, it acquires changed data by comparing the full dataset of the old and new versions, extracting the data that has changed.
[0077] Next, we look up the old data. Because we want to ensure that the data names in the test cases remain unchanged, we need to maintain a baseline database of location elements to ensure that each change is based on the previous version. Therefore, we use the data names in the changed data to look up the old data. If the data is found, we determine if it is a changed element; otherwise, it indicates that it is newly added data.
[0078] Further, to determine the element to be changed, if the old data result is found by locating the element name, this only proves that there is matching data, but does not mean that the current result is the element we need to change. Therefore, we need to check the identifiers of elements within a certain range above the current element (e.g., add, update, etc.). By calculating the number of different identifiers, we can determine whether the old data is a real node that needs to be updated. If it is, then update it; otherwise, we determine that it is new data and append it.
[0079] Specifically: Suppose that the xpath_id of the current element's location data in the baseline's location element database changes by M positions due to the addition of a new element. Then, by querying the identifiers of the M elements above the current element in the baseline's location element database and counting the number of various markers, it can be determined whether the current element needs to be updated or changed.
[0080] The following demo will be used to illustrate the solution of this embodiment.
[0081] The database used to store full data for each version is denoted as database a, the database used to store changed data is denoted as database b, and the database for the baseline's location elements is denoted as database c.
[0082] First page elements such as Figure 4 As shown, the page title is "Demo". All elements on the current page are retrieved and their custom names are generated, such as "Demo.Name" for "Name", "Input Box" for "Demo.NameInputBox", "A" for "Demo.A", and so on. These are stored in database 'a' and synchronized to database 'c' for external use. Specifically, as shown... Figure 5 , Figure 6 As shown.
[0083] When the page elements change for the second time, such as Figure 7As shown, all elements on the current page are retrieved again, and a smart comparison (name matching rate) is performed with the elements stored in database 'a' from the previous version, and then stored. It is found that Demo.D, Demo.B, Demo.C, Demo.Search, and Demo.Reset have changed their positioning elements, and the changed elements are stored in the aforementioned database 'b', as detailed below. Figure 8 , Figure 9 As shown.
[0084] Retrieve all data from database b and compare it sequentially with the data from the previous version of database c. (Here, each changed element can be understood as an independent entity; adding or removing elements will cause changes in the data below.)
[0085] By comparing the data, it was found that Demo.D was not present in the previous version; it was added to database c and marked as "add". Figure 6 , Figure 10 A reverse lookup of Demo.B reveals that the old version contains an XPath_id of demo-4, which differs from the XPath_id of demo-5 in the new version by one digit. Therefore, we query the XPath_ids from demo-4 to demo-5 and count the number of tags. If any are "add" or "update," it means the old version of Demo.B was simply altered by inserting another element at its original position, thus marking it as "update." Otherwise, it's a newly added element (and should be marked as "add"). Figure 11 As shown, the data results can be obtained by following the same logic.
[0086] In one embodiment, a UI automation testing system for intelligently updating page positioning elements is also provided, comprising:
[0087] The page positioning element information update module is used to implement steps 1) to 5) of the UI automation testing method for intelligently updating page positioning elements.
[0088] A test case database is used to store test cases;
[0089] The location element database is specifically divided into three databases (or data tables): a) the first database, which stores all data for each version; b) the second database, which stores change data; and c) the baseline location element database, which serves as the source of test case data.
[0090] The test execution module is used to automatically run the test cases stored in the test case database based on the baseline location element database and output a test report, i.e., to execute the aforementioned step 6).
[0091] In one embodiment, a computer device for UI automation testing is also provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the above-described UI automation testing method for intelligently updating page positioning elements.
[0092] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
Claims
1. A UI automation testing method for intelligently updating page positioning elements, characterized in that, include: Step 1: Obtain the positioning data of all non-hidden elements on the current page, and generate a corresponding custom code name for each non-hidden element according to the set naming logic; the non-hidden elements are divided into clickable positioning elements and input-enabled positioning elements; Step 2: Recursively click all clickable elements on the current page, obtain the location data of newly added elements caused by the clicks, and generate corresponding custom code names for the newly added elements according to the naming logic set above. Step 3: Recursively retrieve the input-accessible elements on the current page, configure the sniffing strategy, obtain the location data of all hidden elements, and generate corresponding custom code names for the hidden elements according to the naming logic set above. Step 4: Store the full data obtained in Steps 1 to 3 into the first database. The first database also stores the full data of several previous versions. The full data includes the code-defined name and location data of each element. Compare the full data of the current version with the full data of the previous version to determine the data that has changed, and record it as the changed data. Step 5: For the changed data, the positioning data of the corresponding element in the baseline positioning element database is intelligently updated by reverse lookup of the full data of the baseline positioning element database and an identifier is added, but the custom code name of the element remains unchanged, so that the test cases in the UI automation test cases can be executed normally. In step five, the location data of the corresponding element in the location element database of the intelligent updated baseline includes: determining whether the element found by reverse lookup is an element that needs to be updated; if so, updating the location data; otherwise, determining it as a new element and appending it to the location dataset of the location element database of the baseline. The determination of whether the element found in the reverse lookup is an element that needs to be updated specifically includes: Using the custom name in the changed data, reverse the search for the full data of the baseline's location element database. If the corresponding location data exists, further determine whether the current element belongs to the changed element; if neither location data exists nor does it belong to the changed element, it indicates that it is a newly added element; otherwise, it is an element that needs to be updated. The method for determining whether the current element is a changed element is as follows: Suppose that the xpath_id of the current element's positioning data in the baseline positioning element database changes by M positions due to the addition of the new element. Then, by querying the identifiers of the M elements above the current element in the baseline positioning element database and counting the number of various markers, it can be determined whether the current element is an element that needs to be updated or a changed element. Step 6: Based on the baseline location element database, run UI automation test cases and output a test report.
2. The UI automation testing method for intelligently updating page positioning elements according to claim 1, characterized in that, The clickable positioning elements include buttons, links, drop-down lists, checkboxes, and labels.
3. The UI automation testing method for intelligently updating page positioning elements according to claim 1, characterized in that, The naming logic is as follows: the custom code name includes the page title and the name or meaning of the element displayed on the page, separated by a period.
4. The UI automation testing method for intelligently updating page positioning elements according to claim 1, characterized in that, In step two, all clickable elements on the current page are clicked recursively to generate new elements. This includes: for hidden pop-ups that require other operations during the clicking process, a pre-written corresponding algorithm is used to assist the click, so as to ensure that all hidden data related to all clickable elements is obtained.
5. The UI automation testing method for intelligently updating page positioning elements according to claim 1, characterized in that, Step four specifically includes: The full data of the current version is compared with the full data of the previous version. AI technology is used to calculate the similarity. If the similarity is lower than the set threshold, it is judged as changed data and stored in the second database, which is used to record changed data. Otherwise, it is judged as unchanged data.
6. A UI automated testing system for intelligently updating page positioning elements, used to implement the UI automated testing method for intelligently updating page positioning elements as described in any one of claims 1 to 5; characterized in that, include: Page positioning element information update module; A test case database is used to store test cases; The element database is located and is specifically divided into three databases: a) The first database, used to store the full data of each version; b. Second database, used to store changed data; c. The baseline location element database serves as the source of test case data; The test execution module is used to automatically run test cases stored in the test case database based on the baseline location element database and output test reports.
7. A computer device for UI automation testing, comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the UI automation testing method for intelligently updating page positioning elements as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Generating method and system for automated testing case
CN105975396A
UI automatic test method and device and electronic device
CN109783388A