Method, system and equipment for repairing element path of front-end page and storage medium
By recording and using multiple candidate paths in the front-end page to locate and repair page elements in automated test cases, the problem of test path failure due to page elements changes is solved, automatic repair is achieved, and manual workload is reduced.
Patent Information
- Application Number
- CN202311378590.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-23
- Publication Date
- 2025-05-06
AI Technical Summary
In the automated test cases of front-end pages, the location and attribute information of page elements often change, resulting in the failure of the test path. The existing technology cannot be automatically repaired and requires manual inspection and modification, which increases the workload of testers.
It provides a method for repairing element paths of front-end pages, recording multiple candidate paths by receiving page operation events, positioning page elements, and repositioning through candidate paths when positioning fails.
Automatic repair of test paths is realized, reducing manual workload, and improving the efficiency and reliability of automated testing.
Smart Images

Figure CN119938497A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of automated testing technology, and in particular to a method, system, device and storage medium for repairing an element path of a front-end page. Background Art
[0002] In the automated test cases of the front-end pages, the test paths used to locate the page elements are usually constructed based on the element attribute information such as the position and color of the page elements in the front-end pages. However, during the development process, the iteration and update of the front-end pages are relatively fast, and the element attribute information such as the position and color of the page elements in the front-end pages is also in a state of frequent changes, which leads to frequent test path failure problems in automated test cases.
[0003] At present, it is not possible to automatically repair the test paths of various page elements in automated test cases, and they can only be checked and modified manually, which undoubtedly increases the workload of testers. Summary of the invention
[0004] In view of this, the embodiments of the present disclosure provide a method for repairing the element path of a front-end page, a method for repairing the element path of a front-end page, an electronic device and a computer-readable storage medium, which can automatically repair the test path used to locate page elements in the test case and reduce manual workload.
[0005] On one hand, the present disclosure provides a method for repairing an element path of a front-end page, wherein the front-end page includes page elements, and the method includes:
[0006] For the target page element that receives the page operation event in the front-end page, recording multiple candidate paths for locating the target page element according to different positioning strategies;
[0007] Locating the target page element in the front-end page based on a test path in the test case for locating the target page element;
[0008] If locating the target page element through the test path fails, the target page element is relocated through the candidate path, and the test path is repaired based on the actual path of the relocated target page element in the front-end page.
[0009] Another aspect of the present disclosure further provides an element path repair system for a front-end page, wherein the front-end page includes page elements, and the system includes:
[0010] A recording module, for recording, for a target page element in the front-end page that receives a page operation event, a plurality of candidate paths for locating the target page element according to different positioning strategies;
[0011] A test positioning module, used to locate the target page element in the front-end page based on a test path used to locate the target page element in a test case;
[0012] The path updating module is used to relocate the target page element through the candidate path if locating the target page element through the test path fails, and repair the test path based on the actual path of the relocated target page element in the front-end page.
[0013] Another aspect of the present disclosure further provides a computer-readable storage medium, wherein the computer-readable storage medium is used to store a computer program, and when the computer program is executed by a processor, the method described above is implemented.
[0014] Another aspect of the present disclosure provides an electronic device, which includes a processor and a memory, wherein the memory is used to store a computer program, and when the computer program is executed by the processor, the method described above is implemented.
[0015] In the technical solutions of some embodiments of the present application, multiple candidate paths for locating target page elements are recorded according to different positioning strategies. In this way, in the case where the target page element fails to be located through the test path in the test case, the target page element can be relocated through the candidate path, and the test path can be repaired based on the actual path of the relocated target page element in the front-end page. Through the solution of the present application, automatic repair of the test path can be achieved, and then there is no need to manually check and modify the failed test path in the test case, reducing the manual workload. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The features and advantages of the present disclosure will be more clearly understood by referring to the accompanying drawings, which are schematic and should not be construed as limiting the present disclosure in any way. In the accompanying drawings:
[0017] Figure 1 Shows from Figure 1 The hierarchical relationship between page elements extracted from the front-end page code;
[0018] Figure 2 A schematic diagram of a process flow of an element path repair method provided by an embodiment of the present application is shown;
[0019] Figure 3 A schematic diagram of a module of an element path repair system provided by an embodiment of the present application is shown;
[0020] Figure 4 A schematic diagram of an electronic device provided by an embodiment of the present application is shown. DETAILED DESCRIPTION
[0021] In order to make the purpose, technical solutions and advantages of the embodiments of the present disclosure clearer, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are part of the embodiments of the present disclosure, not all of the embodiments. Based on the embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present disclosure.
[0022] Before explaining the solution of this application, the relevant concepts involved in this application are first explained.
[0023] The front-end page refers to the web page displayed to users for browsing or operation. The front-end page may include page elements. Page elements can be tags used to define content in the front-end page, such as title elements used to define titles, table elements used to define tables, form elements used to define input boxes, radio buttons, check boxes, buttons, etc. For example, the following provides a schematic code of a front-end page:
[0024]
[0025]
[0026] In the above code, nodes such as html, head, meta, title, p, div, etc. can be page elements.
[0027] In the same front-end page, page elements can have a hierarchical relationship. For example, see Figure 1 , for Figure 1 The hierarchical relationship between page elements extracted from the front-end page code. Figure 1 The structure diagram shown is also called the Dom tree, which represents the hierarchical relationship between page elements. From bottom to top, the page elements at the bottom can have parent nodes. For example, in the above code, the first parent node of the page element span is the page element p, and the second parent node of the page element span is the page element body.
[0028] Each page element can also include one or more element attributes. Element attributes include but are not limited to the data element attribute for customizing data, the id element attribute for defining the page element ID, the class element attribute for defining the page element class name, the tag element attribute for labeling the page element, and the text element attribute for defining the content displayed by the page element. Figure 1In the page meta element, the element attribute charset is used to define the character encoding.
[0029] Each element attribute may include two parts: the attribute name and the attribute value. For example, for the element attribute class, it can be expressed as class=xx, where class is the attribute name and xx is the attribute value. For any element attribute A, if the attribute value of element attribute A is the same in different page elements, it can be said that these different page elements have the same element attribute A; if the attribute value of element attribute A is different in different page elements, it can be said that these different page elements have different element attributes A. For example, assuming that in page element 1, its element attribute class=xx1, and in page element 2, its element attribute class=xx2, then it can be said that page element 1 and page element 2 have different class attributes. For another example, assuming that in page element 1, its element attribute class=xx1, and in page element 2, its element attribute class=xx1, then it can be said that page element 1 and page element 2 have the same class attribute. In the subsequent description of this application, if the element attribute A of a page element is different from the element attribute A of other page elements in the front-end page, it is considered that the element attribute A of the page element is unique in the front-end page.
[0030] In addition, among the page elements of the front-end page, some page elements can be used to receive page operation events that occur in the front-end page. Page operation events include but are not limited to page jumps, clicks, stays, inputs, file uploads, etc. For example, when using form elements to define buttons, form elements can be used to receive click operation events that occur in the front-end page. For another example, when using form elements to define input boxes, form elements can be used to receive input operation events that occur in the front-end page. These page elements used to receive page operation events are also page elements that may be used in automated test cases for front-end pages.
[0031] Based on the above description, this application provides a method for repairing the element path of a front-end page, which can automatically repair the test path used to locate the page elements in the test case, reducing the manual workload. The element path repair method can be applied to electronic devices. Electronic devices include but are not limited to tablet computers, laptops, desktop computers, servers, etc. Please refer to Figure 2 , which is a flow chart of an element path repair method provided in one embodiment of the present application. Figure 2 In the method, the element path repair method includes the following steps:
[0032] Step S31 , for a target page element that receives a page operation event in a front-end page, multiple candidate paths for locating the target page element are recorded according to different positioning strategies.
[0033] Specifically, you can pre-select multiple element attributes, and then combine the selected element attributes in different ways to obtain a positioning strategy. A positioning strategy can represent one or more element attributes. Different positioning strategies represent different element attributes. For example, based on the pre-selected element attributes data, ID, class, and tag, you can combine the following 15 positioning strategies:
[0034] Includes 4 positioning strategies for an element attribute: data, ID, class, tag
[0035] Includes 6 positioning strategies for two element attributes: data+ID, data+class, data+tag, ID+class, ID+tag, class+tag
[0036] Includes 4 positioning strategies for three element attributes: data+ID+class, data+ID+tag, data+class+tag, ID+class+tag
[0037] A positioning strategy including four element attributes: data+ID+class+tag
[0038] For any target location strategy, it is possible to determine whether the target page element has a unique target element attribute in the front-end page according to the target element attribute represented by the target location strategy. If so, the unique target element attribute is recorded as a candidate path recorded according to the target location strategy.
[0039] Specifically, for any target element attribute B, if the target element attribute B of the target page element is different from the target element attribute B of other page elements in the front-end page, it can be determined that the target element attribute B of the target page element is unique in the front-end page. For example, assuming that the target positioning strategy is data+ID (i.e., the target element attributes are data and ID), the target element attribute data of the target page element is data=dd1, and the target element attribute ID of the target page element is ID1. If in the front-end page, the target element attribute data of other page elements is not equal to dd1, and there are other page elements whose target element attribute ID is equal to ID1, then it can be considered that the target element attribute data of the target page element is unique in the front-end page, and the target element attribute ID of the target page element is not unique in the front-end page. In this case, the target element attribute data=dd1 of the target page element can be recorded as a candidate path recorded based on the target positioning strategy for locating the target page element.
[0040] It is understandable that, since the recorded target element attributes are unique in the front-end page, the target page element can be uniquely located in the front-end page according to the recorded target element attributes. For example, if the target element attribute data=dd1 of the target page element is unique, after recording data=dd1, the target page element can be uniquely located based on data=dd1.
[0041] Furthermore, if the target page element does not have a unique target element attribute in the front-end page, a unique first target element attribute combination can be found and recorded between the target page element and the parent node of the target page element as a candidate path recorded according to the target positioning strategy. Specifically, the unique first target element attribute combination can be found according to the following steps:
[0042] 1) Combining the target page element and the target element attribute of the first parent node of the target page element to obtain a first target element attribute combination. Each first target element attribute combination obtained here may include one of the target element attributes of the target page element and one of the target element attributes of the first parent node of the target page element.
[0043] If a first target element attribute combination that is unique in the front-end page is found among the obtained first target element attribute combinations, the first target element attribute combination is recorded; if a first target element attribute combination that is unique in the front-end page is not found, step 2) is executed.
[0044] 2) Combining the target element attributes of the target page element, the first parent node of the target page element, and the second parent node of the target page element to obtain a new first target element attribute combination. Each new first target element attribute combination may include one of the target element attributes of the target page element, one of the target element attributes of the first parent node of the target page element, and one of the target element attributes of the second parent node of the target page element.
[0045] If a first target element attribute combination that is unique in the front-end page is found in the new first target element attribute combination, the unique target element attribute combination is recorded; if a first target element attribute combination that is unique in the front-end page is not found in the new first target element attribute combination, continue to execute step 3).
[0046] 3) Combine the target element attributes of the target page element, the first parent node of the target page element, the second parent node of the target page element, and the third parent node of the target page element to continue searching for a unique first target element attribute combination.
[0047] This process is repeated in turn until a unique first target element attribute combination is found.
[0048] For ease of understanding, an example is given to illustrate how to find a unique first target element attribute combination. For example, assuming the target positioning strategy is data+ID (i.e., the target element attributes are data and ID), the first parent node of the target page element A is page element B, the second parent node of the target page element is page element C, and the target element attributes of the target page elements A, B, and C are:
[0049] Target page element A: data = dd1, ID = ID1;
[0050] Page element B: data = dd2, ID = ID2;
[0051] Page element C: data=dd3, ID=ID3.
[0052] Assume that data=dd1 and ID=ID1 are not unique in the front-end page. Then, the target element attributes of the target page element A and the page element B can be combined to obtain the following first target element attribute combination:
[0053] data=dd1>data=dd2
[0054] data=dd1>ID=ID2
[0055] ID=ID1>data=dd2
[0056] ID=ID1>ID=ID2
[0057] If there is no unique first target element attribute combination among the above first target element attribute combinations, the target element attributes of target page element A, page element B, and page element C are combined to obtain the following new first target element attribute combination:
[0058] data=dd1>data=dd2>data=dd3
[0059] data=dd1>data=dd2>ID=ID3
[0060] data=dd1>ID=ID2>data=dd3
[0061] …
[0062] Assuming that in the above-mentioned new first target element combination, data=dd1>data=dd2>ID=ID3 is unique, data=dd1>data=dd2>ID=ID3 can be recorded as a candidate path for locating the target page element recorded according to the target positioning strategy.
[0063] According to the above principle, according to each positioning strategy, a candidate path for positioning the target page element can be recorded respectively, so that multiple candidate paths are obtained.
[0064] Specifically, in this embodiment, when recording a candidate path, a finder function can be called, and the target element attributes represented by the target positioning strategy are used as input parameters of the finder function. The finder function searches for a unique target element attribute of the target page element, or searches for a unique first target element attribute combination in the target page element and the parent node of the target page element, and returns the found result.
[0065] It should be noted that the candidate path of each target page element may only need to be recorded once. Specifically, the candidate path can generally be recorded for the corresponding target page element when the target page element receives a page operation event for the first time. After recording a candidate path for a target page element, if the target page element subsequently receives a page operation event, there is no need to record a candidate path for the target page element. In other words, when the target page element receives a page operation event, it can first be determined whether a candidate path has been recorded for the target page element. If not, record the candidate path. If so, there is no need to record it again.
[0066] Step S32: locating the target page element in the front-end page based on the test path used to locate the target page element in the test case.
[0067] In this embodiment, the test path may be one of the candidate paths mentioned above. In some other embodiments, the test path may also be generated according to a path generation logic different from that in step S22.
[0068] Based on step S31, after obtaining the candidate path for locating the target page element, a test record can be established for the target page element, and the test record can include the page operation event received by the target page element, the test path of the target page element, and all the candidate paths. For ease of understanding, Table 1 exemplarily gives a list of test records for two of the target page elements.
[0069] Table 1 Test Record
[0070]
[0071] It is understandable that after the test record list is established, under normal circumstances, based on the test path in the test record list, the corresponding target page element can be found, and then the corresponding page operation event can be executed on the found target page element, so that the front-end page can be tested (for example, whether the interface displayed by the target page element after receiving the page operation event is correct). Therefore, one of the records in the test record can be regarded as a test case, that is, in this application, the test case can be automatically generated when the page element receives the page operation event for the first time.
[0072] Specifically, when the front-end page is first developed, the page operation event can be arbitrarily executed in the front-end page by Monkey testing, and through step S31, a candidate path and a corresponding test record are generated for the target page element that receives the page operation event, and a test record list as shown in Table 1 is obtained. During the iterative development of the front-end page, the front-end page in the iterative development process can be tested based on the established test record list. Of course, if a page element for receiving page operation events is added to the front-end page during the iterative development process, the newly added page element can be manually selected to generate a candidate path and a test record for the newly added page element, or the newly added page element can be explored by intelligent exploration during the iterative test process, and a candidate path and a test record are generated for the newly added page element, so that the newly added page element can be tested in the subsequent iterative development process.
[0073] Since the position, color and other element attributes of page elements may change during the iterative development of the front-end page, the test path in the test case (i.e., the test record list) may become invalid. For example, in the front-end page, assume that the test path of target page element A is determined by the hierarchical relationship between page elements, and in the test path of target page element A, target page element A is specified as the 5th subordinate node of page element B. However, during the iterative development of the front-end page, the 5th subordinate node and the 3rd subordinate node of page element B are swapped. In this case, the test path of target page element A will become invalid, and target page element A cannot be located based on the test path of target page element A.
[0074] In this embodiment, if the page operation event corresponding to the target page element can be executed on the page element located based on the test path, it means that the target page element is successfully located; if the page operation event corresponding to the target page element cannot be executed on the page element located based on the test path, it means that the target page element has failed to be located. For example, in Table 1, test path 1 based on target page element A locates page element B, and page element B may be target page element A or may not be target page element A. At this time, if a click operation can be performed on page element B, it can be said that page element B is the target page element A, that is, the target page element A is successfully located; if a click operation cannot be performed on page element B, it can be said that page element B is not the target page element A, that is, the target page element A has failed to be located.
[0075] It should be noted that during the iterative development of the front-end page, the target page elements used to receive the same page operation event may be interchanged. In this case, even if the located target page element is incorrect, it can still be considered that the positioning of the target page element is successful. For example, after the target page element A that receives the click operation event and the target page element B that receives the click operation event are interchanged, the page element actually located based on the test path of the target page element A may be the target page element B, but the click operation can still be performed on the target page element B, then it can be considered that the positioning of the target page element A is successful, that is, the located page element is considered to be the target page element A. However, whether the located target page element is correct can be determined through subsequent tests (such as testing whether the interface displayed by the target page element A after receiving the page operation event is correct).
[0076] Step S33: if locating the target page element through the test path fails, relocating the target page element through the candidate path, and repairing the test path based on the actual path of the relocated target page element in the front-end page.
[0077] It is understandable that, since the candidate paths are recorded according to different positioning strategies, and different positioning strategies represent different element attributes, there can be at least some candidate paths that have not been invalidated during the iterative development of the front-end page. For example, assuming that the test path of the target page element is determined based on the element attributes class+tag, when the element attributes class and tag change, the test path and the candidate paths recorded based on the element attributes class and tag will become invalid. However, among the candidate paths, there may also be candidate paths determined based on the element attributes data and ID, so the candidate paths determined based on the element attributes data and ID can be relocated to the target page element.
[0078] After relocating to the target page element, the test path in the test case can be repaired according to the actual test path of the target page element in the front-end page, and the invalid candidate path can be repaired according to the actual candidate path of the target page element in the front-end page. When repairing the invalid candidate path of the target page element, step S32 can be re-executed to redetermine the candidate path based on the current actual element attributes of the target page element. At the same time, the test path can also be regenerated according to the path generation logic of the test path based on the current actual element attributes of the target page element.
[0079] In summary, in the technical solutions of some embodiments of the present application, multiple candidate paths for locating target page elements are recorded according to different positioning strategies. In this way, in the case where the target page element fails to be located through the test path in the test case, the target page element can be relocated through the candidate path, and the test path can be repaired based on the actual path of the relocated target page element in the front-end page. Through the solution of the present application, automatic repair of the test path can be achieved, and then there is no need to manually check and modify the failed test path in the test case, reducing the manual workload.
[0080] The solution of this application is further described below.
[0081] In some embodiments, in order to ensure that all candidate paths are not invalid, when recording candidate paths, pre-selected element attributes may be combined in all possible combinations, and after obtaining a large number of positioning strategies, a candidate path is recorded based on each positioning strategy. For example, in step S31, after combining the element attributes data, ID, class, and tag in all possible combinations, the following 15 positioning strategies are obtained: data, ID, class, tag, data+ID, data+class, data+tag, ID+class, ID+tag, class+tag, data+ID+class, data+ID+tag, data+class+tag, ID+class+tag, data+ID+class+tag. Then, a candidate path is recorded based on each positioning strategy, and a total of 15 candidate paths can be obtained.
[0082] This method obtains more candidate paths. On the one hand, the storage space consumed to save these candidate paths will be larger. On the other hand, when relocating the target page element, it is necessary to locate the target page element based on each candidate path separately, which takes a long time.
[0083] In view of this, the positioning strategy can be screened to reduce the number of candidate paths while ensuring that all candidate paths will not become invalid. Specifically, in some embodiments, priorities can be set for element attributes, and the priorities represent the probability that the element attributes are unique. The higher the priority of the element attribute, the greater the probability that it is unique in the front-end page. For example, the priority order of the element attributes data, ID, class, and tag can be expressed as: data>ID>class>tag. That is, the priority of the element attribute data is higher than the element attribute ID, the priority of the element attribute ID is higher than the element attribute class, and the priority of the element attribute class is higher than the element attribute tag.
[0084] Based on the priority of the element attribute, the recording of the unique target element attribute in step S32 may include:
[0085] When there are multiple unique target element attributes for the target page element, the target element attribute with the highest priority is recorded.
[0086] Furthermore, when the target page element does not have a unique target element attribute, searching and recording a unique first target element attribute combination from the target page element and the parent node of the target page element in step S32 may include:
[0087] The target element attribute with the highest priority of the target page element is recorded, and each target element attribute of the upper node is respectively combined with the target element attribute with the highest priority to find the first target element attribute combination.
[0088] In this way, among the positioning strategies obtained by combining all possible combinations, there may be equivalent positioning strategies. For example, assuming that the priority order of element attributes data, ID, class, and tag is: data>ID>class>tag, in the positioning strategies data, data+ID, data+class, data+tag, data+ID+class, data+ID+tag, data+class+tag, and data+ID+class+tag, if the element attribute data is unique, then when recording candidate paths based on these positioning strategies, the element attribute data is recorded, that is, these positioning strategies are equivalent. Similarly, in the positioning strategies ID, ID+class, ID+tag, and ID+class+tag, if the element attribute ID is unique, then when recording candidate paths based on these positioning strategies, the element attribute ID is recorded, that is, these positioning strategies are also equivalent.
[0089] In summary, for different positioning strategies, if these positioning strategies have the same element attributes with the highest priority, these positioning strategies can be replaced by one positioning strategy. Among them, the positioning strategy used for replacement can be used to represent all element attributes represented by these positioning strategies. For example, assume that the priority order of element attributes data, ID, class, and tag is: data>ID>class>tag.
[0090] Among the positioning strategies data, data+ID, data+class, data+tag, data+ID+class, data+ID+tag, data+class+tag, and data+ID+class+tag, these positioning strategies have the same element attribute with the highest priority (all data), so one positioning strategy can be used to replace these positioning strategies. And because the element attributes represented by these positioning strategies include data, ID, class, and tag, the positioning strategy data+ID+class+tag can be used to replace all the above positioning strategies.
[0091] Similarly, you can use positioning strategy ID+class+tag to replace positioning strategy ID, ID+class, ID+tag, ID+class+tag, and use positioning strategy class+tag to replace positioning strategy class, class+tag.
[0092] After the location strategy is replaced, the 15 location strategies based on the element attributes data, ID, class, and tag can be reduced to 4, namely: tag, class+tag, ID+class+tag, and data+ID+class+tag. That is, it is only necessary to record candidate paths based on the location strategies tag, class+tag, ID+class+tag, and data+ID+class+tag. In this way, the candidate paths are reduced, and the storage resources used to save the candidate paths are reduced, and the time for relocating the target page elements is reduced.
[0093] In this embodiment, when recording a candidate path, a finder function may be called, and the target element attribute represented by the target positioning strategy may be used as an input parameter of the finder function. The finder function searches for a unique target element attribute of the target page element according to the priority between the target element attributes, or searches for a unique first target element attribute combination in the target page element and the parent node of the target page element, and returns the found result. For example, assume that the priority order of the element attributes data, ID, class, and tag is: data>ID>class>tag. After sending the target page attributes ID, class, and tag represented by the target positioning function to the finder function, the finder function first determines whether the element attribute ID of the target page element is unique. If so, the element attribute ID is directly returned without determining whether the element attributes class and tag are unique. Furthermore, if the page attribute ID, class, and tag of the target page element are not unique, first combine the target element attribute ID of the target page element's parent node with the target element with the highest priority (i.e., data) of the target page element, and determine whether the combination is unique. If so, return the found combination; if not, combine the target element attribute class of the target page element's parent node with the element attribute data of the target page element, and determine whether the combination is unique. And so on.
[0094] Furthermore, in different websites, there may be situations where the attribute values of target element attributes are dynamically generated. It is understandable that target element attributes whose attribute values are dynamically generated cannot be used to record candidate paths. For example, when recording a candidate path, the recorded target element attribute x=xx1, but when the target page element is relocated based on the candidate path, the attribute value of the target element attribute x becomes yy1, then the target element attribute cannot be successfully located based on the recorded candidate path. In other words, the candidate path recorded based on the target element attribute whose attribute value is dynamically generated may be an invalid candidate path.
[0095] In view of this, when recording candidate paths based on the target positioning strategy, the element path repair method of the present application also includes:
[0096] If the target element attributes include a first target element attribute whose attribute value is dynamically generated, remove the first target element attribute from the target element attributes;
[0097] The candidate paths are recorded based on the target element attributes after the first target element attributes are removed.
[0098] Specifically, before calling the finder function, it can be pre-determined whether the target element attribute represented by the target positioning strategy includes the first target element attribute whose attribute value is dynamically generated. If it is included, the first target element attribute is eliminated, and the target element attribute after eliminating the first target element attribute is used as the input parameter of the finder function. The finder function searches the target element attribute after eliminating the first target element attribute to find whether the target page element has a unique target element attribute, or searches the target page element and the parent node of the target page element for a unique combination of first target element attributes. In this way, invalid candidate paths are avoided from being generated based on the first target element attribute that is dynamically generated based on the attribute value.
[0099] For example, taking the element attributes data, ID, class, and tag as an example, we can know from the above description that based on the element attributes data, ID, class, and tag, we can get four positioning strategies, which are:
[0100] tag, class+tag, ID+class+tag, data+ID+class+tag
[0101] Usually, the attribute values of element attributes tag and data are not generated dynamically, so:
[0102] When the attribute value of the element attribute ID is dynamically generated, the element attribute ID is removed from the above four positioning strategies, and the positioning strategies become: tag, class+tag, data+class+tag
[0103] When the attribute value of the element attribute class is dynamically generated, remove the element attribute class from the above four positioning strategies, and the positioning strategies become: tag, ID+tag, data+ID+tag
[0104] And so on.
[0105] Furthermore, in some embodiments, the target element attribute may also include a second target element attribute whose attribute value needs to be input through a human-computer interaction interface. When recording a candidate path based on a target positioning strategy, the element path repair method of the present application also includes:
[0106] If the target element attributes include a second target element attribute whose attribute value needs to be input through the human-computer interaction interface, when the attribute value of the second target element attribute is not received, candidate paths are recorded based on target element attributes other than the second target element attribute; when the second target element attribute is received, candidate paths are recorded based on all target element attributes including the second target element attribute.
[0107] This is understandable. When the attribute value of the second target element attribute does not exist, positioning cannot be performed based on the second target element attribute, so the second target element attribute needs to be eliminated.
[0108] Still taking the element attributes data, ID, class, and tag as an example, assume that the attribute value of the element attribute data needs to be input through the human-computer interaction interface. On this basis:
[0109] If the attribute values of the above four element attributes are not dynamically generated, and the attribute value of the element attribute data is received, then based on the element attributes data, ID, class, and tag, the following four positioning strategies can be obtained: tag, class+tag, ID+class+tag, data+ID+class+tag
[0110] If the attribute values of the above four element attributes are not dynamically generated, and the attribute value of the element attribute data is not received, then based on the element attributes data, ID, class, and tag, the following four positioning strategies can be obtained: tag, class+tag, ID+class+tag, ID+class+tag
[0111] If, among the above four element attributes, the element attribute ID is dynamically generated and the attribute value of the element attribute data is received, then based on the element attributes data, ID, class, and tag, the following three positioning strategies can be obtained: tag, class+tag, data+class+tag
[0112] If, among the above four element attributes, the element attribute ID is dynamically generated and the attribute value of the element attribute data is not received, then based on the element attributes data, ID, class, and tag, the following three positioning strategies can be obtained: tag, class+tag, ID+class+tag
[0113] If, among the above four element attributes, the element attribute class is dynamically generated and the attribute value of the element attribute data is received, then based on the element attributes data, ID, class, and tag, the following three positioning strategies can be obtained: tag, ID+tag, data+ID+tag
[0114] If, among the above four element attributes, the element attribute class is dynamically generated and the attribute value of the element attribute data is not received, then based on the element attributes data, ID, class, and tag, the following three positioning strategies can be obtained: tag, ID+tag, ID+tag
[0115] In this way, recording of invalid candidate paths can be prevented.
[0116] Furthermore, when searching for a target page element with a unique target element attribute, considering that some low-priority target element attributes have a low probability of being unique, it is not necessary to perform a judgment operation on these low-priority target elements to reduce the amount of data processing.
[0117] Specifically, in some embodiments, when determining whether a target page element has a unique target element attribute in the front-end page, if the target element attribute includes a third target element attribute whose priority is higher than the priority threshold, determine whether the target page element has a unique third target element attribute; if the target element attribute includes a fourth target element attribute whose priority is not higher than the priority threshold, then between the kth parent node of the target page element and the target page element, combine the fourth target element attribute of the target page element with the target element attribute of the parent node, and determine whether there is a unique second target element attribute combination; if so, record the second target element attribute combination as a candidate path recorded according to the target positioning strategy.
[0118] In simple terms, for the third target element attribute whose priority is higher than the priority threshold, the third target element attribute is judged to be unique starting from the target page element. For the fourth target element attribute whose priority is not higher than the priority threshold, the second target element attribute combination is judged to be unique between the target page element and the kth parent node of the target page element. The second target element attribute combination includes one of the fourth target element attributes of the target page element and one of the target element attributes of each parent node of the target page element.
[0119] For example, assuming that the priority order of element attributes data, ID, class, and tag is: data>ID>class>tag, and the priority threshold is 2, that is, the priority of element attributes data and ID is higher than the priority threshold, and the priority of element attributes class and tag is not higher than the priority threshold. Then, when the target element attributes represented by the target positioning strategy include data, ID, and tag, you can first determine whether the target element attribute data of the target page element is unique in order of priority. If so, record the target element attribute data, and no subsequent operations are required. If not, continue to determine whether the target element attribute ID of the target page element is unique. If so, record the target element attribute ID, and no subsequent operations are required. If not, combine the target element attribute tag attribute of the target page element with the target element attribute of the parent node to determine whether there is a unique second target attribute combination. For example, assuming the value of k is 3, the target element attribute data can be obtained from the third parent node of the target page element, the target element attribute ID can be obtained from the second parent node of the target page element, and the target element attribute data can be obtained from the first parent node of the target page element. These target element attributes obtained are combined with the target element attribute tag of the target page element to obtain a second target element attribute combination, and it is determined whether the second target element attribute combination is unique. If so, the second target element attribute combination is recorded. If not, other target element attributes of the parent node of the target page element can be combined with the target element attribute tag of the target page element to continue searching for a unique second target element attribute combination.
[0120] If the target page element has neither a unique third target element attribute nor a unique second target element attribute combination, each target element attribute of the parent node is combined with the target element attribute with the highest priority of the target page element to find the first target element attribute combination. The relevant principle can be found in the description of the first target element attribute, which will not be repeated here.
[0121] In the above scheme, among the target element attributes of the target page element, it is not determined whether the target element attributes with a low priority are unique, which can reduce the amount of data processing.
[0122] Further, in some embodiments, the page elements in the front-end page may include text element attributes. The content in the text element attributes may be text for display in the front-end page. Considering that the text element attributes may include too much text content, which is not convenient for locating the page elements, the element attributes represented by the positioning strategy may not include text element attributes. However, in the case of failure to relocate the target page element through all candidate paths, the element path repair method of the present application may also include:
[0123] Repositions a target page element based on its text element properties.
[0124] In this way, the reliability of the solution of the present application can be improved.
[0125] This completes the description of the element path repair method of the present application.
[0126] Corresponding to the element path repair method, the present application also provides an element path repair system for a front-end page. Figure 3 , is a module diagram of an element path repair system provided by an embodiment of the present application. The element path repair system includes:
[0127] A recording module is used to record multiple candidate paths for locating the target page element that receives the page operation event in the front-end page according to different positioning strategies;
[0128] A test positioning module, used to locate the target page element in the front-end page based on the test path used to locate the target page element in the test case;
[0129] The path update module is used to relocate the target page element through the candidate path if the target page element fails to be located through the test path, and repair the test path based on the actual path of the relocated target page element in the front-end page.
[0130] See also Figure 4 , is a schematic diagram of an electronic device provided by an embodiment of the present application. The electronic device includes a processor and a memory, the memory is used to store a computer program, and when the computer program is executed by the processor, the above method is implemented.
[0131] The processor may be a central processing unit (CPU). The processor may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or a combination of the above chips.
[0132] As a non-transitory computer-readable storage medium, the memory can be used to store non-transitory software programs, non-transitory computer executable programs and modules, such as program instructions / modules corresponding to the method in the embodiment of the present invention. The processor executes various functional applications and data processing of the processor by running the non-transitory software programs, instructions and modules stored in the memory, that is, implementing the method in the above method embodiment.
[0133] The memory may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created by the processor, etc. In addition, the memory may include a high-speed random access memory, and may also include a non-transitory memory, such as at least one disk storage device, a flash memory device, or other non-transitory solid-state storage device. In some embodiments, the memory may optionally include a memory remotely disposed relative to the processor, and these remote memories may be connected to the processor 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 combinations thereof.
[0134] One embodiment of the present application further provides a computer-readable storage medium, which is used to store a computer program. When the computer program is executed by a processor, the above method is implemented.
[0135] Although the embodiments of the present disclosure have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present disclosure, and such modifications and variations are all within the scope defined by the appended claims.
Claims
1. A method for repairing the element path of a front-end page, characterized in that: The front-end page includes page elements, and the method includes: For the target page element that receives the page operation event in the front-end page, recording multiple candidate paths for locating the target page element according to different positioning strategies; Locating the target page element in the front-end page based on a test path in the test case for locating the target page element; If locating the target page element through the test path fails, the target page element is relocated through the candidate path, and the test path is repaired based on the actual path of the relocated target page element in the front-end page.
2. The method according to claim 1, characterized in that The page element includes a plurality of element attributes, and the positioning strategy represents one or more of the element attributes; The recording of multiple candidate paths for locating the target page element according to different positioning strategies includes: For any target positioning strategy, judging whether the target page element has a unique target element attribute in the front-end page according to the target element attribute represented by the target positioning strategy; If so, record the unique target element attribute as a candidate path recorded according to the target positioning strategy; If not, a unique first target element attribute combination is searched and recorded between the target page element and the upper-level node of the target page element as a candidate path recorded according to the target positioning strategy.
3. The method according to claim 2, characterized in that The element attribute has a priority, and the priority represents the probability that the element attribute is unique; The recording of the unique target element attribute includes: When the target page element has multiple unique target element attributes, the target element attribute with the highest priority is recorded.
4. The method according to claim 2, characterized in that The element attribute has a priority, and the priority represents the probability that the element attribute is unique; The step of searching and recording a unique first target element attribute combination between the target page element and the parent node of the target page element includes: Recording the target element attribute with the highest priority of the target page element; Each target element attribute of the upper node is combined with the target element attribute with the highest priority to find the first target element attribute combination.
5. The method according to claim 2, characterized in that The element attribute has an attribute value; when recording a candidate path based on the target positioning strategy, the method further includes: If the target element attributes include a first target element attribute whose attribute value is dynamically generated, remove the first target element attribute from the target element attributes; A candidate path is recorded based on the target element attributes after the first target element attributes are removed.
6. The method according to claim 2, characterized in that The element attribute has an attribute value; when recording a candidate path based on the target positioning strategy, the method further includes: If the target element attributes include a second target element attribute whose attribute value needs to be input through the human-computer interaction interface, when the attribute value of the second target element attribute is not received, candidate paths are recorded based on target element attributes other than the second target element attribute; when the second target element attribute is received, candidate paths are recorded based on all target element attributes including the second target element attribute.
7. The method according to claim 2, characterized in that The element attribute has a priority, and the priority represents the probability that the element attribute is unique; The step of judging whether the target page element has a unique target element attribute in the front-end page includes: If the target element attributes include a third target element attribute whose priority is higher than the priority threshold, it is determined whether the target page element has a unique third target element attribute.
8. The method according to claim 7, characterized in that If the target element attributes include a fourth target element attribute whose priority is not higher than the priority threshold, the method further includes: Between the kth parent node of the target page element and the target page element, the fourth target element attribute of the target page element is combined with the target element attribute of the parent node, and it is determined whether there is a unique second target element attribute combination. If so, the second target element attribute combination is recorded as a candidate path recorded according to the target positioning strategy.
9. The method according to claim 2, characterized in that The page element in the front-end page includes text element attributes, and the element attributes represented by the positioning strategy do not include the text element attributes; In the case where relocating the target page element through all the candidate paths fails, the method further includes: The target page element is repositioned based on the text element attribute of the target page element.
10. A front-end page element path repair system, characterized in that: The front-end page includes page elements, and the system includes: A recording module, for recording, for a target page element in the front-end page that receives a page operation event, a plurality of candidate paths for locating the target page element according to different positioning strategies; A test positioning module, used to locate the target page element in the front-end page based on a test path used to locate the target page element in a test case; The path updating module is used to relocate the target page element through the candidate path if locating the target page element through the test path fails, and repair the test path based on the actual path of the relocated target page element in the front-end page.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium is used to store a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 9 is implemented.
12. An electronic device, characterized in that: The electronic device comprises a processor and a memory, wherein the memory is used to store a computer program, and when the computer program is executed by the processor, the method according to any one of claims 1 to 9 is implemented.