Element positioning method and device for test case, computer device and medium
By splitting and comparing page element paths, the problem of inaccurate positioning caused by dynamic element path changes was solved, improving the pass rate of test cases and reducing debugging costs.
Patent Information
- Application Number
- CN202211005007.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-22
- Publication Date
- 2026-02-13
- Estimated Expiration
- 2042-08-22
AI Technical Summary
When recording automated test cases for the interface, changes in the path of dynamic elements can lead to inaccurate element positioning, increasing the maintenance cost of test scripts and requiring testers to have certain experience in automated testing or front-end knowledge.
By using preset element path generation rules, the page element path is split into a first sub-path and a second sub-path. Elements with a non-zero area are identified as suspected elements using the first sub-path. The second sub-path searches for the target element within the range of suspected elements and compares the element positions to determine the accurate target element.
It improved the pass rate of test cases, reduced the debugging costs for testers, and enabled accurate location of dynamic elements.
Smart Images

Figure CN115344494B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application is suitable for the field of automation testing technology, and particularly relates to an element positioning method and device for test cases, a computer device and a medium. BACKGROUND
[0002] Currently, when recording a User Interface (UI) automation test case, a page element that needs to be operated in a test step needs to be selected, and an "element path" is recorded. This step can be automatically generated when an automation test framework is used. The generated element path is generally an XPath absolute path, that is, it contains all levels from the root element html to the target page element, and if there are multiple elements of the same type at each level, the order of the elements at the level will be recorded. However, the level and order will change when the page function changes. Since some elements in the page are dynamically generated according to user operations, such as a selector displayed in a pop-up window, these elements are collectively referred to as "dynamic elements" hereinafter. The absolute path of the dynamic element usually has a different order at a certain level from the order when recording. If you want to avoid the impact of path changes on the success rate of test case execution, you generally need to add an ID selector in the front-end business code to achieve element positioning. However, this method has certain invasiveness to the business code and increases the debugging cost of test case recording. Another method is to use a class selector to position the dynamic element when the content is identified as a dynamic element. However, using a class selector may select multiple page elements, which ultimately leads to the inability to select the correct element during execution, and the test case needs to be re-recorded. In order to reduce the maintenance cost of test scripts, testers generally need to have certain automation testing experience or front-end knowledge to manually identify whether the element path is reliable. Therefore, how to exclude irrelevant elements and achieve accurate positioning of elements has become a problem to be solved. SUMMARY
[0003] In view of this, the embodiments of the present application provide an element positioning method and device for test cases, a computer device and a medium to solve the problem of how to exclude irrelevant elements and achieve accurate positioning of elements.
[0004] In a first aspect, the embodiments of the present application provide an element positioning method for test cases, which comprises:
[0005] According to a preset element path generation rule, a page element path is generated for the test case, and it is detected whether at least two page elements are selected when the page element path is triggered.
[0006] if it is detected that at least two page elements are selected when the page element path is triggered, the page element path is split into a first sub-path and a second sub-path, the first sub-path is triggered to select at least the page element of the outermost page among all the page elements, and the second sub-path is triggered to select all the page elements except the page elements selected by the first sub-path;
[0007] detecting the area of the page element obtained by querying using the first sub-path, determining the page element with a non-zero area as a suspected element, and obtaining the target element with a non-zero area in the page range corresponding to the suspected element using the second sub-path;
[0008] comparing the positions of all the page elements selected using the page element path in the page with the position of the target element in the page, respectively, and determining that the target element is the element positioned by the page element path if the comparison result is that there is the same position.
[0009] In an embodiment, according to a preset element path generation rule, generating a page element path for the test case includes:
[0010] detecting the element characteristics of the page elements contained in the test case;
[0011] if it is detected that the element characteristics are first characteristics, generating a page element path of the corresponding page element using an ID selector;
[0012] if it is detected that the element characteristics are second characteristics, generating a page element path of the corresponding page element using a class selector.
[0013] In an embodiment, after detecting the element characteristics of the page elements contained in the test case, further comprising:
[0014] if it is detected that the element characteristics are text node characteristics and the corresponding element content is not empty, recording the content of the corresponding page element, and generating a text selector for querying the text content according to the content of the element characteristics;
[0015] generating a page element path of the corresponding page element using the text selector.
[0016] In an embodiment, comparing the positions of all the page elements selected using the page element path in the page with the position of the target element in the page includes:
[0017] using a comparison document position class method to sequentially compare the positions of all the page elements selected by the page element path with the target element;
[0018] determine a position comparison result, the position comparison result comprising a position same, a front-back relationship and a containing relationship.
[0019] In an embodiment, the detecting an area of a page element obtained by using the first sub-path query comprises:
[0020] obtaining a length, a width or a height of the page element in a page obtained by using the first sub-path query;
[0021] detecting whether there is a zero item in the length, the width or the height, and if there is a zero item, determining that the area of the corresponding page element is zero, otherwise, determining that the corresponding page element is a suspected element.
[0022] In an embodiment, the splitting the page element path into a first sub-path and a second sub-path comprises:
[0023] extracting a level of a page in which all page elements corresponding to the page element path are located, and determining a page element of an outermost level;
[0024] cutting a path corresponding to the page element of the outermost level from the page element path as the first sub-path, and cutting paths corresponding to the remaining page elements from the page element path as the second sub-path.
[0025] In a second aspect, an element positioning device for a test case is provided, and the element positioning device comprises:
[0026] a path detection module configured to generate a page element path for the test case according to a preset element path generation rule, and detect whether at least two page elements are selected when the page element path is triggered;
[0027] a path splitting module configured to split the page element path into a first sub-path and a second sub-path if it is detected that at least two page elements are selected when the page element path is triggered, the first sub-path selects at least a page element of an outermost page when triggered, and the second sub-path selects all page elements except the page element selected when the first sub-path is triggered;
[0028] a target element determination module configured to detect an area of a page element obtained by using the first sub-path, determine a suspected element with a non-zero area, and obtain a target element with a non-zero area in a page range corresponding to the suspected element by using the second sub-path;
[0029] The positioning determination module is configured to compare the positions of all the page elements selected by the page element path in the page with the position of the target element in the page respectively, and determine that the target element is the element positioned by the page element path if the comparison result is that there is the same position.
[0030] In an embodiment, the path detection module comprises:
[0031] The element feature detection unit is configured to detect an element feature of a page element contained in the test case.
[0032] The first path generation unit is configured to generate a page element path of the corresponding page element using an ID selector if the detected element feature is a first feature.
[0033] The second path generation unit is configured to generate a page element path of the corresponding page element using a class selector if the detected element feature is a second feature.
[0034] In an embodiment, the path detection module further comprises:
[0035] The text element detection unit is configured to record the content of the corresponding page element and generate a text selector for querying the text content according to the content of the element feature if the detected element feature is a text node feature and the content of the corresponding element is not empty after detecting the element feature of the page element contained in the test case.
[0036] The third path generation unit is configured to generate a page element path of the corresponding page element using the text selector.
[0037] In an embodiment, the positioning determination module comprises:
[0038] The position comparison unit is configured to compare the positions of all the page elements selected by the page element path with the target element in sequence using a comparison document position class method.
[0039] The comparison result determination unit is configured to determine a position comparison result, and the position comparison result comprises a same position, a front-back relationship and a containing relationship.
[0040] In an embodiment, the target element determination module comprises:
[0041] The side length acquisition unit is configured to acquire the length, width or height of a page element in the page obtained by using the first sub-path query.
[0042] The suspected element determining unit is configured to detect whether there is a zero-length item, a zero-width item, or a zero-height item, and determine that the area of the corresponding page element is zero if there is a zero-length item, a zero-width item, or a zero-height item, or determine that the corresponding page element is a suspected element if there is no zero-length item, zero-width item, or zero-height item.
[0043] In an embodiment, the path splitting module comprises:
[0044] The splitting point determining unit is configured to extract the level of the page in which all page elements corresponding to the page element path are located, and determine the page element of the outermost level.
[0045] The path splitting unit is configured to extract the path corresponding to the page element of the outermost level from the page element path as a first sub-path, and extract the path corresponding to the remaining page elements from the page element path as second sub-paths.
[0046] In a third aspect, an embodiment of the present application provides a computer device, which comprises a processor, a memory, and a computer program stored in the memory and executable on the processor, and the processor implements the element positioning method according to the first aspect when executing the computer program.
[0047] In a fourth aspect, an embodiment of the present application provides a computer readable storage medium, which stores a computer program, and the computer program is executable on a processor to implement the element positioning method according to the first aspect.
[0048] Compared with the prior art, the embodiment of the present application has the beneficial effects that: according to the preset element path generation rule, the page element path is generated for the test case, it is detected whether at least two page elements are selected when the page element path is triggered, if it is detected that at least two page elements are selected when the page element path is triggered, the page element path is split into a first sub-path and a second sub-path, the first sub-path selects at least the page element of the outermost page when triggered, the second sub-path selects all page elements except the page element selected by the first sub-path when triggered, the area of the page element is detected by using the first sub-path, the page element with a non-zero area is determined as a suspected element, the page element with a non-zero area is determined as a target element by using the second sub-path in the page range corresponding to the suspected element, the positions of all page elements selected by the page element path in the page are compared with the position of the target element in the page, if the comparison result is that there is the same position, the target element is determined as the element positioned by the page element path, thereby accurately positioning the target element, improving the test case execution pass rate, and reducing the debugging cost of the test personnel. BRIEF DESCRIPTION OF DRAWINGS
[0049] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the embodiments or prior art description will be briefly introduced. Obviously, the drawings in the following description only some embodiments of the present application, and for those skilled in the art, other drawings can also be obtained without creative labor.
[0050] Figure 1 is an application environment schematic diagram of an element positioning method of a test case provided by an embodiment of the present application;
[0051] Figure 2 is a flow schematic diagram of an element positioning method of a test case provided by an embodiment of the present application;
[0052] Figure 3 is a flow schematic diagram of an element positioning method of a test case provided by an embodiment of the present application;
[0053] Figure 4 is a structure schematic diagram of an element positioning device of a test case provided by an embodiment of the present application;
[0054] Figure 5 is a structure schematic diagram of a computer device provided by an embodiment of the present application. DETAILED DESCRIPTION
[0055] In the following description, for the purpose of explanation and not limitation, specific details are set forth, such as particular system configurations, techniques, etc., in order to provide a thorough understanding of the embodiments of the present application. However, it will be apparent to those skilled in the art that the present application can be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present application with unnecessary detail.
[0056] It should be understood that, when used in the present application specification and the appended claims, the term "comprising" indicates the presence of the described features, whole, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, whole, steps, operations, elements, components and / or sets thereof.
[0057] It should also be understood that the term "and / or" used in the present application specification and the appended claims means any combination of one or more of the associated listed items and all possible combinations, and includes these combinations.
[0058] As used in the specification and the appended claims, the term "if' can be interpreted as meaning "when" or "upon" or "in response to determining" or "in response to detecting" depending on the context. Similarly, the phrase "if it is determined" or "if [the described condition or event] is detected" can be interpreted to mean "upon determining" or "in response to determining" or "upon detecting [the described condition or event]" or "in response to detecting [the described condition or event]" depending on the context.
[0059] In addition, in the description of the present application and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the description and cannot be understood as indicating or implying relative importance.
[0060] In the present application, the reference "one embodiment" or "some embodiments" and the like means that the specific features, structures or characteristics described in connection with the embodiment are included in one or more embodiments of the present application. Therefore, the statements "in one embodiment", "in some embodiments", "in other some embodiments", "in further some embodiments" and the like appearing in different places in the specification are not necessarily all referring to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized. The terms "include", "contain", "have" and their variants mean "include but not limited to", unless otherwise specifically emphasized.
[0061] The embodiments of the present application can acquire and process related data based on artificial intelligence technology. Among them, artificial intelligence (AI) is to use digital computers or digital computer controlled machines to simulate, extend and expand human intelligence, perceive environment, acquire knowledge and use knowledge to obtain the best results.
[0062] The basic technology of artificial intelligence generally includes technologies such as sensors, special artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operation / interaction system, mechatronics, etc. The software technology of artificial intelligence mainly includes computer vision technology, robot technology, biometric technology, speech processing technology, natural language processing technology, and machine learning / deep learning, etc.
[0063] It should be understood that the size of the serial number of each step in the following embodiments does not mean the order of execution, and the execution order of each process should be determined according to its function and inherent logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0064] In order to illustrate the technical solutions of the present application, the following will be described by specific embodiments. In order to illustrate the technical solutions of the present application, the following will be described by specific embodiments.
[0065] The element positioning method of the test case provided in Embodiment One of the present application can be applied in the application environment as shown in Figure 1 The client communicates with the server. The client includes, but is not limited to, a palm computer, a desktop computer, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, a cloud computer device, a personal digital assistant (PDA), and the like. The server can be implemented by an independent server or a server cluster composed of multiple servers.
[0066] Referring to Figure 2 , which is a flowchart of the element positioning method of the test case provided in Embodiment Two of the present application. The element positioning method of the test case is applied in the server in Figure 1 The computer device corresponding to the server is connected to a corresponding database to obtain a corresponding test case in the database. The computer device can also be connected to a corresponding client, which is operated by a user. The user can provide a corresponding test case to the server through the client. As shown in Figure 2 The element positioning method of the test case can include the following steps:
[0067] In Step S201, a page element path of the test case is generated according to a preset element path generation rule. It is detected whether at least two page elements are selected when the page element path is triggered.
[0068] In the present application, the element path generation rule can be set according to actual application requirements. The actual application requirements can refer to a case where the application scenario does not require dynamic elements in the test case. In this case, it can be determined that a specific element path generation rule is not required to generate the path. For example, the specific element path generation rule can refer to the rules corresponding to the ID selector and the class selector, that is, a conventional path generation rule can be used.
[0069] The element path generation rule described above is used when the test case is recorded. The generation rule is determined according to the selection of the user, so that the selected element path generation rule is used to generate the page element path of the test case.
[0070] In the present application, the preset element path generation rule can include an ID selector, a class selector, a text selector, etc., and specifically can be that if the page element path contains an ID, the ID selector is considered to be used to generate the page element path; in order to avoid adding an ID operation in the business code, when it is identified during recording that the page element path contains some dynamic element features, the class selector is used to generate the page element path; when a page element is identified as a text node and the corresponding content is not empty, the node text content is recorded, a query text selector is generated, and the text selector is used to generate the page element path.
[0071] Optionally, according to the preset element path generation rule, the page element path of the test case is generated, including:
[0072] Detecting element features of the page elements contained in the test case;
[0073] If the detected element feature is a first feature, an ID selector is used to generate the page element path of the corresponding page element;
[0074] If the detected element feature is a second feature, a class selector is used to generate the page element path of the corresponding page element.
[0075] The element feature can refer to attributes, categories, etc. of the page element, for example, if the page element contains a dynamic attribute, it can be determined that the page element is a dynamic page element. The first feature is different from the second feature, the first feature can refer to an ID attribute in the page element, and the second feature can refer to a dynamic attribute in the page element. When the page element contains the ID attribute, i.e., the element feature contains the first feature, the ID selector is used to generate the page element path of the corresponding page element; when the page element contains the dynamic attribute, i.e., the element feature contains the second feature, the class selector is used to generate the page element path of the corresponding page element.
[0076] It should be understood that multiple page elements can exist in one page, and correspondingly, multiple page elements can exist in the test case. Different selectors can be used to generate page paths for different page elements, thereby helping to distinguish different page elements and achieving accurate and efficient positioning of the page elements.
[0077] Optionally, after detecting the element features of the page elements contained in the test case, the method further includes:
[0078] If it is detected that the element feature is a text node feature and the corresponding element content is not empty, the content of the corresponding page element is recorded, a text selector for querying the text content is generated according to the content of the element feature, and the text selector is used to generate the page element path.
[0079] A page element path corresponding to the page element is generated using the text selector.
[0080] The text node feature can refer to that the corresponding page element is a text element, for example, a text box in a page is a text element, and the content in the text box is the corresponding element content.
[0081] Since there may be redundant text boxes set in the operation, but no content is filled in the text box, there is no content in the text box, which does not affect the display of the page, but it will still be detected. In order to avoid processing of useless text boxes, the element content of the page element corresponding to the element feature needs to be limited, i.e., the element content is not empty.
[0082] The element content corresponding to the page element is extracted, and a text selector is generated according to the element content. The purpose of the text selector is to generate a page element path corresponding to the page element. Essentially, the text selector is an expression containing the corresponding element content, as follows:
[0083] page.locator("text=Log in").click()
[0084] page.locator("text='Log in'").click()
[0085] The difference between text=Log in and text='Log in' is that Log in does not have quotes (single or double quotes): fuzzy matching and not case sensitive; 'Log in' has quotes: exact matching and case sensitive.
[0086] In step S202, if it is detected that at least two page elements are selected when the page element path is triggered, the page element path is split into a first sub-path and a second sub-path.
[0087] In this application, when the first sub-path is triggered, at least the page element in the outermost layer of the page is selected from all the page elements, and when the second sub-path is triggered, all the page elements except the page elements selected when the first sub-path is triggered are selected.
[0088] After executing the page element path, two or more page elements are positioned, i.e., a page element path corresponds to multiple page elements. In order to accurately position the target element, the page element path needs to be split, which can refer to splitting the page element path into two segments. The first segment can select the outermost page element, which can be called a "parent element selector"; the second segment can select the remaining page elements, which can be called a "child element selector".
[0089] In the case that the outermost page element includes multiple page elements, the parent element selector also includes multiple page elements, but in general, the outermost page element is one, and the remaining page elements are one or more.
[0090] Optionally, splitting the page element path into a first sub-path and a second sub-path includes:
[0091] Extracting the level of the page in which all page elements corresponding to the page element path are located to determine the page element with the outermost level;
[0092] Extracting the path corresponding to the page element with the outermost level from the page element path as the first sub-path, and extracting the path corresponding to the remaining page elements from the page element path as the second sub-path.
[0093] In which, the level attribute of the page element is extracted to understand the level characteristics of each page element, and the level characteristics of all page elements are compared to determine the page element with the outermost level.
[0094] After obtaining the page element with the outermost level, the path corresponding to the page element is extracted from the page element path, which is the first sub-path, and the paths corresponding to the remaining page elements are obtained from the page element path, which are the second sub-path.
[0095] Step S203, detecting the area of the page element obtained by querying the first sub-path, determining that the page element with a non-zero area is a suspected element, and using the second sub-path to query the page element with a non-zero area in the page range corresponding to the suspected element as the target element.
[0096] In this application, the page elements that can be queried by the parent element selector are traversed to determine whether the corresponding page element is a visible page element. If it is a visible page element, the visible page element is used as a query range, and the corresponding page element is queried using the child element selector. If it is not a visible page element, it is not considered to be the direction currently being searched.
[0097] The visible page element is the area of the corresponding page element displayed in the page, which can also be understood as the length, width and height of the page element being non-zero.
[0098] For visible page elements, among the many page elements, the suspected element that is a suspected target element, wherein the suspected element may eventually include the target element, therefore, after obtaining the suspected element, the corresponding target element can be found in the enclosing range or enclosing area in the page corresponding to the suspected element.
[0099] The page element obtained by using the second sub-path, i.e., the sub-element selector, is the target element, which may be the final target to be positioned or may not be the final target to be positioned. The target element obtained by using the second sub-path may also be multiple, and thus step S204 is further required to confirm.
[0100] Optionally, the area of the page element obtained by using the first sub-path is detected, and the page element with a non-zero area is determined as the suspected element, including:
[0101] The length, width or height of the page element obtained by using the first sub-path is obtained.
[0102] It is detected whether there is a zero item in the length, width or height. If there is a zero item, it is determined that the area of the corresponding page element is zero, otherwise, the corresponding page element is determined as the suspected element.
[0103] The size of the page element in the page can be measured by Page Ruler, which is a page ruler plug-in that can effectively measure the size of the page element.
[0104] In the detection, as long as any size of the page element is zero, it can be determined that the area is zero, and the corresponding page element is not a visible page element and is not a suspected element.
[0105] In step S204, the positions of all the page elements selected by the page element path in the page are compared with the position of the target element in the page. If the comparison result is that there is a same position, it is determined that the target element is the element positioned by the page element path.
[0106] In the present application, after the target element is determined, the target element needs to be further confirmed whether it is the element to be positioned by the test case.
[0107] The position of the target element in the page is also positioned. If the position of the target element in the page is the same as the position of any page element selected by the page element path, it is indicated that the page element is the final element to be positioned.
[0108] Through the above steps, the elements in the page that should not be selected can be excluded, the accuracy of the target element selected by the page element path is greatly improved, the case execution pass rate is ensured, and the debugging cost of the tester is reduced.
[0109] The tester needs to identify the method of using which positioning element when recording the case, and usually adds an ID selector in the business code when debugging fails. The method provided in the application can generate more reliable element positioning according to the actual situation of the page element.
[0110] Meanwhile, for the case that multiple page elements can be positioned when executing the test case, the processing method provided in the application can exclude elements in the page that should not be selected, effectively improving the accuracy of selecting target elements in the page element path, thereby ensuring the passing rate of the case execution and reducing the debugging cost of the tester.
[0111] According to the preset element path generation rule, the page element path of the test case is generated, it is detected whether at least two page elements are selected when the page element path is triggered, if it is detected that at least two page elements are selected when the page element path is triggered, the page element path is split into a first sub-path and a second sub-path, the first sub-path selects at least the page element in the outermost layer of the page when triggered, the second sub-path selects all the page elements except the page element selected when the first sub-path is triggered when triggered, the area of the page element obtained by querying using the first sub-path is detected, the page element with a non-zero area is determined as a suspected element, the page element with a non-zero area obtained by querying using the second sub-path in the page range corresponding to the suspected element is determined as a target element, the positions of all the page elements selected using the page element path in the page are compared with the position of the target element in the page, if the comparison result is that there is the same position, the target element is determined as the element positioned by the page element path, thereby accurately positioning the target element, improving the test case execution passing rate, and reducing the debugging cost of the tester.
[0112] Referring to Figure 3 , Fig. 1 is a flowchart of a test case element positioning method provided in Embodiment Three of the application, as Figure 3 shown, the test case element positioning method can include the following steps:
[0113] Step S301, according to the preset element path generation rule, a page element path of a test case is generated, and it is detected whether at least two page elements are selected when the page element path is triggered.
[0114] Step S302, if it is detected that at least two page elements are selected when the page element path is triggered, the page element path is split into a first sub-path and a second sub-path.
[0115] Step S303, detecting the area of the page element queried using the first sub-path, determining that the page element with a non-zero area is a suspected element, and using the second sub-path to query the page element with a non-zero area in the page range corresponding to the suspected element as a target element.
[0116] Steps S301 to S303 are the same as the contents of steps S201 to S203 described above, and the description of steps S201 to S203 can be referred to, and will not be repeated here.
[0117] Step S304, using the compareDocumentPosition method to compare the positions of all page elements selected by the page element path with the target element in turn.
[0118] In this application, the compareDocumentPosition method in the Document Object Model (DOM) interface is used to compare the positions of two elements. The compareDocumentPosition() method compares the document position of the current node with the specified node in document order. The DOM is a standard programming interface recommended by the W3C organization for processing extensible markup language.
[0119] When using the compareDocumentPosition method, the return value can be:
[0120] 1: No relationship, the two elements do not belong to the same document;
[0121] 2: The first element (P1) is located after the second element (P2);
[0122] 4: The first element (P1) is positioned before the second element (P2);
[0123] 8: The first element (P1) is located within the second element (P2);
[0124] 16: The second element (P2) is located within the first element (P1);
[0125] 32: No relationship, or the two nodes are two attributes of the same element;
[0126] 40: The first element (P1) and the second element (P2) have the same position.
[0127] The return value can be a combination of values, for example, a return value of 20 means that P2 is inside P1 (16), and P1 is before P2 (4).
[0128] Step S305, determine the position comparison result, the position comparison result includes the same position, the front-back relationship and the containing relationship.
[0129] After the above process, the document position of two elements is compared using compareDocumentPosition, and the result is one of the following: same position, A before B, A after B, A in B, B in A, etc.
[0130] Step S306, if the comparison result is that there is a same position, determine that the target element is the element positioned by the page element path.
[0131] In step S306, part of the content is the same as step S204 described above, and the description of step S204 can be referred to, which will not be repeated here.
[0132] According to the preset element path generation rule, the page element path is generated for the test case, it is detected whether at least two page elements are selected when the page element path is triggered, if it is detected that at least two page elements are selected when the page element path is triggered, the page element path is split into a first sub-path and a second sub-path, the first sub-path is triggered to select at least the page element in the outermost layer of all page elements, the second sub-path is triggered to select all page elements except the page elements selected by the first sub-path, the area of the page element obtained by querying using the first sub-path is detected, and the page element with a non-zero area is determined as a suspected element, the second sub-path is used to query the page element with a non-zero area in the page range corresponding to the suspected element as a target element, the position comparison is performed between all page elements selected by the page element path and the target element in turn using the compare document position method, if the comparison result is that there is a same position, the target element is determined as the element positioned by the page element path, thereby accurately positioning the target element, improving the test case execution pass rate, and reducing the debugging cost of the test personnel.
[0133] The element positioning method of the test case corresponding to the above embodiment, Figure 4 The structure block diagram of the element positioning device of the test case provided by the fourth embodiment of the present application is shown, and the above element positioning device is applied to Figure 1 The server corresponding to the computer device is connected to the corresponding database to obtain the corresponding data in the database. The computer device can also be connected to the corresponding client, and the client is operated by the user. The user can provide the corresponding test report to the server through the client. For convenience of description, only the part related to the embodiments of the present application is shown.
[0134] Referring to Figure 4 The element positioning device comprises:
[0135] The path detection module 41 is configured to generate a page element path for the test case according to a preset element path generation rule, and detect whether at least two page elements are selected when the page element path is triggered.
[0136] The path splitting module 42 is configured to split the page element path into a first sub-path and a second sub-path if it is detected that at least two page elements are selected when the page element path is triggered, the first sub-path is triggered to select at least a page element on an outermost page among all the page elements, and the second sub-path is triggered to select all the page elements except the page element selected when the first sub-path is triggered.
[0137] The target element determination module 43 is configured to detect an area of a page element obtained by using the first sub-path, determine a page element with a non-zero area as a suspected element, and determine a page element with a non-zero area obtained by using the second sub-path in a page range corresponding to the suspected element as a target element.
[0138] The position determination module 44 is configured to compare positions of all the page elements selected by using the page element path in the page with a position of the target element in the page, and determine that the target element is an element positioned by the page element path if the comparison result is that there is a same position.
[0139] Optionally, the path detection module 41 comprises:
[0140] The element feature detection unit is configured to detect an element feature of a page element contained in the test case.
[0141] The first path generation unit is configured to generate a page element path of the corresponding page element by using an ID selector if it is detected that the element feature is a first feature.
[0142] The second path generation unit is configured to generate a page element path of the corresponding page element by using a class selector if it is detected that the element feature is a second feature.
[0143] Optionally, the path detection module 41 further comprises:
[0144] The text element detection unit is configured to record content of the corresponding page element and generate a text selector for querying the text content according to the content of the element feature after detecting the element feature of the page element contained in the test case, if it is detected that the element feature is a text node feature and the content of the corresponding element is not empty.
[0145] The third path generation unit is configured to generate a page element path of the corresponding page element by using the text selector.
[0146] Optionally, the position determination module 44 comprises:
[0147] The position comparison unit is used to compare the position of all selected page elements along the page element path with the target element in turn using the document position comparison class method.
[0148] The comparison result determination unit is used to determine the position comparison result, which includes the same position, front-back relationship, and inclusion relationship.
[0149] Optionally, the target element determination module 43 includes:
[0150] The side length acquisition unit is used to obtain the length, width, or height of a page element within the page, obtained by querying using the first sub-path.
[0151] The suspected element determination unit is used to detect whether there are items with a length, width, or height of zero. If an item with a zero value is found, the area of the corresponding page element is determined to be zero; otherwise, the corresponding page element is determined to be a suspected element.
[0152] Optionally, the path splitting module 42 includes:
[0153] The split point determination unit is used to extract the page hierarchy of all page elements corresponding to the page element path, and determine the hierarchy as the outermost page element.
[0154] The path splitting unit is used to extract the path corresponding to the outermost page element from the page element path as the first sub-path, and to extract the paths corresponding to the remaining page elements from the page element path as the second sub-path.
[0155] It should be noted that the information interaction and execution process between the above modules are based on the same concept as the method embodiments of this application. For details on their specific functions and technical effects, please refer to the method embodiments section, which will not be repeated here.
[0156] Figure 5 This is a schematic diagram of the structure of a computer device provided in Embodiment 5 of this application. Figure 5 As shown, the computer device of this embodiment includes: at least one processor ( Figure 5 Only one is shown in the diagram), a memory, and a computer program stored in the memory and capable of running on at least one processor, which, when executing the computer program, implements the steps in the element location method embodiments of any of the above test cases.
[0157] This computer device may include, but is not limited to, a processor and memory. Those skilled in the art will understand that... Figure 5The computer device is only an example and does not limit the computer device. The computer device can include more or less components than shown, or combine some components, or have different components, such as a network interface, a display screen, an input device, and the like.
[0158] The processor can be a CPU, and can also be other general-purpose processors, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA) or other programmable logic device, discrete gate or transistor logic, discrete hardware components, and the like. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor.
[0159] The memory includes a readable storage medium, an internal memory, and the like. The internal memory can be a memory of the computer device, and provides an environment for running an operating system and computer-readable instructions in the readable storage medium. The readable storage medium can be a hard disk of the computer device, and in other embodiments, can also be an external storage device of the computer device, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) card, a Flash Card, and the like. Further, the memory can include both an internal storage unit of the computer device and an external storage device. The memory is used to store an operating system, an application program, a BootLoader, data, and other programs, such as program codes of computer programs. The memory can also be used to temporarily store data that has been output or will be output.
[0160] Those skilled in the art can clearly understand that, for the convenience and brevity of description, only the above-mentioned division of each functional unit and module is exemplified, and in actual application, the above-mentioned functions can be completed by different functional units and modules according to needs, that is, the internal structure of the device is divided into different functional units or modules to complete all or part of the functions described above. Each functional unit and module in the embodiment can be integrated in one processing unit, or each unit can be physically present separately, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of software functional unit. In addition, the specific names of each functional unit and module are only for easy distinction, and do not limit the protection scope of the present application. The specific working process of the units and modules in the device can refer to the corresponding process in the foregoing method embodiments, which will not be repeated here. If the integrated unit is realized in the form of 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, all or part of the processes in the above-mentioned embodiment methods can be completed by a computer program to instruct related hardware, and the computer program can be stored in a computer readable storage medium. When the processor executes the computer program, the steps of the above-mentioned method embodiments can be realized. The computer program includes computer program code, which can be in the form of source code, object code, executable file or some intermediate form. The computer readable medium at least includes any entity or device capable of carrying computer program code, recording medium, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signal, telecommunication signal and software distribution medium. For example, U disk, mobile hard disk, magnetic disk or optical disk, etc. In some jurisdictions, according to legislation and patent practice, the computer readable medium cannot be electrical carrier signal and telecommunication signal.
[0161] The above-mentioned embodiment methods can also be completed by a computer program product, when the computer program product runs on the computer equipment, so that the computer equipment can execute the steps in the above-mentioned method embodiments.
[0162] In the above-mentioned embodiments, the description of each embodiment has its own emphasis, and the parts not described or recorded in detail in a certain embodiment can be referred to the relevant description of other embodiments.
[0163] Those skilled in the art can understand that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be realized in electronic hardware or a combination of computer software and electronic hardware. Whether the functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.
[0164] In the embodiments provided by the present application, it should be understood that the disclosed apparatus / computer device and method can be implemented in other ways. For example, the apparatus / computer device embodiments described above are merely schematic. The division of the modules or units is only a logical function division, and there can be another division manner in actual implementation. For example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the displayed or discussed mutual couplings or direct couplings or communication connections can be indirect couplings or communication connections through some interfaces, devices or units, and can be electrical, mechanical or in other forms.
[0165] The units described as separate components can or can not be physically separate, and the components shown as units can or can not be physical units, i.e. can be located in one place, or can be distributed on a plurality of network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the embodiments.
[0166] The above embodiments are only used to illustrate the technical solutions of the present application, but not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that the technical solutions recorded in the foregoing embodiments can be modified, or some technical features can be replaced by equivalents; and these modifications or replacements do not make the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the protection scope of the present application.
Claims
1. A method for locating elements in a test case, characterized in that, The element positioning method comprises: According to a preset element path generation rule, a page element path is generated for the test case, and it is detected whether at least two page elements are selected when the page element path is triggered; If it is detected that at least two page elements are selected when the page element path is triggered, the page element path is split into a first sub-path and a second sub-path, the first sub-path selects at least a page element on an outermost page when triggered, and the second sub-path selects all page elements except the page element selected when the first sub-path is triggered; The area of the page element obtained by using the first sub-path is detected, and a page element with a non-zero area is determined as a suspected element, and a page element with a non-zero area obtained by using the second sub-path in the page range corresponding to the suspected element is determined as a target element; The positions of all page elements selected by using the page element path in the page are compared with the position of the target element in the page respectively, and if the comparison result is that there is a same position, the target element is determined as the element positioned by the page element path.
2. The element positioning method according to claim 1, characterized by, According to a preset element path generation rule, a page element path is generated for the test case, and it is detected whether at least two page elements are selected when the page element path is triggered; The element characteristics of the page elements contained in the test case are detected; If the element characteristics are detected as first characteristics, an ID selector is used to generate a page element path of the corresponding page element; If the element characteristics are detected as second characteristics, a class selector is used to generate a page element path of the corresponding page element.
3. The element positioning method according to claim 2, characterized by, After detecting the element characteristics of the page elements contained in the test case, the following steps are further included: If the element characteristics are detected as text node characteristics and the corresponding element content is not empty, the content of the corresponding page element is recorded, a text selector for querying text content is generated according to the content of the element characteristics; The text selector is used to generate a page element path of the corresponding page element.
4. The element positioning method according to claim 1, characterized by, Comparing the positions of all page elements selected by using the page element path in the page with the position of the target element in the page respectively comprises: Using a comparison document position class method, all page elements selected by using the page element path are sequentially compared with the target element in position; The position comparison result is determined, and the position comparison result includes position same, front-back relationship and inclusion relationship.
5. The element positioning method according to claim 1, characterized by, Detecting the area of the page element obtained by using the first sub-path to determine that the page element with a non-zero area is a suspected element comprises: The length, width or height of the page element obtained by using the first sub-path in the page is obtained; It is detected whether there is a zero item in the length, width or height, if there is a zero item, it is determined that the area of the corresponding page element is zero, otherwise, it is determined that the corresponding page element is a suspected element.
6. The element positioning method according to any one of claims 1 to 5, characterized by, Splitting the page element path into a first sub-path and a second sub-path comprises: The level of the page where all page elements corresponding to the page element path are located is extracted, and the page element with the outermost level is determined; The path corresponding to the page element at the outermost level in the page element path is a first sub-path, and the paths corresponding to the remaining page elements in the page element path are all second sub-paths.
7. An element positioning apparatus for test cases, characterized by, The element positioning apparatus comprises: The path detection module is configured to generate a page element path for the test case according to a preset element path generation rule, and detect whether at least two page elements are selected when the page element path is triggered. The path splitting module is configured to split the page element path into a first sub-path and a second sub-path if it is detected that at least two page elements are selected when the page element path is triggered. The target element determination module is configured to detect the area of a page element obtained by using the first sub-path to query, determine a page element with a non-zero area as a suspected element, and determine a page element with a non-zero area obtained by using the second sub-path to query within the page range corresponding to the suspected element as a target element. The positioning determination module is configured to compare the positions of all page elements selected by using the page element path in a page with the position of the target element in the page, and determine that the target element is the element positioned by the page element path if the comparison result is that there is a same position.
8. The element positioning device of claim 7, wherein, The path detection module comprises: The element feature detection unit is configured to detect the element feature of a page element contained in the test case. The first path generation unit is configured to generate a page element path of a corresponding page element by using an ID selector if it is detected that the element feature is a first feature. The second path generation unit is configured to generate a page element path of a corresponding page element by using a class selector if it is detected that the element feature is a second feature.
9. A computer device, comprising: The computer device comprises a processor, a memory, and a computer program stored in the memory and executable on the processor, and the processor implements the element positioning method of any one of claims 1 to 6 when executing the computer program.
10. A computer-readable storage medium storing a computer program, the computer program comprising instructions that, when executed by a computer, cause the computer to perform the method of any one of claims 1 to 9. The computer program is executable on the processor to implement the element positioning method of any one of claims 1 to 6.
Citation Information
Patent Citations
An editing method and device for a Web page
CN108710490A
Method and client for controlling way finding of analog object
CN108815850A