Web UI automatic test method and device

By automatic judgment and update element positioning method in the Web UI automation test, the problem of low execution efficiency and poor stability in existing technologies has been solved, and more efficient and stable test script execution is achieved.

CN119336631APending Publication Date: 2025-01-21中国邮政储蓄银行股份有限公司
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411363519.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-27
Publication Date
2025-01-21

AI Technical Summary

Technical Problem

The existing Web UI automation testing methods cannot automatically determine the positioning of elements, resulting in low execution efficiency and poor stability.

Method used

By obtaining the test script, the initial positioning method is to position the elements in the target interface, determine the target priority of the positioning method of each element according to the positioning results, and use the target positioning method to locate the next execution.

Benefits of technology

It realizes the automatic analysis and selection of element positioning methods and the automatic update of element positioning information, which improves the stability and execution efficiency of the script.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119336631A_ABST
    Figure CN119336631A_ABST
Patent Text Reader

Abstract

The invention discloses a Web UI (User Interface) automatic testing method and a Web UI automatic testing device. The method comprises the steps that a test script is obtained, and the test script is a script which is determined according to an element operation method, element attribute information and a plurality of element positioning modes and executes preset operation on a target interface; the test script is executed, an initial positioning mode is adopted to position elements in the target interface, a positioning result is obtained, the positioning result is successful positioning or failed positioning, and the initial positioning mode is one of multiple element positioning modes; according to the positioning result, determining a target priority of each element positioning mode, and determining the element positioning mode with the highest target priority as a target positioning mode; and in the process of executing the test script next time, positioning the elements in the target interface by adopting the target positioning mode. The technical problems that an existing UI automatic testing method cannot automatically judge the element positioning mode, execution efficiency is low, and stability is poor are solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field, and in particular to a Web UI automated testing method and device. Background Art

[0002] In current Web UI automated testing, element positioning is mainly performed through element attributes, coordinate positions, images, etc., and traversal retries are performed by specifying one or more methods. This method has the following technical disadvantages:

[0003] During the execution of the test script, the element positioning methods are used for identification. It is impossible to automatically determine which positioning method is most suitable for the current element. When one or more element identification methods fail, the positioning information needs to be manually re-recorded, which reduces the efficiency and stability of the test script execution.

[0004] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention

[0005] The embodiment of the present invention provides a Web UI automated testing method and device, so as to at least solve the technical problems that the existing UI automated testing method cannot automatically determine the positioning mode of elements, and has low execution efficiency and poor stability.

[0006] According to one aspect of an embodiment of the present invention, a Web UI automated testing method is provided, comprising: obtaining a test script, wherein the test script is a script for executing a preset operation on a target interface determined according to an element operation method, element attribute information, and a plurality of element positioning methods; executing the test script, and positioning the element in the target interface using an initial positioning method to obtain a positioning result, wherein the positioning result is positioning success or positioning failure, and the initial positioning method is one of the plurality of element positioning methods; determining a target priority of each element positioning method according to the positioning result, and determining the element positioning method with the highest target priority as the target positioning method; and positioning the element in the target interface using the target positioning method during the next execution of the test script.

[0007] Optionally, an initial positioning method is used to locate the elements in the target interface to obtain a positioning result, including: obtaining a plurality of element positioning methods, the element positioning methods including: id positioning, name positioning, path positioning, position coordinate positioning and image information positioning; obtaining an initial priority of each element positioning method; determining the element positioning method with the highest initial priority as the initial positioning method; and using the initial positioning method to locate the elements in the target interface to obtain a positioning result.

[0008] Optionally, the candidate personnel are screened according to the target feature attributes to obtain suitable personnel, including: determining multiple scoring levels of the target feature attributes; taking the target feature attributes of each candidate personnel as a sample, taking the scoring level as a cluster category, taking the sum of the squares of the distances from the sample to the cluster centroid of the cluster category as the clustering objective function, and performing cluster analysis on the candidate personnel; and screening the suitable personnel according to the cluster analysis results.

[0009] Optionally, based on the positioning result, the target priority of each of the element positioning methods is determined, including: obtaining initial execution information of the initial positioning method, the initial execution information including the initial execution times, initial execution success times and initial execution success rate of the initial positioning method; determining the sum of the initial execution times and 1 as the update execution times; when the positioning result is a successful positioning, determining the sum of the initial execution success times and 1 as the update execution success times, and when the positioning result is a failed positioning, determining the initial execution success times as the update execution success times; determining the ratio of the update execution success times to the update execution times as the update execution success rate; and determining the target priority of each of the element positioning methods based on the update execution success rate.

[0010] Optionally, based on the update execution success rate, the target priority of each of the element positioning methods is determined, including: sorting the update execution success rate of the initial positioning method and the execution success rate of the non-initial positioning method from large to small to obtain an execution success rate order; using the execution success rate order as the priority order of the element positioning method, and prioritizing each of the element positioning methods to obtain the target priority of each of the element positioning methods.

[0011] Optionally, after determining the target priority of each element positioning method according to the positioning result, the Web UI automated testing method further includes: when the positioning result is successful positioning and the target priority of the initial positioning method is not the highest priority, determining whether the initial positioning method is a preset positioning method, and the preset positioning method is one of the following: id positioning, name positioning, and path positioning; when the initial positioning method is the preset positioning method, obtaining updated attribute information of the element, and the updated attribute information includes at least one of the following: the updated id, updated name, updated path, updated position coordinates and updated image information of the element.

[0012] Optionally, after the element in the target interface is positioned using the initial positioning method and a positioning result is obtained, the Web UI automated testing method further includes: when the positioning result is a positioning failure, the element positioning method with a priority one level lower than the initial positioning method is used to reposition the element in the target interface until the element is successfully positioned.

[0013] Optionally, obtaining a test script includes: obtaining user actual operation information, wherein the user actual operation information is information generated when the user performs real operations on the target interface; determining basic element information of each element on the target interface based on the user actual operation information, wherein the basic element information includes the element's id, name, path, position coordinates on the target interface, and image information on the target interface; generating the test script based on the basic element information of each element on the target interface.

[0014] According to another aspect of an embodiment of the present invention, a Web UI automated testing device is further provided, comprising: an acquisition unit, for acquiring a test script, wherein the test script is a script for executing a preset operation on a target interface determined according to an element operation method, element attribute information, and a plurality of element positioning methods; an execution unit, for executing the test script, and locating the element in the target interface using an initial positioning method to obtain a positioning result, wherein the positioning result is a positioning success or a positioning failure, and the initial positioning method is one of the plurality of element positioning methods; a determination unit, for determining a target priority of each of the element positioning methods according to the positioning result, and determining the element positioning method with the highest target priority as the target positioning method; and a positioning unit, for locating the element in the target interface using the target positioning method during the next execution of the test script.

[0015] Optionally, the execution unit includes: a first acquisition subunit, used to acquire a plurality of the element positioning methods, the element positioning methods including: ID positioning, name positioning, path positioning, position coordinate positioning and image information positioning; a second acquisition subunit, used to acquire the initial priority of each of the element positioning methods; a first determination subunit, used to determine the element positioning method with the highest initial priority as the initial positioning method; a positioning subunit, used to use the initial positioning method to locate the elements in the target interface to obtain a positioning result.

[0016] Optionally, the determination unit includes: a third acquisition subunit, used to acquire initial execution information of the initial positioning method, the initial execution information including the initial execution times, initial execution success times and initial execution success rate of the initial positioning method; a second determination subunit, used to determine the sum of the initial execution times and 1 as the update execution times; a third determination subunit, used to determine the sum of the initial execution success times and 1 as the update execution success times when the positioning result is a successful positioning, and to determine the initial execution success times as the update execution success times when the positioning result is a failed positioning; a fourth determination subunit, used to determine the ratio of the update execution success times to the update execution times as the update execution success rate; and a fifth determination subunit, used to determine the target priority of each element positioning method according to the update execution success rate.

[0017] Optionally, the fifth determination subunit includes: a first sorting subunit, used to sort the update execution success rate of the initial positioning method and the execution success rate of the non-initial positioning method from large to small to obtain an execution success rate order; a second sorting subunit, used to use the execution success rate order as the priority order of the element positioning method, and prioritize each of the element positioning methods to obtain a target priority of each of the element positioning methods.

[0018] Optionally, the Web UI automated test also includes: a second determination unit, used to determine whether the initial positioning method is a preset positioning method after determining the target priority of each element positioning method according to the positioning result, when the positioning result is a successful positioning and the target priority of the initial positioning method is not the highest priority, and the preset positioning method is one of the following: id positioning, name positioning, path positioning; a second acquisition unit, used to obtain the updated attribute information of the element when the initial positioning method is the preset positioning method, and the updated attribute information includes at least one of the following: the updated id, updated name, updated path, updated position coordinates and updated image information of the element.

[0019] Optionally, the Web UI automated test also includes: a second positioning unit, which is used to locate the element in the target interface by adopting the initial positioning method, and after obtaining the positioning result, if the positioning result is a positioning failure, use the element positioning method with a priority one level lower than the initial positioning method to re-position the element in the target interface until the element is successfully positioned.

[0020] Optionally, the acquisition unit includes: a fourth acquisition sub-unit, used to acquire user actual operation information, wherein the user actual operation information is information generated when the user performs real operations on the target interface; a sixth determination sub-unit, used to determine the basic element information of each element on the target interface based on the user actual operation information, wherein the basic element information includes the element's id, name, path, position coordinates on the target interface, and image information on the target interface; a generation sub-unit, used to generate the test script based on the basic element information of each element on the target interface.

[0021] According to another aspect of an embodiment of the present invention, a computer-readable storage medium is further provided, wherein the computer-readable storage medium includes a stored program, wherein when the program is executed, the device where the computer-readable storage medium is located is controlled to execute any one of the above-mentioned Web UI automated testing methods.

[0022] According to another aspect of an embodiment of the present invention, an electronic device is also provided, comprising: one or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by the one or more processors, and the one or more programs include a method for executing the Web UI automated testing method described in any one of the above.

[0023] According to another aspect of an embodiment of the present invention, a processor is further provided, wherein the processor is used to run a program, wherein the program executes any one of the above-mentioned Web UI automated testing methods when running.

[0024] According to another aspect of an embodiment of the present invention, a computer program product is provided, including computer instructions, and when the computer instructions are executed by a processor, any one of the above-mentioned Web UI automated testing methods is executed.

[0025] In an embodiment of the present invention, a test script is obtained, and the test script is a script that performs preset operations on a target interface according to an element operation method, element attribute information, and multiple element positioning methods; the test script is executed, and the element in the target interface is positioned using an initial positioning method to obtain a positioning result, and the positioning result is a successful positioning or a failed positioning, and the initial positioning method is one of multiple element positioning methods; according to the positioning result, the target priority of each element positioning method is determined, and the element positioning method with the highest target priority is determined as the target positioning method; in the process of executing the test script next time, the element in the target interface is positioned using the target positioning method. Through the technical solution provided by the present invention, the purpose of combining attribute recognition, coordinate recognition, and image recognition, adding an adaptive mechanism and an automatic update mechanism for element recognition is achieved, so that the test script is always executable and can automatically select the element recognition method with the highest success rate, thereby achieving the technical effect of automatic analysis and selection of element positioning methods, and automatic updating of element positioning information, improving the stability and execution efficiency of the script, and thus solving the technical problem that the existing UI automation test method cannot automatically determine the element positioning method, and has low execution efficiency and poor stability. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:

[0027] Figure 1 It is a hardware structure block diagram of a mobile terminal of a Web UI automated testing method according to an embodiment of the present invention;

[0028] Figure 2 is a flowchart of a Web UI automated testing method according to an embodiment of the present invention;

[0029] Figure 3 is a device diagram of a Web UI automated testing method according to an embodiment of the present invention;

[0030] Figure 4 is a flowchart of an optional Web UI automated testing method according to an embodiment of the present invention;

[0031] Figure 5 is a schematic diagram of a Web UI automated testing device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0032] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0033] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0034] As introduced in the background technology, the existing UI automation testing method cannot automatically determine the positioning mode of the element, and has low execution efficiency and poor stability. In view of the above defects, an embodiment of the present invention provides a Web UI automation testing method and device, an electronic device, a computer-readable storage medium, a processor, and a computer program product.

[0035] It should be noted that the above-mentioned Web UI automated testing is for Web applications, which simulates human behavior through code or tools to operate the user interface and realize automated testing of the program UI layer.

[0036] The technical solutions in the embodiments of the present invention will be described clearly and completely below in conjunction with the accompanying drawings in the embodiments of the present invention.

[0037] The method embodiments provided in the embodiments of the present invention can be executed in a mobile terminal, a computer terminal or a similar computing device. Taking running on a mobile terminal as an example, Figure 1 FIG. 1 is a hardware structure diagram of a mobile terminal of a Web UI automated testing method according to an embodiment of the present invention. Figure 1 As shown, the mobile terminal may include one or more ( Figure 1Only one is shown in the figure) a processor 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data, wherein the mobile terminal may also include a transmission device 106 and an input / output device 108 for communication functions. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the mobile terminal. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations are shown.

[0038] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the Web UI automated testing method in the embodiment of the present invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, the above method is implemented. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the mobile terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof. The transmission device 106 is used to receive or send data via a network. The above-mentioned specific network examples may include a wireless network provided by a communication provider of the mobile terminal. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0039] According to an embodiment of the present invention, a method embodiment of a Web UI automated testing method is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0040] Figure 2 is a flowchart of a Web UI automated testing method according to an embodiment of the present invention. Figure 2 As shown, the method comprises the following steps:

[0041] Step S202, obtaining a test script, where the test script is a script for executing a preset operation on a target interface according to an element operation method, element attribute information, and multiple element positioning methods.

[0042] It should be noted that the above-mentioned elements refer to a series of elements that meet user interaction requirements and are contained in software or system interfaces that can meet interaction requirements; the above-mentioned element operation methods refer to methods for operating page elements, such as clicking, entering text, getting text, etc.; the above-mentioned element attribute information refers to the attributes of the elements, such as id, class, name, etc.; the above-mentioned multiple element positioning methods refer to positioning page elements in a variety of ways, which may be to locate the elements through the element's unique identifier.

[0043] In this embodiment, the target test script can be obtained according to the element operation method, element attribute information, and multiple element positioning modes.

[0044] Step S204, execute the test script, and use the initial positioning method to locate the elements in the target interface to obtain a positioning result, the positioning result is positioning success or positioning failure, and the initial positioning method is one of multiple element positioning methods.

[0045] In this embodiment, the test script can be executed and the elements in the target interface can be positioned using the initial positioning method, and the accuracy and stability of the positioning method can be verified through multiple executions.

[0046] Step S206: Determine the target priority of each element positioning method according to the positioning result, and determine the element positioning method with the highest target priority as the target positioning method.

[0047] In this embodiment, the target priority of each element positioning method can be determined according to the positioning result, which can help the automated test script to find the page elements more accurately. By setting the priority of the positioning method, it can be ensured that when the page structure changes or the element attributes change, the script can correctly find the target element. Usually, the target positioning method is relatively stable and accurate, so the element positioning method with the highest target priority is set as the target positioning method.

[0048] Step S208, during the next execution of the test script, the elements in the target interface are positioned using a target positioning method.

[0049] In this embodiment, during the next execution of the test script, the element positioning method with the highest target priority can be used to locate the elements in the target interface, ensuring that the script can correctly execute the test cases in different environments, can most effectively locate the target elements, and ensure the accuracy of the test results.

[0050] As can be seen from the above, in an embodiment of the present invention, a test script is obtained, and the test script is a script that performs preset operations on a target interface according to an element operation method, element attribute information, and multiple element positioning methods; the test script is executed, and an initial positioning method is used to locate the element in the target interface to obtain a positioning result, and the positioning result is a successful positioning or a failed positioning, and the initial positioning method is one of multiple element positioning methods; according to the positioning result, the target priority of each element positioning method is determined, and the element positioning method with the highest target priority is determined as the target positioning method; in the process of executing the test script next time, the target positioning method is used to locate the element in the target interface, thereby achieving the purpose of combining attribute recognition, coordinate recognition, and image recognition, increasing the adaptive mechanism and automatic update mechanism of element recognition, so that the test script is always executable and can automatically select the element recognition method with the highest success rate, thereby realizing the technical effect of automatic analysis and selection of element positioning methods and automatic updating of element positioning information, and improving the stability and execution efficiency of the script.

[0051] The technical solution provided by the embodiment of the present invention solves the technical problems that the existing UI automation testing method cannot automatically determine the positioning mode of elements and has low execution efficiency and poor stability.

[0052] According to the above embodiment of the present invention, an initial positioning method is used to locate elements in a target interface to obtain a positioning result, including: obtaining a plurality of element positioning methods, the element positioning methods including: ID positioning, name positioning, path positioning, position coordinate positioning and image information positioning; obtaining the initial priority of each element positioning method; determining the element positioning method with the highest initial priority as the initial positioning method; and using the initial positioning method to locate elements in the target interface to obtain a positioning result.

[0053] Figure 3 is a device diagram of a Web UI automated testing method according to an embodiment of the present invention, such as Figure 3 As shown, it is divided into 5 modules: identification information module, test script generation module, test script execution module, adaptive identification module and automatic update module, among which the test script execution process can include three parts: adaptive rule preset, adaptive element identification and automatic update of element positioning information.

[0054] It should be noted that the above five element recognition methods will establish an adaptive rule table for each element, and will preset relevant rule information before testing, which may include: number of executions (numA), number of successes (numB), success rate (numC) and priority (numD); the above id positioning is to locate the element through the unique identifier (id) of the element. Since the id is unique and will not be affected by changes in the page structure, it is usually the most stable and fastest; the above name positioning is to locate the element through the name attribute of the element (i.e., name), which is usually used for elements with specific name attributes such as drop-down menus and check boxes; the above path positioning is to locate the element through the hierarchical path (i.e., xpath) of the element in the page, which is usually more complex and unstable, and the path positioning will become invalid due to changes in the page structure; the above position coordinate positioning is to locate the element through the absolute position coordinates of the element in the page, which is usually used in situations where precise positioning is required; the above image information positioning is to locate the element by obtaining image information from the element in the page, which is usually used in image recognition technology, and can locate the element by identifying the image in the page.

[0055] Table 1 is an adaptive rule preset information table according to an embodiment of the present invention. As shown in Table 1, the initial priority of ID positioning is 1, the initial priority of name positioning is 2, the initial priority of path positioning is 3, the initial priority of position coordinate positioning is 4, and the initial priority of image information positioning is 5, and the initial priority of ID positioning is the highest.

[0056] Table 1. Adaptive rule preset information table

[0057] Execution times Number of successes Success rate Priority id 0 0 0% 1 name 0 0 0% 2 xpath 0 0 0% 3 coordinate 0 0 0% 4 image 0 0 0% 5

[0058] The embodiment is described below in conjunction with Table 1. First, a variety of element positioning methods and corresponding initial priorities are obtained to help determine the most appropriate positioning method. ID positioning is determined as the initial positioning method, and the ID positioning method is used to locate the elements in the target interface to obtain the positioning result.

[0059] According to the above embodiment of the present invention, the target priority of each element positioning method is determined according to the positioning result, including: obtaining initial execution information of the initial positioning method, the initial execution information including the initial execution times, the initial execution success times and the initial execution success rate of the initial positioning method; determining the sum of the initial execution times and 1 as the update execution times; in the case where the positioning result is a successful positioning, determining the sum of the initial execution success times and 1 as the update execution success times, and in the case where the positioning result is a failed positioning, determining the initial execution success times as the update execution success times; determining the ratio of the update execution success times to the update execution times as the update execution success rate; and determining the target priority of each element positioning method according to the update execution success rate.

[0060] It should be noted that during the execution of the above test script, the recognition status of each test script step is recorded and calculated. The number of executions is the number of times this type is used, the number of successes is the number of times it is used and successfully recognized, and the success rate is equal to the number of successes divided by the number of executions.

[0061] Figure 4 is a flowchart of an optional Web UI automated testing method according to an embodiment of the present invention, such as Figure 4 As shown, after the test script starts to execute, the method with the highest priority is selected as the initial positioning method. First, start from the priority set to 1, obtain its initial execution times, initial execution success times and initial execution success rate, add 1 to the initial execution times to determine the updated execution times, if the positioning is successful, the execution success times are increased by 1, if the positioning fails, the execution success times are the initial execution success times, the updated execution success rate is the ratio of the execution success times to the execution times, and the target priority of each element positioning method is determined according to the execution success rate. The higher the execution success rate, the higher the target priority.

[0062] It should be noted that during the execution of the above test script, each test step starts with the identification method with a priority value of 1. If the identification is successful, the test step is executed normally. During the entire identification process, regardless of whether the identification result is successful or failed each time, the number of executions, number of successes, and success rate of the identification method will be calculated and updated.

[0063] In this embodiment, obtaining the initial execution information of the initial positioning method can help evaluate the effectiveness and stability of the positioning method. By counting the number of executions, the number of successes and the success rate, the performance of each positioning method in actual testing can be understood, so as to make adjustments and optimizations. According to the calculation method of updating the number of executions, the priority of each positioning method can be dynamically adjusted. By updating the execution success rate to determine the target priority of each element positioning method, the automated test script can be made more intelligent and adaptable. According to the actual test results, the priority of the positioning method can be continuously optimized to improve the execution efficiency of the test script.

[0064] In the above-mentioned embodiment of the present invention, the target priority of each element positioning method is determined according to the update execution success rate, including: sorting the update execution success rate of the initial positioning method and the execution success rate of the non-initial positioning method from large to small to obtain the execution success rate order; using the execution success rate order as the priority order of the element positioning method, and prioritizing each element positioning method to obtain the target priority of each element positioning method.

[0065] In this embodiment, each positioning method is sorted from large to small according to the execution success rate to obtain a priority order, thereby determining the priority of each element positioning method. After any recognition method is successfully identified, the priority is assigned to 1, 2, 3, 4, and 5 in sequence according to the success rate from large to small. This can help the script to give priority to positioning methods with higher success rates when locating elements, reduce the possibility of positioning failure, make the selection of positioning methods more accurate and effective, and be able to dynamically select the most appropriate positioning method according to actual conditions.

[0066] Table 2 is an update table of the adaptive rule table according to an embodiment of the present invention. As shown in Table 2, after a step is executed 50 times in total, the adaptive rule table is updated according to the above calculation method based on the execution result. The path positioning method has the highest success rate and its priority is 1. The name positioning method has the lowest success rate and its priority is 5.

[0067] Table 2. Update table of adaptive rule table

[0068]

[0069]

[0070] According to the above embodiment of the present invention, after determining the target priority of each element positioning method according to the positioning result, the Web UI automated testing method further includes: when the positioning result is successful positioning and the target priority of the initial positioning method is not the highest priority, determining whether the initial positioning method is a preset positioning method, the preset positioning method is one of the following: id positioning, name positioning, path positioning; when the initial positioning method is the preset positioning method, obtaining the updated attribute information of the element, the updated attribute information includes at least one of the following: the updated id of the element, the updated name, the updated path, the updated position coordinates and the updated image information.

[0071] In this embodiment, during the execution of the test script, when at least one of the id, name, and xpath positioning methods of a test step is successfully identified, that is, the positioning is successful and the target priority of the initial positioning method is not the highest priority, the updated attribute information of the element can be obtained through the getAttribute method, the coordinate information can be obtained through the element (i.e., element).location method, a screenshot can be taken through the coordinates to obtain image information, and then the test step positioning information is updated according to the latest positioning information, thereby realizing automatic update of the test script positioning method during execution.

[0072] It should be noted that the above updates are related to the product development process, that is, version updates. When the overall style of the front end changes, the image positioning and position positioning will also change.

[0073] According to the above embodiment of the present invention, after the initial positioning method is used to locate the elements in the target interface and the positioning result is obtained, the Web UI automated testing method further includes: when the positioning result is positioning failure, the element positioning method with a priority one level lower than the initial positioning method is used to re-position the elements in the target interface until the element is successfully positioned.

[0074] In this embodiment, if recognition fails, the next priority positioning method can be selected in a loop until successful recognition is achieved. If all recognitions fail, the test execution of this step is terminated. By gradually reducing the priority of the positioning method, multiple positioning methods can be tried to locate the target element, thereby increasing the chance of successful positioning and increasing the robustness and flexibility of the automated test script.

[0075] According to the above embodiment of the present invention, obtaining a test script includes: obtaining user actual operation information, which is information generated when the user performs real operations on the target interface; determining basic element information of each element on the target interface based on the user actual operation information, which basic element information includes the element's id, name, path, position coordinates on the target interface, and image information on the target interface; generating a test script based on the basic element information of each element on the target interface.

[0076] In this embodiment, basic information for element identification can be obtained by recording user operations. The basic information obtained by the element identification information module can be used to automatically generate a test script in the system, which can help the test script accurately locate the target element and perform corresponding operations.

[0077] Optionally, the basic element information may include: id, name, xpath, location coordinates and image information.

[0078] This embodiment is explained by taking the user's click login operation as an example. When converted into a test script, it will be composed of an operation method (click), an element (login button), and a positioning method (id, name, xpath, coordinates, image). Among them, click is the user's actual operation method, and the login button is the element attribute information.

[0079] Through the technical solution provided by the above-mentioned embodiment of the present invention, an automatic identification mechanism is added in the test execution stage. By recording and analyzing the successful element identification in the historical script execution, the best identification method can be automatically determined to ensure that the subsequent test scripts give priority to the execution method with a high success rate, which can reduce the overall execution time of the test script. At the same time, when the interface change is identified, other element location information of the element can be obtained through any element identification method that can successfully locate, and the latest element location information is automatically updated after the script execution is completed, without the need for manual maintenance by the user, further reducing the workload of script maintenance. By analyzing and calculating the cumulative identification of multiple positioning methods, the element identification method with the highest success rate can always be automatically selected, improving the stability of the test script. After each successful element identification, the element information is automatically re-acquired, and the positioning method that failed to identify is updated with the new element attribute information, reducing the workload of test script maintenance.

[0080] As can be seen from the above, in the embodiment of the present invention, based on the element attribute recognition, coordinate recognition, and image recognition capabilities, the basic information of the interface elements is obtained, and five positioning methods are generated by analyzing the attribute and image information: id, name, xpath, coordinates, and images. The results of each execution are recorded in the test execution stage, and the success rate of each positioning method is calculated and analyzed. The subsequent test script automatically selects the element recognition method from high to low according to the success rate based on the analysis results. At the same time, during the execution of the test script, if an element positioning method fails, the latest element positioning information can be re-acquired through any other successfully identified element positioning method, and the element positioning information that failed to be positioned in the test script is automatically updated after the test script is executed, ensuring that each element positioning method in the test script is always available.

[0081] That is, the above-mentioned technical scheme provided by the embodiment of the present invention comprehensively considers various factors, combines attribute recognition, coordinate recognition and image recognition, and adds an adaptive mechanism and an automatic update mechanism of element recognition to the existing automated testing method. It can ensure that the test script is always executable and can automatically select the element recognition method with the highest success rate by continuously and automatically updating the element recognition related information, thereby effectively improving the stability of the test script, and replacing the original manual search and positioning method with the adaptive mechanism and the automatic update mechanism, thereby reducing the workload of script maintenance.

[0082] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.

[0083] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods of each embodiment of the present application.

[0084] According to an embodiment of the present invention, a Web UI automated testing device for implementing the above-mentioned Web UI automated testing method is also provided. Figure 5 is a schematic diagram of a Web UI automated testing device according to an embodiment of the present invention. Figure 5 As shown, the device includes: an acquisition unit 701, an execution unit 703, a determination unit 705 and a positioning unit 707. The Web UI automatic testing device is described below.

[0085] The acquisition unit 701 is used to acquire a test script, where the test script is a script for executing a preset operation on a target interface according to an element operation method, element attribute information, and multiple element positioning methods.

[0086] The execution unit 703 is used to execute the test script and locate the elements in the target interface using the initial positioning method to obtain a positioning result. The positioning result is positioning success or positioning failure. The initial positioning method is one of multiple element positioning methods.

[0087] The determination unit 705 is used to determine the target priority of each element positioning method according to the positioning result, and determine the element positioning method with the highest target priority as the target positioning method.

[0088] The positioning unit 707 is used to position the elements in the target interface by using the target positioning method during the next execution of the test script.

[0089] It should be noted here that the above-mentioned acquisition unit 701, execution unit 703, determination unit 705 and positioning unit 707 correspond to steps S202 to S208 in the above-mentioned embodiments, and the four modules are the same as the instances and application scenarios implemented by the corresponding steps, but are not limited to the contents disclosed in the above-mentioned embodiments.

[0090] As can be seen from the above, in the scheme recorded in the above-mentioned embodiment of the present invention, first, the acquisition unit can be used to acquire the test script, and the test script is a script that performs preset operations on the target interface according to the element operation method, element attribute information and multiple element positioning methods; then the execution unit can be used to execute the test script, and the initial positioning method is used to locate the element in the target interface to obtain a positioning result, and the positioning result is a successful positioning or a failed positioning, and the initial positioning method is one of multiple element positioning methods; secondly, the determination unit can be used to determine the target priority of each element positioning method according to the positioning result, and determine the element positioning method with the highest target priority as the target positioning method; finally, the positioning unit can be used to locate the element in the target interface using the target positioning method during the next execution of the test script, thereby achieving the purpose of combining attribute recognition, coordinate recognition and image recognition, adding an adaptive mechanism and an automatic update mechanism for element recognition, so that the test script is always executable and can automatically select the element recognition method with the highest success rate, thereby realizing the technical effect of automatic analysis and selection of element positioning methods and automatic updating of element positioning information, and improving the stability and execution efficiency of the script.

[0091] The technical solution provided by the embodiment of the present invention solves the technical problems that the existing UI automation testing method cannot automatically determine the positioning mode of elements and has low execution efficiency and poor stability.

[0092] In an optional embodiment, the execution unit includes: a first acquisition subunit, used to acquire multiple element positioning methods, the element positioning methods including: ID positioning, name positioning, path positioning, position coordinate positioning and image information positioning; a second acquisition subunit, used to acquire the initial priority of each element positioning method; a first determination subunit, used to determine the element positioning method with the highest initial priority as the initial positioning method; a positioning subunit, used to use the initial positioning method to locate the elements in the target interface to obtain a positioning result.

[0093] In an optional embodiment, the determination unit includes: a third acquisition subunit, used to acquire initial execution information of the initial positioning method, the initial execution information including the initial execution times, initial execution success times and initial execution success rate of the initial positioning method; a second determination subunit, used to determine the sum of the initial execution times and 1 as the update execution times; a third determination subunit, used to determine the sum of the initial execution success times and 1 as the update execution success times when the positioning result is a successful positioning, and determine the initial execution success times as the update execution success times when the positioning result is a failed positioning; a fourth determination subunit, used to determine the ratio of the update execution success times to the update execution times as the update execution success rate; and a fifth determination subunit, used to determine the target priority of each element positioning method according to the update execution success rate.

[0094] In an optional embodiment, the fifth determination sub-unit includes: a first sorting sub-unit, used to sort the update execution success rate of the initial positioning method and the execution success rate of the non-initial positioning method from large to small to obtain an execution success rate order; a second sorting sub-unit, used to use the execution success rate order as the priority order of the element positioning method, and prioritize each element positioning method to obtain a target priority of each element positioning method.

[0095] In an optional embodiment, the Web UI automated test further includes: a second determination unit, for determining, based on the positioning result, the target priority of each element positioning method, and when the positioning result is successful and the target priority of the initial positioning method is not the highest priority, whether the initial positioning method is a preset positioning method, the preset positioning method being one of the following: id positioning, name positioning, path positioning; a second acquisition unit, for acquiring, when the initial positioning method is the preset positioning method, updated attribute information of the element, the updated attribute information including at least one of the following: the element's updated id, updated name, updated path, updated position coordinates, and updated image information.

[0096] In an optional embodiment, the Web UI automated test also includes: a second positioning unit, which is used to position the elements in the target interface by using the initial positioning method, and after obtaining the positioning result, if the positioning result is a positioning failure, use an element positioning method with a priority level lower than the initial positioning method to reposition the elements in the target interface until the element is successfully positioned.

[0097] In an optional embodiment, the acquisition unit includes: a fourth acquisition sub-unit, used to acquire user actual operation information, the user actual operation information is information generated when the user performs real operations on the target interface; a sixth determination sub-unit, used to determine the basic element information of each element on the target interface based on the user actual operation information, the basic element information includes the element's id, name, path, position coordinates on the target interface and image information on the target interface; a generation sub-unit, used to generate a test script based on the basic element information of each element on the target interface.

[0098] According to another aspect of an embodiment of the present invention, an electronic device is also provided, comprising: one or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by the one or more processors, and the one or more programs include a Web UI automated testing method for executing any of the above items.

[0099] According to another aspect of an embodiment of the present invention, a processor is further provided, and the processor is used to run a program, wherein when the program is run, any one of the above-mentioned Web UI automated testing methods is executed.

[0100] According to another aspect of an embodiment of the present invention, a computer program product is further provided, including computer instructions, and when the computer instructions are executed by a processor, any one of the above-mentioned Web UI automated testing methods is executed.

[0101] According to another aspect of an embodiment of the present invention, a computer-readable storage medium is provided, the computer-readable storage medium including a stored program, wherein when the program is running, the device where the computer-readable storage medium is located is controlled to execute any one of the above-mentioned Web UI automated testing methods.

[0102] Optionally, in this embodiment, the computer-readable storage medium may be located in any one of the computer terminals in a computer terminal group in a computer network, or in any one of the communication devices in a communication device group.

[0103] Optionally, in this embodiment, a computer-readable storage medium is configured to store program code for executing the following steps: obtaining a test script, the test script being a script for performing preset operations on a target interface determined based on an element operation method, element attribute information, and a plurality of element positioning methods; executing the test script, and using an initial positioning method to locate the element in the target interface to obtain a positioning result, the positioning result being a successful positioning or a failed positioning, and the initial positioning method being one of a plurality of element positioning methods; determining a target priority of each element positioning method based on the positioning result, and determining the element positioning method with the highest target priority as the target positioning method; during the next execution of the test script, using the target positioning method to locate the element in the target interface.

[0104] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for executing the following steps: obtaining multiple element positioning methods, the element positioning methods including: ID positioning, name positioning, path positioning, position coordinate positioning and image information positioning; obtaining the initial priority of each element positioning method; determining the element positioning method with the highest initial priority as the initial positioning method; using the initial positioning method to position the elements in the target interface to obtain a positioning result.

[0105] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for executing the following steps: obtaining initial execution information of the initial positioning method, the initial execution information including the initial execution times, the initial execution success times and the initial execution success rate of the initial positioning method; determining the sum of the initial execution times and 1 as the update execution times; when the positioning result is a successful positioning, determining the sum of the initial execution success times and 1 as the update execution success times; when the positioning result is a failed positioning, determining the initial execution success times as the update execution success times; determining the ratio of the update execution success times to the update execution times as the update execution success rate; and determining the target priority of each element positioning method according to the update execution success rate.

[0106] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for executing the following steps: obtaining an execution success rate order according to the update execution success rate of the initial positioning method and the execution success rate of the non-initial positioning method; using the execution success rate order as the priority order of the element positioning method, and prioritizing each element positioning method to obtain a target priority of each element positioning method.

[0107] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for executing the following steps: when the positioning result is successful positioning and the target priority of the initial positioning method is not the highest priority, determining whether the initial positioning method is a preset positioning method, the preset positioning method is one of the following: id positioning, name positioning, path positioning; when the initial positioning method is the preset positioning method, obtaining the updated attribute information of the element, the updated attribute information includes at least one of the following: the element's updated id, updated name, updated path, updated location coordinates, and updated image information.

[0108] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for executing the following steps: when the positioning result is positioning failure, repositioning the elements in the target interface using an element positioning method with a priority level lower than the initial positioning method until the element is successfully positioned.

[0109] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for executing the following steps: obtaining user actual operation information, the user actual operation information being information generated when the user performs real operations on the target interface; determining basic element information of each element on the target interface based on the user actual operation information, the basic element information including the element's id, name, path, position coordinates on the target interface, and image information on the target interface; generating a test script based on the basic element information of each element on the target interface.

[0110] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.

[0111] In the above embodiments of the present invention, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0112] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units can be a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.

[0113] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.

[0114] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0115] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk and other media that can store program codes.

[0116] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.

Claims

1. A Web UI automated testing method, characterized in that: include: Obtaining a test script, wherein the test script is a script for executing a preset operation on a target interface determined according to an element operation method, element attribute information, and multiple element positioning methods; Execute the test script, and use the initial positioning method to locate the element in the target interface to obtain a positioning result, wherein the positioning result is positioning success or positioning failure, and the initial positioning method is one of the multiple element positioning methods; Determine the target priority of each element positioning method according to the positioning result, and determine the element positioning method with the highest target priority as the target positioning method; During the next execution of the test script, the element in the target interface is positioned using the target positioning method.

2. The method according to claim 1, characterized in that: The elements in the target interface are positioned using an initial positioning method to obtain positioning results, including: Acquire multiple element positioning methods, wherein the element positioning methods include: id positioning, name positioning, path positioning, position coordinate positioning and image information positioning; Obtaining the initial priority of each element positioning method; Determine the element positioning mode with the highest initial priority as the initial positioning mode; The elements in the target interface are positioned using the initial positioning method to obtain a positioning result.

3. The method according to claim 1, characterized in that Determining the target priority of each element positioning method according to the positioning result includes: Acquire initial execution information of the initial positioning method, wherein the initial execution information includes the initial execution times, the initial execution success times and the initial execution success rate of the initial positioning method; The sum of the initial execution times and 1 is determined as the update execution times; When the positioning result is a successful positioning, the sum of the initial execution success number and 1 is determined as the update execution success number; when the positioning result is a failed positioning, the initial execution success number is determined as the update execution success number; Determine the ratio of the number of update execution successes to the number of update executions as the update execution success rate; According to the update execution success rate, the target priority of each element positioning method is determined.

4. The method according to claim 3, characterized in that: Determining the target priority of each element positioning method according to the update execution success rate includes: According to sorting the update execution success rate of the initial positioning method and the execution success rate of the non-initial positioning method from large to small, an execution success rate sequence is obtained; The execution success rate sequence is used as the priority sequence of the element positioning method, and the priority of each element positioning method is sorted to obtain the target priority of each element positioning method.

5. The method according to claim 1, characterized in that After determining the target priority of each element positioning method according to the positioning result, the method further includes: When the positioning result is successful positioning and the target priority of the initial positioning method is not the highest priority, determining whether the initial positioning method is a preset positioning method, and the preset positioning method is one of the following: ID positioning, name positioning, and path positioning; In case that the initial positioning mode is the preset positioning mode, update attribute information of the element is obtained, and the update attribute information includes at least one of the following: update ID, update name, update path, update position coordinates and update image information of the element.

6. The method according to claim 1, characterized in that After the element in the target interface is positioned in an initial positioning manner and a positioning result is obtained, the method further includes: When the positioning result is positioning failure, the element in the target interface is repositioned using the element positioning method with a priority level lower than that of the initial positioning method until the element is positioned successfully.

7. The method according to any one of claims 1 to 6, characterized in that: Get the test script, including: Acquire user actual operation information, where the user actual operation information is information generated when the user performs a real operation on the target interface; Determine basic element information of each element on the target interface according to the actual operation information of the user, wherein the basic element information includes the element's ID, name, path, position coordinates on the target interface, and image information on the target interface; The test script is generated according to the basic element information of each element on the target interface.

8. A Web UI automated testing device, characterized in that: include: An acquisition unit, used to acquire a test script, wherein the test script is a script for executing a preset operation on a target interface determined according to an element operation method, element attribute information, and a plurality of element positioning modes; An execution unit, used for executing the test script, and locating the element in the target interface by using an initial positioning method to obtain a positioning result, wherein the positioning result is positioning success or positioning failure, and the initial positioning method is one of the multiple element positioning methods; A determination unit, configured to determine a target priority of each of the element positioning methods according to the positioning result, and determine the element positioning method with the highest target priority as the target positioning method; A positioning unit is used to position the element in the target interface using the target positioning method during the next execution of the test script.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored program, wherein when the program is executed, the device where the computer-readable storage medium is located is controlled to execute the Web UI automated testing method according to any one of claims 1 to 7.

10. An electronic device, characterized in that: include: One or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by the one or more processors, and the one or more programs include a method for executing the Web UI automated testing method described in any one of claims 1 to 7.

Citation Information

Cited By

  • UI automatic test system and method based on database input parameters

    CN121979804A